This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mammal | |
constructor: (@species, @defining_char) -> | |
print: -> | |
"Hello I'm a #{@species}. I have #{@defining_char}." | |
cat = new Mammal 'cat', 'claws' | |
alert cat.print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
› 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bottle import install, get, run | |
def plugin(callback): | |
def wrapper(*args, **kwargs): | |
print args, kwargs | |
return callback(*args, **kwargs) | |
return wrapper | |
install(plugin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
OlderNewer