Skip to content

Instantly share code, notes, and snippets.

View alexrothenberg's full-sized avatar

Alex Rothenberg alexrothenberg

View GitHub Profile
@alexrothenberg
alexrothenberg / gist:4176359
Created November 30, 2012 15:18
class instance variables
# They are different!
class A
def self.me=(value)
@me = value
end
def self.me
@me
end
def double_me=(value)
h = Hash.new([])
h[:a] << 1
h[:a] << 2
h
#=> {} # WTF
h.keys
#=> [] # WTF
@alexrothenberg
alexrothenberg / gist:4089904
Created November 16, 2012 18:58
hash weirdness
h = Hash.new([])
h[:a] << 1
h[:a] << 2
h
#=> {} # WTF
h.keys
#=> [] # WTF
@alexrothenberg
alexrothenberg / gist:2875180
Created June 5, 2012 13:58
Bundler in RubyMotion seems slower
Here are the steps I took to time the slowdown I'm seeing using bundler. I timed "rake spec" because it was easier to time but the slowness is more pronounced when I just run "rake".
1. Create a simple app with `motion create bundler`
2. Add 2 lines to Rakefile
require 'bubble-wrap'
require 'motion-cocoapods'
3. Force a compile with `rake spec`
4. Time it without bundler about 1.7sec
App.Alex = Ember.Object.Extend({
dotColor: function() {
switch (this.get('customer').get('state') {
when 1
'sprite big'
when 2
'sprite small'
}
}.property('customer.state')
})
it "should be able able to overwrite defaults" do
subject.log = "/test"
subject.log.should eql('/test')
end
describe 'overriding log' do
before { subject.log = '/test' }
its(:log) { should == '/test' }
end
@alexrothenberg
alexrothenberg / wxdata.rb
Created March 21, 2011 20:14
Parse WXDATA files to extract snowfall totals
def parse file_name
lines = File.readlines(file_name)
# puts "#{file_name} has #{lines.size} lines"
lines[4] =~ /.*: (\d+)/
data_id = $1.to_i
monthly_data(data_id, lines)
rescue => e
puts "Error with file #{file_name}: #{e}"
[data_id]
end
@alexrothenberg
alexrothenberg / .bashrc
Created December 13, 2010 17:26 — forked from henrik/.bashrc
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
class AddHomeTeamIdAndAwayTeamId < ActiveRecord::Migration
def self.up
add_column :games, :home_team_id, :integer
add_column :games, :away_team_id, :integer
Game.all.each do |game|
home_team = Team.find_or_create_by_name(game.home_team)
away_team = Team.find_or_create_by_name(game.away_team)
# db/seeds.rb
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Major.create(:name => 'Daley', :city => cities.first)