Skip to content

Instantly share code, notes, and snippets.

@nakamuray
nakamuray / gist:970943
Created May 13, 2011 17:26
フォーカスがあたっているターミナル上のシェルの CWD で新しくターミナルを開く XMonad 用関数
getWindowPID :: Window -> X (Maybe Int)
getWindowPID w = withDisplay $ \dpy -> do
atom <- getAtom "_NET_WM_PID"
ret <- io $ getWindowProperty32 dpy atom w
case ret of
Just (pid:_) -> return $ Just $ fromIntegral pid
_ -> return Nothing
spawnTerminalInCWD :: X ()
spawnTerminalInCWD = do
@nakamuray
nakamuray / Object.class.php
Created August 26, 2011 07:58
PHP object system written in PHP
<?php
function mro($class) {
$classes = class_parents($class);
array_unshift($classes, $class);
return $classes;
}
function get_parent($class) {
@nakamuray
nakamuray / Type.class.php
Created August 29, 2011 10:59
python like object system on php
<?php
class Type extends Object {
public $__name__;
public $__base__;
public $__bases__;
public $__mro__;
function __construct() {
// FIXME: construct with Type class itself
@nakamuray
nakamuray / u-nya-.zsh
Created April 20, 2012 15:52
這いよるうんたらかんたら
_U_NYA_STATE=1
_U_NYA_PATTERN=(
'(」・ω・)」うー! '
'(/・ω・)/にゃー!'
'(」・ω・)」うー! '
'(/・ω・)/にゃー!'
'(」・ω・)」うー! '
'(/・ω・)/にゃー!'
"Let's\(・ω・)/にゃー!"
)
@nakamuray
nakamuray / pass-as-is.zsh
Created June 29, 2012 06:42
introduce '$' to zsh command line, which make rest of buffer as a single argument "as-is"
# pass-as-is
#
# introduce '$' to zsh command line, which make rest of buffer as a single argument "as-is"
#
# ex.)
# $ python -c $ print "I'm fine!"
# I'm fine!
#
# NOTE: real command line will remain in command history until you execute other command
def myif(b, then_block, else_block)
h = Hash.new(then_block)
h[false] = else_block
h[nil] = else_block
return h[b].call()
end
def mythen(&block)
return block
@nakamuray
nakamuray / kokomade.py
Created September 21, 2012 05:02
ここまで読んだ
#!/usr/bin/python
# vim: fileencoding=utf-8
'''ここまで読んだ
標準入力を読み出し、標準出力に書き込む。
エンターが押されたら、マーカーを表示する。
'''
import os
import sys
import tty
@nakamuray
nakamuray / instant_rst.vim
Created November 23, 2012 16:09
reST リアルタイムでレンダリングする vim script
python <<EOPython
import vim
class InstantReST(object):
from multiprocessing import Queue
queue = Queue()
process = None
last_rst = None
@nakamuray
nakamuray / async-http.vim
Created December 4, 2012 10:29
vim で非同期 HTTP リクエスト
python << EOP
from twisted.internet.error import ReactorAlreadyInstalledError
try:
from twisted.internet.gtk2reactor import install
install()
except ReactorAlreadyInstalledError:
pass
from twisted.internet import reactor
reactor.run()
@nakamuray
nakamuray / autoself.py
Created December 31, 2012 17:55
python で self 書かなくてもよくしてくれる君
import functools
import inspect
def self():
return inspect.currentframe().f_back.f_back.f_locals['self']
class AutoSelfMeta(type):
def __new__(cls, names, bases, attrs):