Skip to content

Instantly share code, notes, and snippets.

(ns com.freiheit.clojure.appengine.appengine-local
(:use
[compojure.http routes servlet helpers]
clojure.contrib.test-is
compojure.server.jetty
[clojure.contrib def str-utils duck-streams])
(:require
[clojure.contrib.logging :as log])
(:import
[com.google.appengine.api.labs.taskqueue.dev LocalTaskQueue]
@neotyk
neotyk / gist:568486
Created September 7, 2010 14:51
Generating multiple fns on a fly
(doseq [[fn-name fn-doc] [testname "sample doc" anothername "detailed documentation"]]
`(defn ~fn-name ~fn-doc [a] a))
@ibdknox
ibdknox / socket.clj
Created October 31, 2010 06:48
compojure with websockets
(ns wl.core
(:use compojure.core, aleph.core, aleph.http, hiccup.core, hiccup.page-helpers)
(:require [compojure.route :as route])
(:gen-class))
(def broadcast-channel (channel))
(defn chat-handler [ch handshake]
(receive ch
(fn [name]
// http://aboutcode.net/2010/11/11/list-github-projects-using-javascript.html
jQuery.githubUser = function(username, callback) {
jQuery.getJSON("http://github.com/api/v1/json/" + username + "?callback=?", callback);
}
jQuery.fn.loadRepositores = function(username) {
this.html("<span>Querying GitHub for repositories...</span>");
var target = this;
@Test(groups = "standalone")
public void basicDefaultTest() throws Throwable {
AsyncHttpClientConfig client = new AsyncHttpClientConfig.Builder().setResumableDownload(true).build();
AsyncHttpClient c = new AsyncHttpClient(client);
final RandomAccessFile file = new RandomAccessFile("800m.avi", "rw");
Response r = c.prepareGet("http://192.168.2.106:8081/800m.avi").execute(new AsyncCompletionHandlerBase(){
private long byteTransferred = 0;
@jfarcand
jfarcand / gist:769494
Created January 7, 2011 14:16
Friday's Fun: Comparing Apache Http Client with AsyncHttpClient
Configuring Apache Client
HttpParams params = new BasicHttpParams();
params.setParameter(HttpProtocolParams.PROTOCOL_VERSION,
HttpVersion.HTTP_1_1);
params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,
false);
params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK,
false);
params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE,
Client: Mac Pro OS X, 2.8Ghz Quad-Core Intel Xeon, 8 GB 1066 Mhz DDR3
Server: lighttpd/1.4.26 -> Ubuntu, 2.8Ghz Duo-Core Intel Xeon, 6 1066 Mhz DDR3
50 threads that does 50 requests, done 50 times.
Async Http Client 1.5.0 (Config http://is.gd/7rGGWU)
=============================================================
BenchmarkResult{requestsPerSecond=1578.96, threads=50, batches=50, targetRequests=125000, successfulRequests=125000, failedRequests=0, averageRequestTime=0.63ms, averageBatchTime=1583.32ms, totalBenchmarkTime=79166.03ms}
(last 5 runs)
@weavejester
weavejester / gist:1001206
Created May 31, 2011 20:27
Clojure on Heroku
~/$ lein new ring-on-heroku
Created new project in: /home/jim/Development/ring-on-heroku
~/$ cd ring-on-heroku
~/ring-on-heroku$ echo 'web: lein run -m ring-on-heroku.core' > Procfile
~/ring-on-heroku$ cat > src/ring_on_heroku/core.clj
(ns ring-on-heroku.core
(:use ring.util.response
ring.adapter.jetty))
(defn app [req]
@pepijndevos
pepijndevos / test.clj
Created June 6, 2011 10:09
Find a word that spells your phone number
(ns test
(require clojure.java.io
clojure.string))
(def *keys* {\2 #{\a \b \c}, \3 #{\d \e \f}, \4 #{\g \h \i}, \5 #{\j \k \l}, \6 #{\m \n \o}, \7 #{\p \q \r \s}, \8 #{\t \u \v}, \9 #{\w \x \y \z}})
(def *mapping* (into {} (mapcat (fn [[k v]] (map #(vector % k) v)) *keys*)))
(def *words* (line-seq (clojure.java.io/reader "/usr/share/dict/words")))
@stuartsierra
stuartsierra / phone_code.clj
Created July 25, 2011 23:46
Phone number coding program in Clojure
;; Adapted from "An empirical comparison of C, C++, Java, Perl,
;; Python, Rexx, and Tcl for a search/string-processing program"
;; by Lutz Prechelt
;; This was a 15-minute effort while listening to a talk. It's *not*
;; well thought-out or designed.
;; By Stuart Sierra,
;; @stuartsierra on Twitter