Trevor Turk

A chess-playing machine of the late 18th century, promoted as an automaton but later proved a hoax.

Month: September, 2009

Pygments

I’m pleased to announce the immediate availability of http://pygments.appspot.com. It’s an unofficial API for the Pygments syntax highlighting library. It’s designed to provide syntax highlighting for web applications that don’t have Python installed. You can think of it as an HTTP interface for Pygments.

To use it, simply POST to http://pygments.appspot.com with “lang” and “code” parameters in the body. You’ll receive pygmentized HTML back, which you can store for later display on your site.

http://gist.github.com/188359

I’m using it so that I can host Flowcoder on Heroku. I was really impressed with the ease of getting this Pygments app running on Google App Engine. GAE is very much like a Python version of Heroku, which means it’s awesome.

I’m hoping that this little project will spike my interest in learning a bit more about Python, which actually doesn’t seem as evil as all my Ruby friends have made it out to be :P

The source code is on github, in case you’re curious about how this all works.

Enjoy!

http://pygments.appspot.com

Passenger with nginx on Mac OS X

Update: This is a more up-to-date guide here: Passenger with nginx on Mac OS X (2nd edition)

Setting up nginx with Passenger support turns out to be fairly easy.

Start by making sure you have the most recent version of Passenger, then install the nginx module. This will actually install and compile nginx with the Passenger module enabled, which is handy. Choose the recommended/default options when the installer prompts you.

sudo gem update passenger
sudo passenger-install-nginx-module

Then, open up the nginx config file:

mate /opt/nginx/conf/nginx.conf

Add the following line to the top of the file:

daemon off;

This will prevent the “502 Bad Gateway” error you may see otherwise. I’m not sure why this is necessary, but I read about it here, and it seems to do the trick. nginx specifies that this should only be used for development, though.

