Skip to content

Instantly share code, notes, and snippets.

View maeharin's full-sized avatar

Hidenori Maehara maeharin

View GitHub Profile
@maeharin
maeharin / config.ru
Created January 5, 2013 10:20
静的サーバ起動
# original: http://blog.udzura.jp/2011/02/08/rack-one-liner-server-simpler/
Rack::Server.new.tap{|a|
def a.app
Rack::Directory.new(".")
end
}.start
@maeharin
maeharin / gist:4459714
Last active December 10, 2015 16:18
多重代入におけるto_aとto_aryの挙動の違い
# url: http://bugs.ruby-lang.org/issues/show/1393
class C
def to_a; [1,2]; end
def to_ary; [3,4]; end
end
c = C.new
# implicit(暗黙)
grep -rs 'STDERR' ./ | grep -E 'active|action|railties|sinatra|rack'
#!/usr/local/bin/ruby
if ARGV.count < 1 || ARGV.count >= 2
raise '引数が不正です!第1引数に比較したいファイル名を指定してください'
end
file_name = ARGV[0]
full_path = {}
full_path[:a] = File::expand_path(file_name)
<?php
class C
{
public function foo() {
echo "foo";
}
}
$c = new C();
find ./ -name 'filename'
grep -irs 'query' ./
@maeharin
maeharin / autosplit.sh
Created December 28, 2012 01:57
スペース区切りのテキストファイルを読み込んで、各行の最初の列だけ抜き出し、新たなファイルに保存
ruby -ane 'puts $F[0]' hoge.txt > hoge2.txt
#coding: utf-8
class M1
def initialize(app)
@app = app
end
def call(env)
env = env + '1'
res = @app.call(env)
ruby -r pp -e 'pp ENV.to_hash'
ruby -r open-uri -e 'open("http://www.yahoo.co.jp") {|f| puts f.read.scan(/topics.+?>(.+?)</)}'