Skip to content

Instantly share code, notes, and snippets.

(define tolerance 0.00001)
(define (fixed-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance))
(define (try guess)
(let ((next (f guess)))
(if (close-enough? guess next)
next
@youngnh
youngnh / gist:6346490
Created August 26, 2013 20:48
CPS Combinators in Java
public class Next<A, B, C> extends Task<A, C> {
private Task<A, B> task;
private Task<B, C> nextTask;
public Next(Task<A, B> task, Task<B, C> nextTask) {
this.task = task;
this.nextTask = nextTask;
}
@youngnh
youngnh / gist:4177670
Created November 30, 2012 18:45
Starting Plan
(query+ (frame+ {:column-metadata {"x" {:datatype :uri
:expression :one-to-one}}
:alias "topframe__1"
:source "topframe"}
(distinct+)
(project+ [x id])
(bind+ {x (new-function
{:op "iri"
:args [(new-function
{:op "http://www.w3.org/2005/xpath-functions#concat"
@youngnh
youngnh / api.clj
Created September 6, 2011 18:53
State Monad
(ns revelytix.spyder.query.interface
(:require [revelytix.sparql.parse :as sparqlp]
[revelytix.spyder.query.plan :as plan]
[revelytix.spyder.query.optimize :as opt]
[revelytix.spyder.query.process :as process]
[revelytix.spyder.log :as log])
(:import [revelytix.spyder.query.api QueryException]
[revelytix.spyder.sql.plan_tree QueryContext]))
(defn always [x]
@youngnh
youngnh / full_stack_test.clj
Created April 7, 2011 14:28
Quick test for Exception causes in wrap-stacktrace
(use 'ring.middleware.stacktrace)
(defn buggy [_]
(throw (Exception. "splork")))
(defn roachy [req]
(try
(buggy req)
(catch Exception e
(throw (Exception. "splunch" e)))))
@youngnh
youngnh / Display.java
Created April 7, 2011 02:46 — forked from anonymous/Display.java
Main.java
// This class does something with the board. I don't completely understand it, our teacher wrote it
package ui;
import centipede.Main;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JTextArea;
@youngnh
youngnh / gist:872757
Created March 16, 2011 16:22
wtf.clj
(fn [m]
(let [keys (set (keys m))
key-map (into {} (for [k keys] [k k]))]
(select-keys m (vals key-map))))
@youngnh
youngnh / gist:655752
Created October 30, 2010 21:17
pallet_simple.clj
(ns pallet-simple
(:use [pallet core compute resource])
(:use [pallet.crate.automated-admin-user])
(:use [pallet.crate.couchdb :only (couchdb)])
(:use [pallet.crate.java :only (java)])
(:use [pallet.crate.jetty :only (jetty)]))
(def ec2-access-id "Your-Access-ID-Here")
(def ec2-secret-key "Your-Secret-Key-Here")
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
# Greed is a dice game where you roll up to five dice to accumulate
# points. The following "score" function will be used calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
#
(ns revelytix.test-triplestore
(:use [reveltix.triplestore :only (*connection* connect-to dispose execute-command resultMessage= create-graph drop-graph insert-triple load-file)]))
(def *HOST* "rmi://australia/server1")
(def *FAMILY* "family")
(def *N3_FAMILY_FILE* "test/data/family.n3")
(def *SELECT-ALL* "select ?s ?p ?o where { ?s ?p ?o }")
;; Connection Fixture, establishes a connection for all execute-command calls to use
(defn connection-fixture [f]