Skip to content

Instantly share code, notes, and snippets.

(ns ninth-post.websocket
(:use [aleph.http core server]
lamina.core)
(:require [clj-json.core :as json]))
(def square (ref {:x 100 :y 100}))
(def broadcast-channel (channel))
(defn handler [ch handshake]
(siphon ch broadcast-channel)
anonymous
anonymous / gist:734222
Created December 9, 2010 02:00
~/projects/cloby ➔ cat examples/simple.rb
require 'cloby'
class MyClojureObj < Clojure::Object
def initialize
dosync { @foo = 'foo' }
end
attr_accessor :foo
end
watch( 'test/.*\.clj' ) {|md| test_stuff }
watch( 'src/.*\.clj' ) {|md| test_stuff }
def colorize(text, color_code)
"#{color_code}#{text}\e[1;37m"
end
def red(text); colorize(text, "\e[0;31m"); end
def green(text); colorize(text, "\e[0;32m"); end
(defn palindrome-o [x]
(exist [a b c d]
(digit-o a) (digit-o b) (digit-o c) (digit-o d)
(nonrel/project [a b c d]
(== x (* (+ (* 10 a) b)
(+ (* 10 c) d)))
(nonrel/project [x]
(== (> x 0) true)
(== (>= x 100) true)
(== (mod (int (/ x 1000)) 10)
(def alphas (c/one-of "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))
(def digits c/digit)
(def special (c/one-of ".-"))
(def float-value
(domonad c/parser-m
[sign (c/optional (c/is-char \-))
rat c/natural
dec (c/optional (c/>> (c/is-char \.) c/natural))]
(Float/parseFloat (str sign rat "." dec))))
@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]
@ordnungswidrig
ordnungswidrig / state-is-a-fold.clj
Created June 16, 2011 15:50
State is a fold over events
(ns state-is-a-fold
(:use clojure.test))
;;; After all, state is a fold of events. For example let's say the events are a sequence of numbers
;;; and we are folding by addition:
(deftest simple
(let [events [1 5 2 4 3]
state (reduce + events)]
(is (= 15 state))))
@steveklabnik
steveklabnik / quality.rake
Created July 11, 2011 20:18
My new favorite Rake task
require 'flog'
require 'flog_task'
require 'flay'
require 'flay_task'
require 'roodi'
require 'roodi_task'
FlogTask.new :flog, SOME_NUMBER_HERE, %w[app lib]
FlayTask.new :flay, OTHER_NUMBER_HERE, %w[app lib]
RoodiTask.new 'roodi', ['app/**/*.rb', 'lib/**/*.rb']
@ryancrum
ryancrum / jquerytest.cljs
Created July 21, 2011 02:24
How to use jQuery from ClojureScript
(ns jquerytest.core)
(def jquery (js* "$"))
(jquery
(fn []
(-> (jquery "div.meat")
(.html "This is a test.")
(.append "<div>Look here!</div>"))))
@mjg123
mjg123 / ajax.cljs
Created July 21, 2011 22:43
How to make a json(p) request from ClojureScript using jQuery
(def jquery (js* "$"))
(defn show [msg]
(let [data-as-json ((js* "JSON.stringify") msg nil 4)]
((js* "alert") data-as-json)))
(defn make-js-map
"makes a javascript map from a clojure one"
[cljmap]
(let [out (js-obj)]