Skip to content

Instantly share code, notes, and snippets.

@rctay
rctay / gist:1063175
Created July 4, 2011 10:15
[gsoc-diff] more numbers
$ time ~/bin/jgit.sh log -M -p v1.5.0 >/dev/null
0m12.505s
0m12.528s
0m12.734s
$ time ../git/git log -M -p v1.5.0 >/dev/null
0m7.252s
0m7.229s
0m7.268s
@rctay
rctay / gist:1063164
Created July 4, 2011 10:01
[gsoc-diff] numbers
jgit repo
$ time jgit.sh log -M -p v0.99 >/dev/null
0m3.873s
0m3.801s
0m3.919s
$ time ../git/git log -M -p >/dev/null
0m3.032s
0m2.940s
@rctay
rctay / gist:1046368
Created June 25, 2011 10:51
[sh] strip trailing whitespace in a file
#
# why not used sed -i? It seems the implementation I'm using runs into
# problems with permissions:
#
# sed: preserving permissions for `django/contrib/auth/migrations/sed072496': Permission denied
#
# huh?? I'm using this stupid copying-around trick to silence this
# errors and prevent the file from being marked as read-only.
#
strip() { cat "$1" | sed 's/[ \t]*$//g' > /tmp/foo && cp /tmp/foo "$1"; }
@rctay
rctay / IOTest.java
Created April 8, 2011 09:16
[java][junit] i/o testing
package net.rctay.testing;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface IOTest {
@rctay
rctay / __init__.py
Created February 23, 2011 13:37
[python] overloadable decorators
def decorates(dec):
def handler(*args, **kwargs):
if len(args) == 1 and callable(args[0]):
func = args[0]
return dec(func)
else:
def wrapper(func):
return dec(func, *args, **kwargs)
return wrapper
return handler
@rctay
rctay / common.py
Created February 13, 2011 02:59
[python] generator-based implementation of Sieve of Eratosthenes (Euler's mod)
def integers():
i = 1
while True:
yield i
i += 1
def head(iter, n):
return [iter.next() for i in xrange(n)]
@rctay
rctay / gist:819924
Created February 10, 2011 04:04
[Java][GAE][Mockito] testing servlet requests/responses
import static org.junit.Assert.*;
import static org.junit.matchers.JUnitMatchers.*; // for non-hamcrest core matchers
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
@rctay
rctay / float_round.min.rb
Created February 9, 2011 06:21
[ruby] Float.round(prec) for 1.8
class Float; orig_round = self.instance_method(:round); define_method(:round) do |*args| prec = args[0] || 1; if prec == 1 then return orig_round.bind(self).call() else a = 10**prec; return orig_round.bind(self*a).call().to_f / a end end end
@rctay
rctay / errors.py
Created February 7, 2011 15:03
[python] simple matrix operations for my homework
class BaseMatrixException(Exception):
"""Base class for all exceptions from matrix operations."""
class InconsistentRowSizeException(BaseMatrixException):
def __init__(self, size1, size2):
self.size1 = size1
self.size2 = size2
def __str__(self):
@rctay
rctay / .gitmodules
Created December 24, 2010 07:12
tornado: chunked handler (RFC2616)
[submodule "iostream_callback"]
path = iostream_callback
url = git://gist.github.com/753987.git