Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
# codin: utf-8
# memoizing decorator
def memoize(function):
def _memoize(*args, _cache={}):
if args in _cache:
print('return using cached') # just for logging
return _cache[args]
# famous
def gcd(a, b):
if b:
return gcd(b, a%b)
return a
# non-recursive
def Gcd(a, b):
while b:
a, b = b, a%b
@matsub
matsub / clicker.py
Created June 21, 2015 10:52
windows、python用クリッカーです。e(keycode=69)押すと実行/停止の切り替え。waiting中にq(keycode=81)押すと終了。
# coding: utf-8
import sys
import time
from ctypes import windll
user32 = windll.user32
def detector(keycode=69):
@matsub
matsub / rename.sh
Last active June 19, 2016 06:16
rename bulk files to sequential numbers.
ary=(`ls -1 *.*`);for i in $(seq -w `ls -U1 | wc -l`);do;mv $ary[i] $i"."${ary[$i]##*.};done
@matsub
matsub / add_prefixes.scss
Created March 18, 2016 10:06
SCSS mixin to add vendor prefixes.
$PREFIXES: null, -moz-, -webkit-;
@mixin prefix($property, $value){
@each $prefix in $PREFIXES{
#{$prefix}#{$property}: $value;
}
}
@matsub
matsub / pre-push
Last active June 5, 2016 11:41
tweet automatically if you have new posts.
#!/bin/sh
# you need to write title in Front Matter of each post like:
# ---
# title: SOME TITLE
# ---
# require:
# https://github.com/shokai/tw
tw_ID="{{ your twitter ID registered in tw }}"
cname="{{ your GitHub Pages' CNAME }}"
@matsub
matsub / core.py
Created June 14, 2016 16:09
A Skype Bot with Skype4Py (in Python 2.x).
#!/usr/bin/env python2
# coding: utf-8
import re
import time
import logging
import functools
import Skype4Py
@matsub
matsub / mnist.py
Created June 29, 2016 02:18
A parser for MNIST handwritten digits dataset. see http://yann.lecun.com/exdb/mnist/.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import struct
class Image:
def __init__(self, dir='./'):
self.train_files = {
@matsub
matsub / gcd.py
Created November 17, 2016 17:46
gcd with lambda calculus on Python.
GCD = (lambda f: (lambda x: f(lambda y: x(x)(y)))(lambda x: f(lambda y: x(x)(y))))(lambda f: lambda a: lambda b: (lambda L: lambda M: lambda N: L(M)(N))((lambda L: (lambda x: lambda y: x(lambda x: x)) if L else (lambda x: lambda y: y))(b))(lambda g: f(b)(a%b))(a))
@matsub
matsub / README.md
Created December 14, 2016 14:36
An example to paginate with bottlepy.

about this

This is an example to paginate with bottlepy. To run this,

  1. install bottle and bottle_sqlite
  2. run python db_init.py
  3. run python bottle_pagination.py