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
Spec::Matchers.define :be_invalid_on do |field| | |
match do |model_instance| | |
!model_instance.valid? && model_instance.errors.on(field) != nil | |
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
require 'benchmark' | |
d1 = [1,1,1,1,0,0,0,0,0] | |
d2 = [1,0,1,0,1,1,0,0,0] | |
d3 = [0,0,0,0,1,0,1,1,1] | |
def calc_sim vector1, vector2 |
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
use Rack::Logger | |
app = proc do |env| | |
[ 200, {'Content-Type' => 'text/plain'}, "a" ] | |
end | |
run app | |
#This will produce: | |
# Rack::Lint::LintError: rack.errors#close must not be called |
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
#Output | |
#Jerome-Gagners-MacBook-Pro:amazon jgagner$ ruby bids.rb | |
#Current bid: 6, bid total 6, current max 0 | |
#Current bid: 6, bid total 12, current max 6 | |
#Current bid: 6, bid total 18, current max 12 | |
#Current bid: 3, bid total 12, current max 18 | |
#Accepted bids = 666 at 18 | |
#Current bid: 6, bid total 6, current max 0 | |
#Current bid: 5, bid total 10, current max 6 | |
#Current bid: 4, bid total 12, current max 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
//Squished a couple files together | |
package com.jeromegagner.example.trees.binary; | |
/** | |
* Created by IntelliJ IDEA. | |
* User: jgagner | |
* Date: Apr 18, 2010 | |
* Time: 1:30:24 PM | |
* To change this template use File | Settings | File Templates. |
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
There are four ways to do something | |
<ul> | |
<% (1..4).zip([:a,:b,:c,:d]).zip(["face1","face2","face3","face4"]).transpose[0].transpose[0].each do |x| %> | |
<li><%= x %> </li> | |
<% end %> | |
</ul> |
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 do_something &block | |
(1..4).zip([:a,:b,:c,:d]).zip((["face"] * 4).map {|x| x.to_sym}).transpose[0].transpose[0].each(&block) | |
end | |
do_something { puts "face!"} |
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
#doesn't accept args for the methods... probably next on that | |
class Object | |
def try_chain(*args) | |
method = args.shift | |
if respond_to?(method) | |
args.empty? ? self.send(method) : self.send(method).try_chain(*args) | |
else | |
nil | |
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
#mostly pseudo-code | |
#LOLOLOL | |
class Module | |
alias_method :old_method_missing, :method_missing | |
def method_missing(methId) | |
methods = methId.split("_") | |
tmp = self | |
while methods.size > 0 | |
my_meth = methods.pop |
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
du -k * | sort -nr | cut -f2 | xargs -d '\n' du -sh | less |
OlderNewer