Skip to content

Instantly share code, notes, and snippets.

@javisantana
javisantana / test.js
Created May 9, 2011 18:17
quick'n'dirty javascript testing framework
// test utils
function assert(desc, b) {
document.write("**" + desc + "</br>" );
document.write(b ? "OK": "FAIL");
document.write("</br>");
document.write("</br>");
}
function test(desc, fn) {
assert(desc, fn())
@javisantana
javisantana / js_test.html
Created May 10, 2011 21:28 — forked from raul/js_test.html
quick'n'dirty javascript testing framework
<!doctype html>
<html lang=en>
<head>
<title>quick'n'dirty js testing framework</title>
<meta charset=utf-8>
<style type="text/css" media="screen">
h1{ font: 1.5em Helvetica; }
p { font: .9em courier; padding: .5em 1em; margin: 0;}
.result { margin-top: 1px; }
@javisantana
javisantana / gist:1024626
Created June 14, 2011 10:13 — forked from jorgebastida/gist:1023399
Tuenti ejercicio 1
import re
from operator import add, mul, sub
import sys
ops = {'=': add, '@': sub, '#': mul }
r = '\^(.)\s*(\-?\d+)\s*(\-?\d+)\$'
def e(g):
g = g.groups()
@javisantana
javisantana / gist:1024886
Created June 14, 2011 13:25
small context manager to log timing on http request (or whatever)
timing_logger = logging.getLogger('something')
@contextmanager
def timing(name):
t1 = datetime.now()
try:
yield
finally:
t1 = datetime.now() - t1
t1 = t1.seconds + t1.microseconds/1e6
@javisantana
javisantana / gist:1025486
Created June 14, 2011 18:09
small templating languaje
import re
def template(text, vars):
def _t(v):
v = v.groups()[0]
return vars.get(v, '')
return re.sub('\{([^\}]*)\}', _t, text)
print template("hello, my name is {name}", {'name': 'javi'})
# please, do not use this code, instead you could use http://docs.python.org/library/string.html#template-strings
@javisantana
javisantana / heroku_tornado.sh
Created June 15, 2011 14:41
tornado on heroku
virtualenv --no-site-packages .
source bin/activate
bin/pip install tornado
bin/pip freeze > requirements.txt
mkdir app
git init
cat >.gitignore <<EOF
bin/
include/
lib/
@javisantana
javisantana / results.txt
Created June 30, 2011 15:31
tile processing
0 171556606.0
1 10728346.0
2 5160568.0
3 2201743.0
4 934465.0
5 492517.0
6 626750.0
7 1387458.0
8 5171130.0
9 1478714.0
@javisantana
javisantana / resource.py
Created July 12, 2011 17:24
flask REST
from flask import abort, request, Response
class Resource(object):
""" CRUD resource """
def create(self): self._not_implemented()
def list(self): self._not_implemented()
def get(self, id): self._not_implemented()
def delete(self, id): self._not_implemented()
@javisantana
javisantana / lines.html
Created July 14, 2011 07:07
small lines effect on canvas
<!doctype html>
<html>
<head>
<title>G</title>
<meta charset="utf-8" />
</head>
<body>
<!-- <canvas id="c"></canvas> -->
<script>
var G = function(init, loop, options) {
@javisantana
javisantana / gist:1118009
Created August 1, 2011 11:59
fullscreen gvim
if has('gui_running')
set background=light
colorscheme solarized
set guifont=Monaco:h14
set guioptions-=r
set guioptions-=L
set guioptions-=T
set nu
noremap <Leader>f <ESC>:set invfu<CR>
set fuopt+=maxhorz