Skip to content

Instantly share code, notes, and snippets.

@numberoverzero
numberoverzero / Small timer.py
Last active December 20, 2016 19:47
Updated noop callback to correctly handle multiple args.
import time
def timer():
start = time.time()
return lambda: time.time() - start
def timed(callback=None):
if callback is None:
callback = lambda *a, **kw: None
def wrapper(func):
def wrapped_call(*args, **kwargs):
@joni
joni / toUTF8Array.js
Last active May 14, 2024 09:23
toUTF8Array: Javascript function for encoding a string in UTF8.
function toUTF8Array(str) {
var utf8 = [];
for (var i=0; i < str.length; i++) {
var charcode = str.charCodeAt(i);
if (charcode < 0x80) utf8.push(charcode);
else if (charcode < 0x800) {
utf8.push(0xc0 | (charcode >> 6),
0x80 | (charcode & 0x3f));
}
else if (charcode < 0xd800 || charcode >= 0xe000) {