Skip to content

Instantly share code, notes, and snippets.

View letoh's full-sized avatar
💭
I may be slow to respond.

letoh letoh

💭
I may be slow to respond.
View GitHub Profile
#include <stdio.h>
#include "html.h"
int main(int argc, char *argv[])
{
html(
head(
title("Site Title"),
script("http://test.com/test.js"),
static void _head(void)
{
const char *v;
utils_page_head("Demo");
raw(<script type="text/javascript">);
echo("var _debug = 0;");
echo("var cgi_var = ");
cgi_json();
echo(";");
raw(</script>);
@letoh
letoh / gist:2953452
Created June 19, 2012 10:35
coroutine
def coroutine(f):
_co = f()
return lambda : _co.next
@coroutine
def foo():
for i in xrange(5):
yield i
a = foo()
@letoh
letoh / funcsig.py
Created June 22, 2012 08:02
simple function signature checking in python
from itertools import izip
def isiterable(o):
try:
it = iter(o)
except TypeError:
return False
return True
class Args(object):
# http://www.ptt.cc/bbs/Python/M.1349181219.A.3C5.html
def main():
sum = lambda d: (lambda f,a:f(f,a))((lambda s,l,a=0:a if not l else s(s,l[1:],a+l[0])),d)
print sum([3,3,2,2,1])
main()
void print_num(int n)
{
unsigned char buf[12] = {0}, *p = buf + 10;
char minus = (n < 0);
if(n < 0) n = -n;
while(n)
{
*p-- = '0' + (n % 10);
n /= 10;
}
@letoh
letoh / make.rules
Created November 13, 2012 05:15
makefile for avr project
MCU ?= attiny2313
PROJ = test
TARGET = $(PROJ).hex # $(PROJ).bin
INC =
LIBS =
include ../000_common/make.rules
@letoh
letoh / gist:4072651
Created November 14, 2012 15:06
dict test
http://www.doughellmann.com/articles/misc/dict-performance/
$ ./pypy-c --version
Python 2.7.3 (e537e0093563, Oct 13 2012, 22:21:46)
[PyPy 1.9.1-dev0 with GCC 4.4.4]
$ ./pypy-c -m timeit -n 1000000 -r 5 -v 'dict()'
raw times: 0.0186 0.00177 0.00134 0.00134 0.00234
1000000 loops, best of 5: 0.00134 usec per loop
@letoh
letoh / maze.py
Created December 5, 2012 05:41
one-liner maze
#!/usr/bin/python
# -*- encoding: big5 -*-
# http://10print.org/
from random import random as r
print "\n".join(["".join([["\xa2\xac", "\xa2\xad"][int(0.5+r())] for i in xrange(40)]) for j in xrange(24)])
"""
╲╱╱╲╲╱╱╲╱╲╲╲╱╱╲╲╲╱╱╱╱╱╱╲╱╱╲╱╲╲╱╲╱╱╲╲╲╱╲╱
#!/usr/bin/python
import pygame
from pygame import mixer as mixer
import sys
if len(sys.argv) == 1:
sys.exit()
try:
pygame.init()