Skip to content

Instantly share code, notes, and snippets.

View danielcompton's full-sized avatar

Daniel Compton danielcompton

View GitHub Profile
@gfredericks
gfredericks / schema->gen.clj
Created March 26, 2014 16:49
Trying to generate test.check generators from prismatic schemas.
(ns schema->gen
"Functions for generating test data from schemas."
(:require [four.stateful :as four]
[re-rand :refer [re-rand]]
[schema.core :as sch]
[simple-check.generators :as gen]))
(defn ^:private re-randify-regex
"schema requires ^$ while re-rand forbids them"
[re]
@aphyr
aphyr / gist:aa3de337d12ac886eb96
Created October 9, 2014 23:59
Functional clojure.test
(require '[clojure.test :as test])
; Rewrite clojure.test to generate data structures instead of writing to
; stdout
(def ^:dynamic *results*
"Bound dynamically to an atom wrapping a vector of test report maps")
(defn add-name
"Given a testing report map, assoc's on a :name derived from the current
`clojure.test/testing` context."
= P:Cubed Clojure Language Learning Resources =
(Taken from P-Cubed internal wiki. Public site = www.p-cubed.co.za)
Clojure is a dynamic programming language that targets the Java Virtual Machine (and the CLR, and JavaScript).
It is designed to be a general-purpose language, combining the approachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming.
It also focusses a lot on handling concurrency elegantly.
Taster of the language: http://www.tryclj.com/
While it's dynamically typed by default, it can be optionally statically typed using core.typed.
@igorlukanin
igorlukanin / RethinkDB.kt
Last active October 29, 2015 03:35
Using RethinkDB Java driver with Kotlin
/**
* Database.kt
*/
import com.rethinkdb.RethinkDB
import com.rethinkdb.gen.ast.ReqlExpr
import com.rethinkdb.net.Connection
import com.rethinkdb.net.ConnectionInstance
object Database {
private lateinit var db: String
@joshmcarthur
joshmcarthur / validate.rb
Last active December 14, 2015 08:48
Quick demo of validating an XML document against a schema
require 'nokogiri'
# Public: Find the absolute path to a file
#
# This method finds a file that is relative to the
# location of the script, expanding anything that
# needs expanding (~, etc.)
#
# filename - the filename to find
@jiaaro
jiaaro / simpleTarget.js
Last active December 16, 2015 06:39
Partially de-obfuscated simpleTarget() from nodewar.com
// nodewar.com library function…
// o.lib.targeting.simpleTarget(ship, pos)
//
// mostly deobfuscated/deminified
//
function simpleTarget(ship, pos) {
var i, r, h,
torque = 0,
thrust = 0,
dir = o.lib.targeting.dir(ship, pos);
@stuartsierra
stuartsierra / common-dependencies.clj
Created January 23, 2014 21:40
Seed Maven Cache for Clojure Projects
;;; Seed Dependencies for Clojure Projects
;; This file contains Leiningen-style dependencies for many
;; commonly-used Clojure and Java libraries.
;; If you put all of these dependencies in a project.clj file, you
;; will NOT get a working project! However, running `lein deps` will
;; download all of these libraries as well as their transitive
;; dependencies. This is a convenient way to "seed" the local Maven
;; repository cache on a new machine.
@martintrojer
martintrojer / blocking-thread.clj
Last active March 4, 2017 20:59
core.async blocking IO
(time
(def data-thread
(let [c (chan)
res (atom [])]
;; fetch em all
(doseq [i (range 10 100)]
(thread (>!! c (blocking-get (format "http://fssnip.net/%d" i)))))
;; gather results
(doseq [_ (range 10 100)]
(swap! res conj (<!! c)))
@stuarthalloway
stuarthalloway / gist:2519604
Created April 28, 2012 14:50
Add database functions and bytes value types to Datomic
;; Builds of Datomic with revision numbers higher than 0.1.3057 have
;; support for :db.type/fn, :db.type/bytes, and :db/fn.
;; To add these types to a database created using with a pre-0.1.3057
;; build, simply run the database with a newer version of Datomic, and
;; execute the two transactions below.
[{:db/id #db/id [:db.part/db]
:db/ident :db.type/bytes
:fressian/tag :bytes
(resource
{:id ::index
:methods
{:post
{:consumes "application/octet-stream"
:consumer (fn [ctx _ body-stream]
(let [f (java.io.File/createTempFile "yada" ".tmp" (io/file "/tmp"))]
(infof "Saving to file: %s" f)
(save-to-file
ctx body-stream