Sunday, October 9, 2011

Erlang JSON

I've got a Erlang web service (built on Spooky) which I want to return JSON. How hard could that be?

The problem is a multitude of half-assed implementations.

What seems to work is mochijson2, which comes as part of mochiweb, but only the version from Mochi, not the Basho branch.

I have an Erlang structure that looks like this:
[{"colin",[3,2,1]},{"dave",[4,3,2]}]

That's an array with two tuples. Shouldn't be rocket science, but apparently what they really want is:
[{struct,[{<<"colin">>,[1,2,3]}]},{struct,[{<<"dave">>,[4,3,2]}]}]
or some shit. Really? If I have to munge it into that format, I might as well just encode it myself.

P.S. After going a few rounds with mochijson2, I ended up just encoding it myself.

Monday, October 3, 2011

Switching Git Repositories

I just had one of those cases where I pulled down a read-only copy of someone else's GitHub repo, thinking that it'll work just fine and I'll never have to change it, and sure enough, I'm doing something weird that breaks it. I figure out what's going on and fix it, so now I want to fork my own copy on GitHub and push my changes to that, but my local copy is cloned from this other person's repo. What do I do?

This is of course exactly the sort of thing Git was designed to deal with. When I cloned this project from GitHub originally, Git set up a local repository for me, and set the GitHub repo as a remote repository named "origin". Unlike SVN, there's nothing magic about the remote repository - you can have several, and push changes to all of them. The easiest thing to do in this case is just forget about your old origin, and set a new one. Here's a slightly edited command history:
$ git remote -v
origin https://github.com/flashingpumpkin/spooky.git (fetch)
origin https://github.com/flashingpumpkin/spooky.git (push)
$ git remote rm origin
$ git remote -v
$ git remote add origin git@github.com:bluegraybox/spooky.git
$ git remote -v
origin git@github.com:bluegraybox/spooky.git (fetch)
origin git@github.com:bluegraybox/spooky.git (push)
$ git push
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 506 bytes, done.
Total 4 (delta 3), reused 0 (delta 0)
To git@github.com:bluegraybox/spooky.git
a34ae51..b15781e master -> master
$

Ta-daa!

Sunday, October 2, 2011

Erlang on Ubuntu

Ubuntu is still (as of Oct. 2011 on Natty) on Erlang R13B3. The release date for that is 2009-11-23. So, nearly two years out of date. I tried installing Nitrogen, but it requires at least R13B4, so it's time to install the new version from source.

The good news is that the source install doesn't stomp on the Ubuntu package. Ubuntu installs it to /usr/lib and /usr/bin, and the source install goes in /usr/local/lib and /usr/local/bin, which should be on your $PATH before /usr/bin.

Here's how to set up the latest version on a fairly vanilla Ubuntu 11.04. First, you need to download the Erlang source.

You may need to install some build tools - I had to install m4.
Then unpack and build the source:
tar xzf release.tgz
cd release
./configure
make
make install

Sunday, September 18, 2011

Weird filenames in Subversion

Had to add files with '@' in the filenames to Subversion (for iPhone - thanks, Apple). This doesn't work:
svn add Icon@2x.png

You need to do this instead:
svn add Icon\@2x.png@


Thanks to Jeff Kelley.

Friday, August 19, 2011

Ruby Gem executables

$ gem environment | grep "EXECUTABLE DIRECTORY"

- EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin
$ export PATH=$PATH:/var/lib/gems/1.8/bin/

Showoff dependencies

$ git clone git@github.com:bluegraybox/showoff.git

Cloning into showoff...
...
$ cd showoff/
$ gem build showoff.gemspec
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- parslet (LoadError)
...
$ sudo gem install showoff
[sudo] password for colin:
Building native extensions. This could take a while...
Building native extensions. This could take a while...
ERROR: Error installing showoff:
ERROR: Failed to build gem native extension.
...
libxml2 is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
...
$ sudo apt-get install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8
...
$ sudo apt-get install libreadline-ruby1.8 libruby1.8 libopenssl-ruby
...
$ sudo apt-get install libxslt-dev libxml2-dev
...
$ sudo gem install nokogiri
...
$ sudo gem install showoff
Building native extensions. This could take a while...
Successfully installed json-1.5.3
Successfully installed gli-1.3.2
Successfully installed showoff-0.4.2
...
$ sudo gem uninstall showoff
...
$ gem build showoff.gemspec
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- parslet (LoadError)
...
$ sudo gem install parslet
...
$ gem build showoff.gemspec
...
$ sudo gem install -l -n . showoff
Successfully installed showoff-0.5.1
...

Thursday, June 23, 2011

Unwedging Ubuntu

Upgraded my Linux desktop to Ubuntu 11.04. Kicked it off before I went to bed. Woke up sometime in the middle of the night and wandered down to check on it. It had gotten wedged at some point. The only thing to do was reboot.

It came back up unable to mount the / partition (the only non-swap partition). It dropped me to a command prompt with / mounted read-only. e2fsck reported everything ok. So, what up?

Spent a while last night poking at it and Googling around, to no avail. Got a sysadmin buddy of mine to drop by. He was also largely mystified. Eventually, we stumbled across this post, which sounded pretty close to my symptoms. Tried it; it worked.

So, for posterity, reference, and backup, here's the fix:
mount -o remount,rw /
dpkg --configure -a
sync
reboot

The instructions also say to remount the drive read-only, but that failed on "drive busy", and didn't seem to make a difference.

Jekyll Pages List

Getting a list of pages in a Jekyll site is easy, but paring that down to just the top-level files and the index pages is tricky. {% for p...