Key points:
- Using jQuery, jQuery UI and flot
- Site is static, no backend needed
- Data is generated to a .js file
As usual, the code is in bitbucket.
If it won't be simple, it simply won't be. [Hire me, source code] by Miki Tebeka, CEO, 353Solutions
import ingress ingress.install()
usage: avrocat [-h] [-n COUNT] [-s SKIP] [-f {json,csv}] [--header]
[--filter FILTER] [--schema]
filename
`cat` for Avro files
positional arguments:
filename avro file (- for stdin)
optional arguments:
-h, --help show this help message and exit
-n COUNT, --count COUNT
number of records to print
-s SKIP, --skip SKIP number of records to skip
-f {json,csv}, --format {json,csv}
record format
--header print CSV header
--filter FILTER filter records (e.g. r['age']>1)
--schema print schema--langdef=XML --langmap=XML:.xml --regex-XML=/id="([a-zA-Z0-9_]+)"/\1/d,definition/
#!/usr/bin/env python
from functools import wraps
import json
from cherrypy import response, expose
def jsonify(func):
'''JSON decorator for CherryPy'''
@wraps(func)
def wrapper(*args, **kw):
value = func(*args, **kw)
response.headers["Content-Type"] = "application/json"
return json.dumps(value)
return wrapper
def example():
from cherrypy import quickstart
from datetime import datetime
class Time:
@expose
@jsonify
def index(self):
now = datetime.now()
return {
"date" : now.strftime("%Y-%m-%d"),
"time" : now.strftime("%H:%M"),
"day" : now.strftime("%A"),
}
quickstart(Time())
if __name__ == "__main__":
example()
$curl -i localhost:8080
HTTP/1.1 200 OK
Date: Mon, 31 Jan 2011 03:18:34 GMT
Content-Length: 56
Content-Type: application/json
Server: CherryPy/3.1.2
{"date": "2011-01-30", "day": "Sunday", "time": "19:18"}
#!/bin/bash
# Generate svn style diff for current hg feature branch
branch=$(hg branch)
if [ -z $branch ]; then
echo "error: not a mercurial repo" 1>&2
exit 1
fi
if [ "$branch" == "default" ]; then
echo "error: in default branch" 1>&2
exit 1
fi
hg diff --svn -r default > ${branch}.patch
#!/usr/bin/env python
'''Command line interface to Google calculator
gcalc 100f c -> 37.7777778 degrees Celsius
'''
# Idea taken from http://bit.ly/dVL4H3
import json
from urllib import urlopen
import re
def main(argv=None):
import sys
from optparse import OptionParser
argv = argv or sys.argv
parser = OptionParser("%prog FROM TO\n\t%prog 100f c")
opts, args = parser.parse_args(argv[1:])
if len(args) != 2:
parser.error("wrong number of arguments") # Will exit
url = "http://www.google.com/ig/calculator?q=%s=?%s" % tuple(args)
try:
# We decode to UTF-8 since Google sometimes return funny stuff
result = urlopen(url).read().decode("utf-8", "ignore")
# Convert to valid JSON: {foo: "1"} -> {"foo" : "1"}
result = re.sub("([a-z]+):", '"\\1" :', result)
result = json.loads(result)
except (ValueError, IOError), e:
raise SystemExit("error: %s" % e)
if result["error"]:
raise SystemExit("error: %s" % result["error"])
print result["rhs"]
if __name__ == "__main__":
main()
#!/bin/bash
# Template for "svn commit"
# Add "export SVN_EDITOR=/path/to/this/file" to your .bashrc
# Fail one first error
set -e
filename=$1
editor=${EDITOR-vim}
mv $filename /tmp
# The template
cat << EOF > $filename
Bug #
Reviewed-by:
EOF
# Add file list to template
cat /tmp/$filename >> $filename
mtime=$(stat -c %y $filename)
$editor $filename
# Restore old file so svn will see it didn't change
if [ "$(stat -c %y $filename)" == "$mtime" ]; then
mv -f /tmp/$filename $filename
fi