Skip to content

Instantly share code, notes, and snippets.

View akkunchoi's full-sized avatar

Akiyoshi Tanaka akkunchoi

View GitHub Profile
#!/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
interface Hoge{
const MOGE = 'moge';
}
class HogeImpl implements Hoge{
public function __construct(){
var_dump(self::MOGE);
}
}
new HogeImpl(); // "moge"
<?php
class A{
public $obj;
public function __destruct() {
unset($this->obj);
}
}
class B{
public $obj;
public function __destruct() {
#!/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 / yaruki.rb
Created October 8, 2011 01:50
やる気がない時に実行するコマンド
#!/usr/bin/env ruby
list = %w(
部屋を掃除しろ!
部屋を片付けろ!
資料を整理しろ!
タスクを整理しろ!
メモを整理しろ!
「あとで読む」でも読んどけ!
@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
@akkunchoi
akkunchoi / watir_example.rb
Created February 2, 2012 15:34
watir example
require 'rubygems'
require 'watir-webdriver'
browser = Watir::Browser.new
browser.goto 'http://bit.ly/watir-example'
browser.text_field(:name => 'entry.0.single').set 'Watir'
browser.button(:name => 'submit').click
puts browser.title == 'Thanks!'