Skip to content

Instantly share code, notes, and snippets.

View hirokiky's full-sized avatar

Hiroki Kiyohara hirokiky

View GitHub Profile
@hirokiky
hirokiky / monolith_demo.html
Last active December 21, 2015 05:48
Demo page for 'monolith'. 'monolith' is a CSS, for providing a picture, and it's infomation. You can see that information when putting your mouse pointer over the picture. Here a live demo, check it out! http://jsfiddle.net/hzkdQ/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"><html>
<style type="text/css">
<!--
div.monolith {
position: relative;
width: 300px;
height: 400px;
@hirokiky
hirokiky / pocamono.py
Last active December 23, 2015 10:39
pocamono is a decorator for applying another decorator to a function. and it leaves a original (not decorated) function with name provided by a `original_name` argument.
def pocamono(wrappers, original_name=None):
def _dec(function):
if not original_name:
globals()['_' + function.__name__] = function
else:
globals()[original_name] = function
if isinstance(wrappers, list):
# TODO: Accept tuple, iterable too.
return reduce(lambda a, b: b(a), [function] + wrappers)
else:
@hirokiky
hirokiky / fizzbuzz.py
Last active December 25, 2015 01:39 — forked from podhmo/fizzbuzz.py
# -*- coding:utf-8 -*-
from __future__ import print_function
(lambda zero, one, succ, is_zero, pred, AND, IF, Y, undefined:
(lambda add, mul, sub:
(lambda GT, EQ:
(lambda rem, REP:
(lambda three, five, num_from_church:
(lambda fifteen, one_hundred:
(lambda fizzbuzz:
@hirokiky
hirokiky / assert_instance_updated.py
Last active December 25, 2015 05:59
Mixin class for TestCase to add method checking Django Model instance.utime updated or not.
class AssertInstanceUpdatedMixin(object):
""" Mixin class for TestCase to add method checking instance.utime updated or not.
"""
class AssertInstanceUpdatedContext(object):
def __init__(self, instance, test_case, model_class=None):
self.instance = instance
self.test_case = test_case
self.model_class = model_class or instance.__class__
def __enter__(self):
import re
eval_matcher = re.compile(r'<%([\s\S]+?)%>')
def render_template(template):
matched = eval_matcher.match(template)
assert matched is not None
repl_string = str(eval(matched.group(1)))
return eval_matcher.sub(template, repl_string)
@hirokiky
hirokiky / neverresposne.py
Created November 14, 2013 02:22
For some verifications.
from time import sleep
from wsgiref.simple_server import make_server
def never_response_app(environ, start_response):
sleep(2**10) # Forever sleeping
if __name__ == '__main__':
httpd = make_server('', 5000, never_response_app)
@hirokiky
hirokiky / onelineweb.py
Created November 15, 2013 00:45
One line Web application. Special thanks: @shomah4a
from wsgiref.simple_server import make_server; make_server('', 8888, lambda e, s: [s('200 Ok', []), 'hello'][1]).serve_forever()
@hirokiky
hirokiky / doc.py
Created November 22, 2013 06:34
removable decorator for python
def removable_decorators(*decorators):
def wrapper(func):
wrapped = reduce(lambda a, b: b(a), reversed(decorators + (func,)))
wrapped.original_func = func
return wrapped
return wrapper
@hirokiky
hirokiky / truth_table.py
Last active January 1, 2016 16:09
A truth table ASCII Art generator.
import sys
from itertools import product
def build_truth_table(inputs):
"""
>>> print(build_truth_table(['P', 'Q', 'S']))
P | Q | S |
-------+-------+-------+
True | True | True |
@hirokiky
hirokiky / alchemydemo.rst
Last active January 4, 2016 13:39
Tying Mapping class inheritance with SQLAlchemy.

requirements

  • SQLAlchemy==0.9.1
python initialdb.py
python demo.py