Skip to content

Instantly share code, notes, and snippets.

View akkunchoi's full-sized avatar

Akiyoshi Tanaka akkunchoi

View GitHub Profile
var EventEmitter = (function(){
var EventEmitter = function(){
this.listeners = {};
};
EventEmitter.prototype.emit = function(eventName){
var args = Array.prototype.slice.apply(arguments, [1]);
console.log(args);
if (this.listeners[eventName]){
for (var i = 0; i < this.listeners[eventName].length; i++){
this.listeners[eventName][i].apply(this, args);
<?php
// UTF-8文字列をUnicodeエスケープする。ただし英数字と記号はエスケープしない。
function unicode_encode($str) {
return preg_replace_callback("/((?:[^\x09\x0A\x0D\x20-\x7E]{3})+)/", "encode_callback", $str);
}
function encode_callback($matches) {
$char = mb_convert_encoding($matches[1], "UTF-16", "UTF-8");
$escaped = "";
for ($i = 0, $l = strlen($char); $i < $l; $i += 2) {
# coding: utf-8
#
require 'nkf'
p "a a".split(/\s+/) # ムリ
# 以下utf8の場合
# ref http://www.kkaneko.com/rinkou/ruby/hankaku.html
p NKF::nkf('-WwXm0', "アイウエオガギグゲゴ") # アイウエオガギグゲゴ
p NKF::nkf( '-Wwxm0Z0', "123" ) # 123

D3 sample

@akkunchoi
akkunchoi / angular-sample.md
Last active December 30, 2015 06:28
angular test

Angular sample code

<html><head><meta charset="UTF-8" /></head><body>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<a href="#" class="s">Success</a>
<a href="#" class="f">Fail</a>
<script>
var df = jQuery.Deferred();
df.then(function(){
alert('then');
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
function index(){
?><!doctype html>
<html>
<head>
<style type="text/css">
</style>
@akkunchoi
akkunchoi / hoge.html
Last active February 14, 2017 14:06
php tidy dom xpath
<html>
<section>hoge</section>
</html>
@akkunchoi
akkunchoi / HttpBasicAuth.php
Created November 8, 2013 03:36
This is a Slim middleware that provides http basic authentication.
<?php
/**
* This is a Slim middleware that provides http basic authentication.
*
* usage:
*
* $app->add(new HttpBasicAuth(array(
* 'users' => array('username' => 'password'),
* 'when' => function(\Slim\Http\Request $req, $res){
* return $req->getPathInfo() === '/admin';
class CsvFileIterator implements \Iterator{
protected $in;
protected $fp;
protected $index;
protected $current;
public function __construct($in, $options = array()) {
$this->in = $in;
$this->options = array_merge(array(
'column_separator' => ','
), $options);