Skip to content

Instantly share code, notes, and snippets.

View koriroys's full-sized avatar
🐢
Slow and Steady

Kori Roys koriroys

🐢
Slow and Steady
View GitHub Profile
@koriroys
koriroys / doccsv.rb
Created January 19, 2012 01:43
Tom
# encoding: utf-8
require 'csv'
def is_suffix? name
case name
when "Jr"
true
when "JR"
true
<table>
<tr>
<th>Player Name</th>
<th>action</th>
</tr>
<% @players.each do |player| %>
<tr>
<td><%= link_to player.name, player %></td>
<td><%= button_to "Remove from team", :action => "update" %></td>
</tr>
@koriroys
koriroys / game.rb
Created February 12, 2012 18:36
Ugly search
class Game < ActiveRecord::Base
has_many :gamelocations
has_many :locations, :through => :gamelocations
has_many :gameingredients
has_many :ingredients, :through => :gameingredients
belongs_to :source
def self.find_by_criteria(params)
def login_user(email = 'kori', password = 'kori')
user = User.create!(:email => email, :password => password)
post session_path(:email => user.email, :password => user.password)
response.should redirect_to(root_path)
end
def make_valid_post
post posts_path(:title => "whee", :site_link => "whee")
@koriroys
koriroys / change.rb
Created March 17, 2012 02:50
Change Kata
class Changer
attr_accessor :change
def initialize
@change = []
end
def make_change(num)
@koriroys
koriroys / hard_coded.rb
Created March 26, 2012 04:32
How to make an empty column still show up?
<div class="span12">
<div class="row">
<div class="span3">Not Yet Started
<% story.tasks.each do |task| %>
<%= render task if task.not_yet_started? %>
<% end %>
</div>
<div class="span3">In Progress
<% story.tasks.each do |task| %>
<%= render task if task.in_progress? %>
@koriroys
koriroys / return_procs.rb
Created March 29, 2012 20:36
Why do the last two lines work?
def compose proc1, proc2
Proc.new do |x|
proc2.call(proc1.call(x))
end
end
squareIt = Proc.new do |x|
x**2
end
@koriroys
koriroys / gist:2304137
Created April 4, 2012 17:34
Push a new branch
# create & checkout branch in one step
$ git checkout -b branch_name
# push new branch to remote repo
$ git push remote_repo_name branch_name
# example of above:
$ git push origin branch_name
class Stack
attr_accessor :stack
def initialize(input)
self.stack = input
end
def pop(*args)
return stack.pop if args.empty?
stack.pop.reverse # This shouldn't work.
shopping_cart = [
{:name => "iPad 2", :price => 499, :quantity => 5},
{:name => "iMac 27", :price => 1699, :quantity => 1},
{:name => "MacBook Air 13", :price => 1299, :quantity => 1}
]
sales_tax = {
"IL" => 0.115,
"IN" => 0.09,
"MI" => 0.06,