Skip to content

Instantly share code, notes, and snippets.

View yayitswei's full-sized avatar

Wei Hsu yayitswei

  • San Francisco, CA
View GitHub Profile
(ns oauth.digest
(:import (javax.crypto Mac)
(javax.crypto.spec SecretKeySpec)))
(defn hmac
"Calculate HMAC signature for given data."
[^String key ^String data]
(let [hmac-sha1 "HmacSHA1"
signing-key (SecretKeySpec. (.getBytes key) hmac-sha1)
mac (doto (Mac/getInstance hmac-sha1) (.init signing-key))]
Algorithm HmacSHA1 not available
[Thrown class java.security.NoSuchAlgorithmException]
Restarts:
0: [QUIT] Quit to the SLIME top level
Backtrace:
0: javax.crypto.Mac.getInstance(DashoA13*..)
1: user$eval2253.invoke(NO_SOURCE_FILE:1)
2: clojure.lang.Compiler.eval(Compiler.java:5424)
phrygian:tracker wei$ cake repl
user=> (javax.crypto.Mac/getInstance "HmacSHA1")
java.security.NoSuchAlgorithmException: Algorithm HmacSHA1 not available (NO_SOURCE_FILE:0)
phrygian:tracker wei$ lein repl
"REPL started; server listening on localhost:35455."
user=> (javax.crypto.Mac/getInstance "HmacSHA1")
#<Mac javax.crypto.Mac@5759780d>
(defn map-keys [m f]
(into {} (for [[k v] m] [k (f v)])))
;; recursive group-by
(defn group-by-> [starting-target starting-fns]
(loop [target starting-target fns starting-fns]
(if (nil? fns) target
(map-keys (group-by (first fns) target) #(recur % (rest fns))))))
;; usage
function modify_permalinks($permalink_structure, $category_base, $tag_base){
global $wp_rewrite;
$permalink_structure = preg_replace('#/+#', '/', '/' . $permalink_structure);
$wp_rewrite->set_permalink_structure($permalink_structure);
$category_base = preg_replace('#/+#', '/', '/' . $category_base);
$wp_rewrite->set_category_base($category_base);
$tag_base = preg_replace('#/+#', '/', '/' . $tag_base);
(lift loadserver
:compute ec2-service
:phase (phase (pallet.resource.package/package "curl")))
bottime-gae.core=> (baseline/run-threads 1 1)
#<ArityException clojure.lang.ArityException: Wrong number of args (1) passed to: baseline$run-threads$fn>
bottime-gae.core=> (baseline/run-threads 1)
#<ArityException clojure.lang.ArityException: Wrong number of args (1) passed to: baseline$run-threads>
bottime-gae.core=> (baseline/run-threads)
#<ArityException clojure.lang.ArityException: Wrong number of args (0) passed to: baseline$run-threads>
bottime-gae.core=> (baseline/run-threads 1 2 3)
#<ArityException clojure.lang.ArityException: Wrong number of args (3) passed to: baseline$run-threads>
@yayitswei
yayitswei / gist:2308710
Created April 5, 2012 07:15
leaky-filter
(defn leaky-filter [pred l n]
(apply
concat
(filter #(or (some pred %) (< n (count %)))
(partition-by nil? l))))
(is (= (leaky-filter [1 nil 2 nil nil nil nil 1 2 3] identity 3)
[1 2 nil nil nil nil 1 2 3]))
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.clojars.yayitswei</groupId>
<artifactId>java-channels-api</artifactId>
<version>0.1-SNAPSHOT</version>
<name>java-channels-api</name>
<description>jacc</description>
<repositories>
<repository>
@yayitswei
yayitswei / gist:2365902
Created April 12, 2012 09:37
what's the difference between the two?
;; this one fails with
;;#<IllegalStateException java.lang.IllegalStateException: Invalid use of SingleClientConnManager: connection still allocated.
;;Make sure to release the connection before allocating another one.>
(defn run-test [num-requests channel-name]
(let [channel (ChannelAPI.)
requests (init-requests num-requests channel-name)
listener (make-listener requests)]
(connect-at-sim channel channel-name listener)
(doall (map do-request requests))))