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 tetris.core | |
(:import (java.awt Color Dimension BorderLayout) | |
(javax.swing JPanel JFrame JOptionPane JButton JLabel) | |
(java.awt.event KeyListener)) | |
(:use clojure.contrib.import-static deflayout.core | |
clojure.contrib.swing-utils) | |
(:gen-class)) | |
(import-static java.awt.event.KeyEvent VK_LEFT VK_RIGHT VK_DOWN VK_UP VK_SPACE) |
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
if(!d3.chart) d3.chart = {}; | |
d3.chart.brush = function() { | |
var g; | |
var data; | |
var width = 600; | |
var height = 30; | |
var dispatch = d3.dispatch(chart, "filter"); | |
function chart(container) { |
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
;; I was wondering how to show graphs in a web application | |
;; First use pomegranate to add the ring library to your classpath | |
(require 'cemerick.pomegranate) | |
(cemerick.pomegranate/add-dependencies :coordinates '[[ring "1.2.0"]] :repositories {"clojars" "http://clojars.org/repo" } ) | |
;; And pull in jetty | |
(require 'ring.adapter.jetty) | |
;; Create a minimal app |
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 prime-factors.core | |
(:require [clojure.core.logic :refer :all]) | |
(:require [clojure.core.logic.fd :refer [in interval eq]])) | |
(defn factor-pairs [number] | |
(run* [pair] | |
(fresh [factor1 factor2] | |
(in factor1 factor2 (interval 2 number)) | |
(eq (= number (* factor1 factor2))) | |
(== pair [factor1 factor2])))) |
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
object BenchmarkCommon { | |
import scala.util.Random | |
val DatasetSize = 10000 | |
val Iterations = 10000 | |
val ArrayPoolSize = 1000 | |
val ArrayPool = { | |
def randomArray(): Array[Int] = { | |
val array = new Array[Int](DatasetSize) | |
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
/** | |
* Part Zero : 10:15 Saturday Night | |
* | |
* (In which we will see how to let the type system help you handle failure)... | |
* | |
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0) | |
*/ | |
import scalaz._ | |
import Scalaz._ |
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
object DerivingApplicative extends Application { | |
val o1: Option[Int] = Some(1) | |
val o2: Option[Int] = Some(2) | |
val s1 = Stream from 1 | |
val s2 = Stream(0, 1) | |
object Take1 { | |
def tupleOptions[A, B](a: Option[A], b: Option[B]): Option[(A, B)] = | |
(a, b) match { | |
case (Some(a), Some(b)) => Some((a, b)) |
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 solve-logic-puzzle [] | |
(let [people [:amaya :bailey :jamari :jason :landon]] | |
(first | |
(for [[fortune time cosmopolitan us-weekly vogue] (permutations people) ; magazines | |
[asiago blue-cheese mascarpone mozzarella muenster] (permutations people) ; cheeses | |
; We bind the reservations in two steps, so we have a name for the overall order | |
reservations (permutations people) | |
:let [[five six seven seven-thirty eight-thirty] reservations] | |
; THE CONSTRAINTS IN PLAIN ENGLISH |
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 net.cgrand.decay | |
"Exponentially decaying lists. See http://awelonblue.wordpress.com/2013/01/24/exponential-decay-of-history-improved/ | |
for background and http://clj-me.cgrand.net/2013/02/12/decaying-lists-log-scale-for-lists/ for documentation") | |
;; PRNG, formulas straight from java.util.Random javadoc | |
(defn- seed ^long [^long n] | |
(bit-and (unchecked-multiply n 0x5DEECE66D) | |
(unchecked-dec (bit-shift-left 1 48)))) | |
(defn- next-seed ^long [^long seed] |
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 code requires a Clojure built from https://github.com/cgrand/clojure/tree/fold+transients | |
;; | |
;; currently (with master) frequencies can't be written with both fold and transients | |
;; with my branch you can. | |
;; however the contract for the combinef function evolves: | |
;; O arg -> init value for reduce | |
;; 1 arg -> "clean" the return value of reduce (was undefined) -- in general case, it's the identity | |
;; 2 args -> combine the two values | |
;; | |
;; it follows that the true zero of a monoid is now returned by (m (m)) but this affects only people implementing coll-fold. |