Skip to content

Instantly share code, notes, and snippets.

View toshimaru's full-sized avatar

Toshimaru toshimaru

View GitHub Profile
<?php
// add exception_handle
function exception_handler($exception) {
echo "Uncaught exception: file:{$exception->getFile()} line:{$exception->getLine()} {$exception->getMessage()}", "\n";
}
set_exception_handler('exception_handler');
#!/bin/sh
PS3="Which host? > "
select host in `cat ~/.ssh/config | egrep '^Host' | cut -d ' ' -f 2`; do
[[ $host ]] && {
echo "ssh connect to $host"
ssh $host
break;
}
done
@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)>/"
@toshimaru
toshimaru / select.php
Last active December 10, 2015 05:48
compare select query (mysql).
these queries are same run time.
$.ajax({
url: "ajax.html",
success: function(data) {
alert('success!!');
},
error: function(data) {
alert('error!!!');
}
});
@toshimaru
toshimaru / timer.php
Last active October 13, 2015 11:28
パフォーマンス計測コード
<?php
$time_start = microtime(true);
// 何か重い処理
$time = microtime(true) - $time_start;
echo "{$time} 秒";
@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 / 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 / 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 / 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'];
}