This gist is now deprecated as I've finally sorted out and made my dotfiles public.
My ~/.gitconfig is available here, and my git-related shell setup here.
| # | |
| # | |
| # weight.rb (A Ruby on Rails Model). | |
| # Lets you pick a row from a table randomly based on the rows weight. | |
| # | |
| # Your table will need three columns: | |
| # - weight (float) | |
| # - weight_begin (float) | |
| # - weight_end (float) | |
| # |
| # | |
| # The dumbest piece of code I've EVER written. | |
| # | |
| # I REALLY don't know WTF I was thinking, or not thinking. | |
| # I must have been drunk and asleep while I wrote this method. | |
| # | |
| # It's not only stupid, but IT DOESN'T EVEN WORK! *stabs self in face* | |
| # | |
| def stupid_method |
| for (var i=0; i < 100000; i++) { | |
| db.mass_insert.save({ | |
| "first_name": "James", | |
| "middle_name": "Richard", | |
| "last_name": "Windsgate", | |
| "email": "jamesrichardwindsgate@email.com" | |
| }); | |
| }; |
| # | |
| # Run multiple system commands in parallel | |
| # | |
| def call_parallel(cmds = [], check_interval = nil) | |
| if cmds.size > 0 | |
| threads, results = [], [] | |
| cmds.each do |cmd| | |
| threads << Thread.new { results << [cmd, `#{cmd}`, $?] } | |
| end | |
| is_done = false |
| # Dump database "hello_world" | |
| $ ./dump_to_s3.rb hello_world | |
| dumping hello_world database... | |
| uploading /mnt/hello_world-2009-10-30_12-11-44.sql_aa to S3. | |
| uploading /mnt/hello_world-2009-10-30_12-11-44.sql_ab to S3. | |
| uploading /mnt/hello_world-2009-10-30_12-11-44.sql_ac to S3. |
| # A simple Ruby method which checks if the current script | |
| # is running as root, and if not, re-invokes itself by | |
| # using the sudo command. | |
| def sudome | |
| if ENV["USER"] != "root" | |
| exec("sudo #{ENV['_']} #{ARGV.join(' ')}") | |
| end | |
| end |
| require "rubygems" | |
| require "friendly" | |
| require "models/user" | |
| Friendly.configure( | |
| :adapter => "mysql", | |
| :host => "localhost", | |
| :user => "root", | |
| :password => "boot", | |
| :database => "friendlyplay" |
| .DS_Store | |
| data.rb | |
| results.txt |
| #! /usr/bin/env ruby | |
| # | |
| # Convert a MySQL database from latin1 to utf8 charset. | |
| # | |
| # Based on the short but slightly limited shell script in this article: | |
| # http://yoonkit.blogspot.com/2006/03/mysql-charset-from-latin1-to-utf8.html | |
| # | |
| # Use at your own risk! I take not responsiblity for anything or | |
| # anyone that might be damaged, lost, or killed from using this |