Skip to content

Instantly share code, notes, and snippets.

View maeharin's full-sized avatar

Hidenori Maehara maeharin

View GitHub Profile
<?php
// ワンソース
function event() {
$args = func_get_args();
$name = array_shift($args);
$callable = array_pop($args);
$is_call = $callable();
<?php
$t = microtime(ture);
for($i = 0; $i < 1000000; $i++) {(string)$i;}
echo microtime(ture) - $t;
<?php
class C
{
protected $middleware;
public function __construct() {
$this->middleware = array($this); //Cオブジェクト自身を参照させる
}
<?php
namespace A;
class C
{
static function foo() {echo "A_foo\n";}
}
namespace B;
class C
{
$ psql dbname -U username -F ',' -A -c 'select * from users limit 10'
@maeharin
maeharin / gist:4570471
Last active December 11, 2015 07:59
one liner / rename directory at current directory yyyymmdd -> yyyy_mm_dd / scan / sub
$ ls | ruby -nle '$_.scan(/\d{8}/) {|m| File.rename(m, m.sub(/(\d{4})(\d{2})(\d{2})/) {"#{$1}_#{$2}_#{$3}"})}'
var c = {name: 'hoge'};
(function() {this.echo = function() {console.log(this);};}).call(c);
c.echo();
@maeharin
maeharin / sub_gsub.sh
Created January 28, 2013 04:25
ruby one liner oneliner sub gsub sh
# マッチした最初の文字を置換
cat hoge.txt | ruby -pe '$_.sub!("hoge", "fuge")' > fuge.txt
# マッチした全ての文字を置換
cat hoge.txt | ruby -pe '$_.gsub!("hoge", "fuge")' > fuge.txt
@maeharin
maeharin / gist:4680661
Last active December 11, 2015 23:59
標準入力同士のdiff(差分)をとる方法 original:http://blog.bsdhack.org/index.cgi/Computer/20120618.htm
# bash
# <と(の間はスペースが入らない
diff <(command1) <(command2)
# bash以外
command1 | ( command2 | diff /dev/fd/3 -) 3<&0
@maeharin
maeharin / gist:4688506
Last active December 12, 2015 01:08
grepでand or 検索(正規表現を使う) grep -e で古い正規表現。grep -E で拡張正規表現
# カレントディレクトリのディレクトリのみ表示
ls -aF | grep -E '[^\.]+/$'