This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class A{ | |
public $obj; | |
public function __destruct() { | |
unset($this->obj); | |
} | |
} | |
class B{ | |
public $obj; | |
public function __destruct() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface Hoge{ | |
const MOGE = 'moge'; | |
} | |
class HogeImpl implements Hoge{ | |
public function __construct(){ | |
var_dump(self::MOGE); | |
} | |
} | |
new HogeImpl(); // "moge" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer