Alpha Hydrae

Coding on the edge of the web...

Rails 3 Logger Customization

Rails logging is pretty good but sometimes you need to tweak it a bit. In the app I’m currently working on, clients frequently send JSON payloads of up to 100 kilobytes to a Rails app. Since Rails logs the request body, the log file was cluttered and quickly growing beyond what the operations people would be comfortable with. I also couldn’t filter it out with the filter_parameters configuration, as it wasn’t a parameter but the body of the request.

Full-HTTPS Octopress Blog

I wanted this blog to be served over HTTPS for now, but I noticed that there was some HTTP content left after I set up the web server, which makes some browsers feel insecure.

The culprits were Twitter, Google Fonts and Google Search. This is the list of URLs I had to change to https://. There may be more if you use other features such as Delicious or Google Plus.

  • http://twitter.com/... in source/_includes/asides/twitter.html (two URLs)
  • http://platform.twitter.com/... in source/_includes/twitter_sharing.html (one URL)
  • http://fonts.googleapis.com/... in source/_includes/custom/head.html (two URLs)
  • http://google.com/... in the simple_search parameter of _config.yml (one URL)

Also don’t forget to have your url in _config.yml be HTTPS.

Git: How to Log Commits From All Branches

By default, the git log command will only show commits reachable from HEAD.

1
2
3
A---B---C---D (master)
     \
      \-E---F (HEAD, develop)
git log –oneline –graph –decorate
1
2
3
4
* f536261 (HEAD, develop) F
* 1c49789 E
* 0f00043 B
* 5f8165a A

To also show commits from other branches, you have to add the --all option.

git log –oneline –graph –decorate –all
1
2
3
4
5
6
7
* f536261 (HEAD, develop) F
* 1c49789 E
| * e384c0c (master) D
| * 826c7a6 C
|/  
* 0f00043 B
* 5f8165a A

It’s Reborn

My hacker ego has finally had enough of WordPress. Real men use a terminal and write their posts in Markdown. I’m hoping this Octopress will make me feel more at home.

Building Javascript With Grunt

When you develop a Javascript lib, you need to do fun stuff like concatenating source files, validating with JSHint and minifying. After I got past the initial phase of doing it by hand (many headaches, didn’t last long), I started doing it with Rake tasks and npm packages. As you can imagine, the Rake task quickly became a headache of its own.

Enters Grunt, a build tool which does all that for you, plus other goodies. It’s a task-based tool so it has tasks like concat to concatenate files, which you can run with grunt concat at the command line. This post is a quick example of what you can achieve with Grunt.

Pimp Your Vim

In the good ol’ days I used Eclipse, NetBeans, Dreamweaver. Then I switched to TextMate when I started doing Ruby. Now I use Vim for all my Ruby/Javascript development. At this point in my backwards journey through time, I would like to document how you can increase the awesomeness of Vim using a few well-chosen plugins.

Symmetric Encryption With GnuPG 2

I use these commands to symmetrically encrypt files with GnuPG 2. Sometimes you just need to get away from all this private/public key business.

Install gnupg2 with your favorite package manager, then type the following commands. It will prompt for the encryption password:

1
2
3
4
5
# encrypt file.txt to file.txt.gpg
gpg2 -c -a --force-mdc --batch -o file.txt.gpg file.txt

# decrypt file.txt.gpg to file.txt
gpg2 -d --batch -o file.txt file.txt.gpg

If you want to get the password from a file, use these:

1
2
3
4
5
# encrypt file.txt to file.txt.gpg
gpg2 -c -a --force-mdc --batch --passphrase-file passphrase.txt -o file.txt.gpg file.txt

# decrypt file.txt.gpg to file.txt
gpg2 -d --batch --passphrase-file passphrase.txt -o file.txt file.txt.gpg

May your files be secure.

Ruby Configuration DSL

I had been wondering how that kind of Ruby magic works for some time.

1
2
3
4
5
MyClass.new.configure do
  name "the best class"
  purpose "to kick ass"
  tags "ruby", "configuration", "dsl"
end