This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/projects/cloby ➔ cat examples/simple.rb | |
require 'cloby' | |
class MyClojureObj < Clojure::Object | |
def initialize | |
dosync { @foo = 'foo' } | |
end | |
attr_accessor :foo | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/$ 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns jquerytest.core) | |
(def jquery (js* "$")) | |
(jquery | |
(fn [] | |
(-> (jquery "div.meat") | |
(.html "This is a test.") | |
(.append "<div>Look here!</div>")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)] |