Skip to content

Instantly share code, notes, and snippets.

View xtang's full-sized avatar

xiaomin tang xtang

View GitHub Profile
@xtang
xtang / digest.clj
Created August 24, 2012 04:32 — forked from eliasson/digest.clj
Clojure md5 digest
(defn md5-sum
"Compute the hex MD5 sum of a string."
[#^String input]
(let [alg (doto (MessageDigest/getInstance "MD5")
(.update (.getBytes input)))
hash (.toString (new BigInteger 1 (.digest alg)) 16)
length (.length hash)]
(if (> 32 length)
;; 0x065 => 65, leading zero is dropped by BigInteger
(apply str (concat (repeat (- 32 length) \0) hash))
@xtang
xtang / gist:3952180
Created October 25, 2012 11:54
Clojure: Iterate over map
(doseq [[k v] db] (prn k v))
(exec-raw ["select count(*) alg from av_content where caseid = ?" [case-id]] :results)
@xtang
xtang / gist:3957591
Created October 26, 2012 08:19
compile java in clojure project
find src/java -name "*.java" | xargs javac -Xlint:unchecked -encoding utf8 -cp "classes:lib/*:src/" -d classes -sourcepath src/java/
@xtang
xtang / gist:3957787
Created October 26, 2012 09:13
Iterator over map
Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
}
var QueryString = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
@xtang
xtang / API.md
Created January 30, 2013 16:12 — forked from iros/API.md

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@xtang
xtang / brew-sync.sh
Last active August 29, 2015 13:57 — forked from jpawlowski/brew-sync.sh
#!/bin/bash
# Sync Homebrew installations between Macs via Dropbox
#
BREW="/usr/local/bin/brew"
# first get local settings
echo "Reading local settings ..."
rm -f /tmp/brew-sync.*
@xtang
xtang / howto.md
Created June 26, 2014 06:22 — forked from leomelzer/howto.md
  1. You have Ghostscript installed, right? Otherwise sudo apt-get install ghostscript
  2. This is important and installs the headers (iapi.h etc) which are required but don't come with the default Ghostscript package: sudo apt-get install libgs-dev
  3. I also needed sudo apt-get install gs-esp
  4. For me the pre compiled version of ImageMagick never accepted Ghostscript, so let's remove it: sudo apt-get --purge remove imagemagick
  5. Get the source of ImageMagick, untar it, cd ImageMagick-xx
  6. ./configure --with-gslib=yes [and what else you need]
  7. Confirm in the output near the bottom gslib yes yes and not gslib yes no
  8. make
  9. make install
  10. Run convert -list configure | grep DELEGATES => DELEGATES bzlib djvu freetype gs jpeg jng jp2 lcms png tiff x11 xml zlib
// borrowed from http://stackoverflow.com/questions/4006324/how-to-atomically-delete-keys-matching-a-pattern-using-redis
EVAL "return redis.call('del', unpack(redis.call('keys', ARGV[1])))" 0 bearyboard:*
redis-cli KEYS "prefix:*" | xargs redis-cli DEL