Latest Tweet
- Downgraded to iPhone OS 3.1.3, upgraded to responsive 3G iPhone. :P 2 weeks ago
- More updates...
Categories
Tags
academia alcohol animals boyfriend cooking databases email forwards family Flickr food friends health Lexington Linux list Mario math movies music news OS X Perl photos PHP politics programming quizzes Rails rants reading Ruby screenshots shopping Sims sports themes tutorials Twilight is ridiculous vehicles video games videos weather Web development work zombies again-
Recent Comments
-
Random Quote
Sour, sweet, bitter, pungent, all must be tasted.
— Chinese Proverb Syndication
All posts RSS feed
Tag Archives: programming
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 [...]
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 [...]
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 [...]
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:
[...]
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” [...]
conditioner for ActiveRecord-friendly conditions from a collection