Skip to content

Instantly share code, notes, and snippets.

from functools import wraps
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
@wakhub
wakhub / image_converter.py
Created September 27, 2013 09:46
Image converter script for iPhone app and Android app
# http://stackoverflow.com/questions/9166400/convert-rgba-png-to-rgb-with-pil
# http://stackoverflow.com/questions/11484204/python-invert-image-with-transparent-background-pil-gimp
import argparse
import StringIO
import Image
import ImageOps
class Command(object):
@wakhub
wakhub / php54-new-syntax.php
Created April 4, 2013 16:07
PHP5.4 New Syntax Test
<?php
// http://php.net/manual/en/migration54.new-features.php
// http://php.net/manual/en/closure.bindto.php
class Sample {
public static function getArray() {
return [0b100, 0b101, 0b111];
}
@wakhub
wakhub / gist:3732400
Created September 16, 2012 13:11
Prototype based OOP in Python
import new
class ProtoObj(object):
def __init__(self, prototype={}):
self.prototype = prototype
self.__super_prototype = {}
def clone(self):
Obj = new.classobj('ProtoObjClone', (ProtoObj, ), {})
@wakhub
wakhub / quote.js
Created August 11, 2012 01:52
Quote Bookmarklet
// javascript:(function(js,d,s){d=document,s=function(src,sc,date){sc=d.createElement('script');sc.setAttribute('src',src);d.body.appendChild(sc);};date=(new Date()).getTime();s(js+'?'+date);})('//raw.github.com/gist/3319875/quote.js');
(function(){
var d = document,
t = d.getElementById('_____blockQuote');
if (!t) {
t = d.createElement('textarea');
t.setAttribute('id', '_____blockQuote');
d.body.appendChild(t);
}
with (t.style) {
@wakhub
wakhub / goodparts.js
Created August 3, 2012 14:35
Scripting Language: The Good Parts
var f = function(){
console.log('a')
};
f.foo = function(){
console.log('b');
};
f.foo.bar = function(){
console.log('c');
};
f.foo.baz = function(){
@wakhub
wakhub / gist:3236540
Created August 2, 2012 12:01
勘違いに関するメモ

ミームにおける突然変異のようなもの

竹内関数

ジョン・マッカーシーは竹内関数を記憶違いで[2] z を返すように変更し、これがTak関数として広まった。...

なぜλ計算はλ計算と呼ばれているのか

しかしチャーチの文章を出版するとき、当時の印刷技術ではハット付きの文字が印刷できなかった (!) ので、 ^x.2x+1
@wakhub
wakhub / Scala.scala
Created July 15, 2012 05:35
JavaScript Hoisting Test
var a = 0;
def f() = {
if (false) {
var a = 456;
}
println(a);
}
def f2() = {
@wakhub
wakhub / polyglot.pl.php.py.rb.cpp.m
Created June 8, 2012 13:58 — forked from SaswatPadhi/polyglot.pl.php.py.rb.cpp
PHP + Perl + Python + Ruby + C + C++ + Objective-C - polyglot
#/*<?php echo "PHP Code\n"; __halt_compiler();?> */
#include <stdio.h> /*
print (("b" + "0" == 0 and "Perl Code\n") or (0 and "Ruby Code\n" or "Python Code"));
__DATA__ = 1
"""""
__END__
@wakhub
wakhub / liger_and_tigon.py
Created May 26, 2012 15:30
Liger and Tigon
import random
class Female(object): pass
class Male(object): pass
def get_sex():
return [Female, Male][random.randint(0, 1)]
class Animal(object):