Skip to content

Instantly share code, notes, and snippets.

View dissolved's full-sized avatar

Ryan Sandridge dissolved

View GitHub Profile
@dissolved
dissolved / seeds.rb
Created May 12, 2011 16:17
Problem with Dynamic Finders in seeds.rb
# db/seeds.rb
orig = Security.create!(symbol:'NFLX', name:'Overvalued Content Provider')
puts Security.all
puts orig.symbol
s = Security.find_by_symbol(orig.symbol)
puts s.nil? ? "not found" : "found"
s = Security.find(orig.id)
<h2>New Portfolio</h2>
<%= form_for @portfolio do |f| %>
<%= render 'shared/error_messages', :object => @portfolio %>
<div class="field" style="padding-top: 20px;">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field" style="padding-top: 20px;">
<%= f.label :beginning_cash_balance %><br />
@dissolved
dissolved / post.rb
Created February 4, 2012 04:34
Alternative to Fig Leaf
class Post
delegate :errors, :valid?, :save, :to => @record
@@persistance = Class.new(ActiveRecord::Base) do
set_table_name 'posts'
def self.name
'PostRecord'
end
end
@dissolved
dissolved / no_such_thing.rb
Created February 23, 2012 16:21 — forked from bokmann/no_such_thing.rb
The code of the talk from my Feb 22nd Arlington Ruby talk 'There is No Such Thing as Metaprogramming'.
# This is the code from my 'There is No Such Thing as Metaprogramming' talk,
# which premiered at the Arlington, VA Ruby Users Group on Feb 22nd.
# Without the deliver and walk-through to the solution below this example
# will be missing quite an important bit of content (mainly the tracking of
# 'self' while developing the solution, but it still a useful read.
# Here is the Toddler with no metajuju. Note that the developer, as well as
# the code, is completely unuaware of the interpreter. A developer with a
# background in compiled languages would be comfortable looking at this.
#dependencies
require "csv"
def import
filename = "pricing_sample.csv"
@file = CSV.open(filename, {:headers => true, :header_converters => :symbol})
end
def discrepancies
underscans = 0
@dissolved
dissolved / gist:5463419
Created April 25, 2013 21:40
Work in progress for my .slate config
# Configs
config defaultToCurrentScreen true
config checkDefaultsOnLoad true
config keyboardLayout colemak
config windowHintsShowIcons true
config windowHintsIgnoreHiddenWindows true
config windowHintsSpread true
# Monitor Aliases
@dissolved
dissolved / gist:5794223
Created June 17, 2013 01:53
Ever want to go deep (or even "the end") of an infinite scroll? You could spend 10-30 minutes scrolling like a hamster... or you could use javascript to do it for you while you get a cup of java.
// To start scrolling, type this in the javascript console
var theTimeout=setInterval(function(){window.scrollTo(0, document.body.scrollHeight);},500);
// To stop scrolling, type this in the javascript console
clearInterval(theTimeout);
@dissolved
dissolved / gist:6546370
Created September 13, 2013 03:00
Object.tap inconsistancy
{:mutable => false}.tap {|h| h[:mutable] = true}
# => {:mutable=>true}
"Can I mutate?".tap {|str| str = "No!"}
# => "Can I mutate?"
@dissolved
dissolved / functional_alt_gol.rb
Created September 30, 2013 01:50
Our solution to the following challenge: Conway's Game of Life without saving state and without using iteration (or anything provided by Enumerable). Also included is a shorter solution which does use Enumerable.
class NilClass
def [](index) end
end
class Array
def [](index)
(index < 0) ? nil : at(index)
end
end
@dissolved
dissolved / gist:6945327
Created October 12, 2013 03:10
Why Arlington Ruby is so great!
[5:08pm] allie_p: is an instance variable and an instance method the same thing?
[5:09pm] saturnflyer: no
[5:09pm] saturnflyer: an instance variable is some internal value
[5:09pm] saturnflyer: an instance method is some function that object can perform
[5:10pm] allie_p: ok, so they're related but different
[5:10pm] saturnflyer: typically, you might keep the names the same to set and retrieve the instance variable values
[5:10pm] saturnflyer: attr_accessor creates 2 methods that set and retrieve the instance variable
[5:10pm] saturnflyer: but you could have a method called full_name, that returns something other than @full_name
[5:11pm] saturnflyer: it could be @__full_person_name, or whatever you want
[5:15pm] allie_p: thanks!