Skip to content

Instantly share code, notes, and snippets.

View maeharin's full-sized avatar

Hidenori Maehara maeharin

View GitHub Profile
<?php
namespace A;
class C
{
static function foo() {echo "A_foo\n";}
}
namespace B;
class C
{
<?php
class C
{
protected $middleware;
public function __construct() {
$this->middleware = array($this); //Cオブジェクト自身を参照させる
}
<?php
$t = microtime(ture);
for($i = 0; $i < 1000000; $i++) {(string)$i;}
echo microtime(ture) - $t;
<?php
// ワンソース
function event() {
$args = func_get_args();
$name = array_shift($args);
$callable = array_pop($args);
$is_call = $callable();
<?php
function foo() {
$args = func_get_args(); //可変長引数を配列で取得
$v = array_shift($args);
$callable = array_pop($args);
$callable($v); //コールバック関数を呼び出し
}
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
ls | grep -e "[0-9]\{4\}" | xargs mv ../sandbox_daily/
@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
@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>
[1,2].tap {|arr| arr << 3}.display