The Five Minute Lisp Environment

Do you want to try Lisp? Do you have a Mac? Do you have $10? Then this is the post for you! (Ok, you don’t need $10 to try Lisp, but this approach is bloody convenient. And it shows off some really cool tools—and no, sadly I’m not making money on any of them.) First we’re going to install the fantastic Homebrew, which is an easy way to install UNIX tools on your Mac.

git: Pushing (Only) Some Commits

Occasionally I’ll find myself deploying to Heroku but for one reason or another I’m not ready to roll out all of the commits I have on master. Maybe I’d like to roll out some of the changes, test, and then roll out the rest later. You don’t want to just run a git push heroku master because that would push (and therefore deploy) everything. Instead, use git log to get hash of the commit you want to push up to (and including), and then run:

GitX Commit Keyboard Shortcut

It took me way too long to figure this out: from the commit view (⌘2) in GitX you can use ⇧⌘⏎ to commit.

Moved to Octopress

Well, no fanfare necessary, I switched to Octopress and moved this blog to Github Pages. I’m enjoying the new setup and planning to actually post again (*gasp*).

Decisions are Bullshit

So many new things to say, so many thoughts, so many feelings…I’m not particularly interested in leaving California (70°F as I write this, among other reasons) but I have affairs to settle in Dallas as well as people I’d like to see. Again I’m struck with the feeling that I need to make better use of the time I spend in Dallas. Not only because life is short and I need to always be making the best possible use of the time that I have, but also because of a growing awareness that the sun is setting on my time with that city.

Ruby: Implementing progn from Lisp

While hacking on some Ruby code today I started to miss progn from my Common Lisp programming days. If you’re not familiar with progn, it’s a special form which evaluates all of the contained expressions and returns the value of the last one.

Background

The progn construct is more important in the (more-or-less) functional1 programming world than in the imperative world because it allows us to insert multiple expressions where, syntactically, we could otherwise only insert one.

Let’s start with a trivial example:

(if (> x 0)
  x
  0)

If x is greater than zero, return x, else return 0.

But what if we also wanted to output a message whenever x is not greater than 0? We can’t just add our printing line in before (or after) 0 because the compiler knows what’s what based on the positions of the subexpressions in the if expression: it has to be (if test-form then-form [else-form]) 2.

Enter progn:

(if (> x 0)
  x
  (progn
    (print "Returning zero!")
    0))

Boom! It works. How very exciting. Ok, maybe not. In fact, I called progn a “special form” earlier—which basically means that it’s something which defies the basic evaluation rule of the language—but the truth is it’s probably the least special of the special forms. In fact, implicit progns are all over the place in Lisp: case forms, catch forms, when forms, let forms, but most importantly, function bodies.

Rails: Finding Associated Objects Safely

This one’s simple but I’ve run across it a dozen times today so I’ve decided to vent my frustration via education (I think this is healthy…right?). You have the following simple models: class Customer < ActiveRecord::Base has_many :orders end class Order < ActiveRecord::Base belongs_to :customer end Now, almost invariably, in your OrdersController you have a destroy method that needs to ensure that Customers can only delete their own Orders. Assuming @customer holds the current user’s Customer record, don’t waste your time doing this:

iOS: Categories in a Static Library Not Working?

Grrr…if you have category methods in a static library and those methods don’t seem to exist at runtime (unrecognized selector sent to class 0x...), first make sure that your project target is passing the -ObjC flag to the linker (in Other linker flags). If that doesn’t fix the issue, change the -ObjC flag to -all_load. Details from Apple in this Technical Q&A. You might also try using nm to see if your category methods are being properly compiled into your .

iOS: Maintaining Compatibility While Leveraging New Frameworks

If you starting using a framework that didn’t exist in a previous version of iOS, you’ll get dynamic linker errors when attempting to run your application on older devices. For example: dyld: Library not loaded: /System/Library/Frameworks/EventKit.framework/EventKit Referenced from: /Volumes/(...) Reason: image not found To fix this you need to modify your application so that the framework is weak-linked, meaning that the application will continue to run even if linking fails.

Rails: Application-Specific Config File

If there’s one thing I hate in programming or web design, it’s having to repeat myself. So I always do my best to abstract out repeated bits of information and put them in a single, easily changeable location. A nice way to do this in Ruby on Rails is to create your own YAML config file. First create the config file in config/config.yml (or any other name), and then we’ll get it loaded.