Programming
Data-izing arbitrary attributes, the lazy way
Posted August 22nd, 2009 at 2:52 pmFor the Cedar Falls Poker website, there's a stats page in which a particular model is hit pretty hard. There used to be a series of methods handling the retrieval of data in a useful manner, but I standardized the way this happens so I could clean up the model code and make it more useful.
This uses Hashes to return data in a format that is easy to turn into pie charts or bar graphs. This code assumes a few things. It assumes you do not have any other methods with _data in the name. It assumes that you're only going to be pulling data that is available as a method or attribute call; namely, using send. If your classes aren't set up this way, they probably should be.
class << self def data(atr) returning(Hash.new(0)) do |h|
Using YAML as a parameter hash in Ruby
Posted August 11th, 2009 at 2:04 pmSometimes while coding Ruby applications the need develops to have some sort of metadata available as a configuration file. I have written some Ruby code that allows parameters that exist in a yaml file to be used as though they are in the class itself. In addition, I required code that allows the class to modify these parameters and then save them back to the file. Ruby's method_missing is a major player here. Anyway, I thought I would share this code.
To give an example of what exactly this does, assume that there exists a file called 'config.yml' that contains some key value pair such as :name => 'Bob':
--- :name: Bob
Using this class, we could do stuff like:
require 'boilerplate' class Test < Boilerplate def run puts "Name is: #{name}"
Tangents
Posted August 26th, 2008 at 12:09 amLately I've come to realize a very important issue with my work flow is one of tangents. My attention is easily grabbed, probably because many things interest me. This is both a blessing and a curse. Often I find myself browsing the web, usually on some kind of programming blog or programming website. Blogs typically have large amounts of links in their content bodies, which direct the user to other, relevant pages of interest. I click on the ones that interest me, often opening them in tabs behind my current one. This works out ok for a while, but I end up with a browser window with 100 tabs full of stuff I really want to absorb, but there's just not enough time!
Project Euler
Posted May 1st, 2008 at 12:44 amSometime ago I found a pretty swell website with a bunch of math/programming problems called Project Euler. I forgot to bookmark it, and my search for it later when I wanted to try a few of the problems didn't bring me back to it. Luckily, I have no life and spend an absurd amount of time online, so a few days ago I came across it again. Anyway, I've been doing a few of the problems in Ruby. Other then not understanding some of the math, my biggest problem has been optimizing functions so they run quickly enough to not spend hours and hours (or weeks, or years..) running.
Web 2.0 has a future
Posted April 28th, 2008 at 1:23 amNow that the weekend is to an official close, I was doing my typical Sunday night ritual of putting off homework and watching stand up comedy on youtube. To live up to the nerdy-ness all Computer Science students strive for, I tend to multitask frequently. While in the midsts of a silly little python program just to entertain myself, Imagine my surprise when the idea of a lifetime struck me.
No, I will not say what it is at this time, but consider this post a teaser: much php code (or ruby on rails? I hope my host is up for the challenge..) will be written in the near future. Hopefully I'll debut the next MySpace, Facebook or YouTube soon. A guy can dream, right? :)
Recent comments
1 min 52 sec ago
1 min 55 sec ago
1 min 56 sec ago
1 min 56 sec ago
1 min 56 sec ago
1 min 56 sec ago
1 min 56 sec ago
1 min 57 sec ago
1 min 57 sec ago
1 min 58 sec ago