Next, find the http { block, which should start around line 15 or so. You’ll want to add a server { block within the http { block for each of your Rails/Rack applications, like so:

server {
   listen 80;
   server_name eldorado.local;
   root /Users/trevorturk/Code/eldorado/public;
   passenger_enabled on;
   rails_env development;
}

You’ll need an entry in your hosts file if you don’t already have one. Simply open up the file:

mate /etc/hosts

…and add lines for each of the apps you plan to run, like so:

127.0.0.1 eldorado.local 

Now, we can set up a launchd item, so that nginx will start up automatically after a system reboot. Create a new plist file by opening it up in TextMate:

mate /System/Library/LaunchDaemons/nginx.plist

…and paste the following code in, which was kindly provided for us by this helpful person:

http://gist.github.com/188167

Then, run the following command to load it:

launchctl load /System/Library/LaunchDaemons/nginx.plist

Now, you can reboot your system and make sure it’s all working as expected by visiting http://eldorado.local, or whatever address you’ve configured your application to be on.

I believe this nginx installation will override the existing Apache installation you may have running. This doesn’t bother me, so I opened up my System Preferences -> Sharing prefpane and unchecked the Web Sharing box, so Apache is no longer running. If you have any ideas about how to keep both services running cooperatively, please do let me know.

Update: Here are some additionally configuration options I’m using, which I cobbled together from various sources after Googling for things like “nginx, rails, gzip, expires” and such. Their powers combined, and I seem to have a YSlow-approved setup.

Just above your server { block, around line 40, add the following:

gzip on;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6].";
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

That should cover gzip well enough.

Then, amend the aforementioned server { block to include some far future expires goodness that takes advantage of the Rails asset_tag helpers:

server {
  listen 80;
  server_name eldorado.local;
  root /Users/trevorturk/Code/eldorado/public;
  passenger_enabled on;
  rails_env development;
  location ~* .(ico|css|js|gif|jp?g|png)(?[0-9]+)?$ {
      expires max;
      break;
  }
}

These two configuartion tweeks are, I believe, the rough equivalent of the technique previously discussed on this blog for Apache.

Of course, any additional suggestions, comments, or insights you may have would be most welcome. I’m new to this whole nginx thing, but I’m enjoying it so far.

Update: Here’s an easy way to reload nginx, if you need to make a change to your conf. Make sure to have the following in your /opt/nginx/conf/nginx.conf file:

pid /var/run/nginx.pid;

Then, you can make an alias for the reload task in your ~/.bash_profile:

alias nr='sudo kill -HUP `cat /var/run/nginx.pid`'

In case you’re interested, you can check out my full nginx.conf file for local development here:

http://gist.github.com/191331

Static: a super simple Rails CMS for Heroku

Static is a super simple Rails CMS built for Heroku. It supports file uploads to S3, makes image thumbnails, lets you make pages, has an optional admin password, and a customizable application layout that supports erb. It’s really easy to install and deploy to Heroku. If you have an S3 account, you can get up and running in under 5 minutes.

I made this little app a few weekends back because it scratched a personal itch of mine. I maintain a few small “static” or “brochure” sites for friends, which means I get to do boring HTML updates whenever they have a new picture or video they want to add. I figured that I could do a little upfront work and let them to do the rest. So, I looked around for a simple Rails CMS, but I couldn’t find anything simple enough. Thusly, Static was born.

It doesn’t do much for you, but that’s the point. You get a really simple little Rails app that lets you add pages, upload stuff, and wrap everything in a layout that can be updated online. If you ever need to add any cool new functionality (like displaying recent Twitter updates?) you can do it using Ruby/Rails. No more lame old hacked-together PHP sites ;) Static’s well-tested, 175 line code base could be the solid foundation for a site that grows over time.

This thing does exactly and only what I need it to do, but I’m happy to accept patches and such. Give it a shot, fork away, and let me know if you have something good for me to pull.

http://github.com/trevorturk/static/

Enjoy!

Weekly Digest, 9-11-09

Still not weekly ;)

Github and Engineyard part ways

[This Hacker News thread has some more detail from EY and GH. EY couldn't afford to continue with the preexisting arrangement, so GH is moving to Rackspace.]

Tornado Web Server

Tornado is an open source version of the scalable, non-blocking web server and tools that power FriendFeed. The FriendFeed application is written using a web framework that looks a bit like web.py or Google’s webapp, but with additional tools and optimizations to take advantage of the underlying non-blocking infrastructure.

Twitter And The Revenue Dilemma

The company has to decide whether or not to turn revenue on. It sounds ridiculous, but it is a real decision. Once revenue is on, how the company is valued by the market can change dramatically.

Using Ruby Enterprise for Rails script/console

If you want to just use REE for script/console, without setting it for
everything, you can…

If architects had to work like software developers

Please don’t bother me with small details right now. Your job is to develop the overall plans for the house: get the big picture. At this time, for example, it is not appropriate to be choosing the color of the carpet. However, keep in mind that my wife likes blue.

Ravelry

What we’ve done only takes 1 not-even-fulltime (I have lots of other duties) programmer/sysadmin and it’s very cool that the software available today makes this possible. It’s important — we can’t be spending money on “professional services” and we only have 3.5 employees.

How Twitter works in theory

It is said that an economist is someone who sees something that works in practice and wonders whether it works in theory. Twitter clearly works in practice… and I wanted to write about some theories that help me understand it.

MiniBatteryStatus Widget

MiniBatteryStatus is a small Dashboard widget that monitors battery status, charge percentage and remaining battery life. Integrated with Growl to alert you when it’s time to recharge your battery.

Protecting your Paperclip downloads

[Excellent write-up that covers protected downloads using Apache, nginx, the local filsystem, and/or Amazon S3. Awesome.]

Yehuda Katz Interview

A pretty good idea would be to contribute heavily to open source, and then look for work at companies that look at open source work as equivalent to a resume. If you build up enough really good open source work, you’ll soon find people clamoring to hire you. [Even with my limited experience, I've found this to be true. Working in Open Source is a really efficient way to improve your skills, and helps immensely when looking for work.]

Mac OS X 10.6 Snow Leopard: the Ars Technica review – Ars Technica

Mac OS X 10.6, aka Snow Leopard has landed. This time around, Apple goes light on the glitz in favor of some heavy work under the hood. John Siracusa dives deep into Apple’s new OS offering to see what’s new, what’s still the same, and whether it’s worth upgrading.

aM laboratory

Simple sinewave synthesizer triggered by an ordinary 16step sequencer. Each triggered step causes a force on the underlaying wave-map, which makes it more cute.

Poor Man’s Heroku Backups

Here’s a quick and dirty way to back up all of your Heroku-powered databases using their Taps gem with one easy command. It works well enough for my simple needs, but any improvements you’ve got would be most welcome!

Just add the following to your ~/.bash_profile, and you’re good to go:

http://flowcoder.com/59

Update: I’ve posted a technique for enabling automatic nightly PostgreSQL database backups from Heroku to Amazon S3 that may be of interest as well.

Follow

Get every new post delivered to your Inbox.