Skip to content

Instantly share code, notes, and snippets.

def choose(n, k):
"""
A fast way to calculate binomial coefficients by Andrew Dalke (contrib).
"""
if 0 <= k <= n:
ntok = 1
ktok = 1
for t in xrange(1, min(k, n - k) + 1):
ntok *= n
ktok *= t
def fib_n_step_aux(n, k, memo):
if k <= 0:
return 0
if k in [1, 2]:
return 1
if k not in memo:
res = 0
for i in range(1, n + 1):
res += fib_n_step_aux(n, k - i, memo)
memo[k] = res
@defacto133
defacto133 / tmt20ii_status.php
Last active December 7, 2019 07:33
Get TM-T20II Epson ASB status through UDP socket
/*
* $status = {
* "status": "online" | "offline",
* "cover": "open" | "closed", (opt)
* "feeding": "feeding" | "not", (opt)
* "autocutterError": "error" | "not", (opt)
* "unrecoverableError": "error" | "not", (opt)
* "recoverableError": "error" | "not", (opt)
* "paper": "paperEnd" | "paperPresent" (opt)
* }