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
;;Three ways to count the number of occurrences in a collection | |
;; ("orange" "bottle" "coke" "bottle") => [("bottle" "coke" "orange") (2 1 1)] | |
(let [c '("orange" "bottle" "coke" "bottle")] | |
(let [counts (reduce #(conj %1 (hash-map %2 (inc (get %1 %2 0)))) | |
{} c)] | |
[(keys counts) | |
(vals counts)]) | |
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
# print to console for debugging | |
p = (x) -> | |
console.log x | |
x | |
# generate HSL object from normalized arguments | |
hsl = (hue, saturation, lightness) -> | |
h: hue | |
s: saturation | |
l: lightness |
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
$("#marketList tbody.yui-dt-data") | |
.find('tr') | |
.map(function(_,row){ | |
var $r = $(row); | |
var data = { | |
"name": $r.find(".yui-dt-col-market").text() | |
, "sell": parseFloat($r.find(".yui-dt-col-sell").text()) | |
, "buy": parseFloat($r.find(".yui-dt-col-buy").text()) | |
}; | |
return data; |
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
class Cl.errors.Error | |
description: -> "An error has occurred in Cassowary Coffee" | |
toString: -> @description() | |
class Cl.errors.ConstraintNotFound extends Cl.errors.Error | |
description: -> "Tried to remove a constraint never added to the tableau" | |
class Cl.errors.NonlinearExpression extends Cl.errors.Error | |
description: -> "The resulting expression would be nonlinear" |
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
;;ClojureScript compiler 329708 (2011.12.14) | |
;;Based on RangeNum protocol by Tassilo Horn: | |
;; http://groups.google.com/group/clojure/browse_thread/thread/f3192b351b0ab2b4/ec6c106dfdcf0cf9?lnk=gst&q=ranged#msg_ed6de8b7a5cabf41 | |
(ns c2.main | |
(:refer-clojure :exclude [+]) | |
(:use-macros [c2.util :only [typeof]])) | |
(defprotocol RangeNumProtocol |
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
;;Using the Cassowary constraint solver from ClojureScript | |
;;This demo shows using multimethods for readable constraint syntax using +, -, and =. | |
;;Output is a row of circles with random radii spaced so that the space between their boundaries is uniform. | |
(ns c2.main | |
;;refer-clojure :exclude is currently broken in ClojureScript master | |
;;Ticket open: http://dev.clojure.org/jira/browse/CLJS-114 | |
;;Fix applied here: https://github.com/lynaghk/clojurescript/tree/114-refer-clojure-exclude | |
(:refer-clojure :exclude [+ - =]) | |
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 termite.core | |
(:refer-clojure :exclude [==]) | |
(:use [clojure.core.logic])) | |
(defn- meta-guard [key] | |
#(do | |
(println % ":\t" (meta %)) | |
(-> % meta key (= true)))) | |
;;remove anything that has {:clj true} metadata, including on var declarations. |
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 form '(defmacro nom [x] (some (delicious)) forms)) | |
;;this works nicely | |
(let [x (lvar) | |
rest (lvar)] | |
(run* [q] | |
(== form (llist 'defmacro x rest)) | |
(== q x))) | |
;;=> (nom) | |
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
.event.scientific | |
color: gray | |
padding-left: 20px | |
//Add a blue CSS triangle | |
//could use any kind of icon or sprite in here too, of course | |
&:before | |
width: 0px | |
height: 0px | |
content: "" | |
position: absolute |
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;Sketches of code I want to be able to write in ClojureScript | |
;; | |
;;See | |
;; | |
;; lampwww.epfl.ch/~imaier/pub/DeprecatingObserversTR2010.pdf | |
;; http://www.flapjax-lang.org/ | |
;; https://parasol.tamu.edu/groups/pttlgroup/property-models/index.html | |
;; | |
;; perf consideration (thanks dnolen): https://github.com/clojure/core.logic/blob/master/src/main/clojure/cljs/core/logic.cljs#L111 |