Skip to content

Instantly share code, notes, and snippets.

View sunng87's full-sized avatar
👑
keep calm and git push -f

Ning Sun sunng87

👑
keep calm and git push -f
View GitHub Profile
@sunng87
sunng87 / Compiler.java
Created October 27, 2012 02:39
hacking clojure compiler, adding -var-missing
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java
index e2146a6..2dfa208 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -6728,6 +6728,16 @@ static Namespace namespaceFor(Namespace inns, Symbol sym){
return ns;
}
+static public Var varMissing(Symbol sym) {
+ if (sym.ns != null) {
@sunng87
sunng87 / gist:3957289
Created October 26, 2012 06:44
Hacking mouse scrolling
var mousewheel_buffer = [];
var mousewheel_buffer_size = 5;
$(document).mousewheel(function(e, d){
// not for landing page
if (!app.current_timeline) {
return true;
}
if (mousewheel_buffer.length === mousewheel_buffer_size) {
mousewheel_buffer.shift();
@sunng87
sunng87 / results
Created July 19, 2012 06:31
TOP github users in China
imakewebthings | Caleb Troughton | #{"JavaScript" "CoffeeScript" "Ruby" "Python"} | 6840.0
flyerhzm | Richard Huang | #{"Java" "JavaScript" "Ruby"} | 3407.5
fredwu | Fred Wu | #{"JavaScript" "CoffeeScript" "PHP" "Ruby" "Python"} | 3226.0
kissyteam | kissyteam | #{"Java" "JavaScript" "PHP"} | 2138.0
JeffreyZhao | Jeffrey Zhao | #{"C#" "Java" "JavaScript" "CoffeeScript" "Ruby"} | 1943.0
livid | Xin Liu | #{"JavaScript" "Ruby" "Python"} | 1928.5
thoughtworks | ThoughtWorks Inc. | #{"Java" "C++" "JavaScript" "Objective-C" "Ruby" "Python"} | 1392.5
sofish | sofish | #{"Ja
({:username "imakewebthings",
:name "Caleb Troughton",
:language "JavaScript",
:score 5476.8}
{:username "flyerhzm",
:name "Richard Huang",
:language "Ruby",
:score 2776.2}
{:username "fredwu",
:name "Fred Wu",
@sunng87
sunng87 / MultiFuture.java
Created May 8, 2012 08:16
A combined future impl
/**
*
*/
package info.sunng.util.concurrent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@sunng87
sunng87 / proxy.py
Created April 24, 2012 08:11
python method missing
class Proxy(object):
def __init__(self, target):
self.target = target
def __getattr__(self, name):
print "calling: ", name
return (lambda *x: self._call(*x))
def _call(self, *args):
@sunng87
sunng87 / protocol.py
Created April 23, 2012 08:26
slacker protocol in python
import struct
import json
import clj
PROTOCOL_VERSION = 5
PROTOCOL_HEADER = "bib"
PROTOCOL_HEADER_SIZE = 6
@sunng87
sunng87 / tcp.clj
Created March 16, 2012 06:12
An echo server example for link
(ns link-test.tcp
(:refer-clojure :exclude [float byte double])
(:use [link core tcp codec]))
(def echo-handler
(create-handler
(on-message [ctx e]
(let [channel (.getChannel ctx)]
(.write channel
(.getMessage e))))))
@sunng87
sunng87 / dosync-plus.clj
Created February 24, 2012 06:25
dosync+
(defmacro dosync+ [listeners & body]
`(let [on-start# (get ~listeners :on-start identity)
on-retry# (get ~listeners :on-retry identity)
on-committed# (get ~listeners :on-committed identity)
retires# (atom 0)
ctx# (atom {})]
(dosync
(if (zero? @retires#)
(swap! ctx# on-start#)
(swap! ctx# on-retry#))
@sunng87
sunng87 / t.py
Created February 14, 2012 05:44
Evaluating clojure literals in ruby and python
import clj
import time
s = "[1 2 3 true false nil {:a 21.3 :b 43.2} \"Hello\"]"
t1 = time.time()
for i in range(10000):
clj.loads(s)
print time.time()-t1