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 / ip_only.py
Created June 29, 2013 09:45
Displaying IP address of wlan0 on LCD.
#!/usr/bin/python
from Adafruit_CharLCD import Adafruit_CharLCD
from subprocess import *
from time import sleep, strftime
from datetime import datetime
lcd = Adafruit_CharLCD()
cmd = "ip -4 addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1"
@sunng87
sunng87 / index.html
Created March 13, 2013 14:06
tornado + websocket + rpi
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="dns-prefetch" href="//1-ps.googleusercontent.com"></head>
<body>
<div class="main">
<h2>Shake your phone</h2>
@sunng87
sunng87 / Disney Wiki Crawler.cljs
Last active August 15, 2018 13:57
ClojureScript to download pages from Disney Wiki. Target to nodejs.
(ns crawler.core
(:require [cljs.nodejs :as node]))
(def http (node/require "http"))
(def fs (node/require "fs"))
(def local-path-root "out/")
(.mkdir fs local-path-root (fn [e]))
(defn start-req [url res-fn]
@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