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
GET "/home/index" { (name, age) => | |
println("my name is " + name + ". Im " + age) | |
} | |
// We need it in scala | |
//rossabaker's Step is wonderful. I would like to see 'params(..)' go away like: | |
get("/date/:year/:month/:day") { (year, month, day) => | |
<ul> | |
<li>Year: { year }</li> |
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 functools | |
def printAround(key): | |
""" | |
snipet to remember prepare cached invocations in memcached. | |
""" | |
def decorator(f): | |
@functools.wraps(f) | |
def new_f(*args): | |
print 'entering', f.__name__ | |
print 'key ', key |
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
#Server | |
from multiprocessing.connection import Listener | |
from array import array | |
data = {} | |
address = ('localhost', 6000) | |
listener = Listener(address, authkey='s') | |
conn = listener.accept() |
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 fabric.operations import sudo, local | |
from fabric.api import env, settings | |
from fabric.context_managers import cd | |
env.cwd = '/home/user' | |
def _switch_resolv(): | |
with cd('/etc'): | |
local('sudo rm resolv.conf') | |
local('sudo cp resolv.tmp.conf resolv.conf') |
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 tornado.httpserver | |
import tornado.ioloop | |
import tornado.web | |
import tornado.autoreload | |
import logging | |
from multiprocessing import Pool | |
import time | |
def delayed_log(user): | |
logging.warning('delayed logging for %s' % user) |
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
h = {} | |
w = ['paulo', 'saulo', 'carolina', 'rafael', 'mauro', 'joao', 'abraao'] | |
[[[(h.has_key(c) and not h[c].append(word)) or not h.update({c : [word]})] for c in word] for word in w] | |
def search(chars): | |
s = set([]) | |
[[s.add(w) for w in [e for e in h.get(char) if e.find(chars) >= 0]] for char in chars] | |
return s |
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
public void start() throws Exception { | |
List<EventHandlerTask> h = new LinkedList<IOLoop.EventHandlerTask>(); | |
while (true) { | |
Iterator<EventHandlerTask> iterTask = h.iterator(); | |
System.out.println(h.size()); | |
while (iterTask.hasNext()) { | |
pool.execute(iterTask.next()); | |
iterTask.remove(); | |
} |
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 '(org.jtornadoweb HttpServer App$MainHandler Web$Application)) | |
(.listen | |
(new HttpServer (.add (new Web$Application) "/" App$MainHandler) false nil false) 8089) |
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
; Starts an JTornado HTTP Server and a sample RequestHandler. | |
; Bit verbose due to compilation directives. Recommendation is to generate | |
; a set of macros to hide this. | |
(ns org.ctornadoweb | |
; Compiled and implements a static main method to start the server | |
(:import (org.jtornadoweb HttpServer) | |
(org.jtornadoweb.Web$Application) | |
(org.jtornadoweb.Web$RequestHandler)) | |
(:gen-class :prefix "server-")) |
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
(ns org.jtornadoweb.cljhttputils | |
(:gen-class | |
:name org.jtornadoweb.CljHttpUtils | |
:methods [[parseQueryString [String] java.util.HashMap]] | |
:main false)) | |
(defn #^:static | |
-parseQueryString | |
"Return all parameters in a HashMap. Same as python cgi.pase_qs. If no parameters are | |
found , returns an empty Map of parameters (not null)." |
OlderNewer