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
<?php | |
$i = 0; | |
while($i < 10000){ | |
$i++; | |
} | |
echo "There's Hell In Hello But More In Goodbye\n"; |
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
$r = 10 * 1000 * 1000; | |
$start = microtime(true); | |
while($r-- > 0) { | |
new StdClass(); | |
} | |
$finish = microtime(true); | |
echo "time taken: " . ($finish - $start) . "\n"; |
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 Gear | |
attr_reader :chainring, :cog, :wheel | |
def initialize(chainring, cog, wheel = nil) | |
@chainring = chainring | |
@cog = cog | |
@wheel = wheel | |
end | |
def ratio |
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
# This is port of https://gist.github.com/4029778 (ActiveRecord extension to print FactoryGirl definition!) | |
class ActiveRecord::Base | |
def to_fabrication | |
ignores = %w(id created_at updated_at) | |
array = [] | |
array << "Fabricator(:#{self.class.model_name.underscore}) do" | |
width = attributes.map{ |a| a[0].size }.max.to_i | |
attributes.each do |key, value| | |
next if ignores.include?(key) |
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
# coding: utf-8 | |
s = " | |
[10/25 Thu] (01:40:39) @nrkkkkk : のりこはのりぞと呼ばれることが多いですが、ついにノーになった | |
[10/25 Thu] (01:41:22) @ainame : そもそもニコニコ動画を見なかった理由として読み込みが遅いしなんか好みの動画見つけるのめんどいしってのがあったけど、プレミアム会員になったら一瞬でロードされてしまってあっけにとられた。 | |
[10/25 Thu] (01:41:58) @ssig33 : でろん | |
[10/25 Thu] (01:41:59) @ainame : プレミアムじゃないニコニコ動画って全然ニコニコ出来ないな | |
[10/25 Thu] (01:42:16) @ssig33 : NIC を蟹から Intel に変えるだけでマジ人生変わった | |
[10/25 Thu] (01:42:19) @ssig33 : 蟹は害悪 |
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 bar | |
raise NoMemoryError | |
rescue puts "hi" | |
end | |
bar # Exception は補足できない | |
# /Users/kohei/lang/ruby/exception.rb:3:in `foo': NoMemoryError (NoMemoryError) | |
# from /Users/kohei/lang/ruby/exception.rb:8:in `<main>' | |
def foo |
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
# http://yehudakatz.com/2010/11/30/ruby-2-0-refinements-in-practice/ | |
# http://www.rubyist.net/~matz/20060104.html | |
# http://www.rubyist.net/~matz/20101113.html | |
module Foo | |
refine String do | |
def to_s | |
"hello" | |
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
# -*- coding: utf-8 -*- | |
describe Array do | |
let(:array) { [1,2,3,4,5] } | |
let(:words) { ['paperboy', 'lolipop', 'muumuu-domain', '30days album', 'sqale', 'osaipo', 'heteml'] } | |
it "配列の各要素を二倍した配列を返すこと" do | |
array.map{|n| n * 2 }.should == [2,4,6,8,10] | |
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
# -*- coding: utf-8 -*- | |
describe Array do | |
let(:array) { [1,2,3,4,5] } | |
subject &:array | |
it "先頭の要素(1)を返すこと" do | |
subject.first.should == 1 | |
subject[0].should == 1 | |
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 deamonize | |
# fork は2個返り値を返す | |
# 親プロセスは child's pid | |
# 子プロセスは nil | |
# 親プロセスは true, 子プロセスは false と評価され、 | |
# 親プロセスは抜け、子プロセスが続く | |
exit if fork | |
# Process.setsid は新しいセッションを作成して、tty を切り離す | |
# セッションを生成するプロセスはプロセスグループのリーダー "以外" でなくてはならない |