Skip to content

Instantly share code, notes, and snippets.

View suin's full-sized avatar
😃

suin

😃
View GitHub Profile
<?php
/**
* A simple description for this script
*
* PHP Version 5.2.0 or Upper version
*
* @package SampleGetBlockContent
* @author Hidehito NOZAWA aka Suin <http://ryus.co.jp>
* @copyright 2010 Hidehito NOZAWA
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2
@suin
suin / gist:1170149
Created August 25, 2011 07:17
【混ぜるな!危険】mysql_connectとPDOを併用した場合、トランザクションが機能しないです
<?php
/*
CREATE TABLE `transaction_test` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
*/
@suin
suin / gist:1196652
Created September 6, 2011 05:15
[PHP5.4] Arrayの短い版どう書く?
<?php
array(
'aaaa' => 'aaaa',
'bbbb' => 'bbbb',
);
// はいいけど
[
'aaaa' => 'aaaa',
@suin
suin / FooBar.js
Created November 5, 2011 12:48
registerEventListeners()はどこでよべばいいんだろう? ref: http://qiita.com/items/882
/**
* @constructor
*/
var FooBar = function() {};FooBar.prototype = { /**
* イベントリスナ登録
*/
registerEventListeners: function() {
var self = this;
$(document).delegate('.foobar', 'click', function(event){ return self._foobarClickEventHandler(this, event); });
}, /**
@suin
suin / file0.php
Created November 15, 2011 13:12
HTTP_ACCEPT_LANGUAGEをパースする関数 ref: http://qiita.com/items/1076
<?php
$cases = array(
'ja',
'ja-jp',
'ja;q=1',
'da, en-gb;q=0.8, en;q=0.7',
);
foreach ( $cases as $case )
{
@suin
suin / file0.txt
Created November 20, 2011 07:33
[PHP] ReflectionClassで親クラスのクラス名を取得してみる ref: http://qiita.com/items/1106
<?php
class Foo
{
}
class Bar extends Foo
{
}
@suin
suin / file0.txt
Created November 20, 2011 07:48
自分のクラスで定義しているメソッドのみを返す: ReflectionClassを拡張して ref: http://qiita.com/items/1107
<?php
class Foo
{
public function aaa()
{
}
}
class Bar extends Foo
@suin
suin / file0.php
Created December 6, 2011 02:24
制御文字を取り除く方法(改行コードは保持) ref: http://qiita.com/items/1295
<?php
preg_replace('/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F]/', '', $string); // The line feed and carriage return will be saved.
@suin
suin / file0.txt
Created December 6, 2011 13:15
cron + uptimeでロードアベレージのログを取るやつ ref: http://qiita.com/items/1305
echo `date +"%Y-%m-%d %H:%M:%S"` `uptime | awk '{print $10, $11, $12}'` >> /var/log/uptime.log
@suin
suin / file0.php
Last active February 10, 2016 04:59
mb_levenshtein 二つの文字列のレーベンシュタイン距離を計算する(マルチバイト対応版) ref: http://qiita.com/suin/items/a0a8227addad11ff2ea7
<?php
function mb_levenshtein($string1, $string2)
{
$tokens1 = preg_split('/(?<!^)(?!$)/u', $string1);
$tokens2 = preg_split('/(?<!^)(?!$)/u', $string2);
$tokens = array_unique(array_merge($tokens1, $tokens2));
if ( count($tokens) > 26 )
{