Skip to content

Instantly share code, notes, and snippets.

View toshimaru's full-sized avatar

Toshimaru toshimaru

View GitHub Profile
@toshimaru
toshimaru / SplClassLoader.php
Last active October 12, 2015 06:37 — forked from jwage/SplClassLoader.php
SplClassLoader implementation
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
* $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine');
@toshimaru
toshimaru / gist:3985903
Created October 31, 2012 08:44
check 8-digits-date
<?php
/**
* check 8-digits-date is correct
*
* @param string $date
* @return boolean
*/
protected function checkDate($date)
{
$len = strlen($date);
@toshimaru
toshimaru / convertDate.php
Created November 6, 2012 09:16
(php) date_parse_from_format
<?php
/**
* convert 20120102 to 2012-1-2
*
* @return string
*/
function convertDate($date) {
$dateInfo = date_parse_from_format('Ymd', $date);
return $dateInfo['year'] . '-' . $dateInfo['month'] . '-' . $dateInfo['day'];
}
@toshimaru
toshimaru / multiple_host_tail.sh
Last active October 12, 2015 19:28
複数ホストに ssh しながら tail -F
#!/bin/bash
#refs. http://blog.64p.org/entry/2012/08/24/165701
function kill_children {
pkill -P $$;
wait;
}
trap "kill_children" EXIT
@toshimaru
toshimaru / gist:4098368
Created November 17, 2012 18:08
C# Func<> sample.
class Program
{
static void Main(string[] args)
{
Func<int, int, int> abc = (n, i) => { return (n * i); };
Console.WriteLine(abc(3, 4));
/**
* output:
* 12
@toshimaru
toshimaru / gist:4158748
Created November 28, 2012 02:56
[PHP]test function
<?php
$test = function ($expect, $actual) {
if ($expect === $actual) {
echo 'OK, ';
} else {
echo "NG expect:{$expect} actual:{$actual} <br>";
}
};
@toshimaru
toshimaru / timer.php
Last active October 13, 2015 11:28
パフォーマンス計測コード
<?php
$time_start = microtime(true);
// 何か重い処理
$time = microtime(true) - $time_start;
echo "{$time} 秒";
$.ajax({
url: "ajax.html",
success: function(data) {
alert('success!!');
},
error: function(data) {
alert('error!!!');
}
});
@toshimaru
toshimaru / select.php
Last active December 10, 2015 05:48
compare select query (mysql).
these queries are same run time.
@toshimaru
toshimaru / .bashrc
Last active December 10, 2015 23:08 — forked from henrik/.bashrc
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/<\1$(parse_git_dirty)>/"