This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| def toggle(i) | |
| i == 0 ? 1 :0 | |
| end | |
| # turn on every bulb | |
| bulbs = Array.new 100, 1 | |
| # Turn off every x bulb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function parse_git_branch { | |
| git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
| } | |
| PS1="\h:\W (\$(~/.rvm/bin/rvm-prompt i v g s))\$(parse_git_branch)\$ " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'active_record' | |
| ActiveRecord::Base.configurations['db1'] = { | |
| :adapter => "mysql", | |
| :host => "", | |
| :database => "", | |
| :username => "", | |
| :password => "" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAlC6wPNa07k8mjVJCbiLwQoJQp3Kd4fJQX2g7ZwmNXVY0lG0IMkgpv7CGZ5llaZpOLHG54rHGsR0nq/G1xqh774NxAnFA8sceYb4Pb7kEdmkBkSKbSfUqEVF9B7GWtANz+dntzyM5OhOQcj+tQKBRR5tvK6USCnkCO6a0vCh+GdW2P4oD6X5JwuiJm2zcdPnmecK3AK6wTljc1SHERN1vbE/tjb6kozIpEKcVpH/Up5VcLoQGO6JsmP7mOU37SvYaJzgnSANtLP+CIf6MS7LbCmL9a8B6R6FZLjmuxJFvupS/0+kpYllzyuu7FkMvzg/Pxqe/6GqjHLX5OsgwzhSBkw== Chris@ack |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| page = Hpricot( open( 'http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=sf-muni&r=23&s=4198&useShortTitles=true' ) ) | |
| (page/:predictions/:direction/:prediction).each do |p| | |
| times_to_depart << p.get_attribute("minutes").to_i | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AccessPrivate | |
| def a | |
| end | |
| private :a # a is now a private method | |
| def accessing_private | |
| a # sure! | |
| self.a # nope! private methods cannot be called with an explicit receiver at all, even if that receiver is "self" | |
| other_object.a # nope, a is private, you can't get it (but if it was protected, you could!) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Place in rails config/initializers/ | |
| db_config = YAML::load(File.read(RAILS_ROOT + "/config/database.yml")) | |
| if db_config[Rails.env] && db_config[Rails.env]['adapter'] == 'mongodb' | |
| mongo = db_config[Rails.env] | |
| MongoMapper.connection = Mongo::Connection.new(mongo['hostname']) | |
| MongoMapper.database = mongo['database'] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| db_config = YAML::load(File.read(RAILS_ROOT + "/config/mongodb.yml")) | |
| if db_config[RAILS_ENV] && db_config[RAILS_ENV]['adapter'] == 'mongodb' | |
| mongo = db_config[RAILS_ENV] | |
| connection = Mongo::Connection.new(mongo['host']) | |
| MongoMapper.connection = connection | |
| MongoMapper.database = mongo['database'] | |
| if mongo['user'] && mongo['password'] | |
| MongoMapper.database.authenticate mongo['user'], mongo['password'] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| URL_CHARS = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a + ['-', '_'] - ['a', 'e', 'i', 'o', 'u'] - ['A', 'E', 'I', 'O', 'U'] | |
| URL_BASE = URL_CHARS.size | |
| def generateUrl(idNumber) | |
| localCount = idNumber | |
| result = ''; | |
| while localCount != 0 | |
| rem = localCount % URL_BASE | |
| localCount = (localCount - rem) / URL_BASE | |
| result = URL_CHARS[rem] + result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'json' | |
| require 'open-uri' | |
| require 'mongo' | |
| include Mongo | |
| url = 'http://search.twitter.com/trends.json' | |
| buffer = open(url, 'UserAgent' => 'Ruby-Wget').read | |
| result = JSON.parse(buffer) |