Skip to content

Instantly share code, notes, and snippets.

View zeekay's full-sized avatar
💎
👋

Zach Kelling zeekay

💎
👋
View GitHub Profile
let square x = x *. x;;
square 10;;
def square(x): x**x
square(10)
let rec fib n = if n < 2 then 1 else fib(n-1) + fib(n-2);;
fib 10;;
rec fib(n):
@zeekay
zeekay / gist:1214650
Created September 13, 2011 18:43 — forked from rfreedman/gist:1214540
modified Mammal CoffeeScript example
class Mammal
constructor: (@species, @defining_char) ->
print: ->
"Hello I'm a #{@species}. I have #{@defining_char}."
cat = new Mammal 'cat', 'claws'
alert cat.print()
@zeekay
zeekay / 2014-history.txt
Last active September 27, 2015 05:18 — forked from kennethreitz/history.txt
Most used commands, in order by usage, since last install
› history 1 | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}'|sort -rn |head -n 20
338 vim
285 cd
104 rm
97 ack
96 git
82 brew
63 ssh
60 npm
59 v
@zeekay
zeekay / gist:1221752
Created September 16, 2011 10:12
bottle_websocket.py
from bottle import ServerAdapter
from bottle import request
import json
def websocket(callback):
def wrapper(*args, **kwargs):
ws = request.environ['wsgi.websocket']
ws.json = lambda x: ws.send(json.dumps(x))
rv = callback(ws, *args, **kwargs)
return rv
@zeekay
zeekay / gist:1221757
Created September 16, 2011 10:13
chat.py
from bottle import route, request, run, static_file, template
from bottle_websocket import websocket, GeventWebSocketServer
from collections import defaultdict, deque
class ChatRoom(object):
users = {}
buffer = deque(maxlen=15)
def message(self, name, message):
self.buffer.append((name, message))
@zeekay
zeekay / gist:1221762
Created September 16, 2011 10:16
index.tpl
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Chat</title>
<link rel="stylesheet" href="/static/style.css">
<script type="text/javascript" src="/static/web-socket-js/swfobject.js"></script>
from bottle import install, get, run
def plugin(callback):
def wrapper(*args, **kwargs):
print args, kwargs
return callback(*args, **kwargs)
return wrapper
install(plugin)
CACHE_DIR = 'static'
def cache_routes(app):
for route in app.routes:
path = os.path.join(CACHE_DIR, route.rule[1:])
os.mkdir(path)
with open(os.path.join(path, 'index.html'), 'w') as html:
html.write(route.call())
Render script inline using id kwarg:
- mustache id=test
%ul
%li
Hello {{name}}
%li
You have just won ${{value}}!
{{#in_ca}}
%li
Well, ${{taxed_value}}, after taxes.
import gevent
from gevent import queue, socket
class Tcp(object):
def __init__(self, settings):
self.host = settings['host']
self.port = settings['port']
self.recv_queue = queue.Queue()
self.send_queue = queue.Queue()
self.socket = socket.socket()