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
(defn assoc-some [m & kvs]
(if-not (even? (count kvs))
(throw (IllegalArgumentException. "even number of key-values required."))
(if-let [kvs (not-empty (filter #(some? (second %)) (partition 2 kvs)))]
(apply assoc m (flatten kvs))
m)))
sel=geany.selection()
geany.launch('rxvt-unicode', '-e', 'man','2', sel)
@sunng87
sunng87 / gist:846150
Created February 27, 2011 12:42
Seat Query of TOEFL in China
#! /usr/bin/python3
import urllib.parse
import http.client
import html.parser
from datetime import datetime
def get_seat_status(location, month):
""" get free seat status for given location(Beijing) and month(201104)
"""
@sunng87
sunng87 / gist:865574
Created March 11, 2011 07:28
Lifestream widget on my site
var YAHOO_PIPE_URL = "http://pipes.yahoo.com/pipes/pipe.run?_id=7NxhUNSA3RG_BCC6BBNMsA&_render=json";
function lifeStreamCallback(stream){
var lifeStreamRootDom = document.getElementById("lifestream");
try{
lifeStreamRootDom.removeChild(lifeStreamRootDom.getElementsByTagName("ul")[0]);
}catch(e) {}
var lifeStreamListDom = document.createElement("ul");
for(var i=0; i<stream.count; i++) {
@sunng87
sunng87 / anonymous_class.py
Created April 29, 2011 06:08
Convert a python function to a Java anonymous class
#
# usage, convert this work method to a Runnable anonymous class
#
# @anonymous_class(Runnable, 'run')
# def work(dummy):
# print 'hello world'
#
# work.run()
#
import types
@sunng87
sunng87 / .conkyrc
Created September 16, 2011 12:42
My OpenBox Desktop
# conky configuration
# edited by darcon@gmail.com
# set to yes if you want Conky to be forked in the background
background no
# X font when Xft is disabled, you can pick one with program xfontsel
#font 5x7
#font 6x10
#font 7x13
@sunng87
sunng87 / project.clj
Created October 26, 2011 05:58
upvotes in subreddits
(ns reddit-visualization.core
(:require [reddit.clj.core :as reddit])
(:import [javax.swing JFrame])
(:import [org.jfree.chart ChartFactory ChartPanel])
(:import [org.jfree.data.general DefaultPieDataset])
(:import [org.jfree.util SortOrder]))
(def reddit-client (reddit/login nil nil))
(defn map-reddits [user after-id]
@sunng87
sunng87 / core.clj
Created October 28, 2011 07:34
clojure code for mining reddit upvotes
(ns reddit-visualization.core
(:refer-clojure :exclude [replace])
(:use [clojure.pprint])
(:use [clojure.string :only [lower-case replace split]])
(:require [clojure.java.jdbc :as jdbc])
(:require [reddit.clj.core :as reddit])
(:import [javax.swing JFrame])
(:import [org.jfree.chart ChartFactory ChartPanel])
(:import [org.jfree.data.general DefaultPieDataset])
(:import [org.jfree.util SortOrder]))
@sunng87
sunng87 / imgscale.clj
Created November 22, 2011 06:30
Image scalling with java-image-scaling
(ns gen-class-test.imgscale
(:use [clojure.java.io])
(:import [javax.imageio ImageIO])
(:import [com.mortennobel.imagescaling ResampleOp ResampleFilters]))
(defn read-img [path]
(ImageIO/read (file path)))
(defn write-img [img path]
(ImageIO/write img "jpg" (file path)))
@sunng87
sunng87 / core.clj
Created December 9, 2011 02:29
client code for benchmarking slacker
(ns slackerbench.core
(:use [slacker.client])
(:import [java.util.concurrent Executors TimeUnit])
(:gen-class))
(defn -main [& args]
(def host (first args))
(def total-connections (Integer/valueOf (nth args 2)))
(def scp (slackerc-pool host 2104