# in one terminal
$ lein deps
$ lein run -m server
# in another terminal
$ curl -i http://localhost:8080/sync
$ curl -i http://localhost:8080/poll
$ curl -i http://localhost:8080/stream
$ ./wsclient ws://localhost:8080/websocket?name=bob
=> hi
(import 'org.httpkit.client.Decoder) | |
(import 'java.nio.ByteBuffer) | |
(.decode (Decoder. nil nil) (ByteBuffer/wrap (.getBytes "HTTP/1.1 200 \r\n" "UTF-8"))) | |
;;=> ProtocolException not http protocol? HTTP/1.1 200 org.httpkit.client.Decoder.parseInitialLine (Decoder.java:77) | |
(pst) | |
;;; ProtocolException not http protocol? HTTP/1.1 200 | |
;;; org.httpkit.client.Decoder.parseInitialLine (Decoder.java:77) | |
;;; org.httpkit.client.Decoder.decode (Decoder.java:88) |
RATE_LIMIT_SCRIPT = r''' | |
local now = tonumber(ARGV[1]) | |
local required = tonumber(ARGV[2]) | |
local rate = tonumber(ARGV[3]) | |
local per_secs = tonumber(ARGV[4]) | |
local do_subtract = tonumber(ARGV[5]) == 1 | |
local full_at = tonumber(redis.call('GET', KEYS[1])) or 0 | |
local score, result | |
if full_at < now then | |
score = rate |
# in one terminal
$ lein deps
$ lein run -m server
# in another terminal
$ curl -i http://localhost:8080/sync
$ curl -i http://localhost:8080/poll
$ curl -i http://localhost:8080/stream
$ ./wsclient ws://localhost:8080/websocket?name=bob
=> hi
(defmacro _-> | |
([x] x) | |
([x form] (if (seq? form) | |
(if (seq-utils/includes? form '_) | |
(with-meta `(~@(replace {'_ x} form)) (meta form)) | |
(with-meta `(~(first form) ~x ~@(next form)) (meta form))) | |
(list form x))) | |
([x form & more] `(_-> (_-> ~x ~form) ~@more))) | |
;-> and _-> are almost the same behavior until _ is specified. |
jQuery.format = function(s, args) { | |
return s.replace(/\{([^}]+)\}/g, function(_, match){return args[match] || '';}); | |
}; | |
>> $.format('Hello {world}, {again}', {world: "universe", again: "testing"}); | |
"Hello universe, testing" | |
>> $.format('Hello {0}, {1}', ["foo", "bar"]); | |
"Hello foo, bar" |
(ns `(let* ((nsname '()) | |
(dirs (split-string (buffer-file-name) "/")) | |
(aftersrc nil)) | |
(dolist (dir dirs) | |
(if aftersrc | |
(progn | |
(setq nsname (cons dir nsname)) | |
(setq nsname (cons "." nsname))) | |
(when (or (string= dir "src") (string= dir "test")) | |
(setq aftersrc t)))) |
# install git | |
sudo apt-get install g++ curl libssl-dev apache2-utils | |
sudo apt-get install git-core | |
# download the Node source, compile and install it | |
git clone https://github.com/joyent/node.git | |
cd node | |
./configure | |
make | |
sudo make install | |
# install the Node package manager for later use |
/* don't use this, it's just for a timing demonstration */ | |
public class ReturningException extends RuntimeException { | |
transient public final Object data; | |
transient public final Object context; | |
public ReturningException(Object o){ | |
this(null, o); | |
} | |
public ReturningException(Object c, Object o){ | |
super("Not really an exception"); |
(ns virgil | |
(:require | |
[clojure.java.io :as io] | |
[clojure.string :as str] | |
[filevents.core :as fe]) | |
(:import | |
[javax.tools | |
DiagnosticCollector | |
ForwardingJavaFileManager | |
JavaCompiler |
;; Requires Outlet to run: https://github.com/jlongster/outlet | |
;; | |
;; Run with: `ol main.ol <input-file>` | |
;; | |
;; This is a meta-circular evaluator for a basic Lisp. It is | |
;; mostly taken from SICP 4.1*. I wanted to see if I could write a | |
;; debugger with it. Turns out if I want control over control flow I | |
;; need a register-based interpreter. | |
;; | |
;; * http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html#%_sec_4.1 |