Skip to content

Instantly share code, notes, and snippets.

View jmgimeno's full-sized avatar

Juan Manuel Gimeno jmgimeno

View GitHub Profile
(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)
@jmgimeno
jmgimeno / brush.js
Created September 21, 2013 22:13 — forked from enjalot/brush.js
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) {
;; 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
(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]))))
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)
/**
* 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._
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))
(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
@jmgimeno
jmgimeno / decay.clj
Created February 12, 2013 14:52 — forked from cgrand/decay.clj
(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 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.