A A

Archive | Snippets

Calculate Your GPA Using this Bash Script

Thursday, May 21, 2009

0 Comments

This Bash script is used to calculate your Grade Point Average (GPA) on the command line. Usage might not be intuitive. Please see the usage function or just run the script without passing it any arguments. The gval function should be edited to reflect your own region or university. It has been written and tested on [...]

How to Maintain Static Sites with Git & Jekyll

Tuesday, March 31, 2009

4 Comments

Static sites in this context just means non-database driven sites. Your static site can be an elaborate PHP script or just a few markup and image files. For this I am using Jekyll – A neat Ruby gem that makes your static sites dynamic. It lets you create layouts and embed custom variables in your [...]

Refactoring Tip: Eliminating Model.find(params[:id]) Duplication

Sunday, December 7, 2008

0 Comments

In a controller, you’ll commonly have a method that requires you have an instance variable containing the object you’re working with. An example would be the show, edit, update, and destroy methods (REST). To eliminate having find(params[:id]) in multiple methods, you can use before_filter, like this: class Admin::PostsController < Admin::ApplicationController before_filter :find_post, :only => [:show, :edit, [...]

Using Javascript to Populate Forms During Development

Sunday, December 7, 2008

1 Comment

During development, working with forms quickly gets annoying because you have to constantly fill in each field, sometimes with unique info. One way around this is to write a little Javascript code that just populates the fields. I use something like this on the bottom of the form. I had jQuery no-conflict mode on in [...]

How to POST Form Data Using Ruby

Thursday, April 24, 2008

2 Comments

POSTing data on web forms is essential for writing tools and services that interact with resources already available on the web. You can grab information from your Gmail account, add a new thread to a forum from your own app, etc. The following is a brief example on how this can be done in Ruby [...]