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
class User < ActiveRecord::Base | |
has_many :emails, :inverse_of => :user | |
end | |
class Email < ActiveRecord::Base | |
belongs_to :user , :inverse_of => :emails | |
end | |
# spec 1 | |
u = User.find(1) |
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 'benchmark' | |
array = (1..10_000).to_a | |
m = Benchmark.bm(15) do |x| | |
x.report("inject") do | |
array.inject({}) do |hash, element| | |
hash[element] = element |
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
# When everything work | |
class TestMailer < ActionMailer::Base | |
default :from => "[email protected]", :to => "[email protected]" | |
def hello | |
mail do |format| | |
format.text { render :text => "Hello!" } | |
format.html { render :text => "<h1>Hello!</h1>" } | |
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
class Art | |
L = 2 | |
MAX_EPOCH = 20 | |
def initialize(n, m, p = 0.45) | |
@n = n | |
@m = m | |
@p = p | |
@w1 = Array.new(n) { Array.new(m) { 1.0 / (1+n) } } | |
@w2 = Array.new(m) { Array.new(n) { 1.0 } } |
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
# git branch | |
function parse_git_dirty { | |
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*" | |
} | |
function parse_git_branch { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/" | |
} | |
export PS1='\u@\h \[\033[1;34m\]\w\[\033[0m\]\[\033[0;33m\]$(parse_git_branch)\[\033[0m\]$ ' |
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 'cgi' | |
# Refresh period | |
PERIOD = 1 # seconds | |
# Calculate random value from 1 to 10 | |
value = rand(10) + 1 |
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
# Override some stuff to detect FacotoryGirl usage out of `it` | |
module RSpec | |
module Core | |
class ExampleGroup | |
class << self | |
# redefine to do nothing | |
def it(*args) | |
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
def show_page | |
filename = "/tmp/shot.png" | |
driver = page.driver | |
driver.save_screenshot(filename) | |
system "eog #{filename}" | |
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
# Result | |
# | |
# user system total real | |
# REXML 8.190000 0.020000 8.210000 ( 8.211740) | |
# LibXML 1.140000 0.000000 1.140000 ( 1.141131) | |
# Nokogiri 1.600000 0.000000 1.600000 ( 1.604999) | |
# | |
require 'benchmark' |
OlderNewer