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
/* | |
After watching a few of Notch's (and Mojan's) "write a game in a weekend" livecasts and | |
pulling apart some of the code (http://www.mrspeaker.net/2011/12/30/colorising-sprites-1/) | |
I've noticed that the collision detection routines are broken into two methods - usually | |
called "move" and "move2". | |
The move method gets the amount the entity will move on the X axis and calls | |
move2 with move2(x, 0). Then the same thing is done with the Y: move2(0,y). | |
Why would this be necessary? I've broken the code down into pseudo code to see if I |
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 ded | |
"Structural Data EDitor for Clojure with zippers. Inspired by Interlisp: http://larry.masinter.net/interlisp-ieee.pdf" | |
(:require [clojure.zip :as z]) | |
(:use [clojure.pprint :only (with-pprint-dispatch code-dispatch pprint)] | |
[clojure.repl :only (source-fn)])) | |
(defn print-hr | |
"Prints 30 dashes and a newline." | |
[c] | |
(println (apply str (repeat 30 c)))) |
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 map-incr-unsafe [] | |
(let [m (java.util.HashMap.)] | |
(.put m "a" 0) | |
(doseq [i (range 1000000)] | |
(let [a (.get m "a")] | |
(.put m "a" (inc a)) | |
)))) | |
(defn map-incr-safe [] | |
(let [o (Object.) |
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 ignacio.tfidf (:require [clojure.contrib.string :as string])) ;; Simple tfidf in clojure, for fun. | |
(def stopwords (set (string/split #"\n" (slurp "./stopwords.txt")))) | |
(defn tokenize [raw-text] ;; Lowercases and splits on non-letters, non-numbers. | |
(remove stopwords (string/split #"[^a-z0-9äöüáéíóúãâêîôûàèìòùçñ]+" (string/lower-case raw-text)))) | |
(defn idf2 [n-docs match] (Math/pow (Math/log (/ n-docs (count (keys match)))) 2)) | |
(defn index-one [fname] ;; Index for one file. Given an fname, returns a map of token -> map of (fname, count) |
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 example.flash | |
(:use compojure.core) | |
(:use ring.util.response) | |
(:use ring.middleware.session) | |
(:use ring.middleware.flash) | |
(:require [compojure.route :as route])) | |
(defn show-new [flash] | |
(str "Flash: " flash | |
"<br/> |
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
;annotation syntax | |
(import [java.lang.annotation Retention RetentionPolicy Target ElementType] | |
[javax.xml.ws WebServiceRef WebServiceRefs]) | |
(definterface Foo (foo [])) | |
;annotation on type | |
(deftype ^{Deprecated true | |
Retention RetentionPolicy/RUNTIME | |
javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"] |
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
#!/usr/bin/env python | |
""" | |
Draws Hinton diagrams using matplotlib ( http://matplotlib.sf.net/ ). | |
Hinton diagrams are a handy way of visualizing weight matrices, using | |
colour to denote sign and area to denote magnitude. | |
By David Warde-Farley -- user AT cs dot toronto dot edu (user = dwf) | |
with thanks to Geoffrey Hinton for providing the MATLAB code off of | |
which this is modeled. |
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
overtcards = [] | |
currentplayer = 0 | |
score = {0=>0,1=>0} | |
def shuffle(arr) | |
new=[] | |
new2=arr.select do |x|x end | |
arr.size.downto(1) { |n| new.push new2.delete_at(rand(n)) } | |
new | |
end |