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
(use 'clojure.contrib.seq-utils) | |
(use 'clojure.walk) | |
(import '(java.io File LineNumberReader InputStreamReader PushbackReader) | |
'(java.lang.reflect Modifier Method Constructor) | |
'(clojure.lang RT Compiler Compiler$C)) | |
;; Yoinked and modified from clojure.contrib.repl-utils. | |
;; Now takes a var instead of a sym in the current ns | |
(defn get-source-from-var | |
"Returns a string of the source code for the given symbol, if it can |
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
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.Comparator; | |
public class KalaTournament { | |
private enum WIN_FLAG { | |
PLAYER_0, PLAYER_1, DRAW | |
} | |
private static class AIComparer implements Comparator<KalaPlayer> { |
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
- [2] => Paper Object | |
- ( | |
- [id:Paper:private] => | |
- [title:Paper:private] => TestPaper | |
- [author:Paper:private] => | |
- [authorID:Paper:private] => 0 | |
- [lastEditor:Paper:private] => | |
- [dateSubmitted:Paper:private] => | |
- [lastEdited:Paper:private] => | |
- [paperSynopsis:Paper:private] => |
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 my-count [coll] | |
(reduce (fn [n x] (inc n)) 0 coll)) | |
(my-count [1 2 3 3]) | |
(defn my-reverse [coll] ;;only works for vectors atm | |
(reduce (fn [xs x] (into [x] xs)) [] coll)) | |
(my-reverse [1 2 3]) |
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 count-dots [s] | |
(count (filter #(= \. %) s))) |
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 reverse-int | |
"Returns an integer with its digits reversed, e.g. 123 returns 321" | |
[x] | |
(BigInteger. (su/reverse (pr-str x)))) | |
(defn palindromic? | |
"Returns true if the number is palindromic, e.g. 121, 1234321" | |
[x] | |
(= x (reverse-int x))) |
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
(->> (clojure.lang.Compiler/analyze clojure.lang.Compiler$C/EVAL | |
'(let [a 3 b 4] a)) .fexpr .methods first .locals keys (map #(.sym | |
%))) |
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
(defmodel User | |
:username | |
:password) | |
(defmodel Comment | |
:text | |
[:belongs-to User]) | |
(defmodel Post | |
:text |
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 clojure_refactoring.rename-fn-test | |
(:use clojure.test)) | |
(deftest test-fn-location | |
(in-ns 'refactoring-test-fn-rename) | |
(clojure.core/refer-clojure) | |
(defn a [b] (inc b)) | |
(in-ns 'clojure_refactoring.rename-fn-test) | |
(refer 'refactoring-test-fn-rename) | |
(is (not= (find-var 'refactoring-test-fn-rename/a) |
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
(deftest test-fn-location | |
(create-ns 'refactoring-test-fn-rename) | |
(with-ns 'refactoring-test-fn-rename | |
(clojure.core/refer-clojure) | |
(defn ^{:line 19 :file "foo.clj"} a [b] (inc b))) | |
(is (= (:line (meta (find-var 'refactoring-test-fn-rename/a))) | |
19)) | |
(remove-ns 'refactoring-test-fn-rename)) |