Skip to content

Instantly share code, notes, and snippets.

View jmgimeno's full-sized avatar

Juan Manuel Gimeno jmgimeno

View GitHub Profile
@jmgimeno
jmgimeno / split-at-subsequence.clj
Created February 24, 2012 16:04
split-at-subsequence
(defn split-at-subsequence [mark input]
(when-let [sequence (seq input)]
(let [len (count mark)
mark-seq (seq mark)
partition (partition-all len 1 sequence)
step (fn step [pieces]
(when pieces
(let [[fst rst] (split-with #(not= mark-seq %) pieces)
tail (lazy-seq (step (nthnext rst len)))]
(if (empty? fst)
@jmgimeno
jmgimeno / rps.clj
Created March 17, 2012 18:59
Rock, paper, scissors
;; Una de les formes de trobar bones solucions és trobar bones
;; estructures de dades de partida.
;; Aquí has de representar tres coses:
;; 1. Regles del joc (quina cosa guanya a què)
;; 2. Resultats d'una ronda
;; 3. Resulatats d'un torneig
;; Formes de representar 1.
@jmgimeno
jmgimeno / playing-cps.clj
Created March 21, 2012 14:20
Playing with continuation passing style
(defn vec-cps
[x y k]
(k [x y]))
(defn dec-cps
[x k]
(k (dec x)))
(defn *-cps
[x y k]
@jmgimeno
jmgimeno / crazy-seq.clj
Created April 18, 2012 06:56
Does not hold the head of a sequance only its first element and the generating function.
(defn crazy-seq [head f]
(reify
clojure.lang.ISeq
(first [_] head)
(more [_] (crazy-seq (f head) f))
(next [this] (rest this))
(seq [this] this)
(equiv [_ _] false)))
(def s (crazy-seq 0 inc)) ; hold head
@jmgimeno
jmgimeno / ants.clj
Created June 13, 2012 13:26
Modernized version of ant simulation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;;; Updated to Clojure 1.4 by Baishampayan Ghose <[email protected]>
@jmgimeno
jmgimeno / bfc.clj
Created June 14, 2012 07:20
Brainf*** compiler (Alan Dipert)
(defn bfc
[program]
(let [allowed #{\+ \- \< \> \[ \] \.}
src (->> program (filter allowed)
(interpose \space) (apply str))
fns (zipmap '(- + < > . ?) (repeatedly gensym))]
(letfn [(bfc* [s]
(if (vector? s)
`(while (not (~(fns '?))) ~@(map bfc* s))
`(~(fns s))))]
@jmgimeno
jmgimeno / index.html
Created June 15, 2012 07:44 — forked from mbostock/.block
Squares ↔ Hexagons
<!DOCTYPE html>
<meta charset="utf-8">
<style>
path {
fill: none;
stroke: #000;
stroke-width: .6px;
}
@jmgimeno
jmgimeno / index.html
Created June 15, 2012 10:49 — forked from bunkat/index.html
Swimlane Chart using d3.js
<html>
<head>
<title>Swimlane using d3.js</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.js"></script>
<script type="text/javascript" src="randomData.js"></script>
<style>
.chart {
shape-rendering: crispEdges;
}
@jmgimeno
jmgimeno / histogram-chart.js
Created June 15, 2012 11:00 — forked from mbostock/.block
Histogram Chart
function histogramChart() {
var margin = {top: 0, right: 0, bottom: 20, left: 0},
width = 960,
height = 500;
var histogram = d3.layout.histogram(),
x = d3.scale.ordinal(),
y = d3.scale.linear(),
xAxis = d3.svg.axis().scale(x).orient("bottom").tickSize(6, 0);
@jmgimeno
jmgimeno / COMBO17.csv
Created June 16, 2012 19:41 — forked from syntagmatic/COMBO17.csv
Galactic Parallel Coordinates
We can't make this file beautiful and searchable because it's too large.
Nr,Rmag,e.Rmag,ApDRmag,mumax,Mcz,e.Mcz,MCzml,chi2red,UjMAG,e.UjMAG,BjMAG,e.BjMAG,VjMAG,e.VjMAG,usMAG,e.usMAG,gsMAG,e.gsMAG,rsMAG,e.rsMAG,UbMAG,e.UbMAG,BbMAG,e.BbMAG,VnMAG,e.VbMAG,S280MAG,e.S280MA,W420FE,e.W420FE,W462FE,e.W462FE,W485FD,e.W485FD,W518FE,e.W518FE,W571FS,e.W571FS,W604FE,e.W604FE,W646FD,e.W646FD,W696FE,e.W696FE,W753FE,e.W753FE,W815FS,e.W815FS,W856FD,e.W856FD,W914FD,e.W914FD,W914FE,e.W914FE,UFS,e.UFS,BFS,e.BFS,VFD,e.VFD,RFS,e.RFS,IFD,e.IFD
6,24.995,0.097,0.935,24.214,0.832,0.036,1.4,0.64,-17.67,0.14,-17.54,0.25,-17.76,0.25,-17.83,0.14,-17.6,0.25,-17.97,0.25,-17.76,0.14,-17.53,0.25,-17.76,0.25,-18.22,0.17,6.60E-04,3.85E-03,1.27E-02,3.72E-03,1.89E-02,4.48E-03,1.82E-02,3.55E-03,1.47E-02,3.01E-03,1.66E-02,4.09E-03,1.88E-02,5.63E-03,2.46E-02,3.51E-03,2.45E-02,5.24E-03,2.16E-02,2.66E-03,2.44E-02,5.46E-03,3.77E-02,6.10E-03,1.17E-02,1.01E-02,1.87E-02,2.39E-03,1.63E-02,1.29E-03,1.73E-02,1.41E-03,1.65E-02,4.34E-04,2.47E-02,4.83E-03
9,25.013,0.181,-0.135,25.303,0.927,0.122,0.864,0.41,-18.28,0.22,17.86,0.55,-18