Skip to content

Instantly share code, notes, and snippets.

View hirak's full-sized avatar

Hiraku NAKANO hirak

View GitHub Profile
@hirak
hirak / file0.php
Created April 6, 2012 16:33
curl_multiでHTTP非同期リクエストを行うサンプル ref: http://qiita.com/items/1c67b51040246efb4254
<?php
/**
* curl_multiでHTTP複数リクエストを並列実行するテンプレ
*
*/
//タイムアウト時間を決めておく
$TIMEOUT = 10; //10秒
/*
@hirak
hirak / file0.php
Created April 7, 2012 14:42
pecl-HTTPによる複数リクエストを並列実行するサンプル ref: http://qiita.com/items/ccf6b111f1f3a7ad5e41
<?php
/**
* pecl-HTTPで並列リクエストを行うサンプル
*
*/
$urls = array(
'http://localhost/sleep.php?wait=1',
'http://localhost/sleep.php?wait=2',
'http://localhost/sleep.php?wait=3',
);
@hirak
hirak / file0.php
Created April 17, 2012 16:26
echoの後にスペースを開けなくてよい場合 ref: http://qiita.com/items/117f2e94222a9fd506cb
<?php
echo"引用符\n";
$a = "変数\n";
echo$a;
@hirak
hirak / file0.php
Created April 18, 2012 16:13
call_user_funcで引数を参照渡しする ref: http://qiita.com/items/2329acf12f9a182610a5
<?php
function testRef(&$a) {
$a = 1;
}
testRef($b);
//$b === 1になる
call_user_func('testRef', $c); //エラー発生
call_user_func('testRef', &$c); //deprecatedな書き方
@hirak
hirak / file0.php
Created April 18, 2012 20:34
func_get_args()は値渡しになる ref: http://qiita.com/items/5ba0f84594e18dafce98
<?php
function testRef(&$a) {
$args = func_get_args();
$args[0] = 1;
}
testRef($a);
var_dump($a); //->null
var a = "global";
with ({a:"local"}) {
console.log(a); //"local"
with ({a:"local2"}) { /* 入れ子にできる */
console.log(a); //"local2"
}
console.log(a); //"local"
}
console.log(a); //"global"
@hirak
hirak / file0.txt
Created May 3, 2012 13:09
名前空間用のオブジェクトを作る関数 ref: http://qiita.com/items/ae2639e0b91af0186b08
function namespace(str) {
var names=str.split(".")
, i, l, cur = Function("return this")()
;
for (i=0,l=names.length; i<l; i++) {
cur[names[i]] = cur[names[i]] || {};
cur = cur[names[i]];
}
return cur;
}
@hirak
hirak / file0.txt
Created May 4, 2012 05:22
globalオブジェクトを取得する ref: http://qiita.com/items/d249a2f2f13532748324
var global = this;
function Class(c) {
if (c == null) {
c = function(){};
}
c.extend = _extends;
c.mixin = _mixin;
c.statics = _static;
return c;
}
function _extends(uber) {
@hirak
hirak / file0.php
Created October 31, 2012 22:34
new演算子が作用できるもの ref: http://qiita.com/items/8ebed8e3b0b4be776572
<?php
class A {
}
$classname = 'A';
$a = new A; //Aオブジェクト1
$b = new $classname; //Aオブジェクト2
$c = new $a; //Aオブジェクト3