Skip to content

Instantly share code, notes, and snippets.

AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build());
WebSocket websocket = c.prepareGet("ws://127.0.0.1:8080/atmosphere-jquery-pubsub/pubsub/chat")
.execute(new WebSocketUpgradeHandler()).get();
websocket.addMessageListener(new WebSocketListener() {
@Override
public void onMessage(byte[] message) {
System.out.println(new String(message));
}
@Override
@sritchie
sritchie / hslint
Created September 25, 2011 20:00
hslint!
#!/usr/bin/env perl
# Remember `chmod a+x hslint, after putting on path.
$ghc = '/usr/bin/ghc'; # where is ghc
@ghc_options = ('-Wall'); # e.g. ('-fglasgow-exts')
@ghc_packages = (); # e.g. ('QuickCheck')
### the following should not been edited ###
@pepijndevos
pepijndevos / core.clj
Created September 16, 2011 11:17
Micro Wiki
(ns wiki.core
(:use net.cgrand.moustache
ring.adapter.jetty
ring.util.response
[ring.middleware params stacktrace reload]
hiccup.core
com.ashafa.clutch)
(:require [clojure.string :as s])
(:import org.pegdown.PegDownProcessor))
@swannodette
swannodette / Coder.scala
Created July 26, 2011 19:09
phone_code.clj
package demo
class Coder(words: List[String]) {
private val mnemonics = Map(
'2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ")
private val charCode: Map[Char, Char] =
for ((digit, str) <- mnemonics; letter <- str) yield letter -> digit
@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
@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")))
@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]
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)
@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,
@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;