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);
#!/bin/sh
function http_status(){
curl -LI $1 -o /dev/null -w '%{http_code}\n' -s
}
function alive(){
code=`http_status $1`
if [ "$code" != "200" ]; then
echo "$1 is $code!" | mail -s "[Alert] $1 is $code" sample@example.com
fi
@akkunchoi
akkunchoi / jquery.ticker.js
Created October 16, 2014 05:49
jquery.ticker.js
(function(){
/*
thanks to http://on-ze.com/archives/618, http://on-ze.com/archives/618
<div class="ticker" rel="fade"><!-- fade or roll or slide-->
<ul>
<li>テキスト1</li>
<li>テキスト2</li>
<li>テキスト3</li>
</ul>
#!/bin/sh
# pearc: wrapped pear command to install a local directory
#
# 1) pearc init [dir] [config_file]
# 2) pearc [pear_command..]
#
config=$(pwd)/.pearrc
if [ $1 = "init" ]; then
target=$(pwd)
<?php
// The Difference between json_encode/json_decode and Zend_Json
$arr = array('a' => 'b', 'c' => 'd');
$arrJson = json_encode($arr);
var_dump(json_decode($arrJson)); // stdClass
$arr = array('a' => 'b', 'c' => 'd');
$arrJson = Zend_Json::encode($arr);
var_dump(Zend_Json::decode($arrJson)); // array
<?php
class A{
public $obj;
public function __destruct() {
unset($this->obj);
}
}
class B{
public $obj;
public function __destruct() {
<?php
interface Hoge{
const MOGE = 'moge';
}
class HogeImpl implements Hoge{
public function __construct(){
var_dump(self::MOGE);
}
}
new HogeImpl(); // "moge"
#!/usr/bin/ruby
require 'time'
list = `mysql -uroot -e "show full processlist"`
print list
list.split("\n").each { |line|
d = line.split(" ", 8)
if d[4] == "Query" and d[5].to_i >= 60
print "kill #{d[0]}\n"
@akkunchoi
akkunchoi / download-images.js
Created October 2, 2011 03:25
chrome image download bookmarklet
// This script is modified from http://d.hatena.ne.jp/Griever/20100904/1283603283
// The original happens a error "TypeError: object is not a function" on chrome 14
javascript:(function(){
var regexp = /https?:\/\/[^&?#]+?\.(?:jpe?g|png|gif|bmp)(?:$|\b)/i;
var array = Array.prototype.slice.call(document.querySelectorAll(
'a[href*=".png"], a[href*=".gif"], a[href*=".jpg"], a[href*=".jpeg"], a[href*=".bmp"],' +
'a[href*=".PNG"], a[href*=".GIF"], a[href*=".JPG"], a[href*=".JPEG"], a[href*=".BMP"]'
));
for (var i = 0, l = array.length; i < l; i++) {
@akkunchoi
akkunchoi / download_as_file.rb
Created February 2, 2012 15:29
download file
require 'open-uri'
def download_as_file(url)
filename = File.basename(url)
open(filename, 'wb') do |file|
open(url) do |data|
file.write(data.read)
end
end
end