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
# Stef try this in your ~/.irbrc | |
class Object | |
def method_missing(name, *args) | |
result = `#{name} #{args.join}` | |
puts result | |
result | |
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
1 " Wrap too long lines | |
2 set wrap | |
3 | |
4 " Tabs are 2 characters | |
5 set tabstop=2 | |
6 | |
7 " (Auto)indent uses 2 characters | |
8 set shiftwidth=2 | |
9 | |
10 " spaces instead of tabs |
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
export ORIGPATH=$PATH | |
alias mr187='export PATH=~/.multiruby/install/1.8.7-p72/bin:$ORIGPATH' | |
alias mr191='export PATH=~/.multiruby/install/1.9.1-p0/bin:$ORIGPATH' | |
alias mrj116='export PATH=~/.multiruby/install/jruby-1.1.6/bin:$ORIGPATH' | |
alias mrj120='export PATH=~/.multiruby/install/jruby-1.2.0RC1/bin:$ORIGPATH' | |
alias mroff='export PATH=$ORIGPATH' | |
mr187 |
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
require 'fastercsv' | |
task 'usda:import' => ['usda:import:food_items','usda:import:food_groups','usda:import:nutrients','usda:import:food_item_nutrients', 'usda:import:weights'] | |
namespace :usda do | |
namespace :import do | |
task :food_items => :environment do | |
puts "Importing Food Items..." | |
fname = File.join(RAILS_ROOT,"/db/usda_sr21/FOOD_DES.txt") |
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
require 'fastercsv' | |
task 'usda:import' => ['usda:import:food_items','usda:import:food_groups','usda:import:nutrients','usda:import:food_item_nutrients', 'usda:import:weights'] | |
namespace :usda do | |
namespace :import do | |
task :food_items => :environment do | |
puts "Importing Food Items..." | |
fname = File.join(RAILS_ROOT,"/db/usda_sr21/FOOD_DES.txt") |
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
require 'fastercsv' | |
task 'usda:import' => ['usda:import:food_items','usda:import:food_groups','usda:import:nutrients','usda:import:food_item_nutrients', 'usda:import:weights'] | |
namespace :usda do | |
namespace :import do | |
task :food_items => :environment do | |
puts "Importing Food Items..." | |
fname = File.join(RAILS_ROOT,"/db/usda_sr21/FOOD_DES.txt") |
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
# helpfull for performing actions that require temp directories | |
# 1. handles temp file creation | |
# 2. lets you do your business in da 'block' | |
# 3. cleans up after itself | |
# usage | |
require 'fileutils' | |
include FileUtils | |
temp do |
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
#!/usr/bin/env ruby | |
require 'fileutils' | |
dest_filename = 'screenshot.png' | |
domain = 'hammerofcode.com' | |
remote_user = 'ryan' | |
local_file = Dir["#{ENV['HOME']}/Desktop/Screenshot*"].last |
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 process_nethack_log(log) | |
data = log.scan(/#{"(.*) "*15}(.*),(.*)/)[0] | |
fields = %W| version score dun_number dun_level max_level hp max_hp deaths end start uid role race gender alignment name ending| | |
results = {} | |
(0..16).each do |i| | |
results[fields[i]] = data[i] | |
end | |
results | |
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
# So Tags has many "Freetaggables", a polymorphic association. Contacts is one of those freetaggables. | |
# My mentor was working on some old imports and this bug crops up. | |
# The code below raises an error. The record is invalid for some reason. | |
# Turns out since the join has a composite key it is failing - it isn't unique. That doesn't seem possible. | |
# It just so happens there is a really subtle bug where if you don't save both models before associating them you get a duplicate record in the join |