Skip to content

Instantly share code, notes, and snippets.

@rctay
rctay / gist:1226563
Created September 19, 2011 14:05 — forked from qoelet/gist:1225838
[fork] currying in python (from http://pydroid.posterous.com/nextpy-currying)
"""
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
@rctay
rctay / appender3.xml
Created November 2, 2011 13:41 — forked from iwein/appender3.xml
[fork] Appender filtering particular trace logging
<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>
@rctay
rctay / bashrc
Created November 14, 2011 07:40 — forked from shawntan/bashrc
[fork] my .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 / sieve1.py
Created November 17, 2011 18:26 — forked from ejamesc/gist:1373187
[fork] Sieve
"""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 / pyrefactors.py
Created November 14, 2012 03:08 — forked from geeknam/pyrefactors.py
Python refactors
"""
Use setattr
"""
# Normal
item.price = self.request['price']
item.quantity = self.request['quantity']
item.shipping = self.request['shipping']
item.save()
#!/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 / SimpleHTTPServerWithUpload.py
Created December 19, 2015 15:20 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload
#!/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.
"""