This file contains 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
def pie_to(val, r) | |
rads = (val*3.60) * Math::PI / 180 # 360 deg of val % in radians | |
sr = (r * Math.sin(rads)).to_i | |
cr = (r * Math.cos(rads)).to_i | |
arc = val <= 50 ? 0 : 1 | |
[sr, r-cr, arc] | |
end |
This file contains 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
@user.allotments.map &:destroy # delete old allotments | |
# format: [ ['role', 'human-role', [1,2,3]], ['role', 'human-role', [1,2,3]] ] defined in user model. | |
allots = [] | |
params[:roles_divisions].each do |rd| | |
rd[2].each do |d| | |
allots << Allotment.create(:user_id => @user.id, :division_id => d.to_i, :role_name => rd[0]) | |
end | |
end |
This file contains 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
allotments = [] | |
params[:roles_divisions].map do |rd| | |
rd[2].each do |d| | |
allotments << Allotment.create(:user_id => @user.id, :division_id => d.to_i, :role_name => rd[0]) | |
end | |
end | |
@user.allotments = allotments |
This file contains 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
#@data = Hash.new { |h,k| h[k] = Hash.new { |h1,k1| h1[k1] = Array.new(8) {0} } } #Interesting |
This file contains 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
.s@\(\d\+\)@\=(submatch(1) + 17)@ | |
Search for numbers and replace them with results of expressions involving them. submatch(1) is \1 (groups in regexes) |
This file contains 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
SubdomainFu.configure do |config| | |
config.tld_size = 1 | |
config.mirrors = %w( support blog www billing help api ) | |
config.preferred_mirror = 'www' | |
end |
This file contains 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
Dir[File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'hoptoad_notifier-*')].each do |vendored_notifier| | |
$: << File.join(vendored_notifier, 'lib') | |
end |
This file contains 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
rvm use ree-1.8.7-2010.02@global | |
rvm gemset create rails2310 | |
gem install rails -v=2.3.10 |
This file contains 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
"ensure" makes sure code is run regardless of begin-rescue outcome. (equivalent of Java finally) | |
Pass a number parameter to Array#first and Array#last to get the first n or the last n values. | |
http://rubyquicktips.tumblr.com/post/870337608/grep-anything-from-your-enumerables |
This file contains 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
run "rm public/index.html" | |
generate(:scaffold, "item name:string") | |
route "root :to => 'items#index'" | |
rake("db:migrate", "production") | |
gem 'ruby-openid' | |
gem 'will-paginate', :git => 'git://github.com/mislav/will_paginate.git' | |
add_source "http://code.whytheluckystiff.net" | |
gem "hpricot", :version => '0.6' |