VCR for shell scripts · Jan 24, 2014
The VCR gem is really handy for testing calls to external web services, such as AWS commands made through Fog. You make your call for real once and VCR records a new “cassette” of the request and response. Subsequent calls use the cassette, so VCR plays back the response it recorded instead of actually reaching out and touching the external service. It’s good for testing how your own program makes requests and how it handles the responses it gets back. I recently had a need for similar functionality but with command line tools. Namely, the
ec2-cmdscript for importing an instance into Amazon.
a Boolean query parser in Python · Aug 21, 2012
Last summer I worked on a project where I needed a search engine that supported simple Boolean queries and key-value parameters. This was to be used on a Python site, so I wanted to write the query parser in Python too. At the time, Lepl seemed like a good choice. I figured out the grammar necessary to support the search query language I wanted, and all was good. I went to check out Lepl just now and I see it has been discontinued, which is a little disheartening. Regardless, I figured better late than never to post this since it still works and Lepl did the job.
Ruby Matrix and Vector additions · Oct 20, 2010
Working with matrices and vectors in Ruby before has been annoying because methods I expected to find were not there, and there wasn’t much documentation. Here, I present some simple additions to the
Vectorclasses that I found helpful.
convenient file searching with Ruby, grep, and file · Feb 23, 2010
For my Linux kernel class, I often know that some
structexists somewhere, or remember seeing a macro defined in some file and it might be useful, but I can’t remember where I saw something. I also end up trying to track down all the places a particular function is called, and don’t want grep to go digging through every… single… file in the entire kernel directory structure when I only care about .c files. So, I dug up a lengthy combination of file and grep that limits grep’s searching to particular files. I’m lazy about remembering this and retyping it on different computers, too, though, so I wrote a quick Ruby script to do it for me:
representing rational numbers in Smalltalk · Feb 7, 2010
For my graduate-level programming languages class, I wrote this class that represents a rational number in Smalltalk. I figured I would share my source code with the interwebs for anyone else trying to learn the language. I release the code under the GNU General Public License v3.
heap sort in ML · Dec 23, 2009
This past semester for my programming languages class, we had to implement heap sort in Standard ML. This is my implementation, which I release under the GNU General Public License v3. I split the code into two separate files: shared.ml and heap_sort.ml, where shared.ml contains functions that might be of use with other sorting algorithms and heap_sort.ml contains functions and code specific to heap sort.
code reports Rake task · Apr 7, 2009
sortable arrays of symbols in Ruby · Apr 7, 2009
I got this error in my Rails app because I was trying to sort an array of symbols: undefined method `<=>’ for :my_symbol:Symbol. I defined the spaceship method for the Symbol class and included the Comparable module in order to have other comparison methods available for symbols.
C++ shell with forks and pipes · Nov 29, 2008
As an assignment for my operating systems class, we were to write a shell in C or C++. I’m putting my work here under the GNU General Public License v3 in hopes that it will be helpful for someone else, presumably some future student arguing with the C language, which I find infinitely frustrating to work with sometimes.
my Qbee PHP script · Mar 21, 2008
I’m a member of the Quilting Bee and I use a very simple PHP script I wrote for displaying my quilt. I figure someone else might get some use out of it, so here it is for your coding pleasure:
chmodding and Ruby · Feb 1, 2008
Recently, I switched from a Powerbook to a Macbook, and to copy my files from one to the other, I used a pen drive. Since my pen drive has a FAT file system, it treats everything as being executable. This, however, is not the case on a UNIX-like file system like OS X. In order to save myself the hassle of manually chmodding thousands of files, I wrote this Ruby script:
using Ruby to rename files and edit their content · Nov 21, 2007
Recently at work, the web admin for the computer science department came into our lab and told us that my employer’s site was broken. The admin had need to make all .php files not act as PHP scripts, and instead, all files with the extension .sphp would now run as PHP scripts. Since my employer’s site was built using PHP, that meant all of its pages were showing the source code instead of actually executing. I had to whip up a quick Ruby script in order to:
finding invalid foreign keys in Rails · Nov 15, 2007
Sometimes it would be useful to tell users of your Ruby on Rails application if there is a problem in the database, such as some foreign keys are invalid. As an example, let’s assume you have two models, Book and Author, such that each Book has an author_id which connects with Author via its primary key, id. That is, the tables are: books(id, author_id) and authors(id). Each table probably has fields other than that, but those are the only fields we need to worry about. Below is a method that generates an unordered HTML list for display to the users:
the many methods to #find things in Rails · Nov 22, 2006
For the longest time, I didn’t understand the full power of the various #find methods in Rails. I probably still don’t, but my understanding of them has certainly expanded. I used to use plain #find for everything. If I wanted to find all rows in the table ‘groups’ that had an ‘id’ field value of 1, 2, 3, or 4, I would do something like this:
#post method in tests with a different controller · Nov 14, 2006
I wanted a #login method in test_helper that would allow me to easily login from any of my functional tests. However, the #post method won’t allow you to set a different controller than the one in the @controller instance variable that’s defined in your test’s #setup. Well, by looking at how the #process method works, you can see that it just grabs the controller from @controller. Redefine that, and you’re good to go:
go from model to associated table name and back · Aug 31, 2006
Given a table object, it returns the related string object; e.g.
SubAttribute => 'sub-attribute'. Useful if you want to make a list of all your tables with perhaps their fields listed out to the side.
I frequently have a collection of values that I want to match in an ActiveRecord query, but it would be nice if I could let ActiveRecord handle checking the data and escaping it properly. So, I wrote this method to return ActiveRecord-friendly conditions, such as:
["user_id=? AND job_id=?", 3, 4]
measuring volume in C++ · Sep 29, 2004
This is a program I wrote earlier while killing time in the Multilab.