Skip to content

Instantly share code, notes, and snippets.

View jmgimeno's full-sized avatar

Juan Manuel Gimeno jmgimeno

View GitHub Profile
@jmgimeno
jmgimeno / README.md
Created June 18, 2012 15:54 — forked from mbostock/.block
Pie Multiples

An example of multiple pie (donut) charts created with D3. The data is represented as a two-dimensional array of numbers; each row in the array is mapped to a pie chart. Thus, each pie represents the relative value of a number (such as 1,013) within its rows. Note that in this dataset, the totals for each row are not equal.

@jmgimeno
jmgimeno / arctween.js
Created June 24, 2012 08:59 — forked from enjalot/arctween.js
inlets for tributary
var data = [5, 25, 40, 20, 10];
var sw = parseInt(svg.style("width"), 10);
var sh = parseInt(svg.style("height"), 10);
var r = Math.min(sw, sh)/2;
var color = d3.scale.category20();
var arc = d3.svg.arc().outerRadius(r);
var donut = d3.layout.pie();
@jmgimeno
jmgimeno / monads.clj
Created November 24, 2012 20:59 — forked from martintrojer/monads.clj
The M word
(ns monads
(:require clojure.set))
(declare ^:dynamic return
^:dynamic bind)
(defn lift-inc [v]
(return (inc v)))
(defn m-add [mv n]
@jmgimeno
jmgimeno / roman.clj
Created November 29, 2012 15:05 — forked from puredanger/roman.clj
Roman numeral kata in Clojure
(use 'clojure.test)
(def numerals {1 "I",
4 "IV",
5 "V",
9 "IX",
10 "X",
40 "XL",
50 "L",
90 "XC"
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>One Graph</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.js"></script>
<script type="text/javascript" src="simple-graph.js"></script>
<style type="text/css">
body { font: 13px sans-serif; }
rect { fill: #fff; }
;; 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.
@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]
(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
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))
/**
* 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._