Skip to content

Instantly share code, notes, and snippets.

View uzulla's full-sized avatar
🚧
WORK,WORK,WORK.

uzulla / Junichi Ishida uzulla

🚧
WORK,WORK,WORK.
View GitHub Profile
@uzulla
uzulla / composer.json
Created April 26, 2014 19:38
PHPでCLIのプログレスバーっぽいやつをつくる件 例:http://pyazo.cdn.cfe.jp/image/zFrO88JGgrj4fUJN139854090597644.gif
{
"require": {
"donatj/cli-toolkit": "dev-master"
}
}
@uzulla
uzulla / psysh_test.php
Created April 14, 2014 16:49
Psysh をなんかこうグローバルで良い感じに…うーん、良い感じの書き方がおもいつかないでござる。
<?php
// config
define("DEBUG", true);
// loading
if(DEBUG)
include('/path/to/psysh');
// setup
set_error_handler(function($errno, $errstr, $errfile, $errline){
<?php
$foo = 'ふー';
$bar = 'ばー';
$func1 = generate($foo,$bar);
// $app->get($key, generate($foo, $bar));
$foo = "FOOO!!!";
@uzulla
uzulla / jabai.php
Created April 3, 2014 13:20
PHP無名関数(クロージャ)の$thisをあとからかきかえるやつ
<?php
class world {
public $v;
public function main(){
$this->v = 'じゃばい';
$f = function(){
echo $this->v;
};
@uzulla
uzulla / guard.php
Created April 1, 2014 12:55
PHPで、いわゆるPerlのGuard(ブロックを抜けたら実行するコードを前もって動的に設定する)をやる。 see also http://search.cpan.org/~mlehmann/Guard-1.022/Guard.pm
<?php
class Guard{
public $destruct;
public function __construct($callable){
$this->destruct = $callable;
}
public function __destruct(){
call_user_func($this->destruct);
}
}
@uzulla
uzulla / ThumbnailImageMaker.php
Last active August 29, 2015 13:57
あるライブラリと一部機能のサブセット互換のサムネイル生成ライブラリ(これくらいちがってたらGPL違反にならないですかね???)参考:http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/
<?php
/**
* ThumbnailImageMaker
*
* require GD
*
* @author Junichi Ishida <[email protected]>
* @license MIT License
* @version v0.0.1
@uzulla
uzulla / funny.php
Created March 9, 2014 08:57
「継承できるテンプレートとは」(ネタです)
<?php
class Mother {
static $html = '
<html>
<body>
{{content}}
</body>
</html>
';
public function __construct($my_name=null, $var=null){
@uzulla
uzulla / match_test.php
Created January 28, 2014 13:14
WAFのRouterなどで、'/test/:hoge/'とか指定してルートを登録するときそれを正規表現にコンパイルするやつ http://uzulla.hateblo.jp/entry/2014/01/28/215038
<?php
$pattern = '/test/:id/';
$regexPattern = preg_replace_callback(
'#:([\w]+)#',
function($m){
return '(?P<'.$m[1].'>[^/]+)';
},
$pattern
);
@uzulla
uzulla / getip.php
Created January 22, 2014 20:57
get REMOTE_ADDR (ip address)
public function getRemoteIP(){
$_SERVER_UC = array_change_key_case($_SERVER, CASE_UPPER);
if(isset($_SERVER_UC['HTTP_CLIENT_IP']))
return $_SERVER_UC['HTTP_CLIENT_IP'];
if(isset($_SERVER_UC['HTTP_X_CLUSTER_CLIENT_IP']))
return $_SERVER_UC['HTTP_X_CLUSTER_CLIENT_IP'];
if(isset($_SERVER_UC['HTTP_FORWARDED_FOR']))
return $_SERVER_UC['HTTP_FORWARDED_FOR'];
@uzulla
uzulla / emlx_format
Created January 13, 2014 02:29
mac mail.appでつかわれたりするemlxフォーマットのメモ、 自分で調べた物なので、信用性は薄い
基本的にはemlフォーマット(メールのソースである)
改行コードはどうやらLFである
一行目にメールソースの長さが入る、
つまり後述のXMLが開始するまでのバイト数、ただし先頭の数字(サイズ)の行を除く
なので、ボディサイズをいきなりカウントして、
その数字を先頭にいれて、ボディをいれて、XMLをつっこめばよい。