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
; this page: http://tinyurl.com/ndfzluz | |
; "higher order functions" basically means using functions as parameters to functions. Lots of languages have this - even C has function pointers | |
; Structure and Interpretation of Computer Programs, a classic 1993 text from MIT, says: | |
; "It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures" | |
; http://mitpress.mit.edu/sicp/ | |
; simple example - define "is-even": | |
(def is-even (fn [x] (= (mod x 2) 0))) |
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
package foo; | |
import java.util.*; | |
public class BadMap implements Map<String,String> { | |
private Map<String,String> theMap; | |
public BadMap(Map<String,String> m) { | |
theMap = m; | |
} |
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
(def moneys {:nickel 5 :dime 10 :quarter 25 :dollar 100}) | |
(def prices {:a 65 :b 100 :c 150}) | |
(def initial-state | |
{:inserted-money [:nickel :dime] | |
:items {:a 15 :b 3} | |
}) | |
(defn in-stock? [state item] | |
(let [stock-level (item (:items state))] |
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 game-loop [] | |
(let [anim-chan (au/anim-ch active) | |
ajax-chan (au/ajax-loop "world" slowth active)] | |
(go | |
(loop [state {:world {} :timestamp (js-now)}] | |
(when @active | |
(let [next-state | |
(alt! | |
anim-chan ([val] (do | |
(graphics/draw-map |
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 wikiparse.core | |
(:require [clojure.java.io :as io] | |
[clojure.data.xml :as xml] | |
[clojure.zip :refer [xml-zip]] | |
[clojure.data.zip.xml :refer [xml-> xml1-> text]]) | |
(:import [ org.apache.commons.compress.compressors.bzip2 BZip2CompressorInputStream]) | |
(:gen-class :main true)) | |
(defn bz2-reader | |
"Returns a streaming Reader for the given compressed BZip2 |
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 test.core) | |
(defn foo | |
"I don't do a whole lot." | |
[x] | |
(println x "Hello, World!")) |
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
sealed trait Aggregation | |
final object Aggregation | |
{ | |
def apply(dependencies: Seq[ProjectReference], transitive: Boolean = true): Aggregation | |
= new Explicit(dependencies, transitive) | |
implicit def fromBoolean(b: Boolean): Aggregation = if(b) Enabled else Disabled | |
val Enabled = new Implicit(true) | |
val Disabled = new Implicit(false) | |
final case class Implicit(enabled: Boolean) extends Aggregation | |
final class Explicit(val dependencies: Seq[ProjectReference], val transitive: Boolean) |
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
val scalatra = "org.scalatra" %% "scalatra" % scalatraVersion withSources () | |
val scalate = "org.scalatra" %% "scalatra-scalate" % scalatraVersion withSources () | |
val servletApi = "org.mortbay.jetty" % "servlet-api" % "2.5-20081211" % "provided" | |
val specs = "org.scalatra" %% "scalatra-specs" % scalatraVersion % "test" withSources () | |
val mockito = "org.mockito" % "mockito-all" % "1.8.5" % "test" withSources () |
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
lazy val javascriptIntegrationTest = task { | |
val statusLogger: JasmineStatusLogger = new JasmineStatusLogger(log) | |
val workingDirectory = new File(info.projectPath.asFile, "src/it/javascript").getPath | |
val phantomJasmine = workingDirectory + "/phantom-jasmine.js" | |
val specRunner = workingDirectory + "/SpecRunner.html" | |
val reportDir = new File(info.projectPath.asFile.getParent, | |
"app/target/reports/javascript-test/").getPath | |
try { | |
run(List("/usr/bin/phantomjs", phantomJasmine, specRunner, reportDir), true) |
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 org.apache.solr.client.solrj.SolrQuery | |
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer | |
def build(fullName: String, maxRows: Int): SolrQuery = { | |
val (firstInitial, firstName, bits, lastName) = split(fullName) | |
val queryString = | |
"{!type=dismax mm=-1 qf='name^100.0 name_phonetic^10.0 name_synonym^10.0'} %s %s %s %s" | |
.format(firstInitial, firstName, bits, "+" + lastName) | |
val query = new SolrQuery(queryString) |