Skip to content

Instantly share code, notes, and snippets.

@yanolab
yanolab / lineon.py
Created July 29, 2011 03:46
support __line__ vriable.
# -*- coding: utf-8 -*-
__doc__ = """
usage:
python lineon.py somefile.py
or
# write your top of source.
lineon.apply(sys)
@yanolab
yanolab / html_fibo.patch
Created August 1, 2011 03:56
apply patch to html_fibo.py
--- html_fibo.orig 2011-08-01 12:51:29.063696436 +0900
+++ html_fibo.py 2011-08-01 12:50:58.703267469 +0900
@@ -2,6 +2,8 @@
The most complicate ever way to produce an HTML list of fibonacci numbers
"""
+import gc
+
def fibo():
a, b = 1, 1
@yanolab
yanolab / benchmark_filter.py
Created August 8, 2011 07:14
benchmark of builtin filter function
# -*- coding: utf-8 -*-
from timeit import Timer
import random
import string
import sys
def redef_builtin_filter(pred, iterable):
"""redefined builtin filter function"""
ret = [x for x in iterable if pred(x)]
@yanolab
yanolab / mkproj.sh
Created September 8, 2011 01:37
create django-nonrel first project.
#!/bin/bash
hg clone https://bitbucket.org/wkornewald/django-nonrel
hg clone https://bitbucket.org/wkornewald/djangoappengine
hg clone https://bitbucket.org/wkornewald/djangotoolbox
hg clone https://bitbucket.org/twanschik/django-autoload
hg clone https://bitbucket.org/wkornewald/django-dbindexer
hg clone https://bitbucket.org/wkornewald/django-testapp
mkdir $1
@yanolab
yanolab / .emacs
Created November 11, 2011 02:52
my emacs settings
;;;
;;; キーバインド
;;;
;;; undo
(define-key global-map (kbd "C-z") 'undo)
;;; コメント切り替え
(define-key global-map (kbd "C-c ;") 'comment-or-uncomment-region)
;;;
@yanolab
yanolab / unless.patch
Created December 8, 2011 08:09
add unless stmt to pypy
diff -r c62cca56f289 pypy/interpreter/pyparser/pytokenizer.py
--- a/pypy/interpreter/pyparser/pytokenizer.py Tue Dec 06 18:47:03 2011 +0900
+++ b/pypy/interpreter/pyparser/pytokenizer.py Thu Dec 08 13:30:38 2011 +0900
@@ -169,7 +169,7 @@
if start == end:
raise TokenError("Unknown character", line,
lnum, start + 1, token_list)
-
+ bpos = pos
pos = end
@yanolab
yanolab / fizzbuzz.py
Created December 15, 2011 03:53
fizzbuzz
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def main(maxnum):
for idx in xrange(1, maxnum+1):
val = idx
if idx % 3 == 0:
@yanolab
yanolab / pypypcre.py
Created December 19, 2011 09:11
pcre for pypy
""" libpcre wrapping"""
from pypy.rpython.tool import rffi_platform
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from pypy.translator.platform import platform
from pypy.tool.ansi_print import ansi_log
import py
import os
@yanolab
yanolab / benchmark.txt
Created December 20, 2011 09:46
benchmark functional programming pypy1.6 - 1.7 and python2.7.1
Python2.7.1
==================
In [1]: import sys
In [2]: sys.version
Out[2]: '2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) \n[GCC 4.5.2]'
In [3]: import p002, p002_functional
In [4]: timeit p002.sumevenfibo(4000000)
@yanolab
yanolab / argguard.py
Created April 17, 2012 11:08
argment type guard
# -*- coding: utf-8 -*-
import operator
def guard(*guardArgs, **guardKw):
def _argGuard(f):
def _inner(*args, **kw):
argTypes = map(lambda x: type(x), args)
if not all(map(operator.eq, guardArgs, argTypes)):
raise Exception("Type Error: not match type {0}, {1}".format(guardArgs, argTypes))