Skip to content

Instantly share code, notes, and snippets.

@soundkitchen
soundkitchen / bind.js
Created August 15, 2012 11:38
js で this を保証する的な。
var Spam = function() {
// some construction...
};
Spam.prototype = {
// タイマーセットするメソッド
egg: function() {
var $_ = this;
setInterval(function() {
// 実際行いたい処理
@soundkitchen
soundkitchen / bytecodecache.py
Created June 2, 2012 11:05
redis な jinja2 の BytecodeCache など。
import logging
from jinja2 import BytecodeCache
from redis import Redis
class RedisBytecodeCache(BytecodeCache):
"""bytecode cache on redis for jinja2
"""
def __init__(self, host='localhost', port=6379, db=0, expire=0):
self._conn = Redis(host=host, port=port, db=db)
@soundkitchen
soundkitchen / create_application.py
Created May 23, 2012 10:08
werkzeug な redis 使った SessionStore とかとか
# vim: fileencoding=utf-8 :
from werkzeug.contrib.sessions import SessionMiddleware
from sessions import RedisSessionStore
def create_application():
app = Application()
app = SessionMiddleware(app, RedisSessionStore())
@soundkitchen
soundkitchen / jquery.mixi.js
Created March 22, 2012 08:21
まぁ、やっつけ仕事ぎみに :-P
(function ($) {
$.fn.mixi = function () {
var buildQueries = function (params) {
var queries = [];
for (var i = 0, n = 0; i < params.length;) {
var key = params[i++];
var value = params[i++];
if (!value) continue;
queries[n++] = key + "=" + encodeURIComponent(value);
@soundkitchen
soundkitchen / gist:2049773
Created March 16, 2012 12:00
FC Sequencer
// boot default server.
(
s = Server.default;
s.boot;
);
// define synth.
(
SynthDef("a", {|freq=440, amp=1, pan=0|
@soundkitchen
soundkitchen / gist:2048435
Created March 16, 2012 03:48
SC140 な感じ
{t=124;b=t/15;Pan2.ar(LFSaw.ar(Latch.ar(WhiteNoise.ar(24,39).midicps,Impulse.ar(b)),0,0.25),LFNoise0.ar(b))}.play
@soundkitchen
soundkitchen / run_cgi.py
Created October 11, 2011 10:06
CGIHTTPServer を / でも動くように野良化してみた。
#!/usr/bin/env python
# vim: fileencoding=utf-8 :
from CGIHTTPServer import test, CGIHTTPRequestHandler as BaseRequestHandler
class CGIHTTPRequestHandler(BaseRequestHandler):
def is_cgi(self):
path = self.path
if path.endswith('.py'):
try:
# vim: filetype=nginx :
# this line required.
daemon off;
(snip...)
@soundkitchen
soundkitchen / hotwo_use_logging.py
Created August 7, 2011 15:47
how to use python logging module
# import logging module.
import logging
# get default logger.
logger = logging.getLogger()
# set logging level.
# valid level is CRITICAL(FATAL), ERROR, WARNING(WARN), INFO and DEBUG.
logger.setLevel(logging.DEBUG)
$ pwd
/usr/local/src
$ curl -O http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
$ tar zxf ./Imaging-1.1.7.tar.gz
cd Imaging-1.1.7
$ ARCHFLAGS="-arch x86_64 -arch i386" python setup.py build