ruby
A book auto-renewer for UNI's library
Posted October 8th, 2009 at 9:20 pmA while ago I wrote an auto renewer for UNI's library. I thought I would share that code in this post. It's not the best code I've ever written, but it works, and it's much better then trying to remember to do it manually.
So, without further ado, get it.
It's pretty simple to run, basically you just do
ruby rod_library_renewer.rb last_name UNI_id_including_000_in_the_front
The default action as demo'd above is to renew all books. I set this on up on my system using cron to run every day.
This will almost certainly fail if someone reserves one of the books you have..but I don't know how the web interface reports this, so my script doesn't catch it. So. Be aware!
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}"
Recent comments
1 sec ago
1 min ago
8 min 52 sec ago
13 min 14 sec ago
14 min 43 sec ago
15 min 52 sec ago
30 min 30 sec ago
31 min 6 sec ago
37 min 20 sec ago
41 min 36 sec ago