Tag Archives: programming

conditioner for ActiveRecord-friendly conditions from a collection

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] based on the ‘raw’ conditions you feed [...]
Posted in Programming | Also tagged , | Leave a comment | Current music Hung Up by Madonna

simple Rails preference storage

So you’ve got some Rails application and you need to store information from the users across their interactions with the app. Here’s a simple, straightforward way to do that. In your controller: if params[:option]   @option = session[:option] = params[:option] elsif session[:option]   @option = session[:option] else   @option = 'default value' end This checks to see if ‘option’ was passed via a parameter in the [...]
Posted in Programming | Also tagged , | Leave a comment | Current music Post Blue by Placebo

if succinctly

In Ruby, if is an expression, not a statement, thus it returns a value. This may not seem useful at first glance, but it lends itself to forming neat, concise code… Like most things in Ruby, actually. Setting Values Concisely Say you want to define a variable differently based on the result of an if [...]
Posted in Programming | Also tagged | 2 Comments

the power of yield and super

The two keywords yield and super allow you to pass control back and forth between parent and child methods, to weave power between a more general method (in the parent class) and a more specific method (in the child class) with ease and logic. Using yield and super effectively can help you maintain the [...]
Posted in Programming | Also tagged | Leave a comment

enqueue and dequeue

Source for enqueue() and dequeue() functions to add and remove data from a queue in a class. Node Struct Definition C++ struct node {      string what; // Used for brand      string serialNumber;      node* next; // For accessing next node in queue }; Class Definition File C++ class car {           public:           [...]
Posted in Programming | Also tagged | 5 Comments

Makefile

In a Unix environment when working with C++ or C, a Makefile can be a very handy thing. Instead of typing several separate commands each time you update a file and want to recompile, you can just type make and the Makefile is executed. A Makefile is a plain-text file traditionally named “Makefile” or “makefile” [...]
Posted in Programming | Also tagged | 1 Comment