This file contains hidden or 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
(import [java.util HashMap]) | |
(def mymap (new HashMap)) | |
(. mymap put (hash "http://www.google.com/") "serp") | |
(def myhash (hash "http://www.google.com/")) | |
myhash | |
;;-87748806 | |
(. mymap get myhash) | |
;;"serp" | |
(spit "mytest.fb" (into {} mymap)) | |
(def mymap2 (java.util.HashMap. (read-string (slurp "mytest.fb")))) |
This file contains hidden or 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
(declare ^:dynamic myvar) | |
(def myvar nil) | |
(defn mycounter [x] | |
(inc x)) | |
(defn testdynvar [x] | |
(myvar x)) |
This file contains hidden or 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 ident.viterbi | |
(:use [clojure.pprint])) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Example | |
;; (def initpr (to-array [0.6 0.4])) | |
;; (def transpr (to-array-2d [[0.7 0.3][0.4 0.6]])) | |
;; (def emisspr (to-array-2d [[0.1 0.4 0.5][0.6 0.3 0.1]])) | |
;; (def hmm (make-hmm {:states ["rainy" "sunny"] :obs ["walk" "shop" "clean"] :init-probs initpr :emission-probs emisspr :state-transitions transpr})) | |
;; optimal state sequence and probability of sequence |
This file contains hidden or 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 remove-duplicates | |
"Returns a lazy sequence of the elements of coll with duplicates removed using a predicate" | |
[coll pred] | |
(let [step (fn step [xs seen] | |
(lazy-seq | |
((fn [[f :as xs] seen] | |
(when-let [s (seq xs)] | |
(if (some #(pred f %) seen) | |
(recur (rest s) seen) | |
(cons f (step (rest s) (conj seen f)))))) |
This file contains hidden or 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
// Ex 13.1 of Chapter 13 in Eloquent Javascript | |
// Write a function called registerEventHandler to wrap the | |
// incompatibilities of these two models. It takes three arguments: first | |
// a DOM node that the handler should be attached to, then the name of | |
// the event type, such as "click" or "keypress", and finally the handler | |
// function. | |
function registerEventHandler (node, eventType, handlerFN) { | |
if (node.attachEvent) { //IE |
This file contains hidden or 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
// Ex. 12.1 | |
//Write a function asHTML which, when given a DOM node, | |
//produces a string representing the HTML text for that node | |
//and its children. You may ignore attributes, just show nodes | |
//as <nodename>. The escapeHTML function from chapter 10 is | |
//available to properly escape the content of text nodes. | |
function escapeHTML(text) { | |
var replacements = {"<": "<", ">": ">", |
This file contains hidden or 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
<script type="text/javascript"> | |
function walkTheDOM(node, func) { | |
func(node); | |
node = node.firstChild; | |
while (node) { | |
walkTheDOM(node, func); | |
node = node.nextSibling; | |
} | |
} | |
function countTextNodes() { |
This file contains hidden or 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
<script type="text/javascript"> | |
function walkTheDOM(node, func) { | |
func(node); | |
node = node.firstChild; | |
while (node) { | |
walkTheDOM(node, func); | |
node = node.nextSibling; | |
} | |
} | |
function countTextNodes() { |
This file contains hidden or 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
<script type="text/javascript"> | |
function walkTheDOM(node, func) { | |
func(node); | |
node = node.firstChild; | |
while (node) { | |
walkTheDOM(node, func); | |
node = node.nextSibling; | |
} | |
} | |
function countTextNodes() { |
This file contains hidden or 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
// coming soon | |
// Ex. 6.1 | |
function forEach(array, action) { | |
for (var i = 0; i < array.length; i++) | |
action(array[i]); | |
} | |
function reduce(combine, base, array) { | |
forEach(array, function (element) { |
NewerOlder