Skip to content

Instantly share code, notes, and snippets.

We couldn’t find that file to show.
(with-test
(defn prime-factors [n]
((fn this [n_ last-divisor]
(if (= n_ 1)
[]
(let [
divisor
(or
(some
#(when (zero? (mod n_ %)) %)
(use 'clojure.contrib.test-is)
(use 'clojure.contrib.trace)
(with-test
(defn prime-factorials [n]
(if (= n 1)
'()
(if-let [
divisor
(some
(use 'clojure.contrib.test-is)
(def now (new java.util.Date))
(defn date [year month day]
(new java.util.Date (- year 1900) (dec month) day))
(with-test
(defn business-method [date]
(let [after #(pos? (compare %1 %2))]
; Refactor of http://www.fatvat.co.uk/2009/05/neural-networks-and-clojure.html
(defn create-network
[out]
(repeat out 0))
(defn run-network
[input weights]
(if
(> (reduce + (map * input weights)) 0.001)
@pbadenski
pbadenski / gist:731903
Created December 7, 2010 15:27
Newspeak start error
7 December 2010 4:26:41 pm
VM: Win32 - Newspeak Virtual Machine 10.02.2201
Image: nsboot-2010-02-22.00 [latest update: #0]
SecurityManager state:
Restricted: false
FileAccess: true
SocketAccess: true
Working Dir c:\Program Files\Newspeak Virtual Machine
@pbadenski
pbadenski / gist:2688654
Created May 13, 2012 14:20
haskell money types
data Dollars = Dollars
data Euro = Euro
class Money a where
(+) :: (Int, a) -> (Int, a) -> Int
(+) (a, _) (b, _) = (Prelude.+) a b
instance Money Dollars
instance Money Euro
// from http://mbostock.github.com/d3/ex/chord.html
var chord = d3.layout.chord()
.padding(0.05)
.sortSubgroups(d3.descending)
.matrix([
[11975, 5871, 8916, 2868],
[ 1951, 10048, 2060, 6171],
[ 8010, 16145, 8090, 8045],
[ 1013, 990, 940, 6907]
@pbadenski
pbadenski / Outer$delayedInit$body.class
Created July 12, 2016 10:19
Outer implements DelayedInit
public final class io.halik.scala.Outer$delayedInit$body extends scala.runtime.AbstractFunction0
minor version: 0
major version: 50
flags: ACC_PUBLIC, ACC_FINAL, ACC_SUPER
{
private final io.halik.scala.Outer $outer;
descriptor: Lio/halik/scala/Outer;
flags: ACC_PRIVATE, ACC_FINAL
(...)
@pbadenski
pbadenski / priority-based-task-execution.ts
Created February 28, 2017 16:49
Priority based task execution in JS using WebWorker
const FastPriorityQueue = require("fastpriorityqueue");
const setZeroTimeout = (callback: any) => {
const channel = new MessageChannel();
channel.port1.onmessage = callback;
channel.port2.postMessage("");
};
const queue: any = new FastPriorityQueue( (a: any, b: any) =>
a.data.priority > b.data.priority