Skip to content

Instantly share code, notes, and snippets.

View killme2008's full-sized avatar
🎯
Focusing

dennis zhuang killme2008

🎯
Focusing
View GitHub Profile
@bryanjswift
bryanjswift / UAgentInfo.java
Created March 1, 2010 09:43
User Agent detection in Java
/* *******************************************
// LICENSE INFORMATION
// The code, "Detecting Smartphones Using PHP"
// by Anthony Hand, is licensed under a Creative Commons
// Attribution 3.0 United States License.
//
// Updated 01 March 2010 by Bryan J Swift
// - Remove un-needed if statements instead just returning the boolean
// inside the if clause
//
;annotation syntax
(import [java.lang.annotation Retention RetentionPolicy Target ElementType]
[javax.xml.ws WebServiceRef WebServiceRefs])
(definterface Foo (foo []))
;annotation on type
(deftype ^{Deprecated true
Retention RetentionPolicy/RUNTIME
javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]
@michalmarczyk
michalmarczyk / letrec.clj
Created July 23, 2010 01:21
a letrec macro for Clojure
(defmacro letrec [bindings & body]
(let [bcnt (quot (count bindings) 2)
arrs (gensym "bindings_array")
arrv `(make-array Object ~bcnt)
bprs (partition 2 bindings)
bssl (map first bprs)
bsss (set bssl)
bexs (map second bprs)
arrm (zipmap bssl (range bcnt))
btes (map #(walk/prewalk (fn [f]
@ithayer
ithayer / tf-idf.clj
Created June 28, 2011 06:32
Simple tf-idf in 30 lines of clojure. Inspired by a nice simple scala implementation: https://github.com/felipehummel/TinySearchEngine/blob/master/scala/tinySearch.scala and matches as closely as possible the computation.
(ns ignacio.tfidf (:require [clojure.contrib.string :as string])) ;; Simple tfidf in clojure, for fun.
(def stopwords (set (string/split #"\n" (slurp "./stopwords.txt"))))
(defn tokenize [raw-text] ;; Lowercases and splits on non-letters, non-numbers.
(remove stopwords (string/split #"[^a-z0-9äöüáéíóúãâêîôûàèìòùçñ]+" (string/lower-case raw-text))))
(defn idf2 [n-docs match] (Math/pow (Math/log (/ n-docs (count (keys match)))) 2))
(defn index-one [fname] ;; Index for one file. Given an fname, returns a map of token -> map of (fname, count)
@stepahn
stepahn / gist:1099278
Created July 22, 2011 11:27
growl iChat
-- growl notifications for ichat, based on
-- http://scriptingosx.com/2010/11/ichat-notification-with-growl/
property growlAppName : "Growl iChat"
property notificationNames : {"Buddy Became Available", ¬
"Buddy Became Unavailable", ¬
"Message Received", ¬
"Completed File Transfer"}
property defaultNotificationNames : {"Buddy Became Available", ¬
@noahlz
noahlz / joy-of-clojure-lazy-qsort.clj
Created January 11, 2012 03:37
Lazy QuickSort implementation in Clojure, from Joy of Clojure chapter 6.
(ns joy.q)
;; nil
(defn nom [n] (take n (repeatedly #(rand-int n))))
;; #'joy.q/nom
(defn sort-parts [work]
(lazy-seq
(loop [[part & parts] work] ;; Pull apart work - note: work will be a list of lists.
(if-let [[pivot & xs] (seq part)] ;; This blows up unless work was a list of lists.
@rednaxelafx
rednaxelafx / TraceSystemGCCall.java
Created March 8, 2012 13:15
BTrace script to log System.gc() calls
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
@BTrace
public class TraceSystemGCCall {
@OnMethod(
clazz="/.*/",
method="/.*/",
location=@Location(
value=Kind.CALL,
@dcampano
dcampano / Mysql slow query log quick parse
Created April 15, 2012 14:14
Parse a mysql slow query log and show how many times queries over a certain threshold happened
# Script used to quickly get a glance of how many queries since a certain time period were longer than X seconds
# Customize these 2 parameters
STARTDATE="120413" # 2 Digit Year, 2 Digit Month, 2 Digit Day
QUERYTIME=3.0
# Runs the commands and prints out Query_time lines
FIRST=`grep -n -m 1 "# Time: $STARTDATE" /var/log/mysql-slow.log | cut -d : -f 1`; TOTAL=`wc -l /var/log/mysql-slow.log | cut -d ' ' -f 1`; tail -n `echo "$TOTAL-$FIRST" | bc` /var/log/mysql-slow.log | grep Query_time | awk -v time="$QUERYTIME" '$3 > time {print; }'
(ns monads
(:require clojure.set))
(declare ^:dynamic return
^:dynamic bind)
(defn lift-inc [v]
(return (inc v)))
(defn m-add [mv n]
(deftheme bubbleberry "bubbleberry")
;; Based on the theme used for LightTable (see: http://www.chris-granger.com/images/lightable/main.png )
(custom-theme-set-variables
'bubbleberry
'(linum-format " %7i ")
'(fringe-mode 5 nil (fringe))
'(powerline-color1 "#3d3d68")
'(powerline-color2 "#292945")