Skip to content

Instantly share code, notes, and snippets.

@rctay
rctay / SimpleHTTPServerWithUpload.py
Created Dec 19, 2015 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload
View SimpleHTTPServerWithUpload.py
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
View jsonpath.js
#!/usr/bin/env node
// Reads JSON from stdin, and runs a JSONPath expression from the command-line on it.
//
// eg.
// $ npm install # install dependencies
// $ echo '{"store": {"book":[{"category":"fiction"}]}}' | node jsonpath.js '$.store.book[0].category'
// fiction
var stdin = process.stdin,
@rctay
rctay / pyrefactors.py
Created Nov 14, 2012 — forked from geeknam/pyrefactors.py
Python refactors
View pyrefactors.py
"""
Use setattr
"""
# Normal
item.price = self.request['price']
item.quantity = self.request['quantity']
item.shipping = self.request['shipping']
item.save()
@rctay
rctay / sieve1.py
Created Nov 17, 2011 — forked from ejamesc/gist:1373187
[fork] Sieve
View sieve1.py
"""Translated from Haskell:
let sieve(p:xs) = p : sieve (filter (\ x -> x `mod` p /= 0) xs) in sieve [2..]
"""
from itertools import ifilter
def ints(k):
while True:
yield k
k+=1
@rctay
rctay / bashrc
Created Nov 14, 2011 — forked from shawntan/bashrc
[fork] my .bashrc
View bashrc
# /etc/bash/bashrc
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output. So make sure this doesn't display
# anything or bad things will happen !
# Test for an interactive shell. There is no need to set anything
@rctay
rctay / appender3.xml
Created Nov 2, 2011 — forked from iwein/appender3.xml
[fork] Appender filtering particular trace logging
View appender3.xml
<appender name="STDOUT2" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>TRACE</level>
<OnMatch>NEUTRAL</OnMatch>
<OnMismatch>DENY</OnMismatch>
</filter>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>STDOUT1 %logger{36} - %msg%n</Pattern>
</layout>
</appender>
View gist:1226563
"""
See also:
- http://code.activestate.com/recipes/52549/#c6
- http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application
"""
class curry:
def __init__(self, fun):
import inspect
self.fun = fun