Skip to content

Instantly share code, notes, and snippets.

@nakamuray
nakamuray / statefulcallbacks.py
Created October 30, 2013 12:56
state monad like feature for python, with deferred support (it's not monad at all, though)
from __future__ import print_function
import functools
import types
from twisted.internet import defer
__all__ = ['StatefulCallbacks', 'statefulCallbacks', 'returnValue']
@nakamuray
nakamuray / state.py
Created October 29, 2013 13:10
state monad like feature for python (it's not monad at all, though)
import functools
import types
class State(object):
def __init__(self, gen, args, kwargs):
self._gen = gen
self._args = args
self._kwargs = kwargs
@nakamuray
nakamuray / __init__.py
Created October 26, 2013 03:11
[WIP] monad for python
from monad import *
@nakamuray
nakamuray / nautilus-disable-recursive-search.patch
Created July 4, 2013 08:52
I don't want nautilus to search directory recursively.
--- nautilus-3.8.2/libnautilus-private/nautilus-search-directory.c.orig 2013-07-04 17:39:05.893879085 +0900
+++ nautilus-3.8.2/libnautilus-private/nautilus-search-directory.c 2013-07-04 17:39:12.226879030 +0900
@@ -171,7 +171,7 @@
nautilus_search_engine_model_set_model (model_provider, search->details->base_model);
simple_provider = nautilus_search_engine_get_simple_provider (search->details->engine);
- g_object_set (simple_provider, "recursive", TRUE, NULL);
+ g_object_set (simple_provider, "recursive", FALSE, NULL);
reset_file_list (search);
@nakamuray
nakamuray / tornado_wsgi_pool.py
Created June 5, 2013 08:27
running WSGI application on Tornado using thread pool
from concurrent import futures
from tornado import escape, gen, web
from tornado.wsgi import WSGIContainer
class WSGIHandler(web.RequestHandler):
thread_pool_size = 10
def initialize(self, wsgi_application):
self.wsgi_application = wsgi_application
@nakamuray
nakamuray / Common.hs
Last active December 17, 2015 19:38
指定されたファイルもしくは標準入力から正規表現にマッチする部分を抜きだし、その出現回数を表示する。
{-# LANGUAGE FlexibleContexts #-}
module Common
( Result
, ResultPair
, Regex -- re-export
, match
, addResult
, emptyResult
, showResultPair
, main_
@nakamuray
nakamuray / tornado-on-twisted.py
Created May 16, 2013 11:37
twisted 上で tornado を web application framework として利用するテスト
# try to use tornado as a web application framework on twisted
# http://twistedmatrix.com/pipermail/twisted-python/2011-January/023296.html
from concurrent.futures import Future
from twisted.internet import defer
def futureFromDeferred(deferred):
assert isinstance(deferred, defer.Deferred)
f = Future()
@nakamuray
nakamuray / httpd.go
Created April 3, 2013 14:43
go はじめました。
package main
import (
"bytes"
"fmt"
"io"
"net"
"os"
"path"
"path/filepath"
@nakamuray
nakamuray / httpstatus.zsh
Created February 21, 2013 07:38
httpstatus コマンドで(略)
function zaw-src-httpstatus() {
candidates=(
"100 Continue"
"101 Switching Protocols"
"102 Processing"
"200 OK"
"201 Created"
"202 Accepted"
"203 Non-Authoritative Information"
"204 No Content"
@nakamuray
nakamuray / maybe.py
Created January 3, 2013 14:51
python の decorator と generator で maybe monad みたいなの。 最後に yield した値が関数を置き換える。 None が yield されたらその場で終わり。 decorator が関数を返さないという最低にキモいことをしているので、実用性はない。
def maybe(gen):
it = gen()
v = next(it)
try:
while v is not None:
v = it.send(v)
except StopIteration:
return v