Category Archives: Programming

Using Java 8 Lambdas with Google Guava Caches

With Guava, you can define a simple in-memory cache with import static java.util.concurrent.TimeUnit.DAYS; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; Cache cache = CacheBuilder.newBuilder() .maximumSize(100000) .expireAfterAccess(7, DAYS) .build(); With this you can use .put(K, V) to load values, and .getIfPresent(K), which returns null if the key isn’t present. Sometimes it’s more convenientĀ to use get(K key, Callable<? extends V> […]

How to parameterize an RSpec shared context

I had a RSpec shared_context which was creating a FactoryGirl user mock and then logging in with it, and then running some shared examples for testing permissions on a generic user. I needed to modify it to accept a parameter of using a different user. It originally looked like this: RSpec.shared_context “auth” do let(:current_user) { […]

How to use JUnit4 Hamcrest Matchers

JUnit borrows matchers from a library called Hamcrest, which look a lot like RSpec matchers in Ruby. They can be tricky to write, but end up being much more readable for complex assertions. At its simplest case, we can turn this assertion assertTrue(board.isGameOver()); into assertThat(board.isGameOver(), is(true)); It’s slightly wordier, but I think it reads in […]

Using SUBSTR on the left of an assignment in SAS

This is a pretty cool feature, and as far as I know it’s unique to SAS and Perl. In SAS, you can have a substr to the left of an assignment. stringDate=’29MAR1984′; substr(stringDate,3,3)=’FEB’; This avoids potentially awkward situations like this: stringDate=’29MAR1984′; stringDate=substr(stringDate,1,2)||’FEB’||substr(stringDate,6,4); The bounds don’t have to be static. Lets suppose we have a dataset […]

Installing SAS 9.4 on Ubuntu 14.04

Officially SAS does not support Ubuntu Linux as a platform, in spite of it being the most popular desktop distribution. It will run, but there are two things you need to do: First, reconfigure Ubuntu not to use dash. The SAS Deployment Wizard will freeze when you first click “Next” during the install if you […]

SAS Macro Variable Resolution Timing

I thought this was neat and quirky. The implications of it are important, too. When you assign a macro variable in SAS, it doesn’t resolve immediately. It resolves It will also warn you if the variable doesn’t exist yet, too. %let x = &y; %let y = z; %put &x; Will output z Even though, […]

Using Secure HTTPS (SSL) URLs in SAS on Linux

Out of the box SAS 9.4 is not configured to use SSL on Linux x64. If you try to do this, you’ll get the error ERROR: SSL Error: Missing CA trust list This happens because when SAS gets the SSL certificate from the server, it sees that it’s signed by a Certificate Authority, but it […]

Handlebars #each in a Play Scala View

If you’re using Play Scala views with Handlebars in them, and you get errors that look like these: not found: value key In /home/phil/myproject/app/views/myview.scala.html at line 108. or not found: value index In /home/phil/myproject/app/views/myview.scala.html at line 108. It’s probably because you’re using {{@index}} when iterating through an array with {{#each myarray}} or {{@key}} when iterating […]

Using a Backbone Model with Handlebars

A Backbone model’s property has to be accessed with the get(property) method. var myObj = Backbone.Model.extend({ … }); //don’t do this console.log(myObj.myProp); //do this instead console.log(myObj.get(‘myProp’)); If you’re trying to pass this object to a Handlebars.js, things start to get messy. If you’ve got a template like this var myTemplate = Handlebars.compile(“Property: {{ myObj.myProp }}”); […]

Automatic Base SAS Library Assignments

If you stick a file named autoexec.sas in the directory where SAS is installed, it will run automatically when SAS starts up. By default, this place is C:Program FilesSASHomeSASFoundation9.3. This has worked since at least SAS 8.2, probably before. I like to use my Windows desktop as a temporary staging area, so I have my […]