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' |
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
# | |
# user system total real | |
# json_gem 1.970000 0.000000 1.970000 ( 1.969385) | |
# yajl 2.090000 0.000000 2.090000 ( 2.096399) | |
# oj 1.240000 0.000000 1.240000 ( 1.234021) | |
# json_pure 23.400000 0.000000 23.400000 ( 23.432088) | |
# | |
require 'benchmark' |
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
# Since ruby 2.1, method definition returns a name of a method as a symbol. | |
# Example: | |
def aaa; end # => :aaa | |
# How we do it currently | |
class SomeClass | |
def pub_meth | |
# ... | |
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
# Finds ruby files that was changed in HEAD against passed branch | |
# and run rubocop with them. It's supposed to help to detect | |
# rubocop offenses introduced by YOU. | |
# | |
# Examle: | |
# rubocop-detect develop | |
function rubocop-detect(){ | |
local branch=${1:-master} | |
echo -e "\e[1mCOMPARING:\e[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
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 => "from@example.com", :to => "to@example.com" | |
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 |
OlderNewer