Skip to content

Instantly share code, notes, and snippets.

View maeharin's full-sized avatar

Hidenori Maehara maeharin

View GitHub Profile
#!/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)
grep -rs 'STDERR' ./ | grep -E 'active|action|railties|sinatra|rack'
@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(暗黙)
@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
[1,2].tap {|arr| arr << 3}.display
@maeharin
maeharin / gist:4461321
Last active May 15, 2023 06:29
WEBrickを起動させるワンライナー
# 起動
$ ruby -r webrick -e 'WEBrick::HTTPServer.new(:DocumentRoot => "./", :Port => 8080).start'
# 停止
$ ps aux | grep ruby
$ kill -9 <pid>
@maeharin
maeharin / gist:4472037
Last active December 10, 2015 18:08
Postgresのselect結果を、シェルからワンライナーでテキストファイルに保存する
psql -U <username> -d <dbname> -c 'SELECT * FROM users where id > 10;' -A > log.txt
ls | grep -e "[0-9]\{4\}" | xargs mv ../sandbox_daily/
require 'optparse'
OptionParser.new do |o|
o.on("-r") {puts 'read mode'}
o.on("-w") {puts 'write mode'}
o.on("-e") {puts 'edit mode'}
o.on("-d") {puts 'delete mode'}
end.parse! ARGV
<?php
function foo() {
$args = func_get_args(); //可変長引数を配列で取得
$v = array_shift($args);
$callable = array_pop($args);
$callable($v); //コールバック関数を呼び出し
}