Skip to content

Instantly share code, notes, and snippets.

(page "index.html"
(:require [tailrecursion.hoplon.reload :refer [reload-all]]
[clojure.set :refer [intersection]]))
(reload-all 0)
(defn random-mines [size n]
(loop [mines #{}]
(if (< (count mines) n)
(recur (conj mines [(rand-int size) (rand-int size)]))
@eschulte
eschulte / neural-net.clj
Created November 10, 2010 22:13
Neural Network DSL
(ns neural-net.core) ; Copyright Eric Schulte, GPL V3
(defprotocol Neural
"Protocol implemented by any element of a neural network."
(run [this x] "Evaluates the net")
(train [this x y d] "Trains the net returning the updated net and deltas")
(collect [this key] "Collect key from the network")
(inputs [this] "Number of inputs")
(outputs [this] "Number of outputs")
(check [this] "Ensure that the number of inputs matches the outputs"))
(defn fight-one-round [[a b :as fighters]]
(let [ticks (apply min (map :cooldown-remaining fighters))
damage-dealt (fn [fighter]
(if (= ticks (:cooldown-remaining fighter))
(:dmg fighter)
0))
tick (fn [fighter]
(update-in fighter [:cooldown-remaining]
(fn [cdr]
(if (= cdr ticks)
@abp
abp / draft.txt
Last active December 13, 2015 19:59
Every request is an endpoint to start some computation.
The input is the request, the output is the response.
Typical stages between those are:
Parsing, validation, storage, retrieving stored data and rendering an output.
Based on Ring and Compojure, we do the following to integrate routes with
Prismatic Graph:
Compojure matches the request against routes, calling the route handlers,
until a non nil result is returned.
Routes for integration with the Graph return route-keys,
@alandipert
alandipert / index.cljs
Last active March 7, 2016 04:17
Hoplon dataflow positioning example http://tailrecursion.com/~alan/tmp/css5000/
(page "index.html"
(:require [tailrecursion.hoplon.reload :refer [reload-all]]
[inputs :refer [slider]])
(:refer-hoplon :exclude [center]))
(reload-all)
(defn px [x] (str (.floor js/Math x) "px"))
(defn xp [x] (int (.slice x 0 -2)))
(ns racehub.om.facebook
(:require [cljs.core.async :as a]
[racehub.schema :as rs]
[schema.core :as s :include-macros true]))
;; ## Utilities
(defn prune
"Takes a mapping of keys -> new key names and a map and returns a
map with nils removed and keys swapped where they're present in the
(ns workflow.form
(:require
[castra.core :as castra]
[clojure.walk :as walk]
[clojure.data :as data]))
;; Form data manager ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- reset-vals!
[map-of-cells default]
@Quantisan
Quantisan / corr_demo.clj
Created June 26, 2011 00:49
first try using Incanter to analyse stocks data
(ns inc-sandbox.corr-demo
(:require [clojure.set :as set])
(:use (incanter core stats charts io))
(:require [clj-time.core :as time])
(:use (clj-time [format :only (formatter formatters parse)]
[coerce :only (to-long)])))
(defn sym-to-dataset
"returns a dataset read from a local CSV in './data/' given a Yahoo Finance symbol name"
[yf-symbol]

repl time

$ boot repl

boot.user=> (require :reload '[pipeline :refer [engine]]
                             '[mount.core :as mount])
"|| mounting... #'pipeline/engine"

starting it

@austinhaas
austinhaas / core.clj
Created September 4, 2012 23:53
Using virtual hosts with Clojure and Jetty
;;; This is my first pass at setting up virtual hosts; it works, but there is room for improvement.
;;; dependencies
;;[ring "1.1.5"]
;;[javax.servlet/servlet-api "2.5"]
;;[org.eclipse.jetty/jetty-server "7.6.1.v20120215"]
;;[org.eclipse.jetty/jetty-servlet "7.6.1.v20120215"]
(ns app.core
(:require [ring.util.servlet :refer (servlet)]