Skip to content

Instantly share code, notes, and snippets.

@ecmendenhall
ecmendenhall / speclj-check-that.clj
Created October 21, 2013 20:45
A macro for Speclj-style simple-check assertions.
(ns my-great-project.core-spec
(:require [speclj.core :refer :all]
[simple-check.core :as sc]
[simple-check.generators :as gen]
[simple-check.properties :as prop]
[my-great-project.core :refer :all]))
(defmacro check-that [desc n property]
`(it ~desc
(let [check# (sc/quick-check ~n ~property)
@myitcv
myitcv / time_travel_trigger.sql
Last active March 8, 2022 06:50
Trigger-based equivalent of old PostgreSQL time travel module - see https://blog.myitcv.io/2014/02/25/row-level-version-control-with-postgresql.html for more details
/*
Copyright (c) 2015 Paul Jolly <paul@myitcv.org.uk)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
(import '[javax.script ScriptEngineManager])
(let [engine (.getEngineByName (ScriptEngineManager.) "nashorn")]
(println (= (.eval engine "' \\r\\n' == 0") true)))
; CIDER 0.6.0alpha (package: 20140316.1007) (Clojure 1.5.1, nREPL 0.2.3)
user> (.maxMemory (Runtime/getRuntime))
103284736
user> (require '[clojure.java.io :as io])
nil
user> (with-open [f (io/writer "/tmp/foo")] (doseq [x (range 50000)] (.write f (prn-str [x (range 1000)]))))
nil
user> (.length (io/file "/tmp/foo"))
194988890
user> (slurp "/tmp/foo")
@mikaelbr
mikaelbr / destructuring.js
Last active April 25, 2024 13:21
Complete collection of JavaScript destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
@candera
candera / ssh-repl.org
Last active February 9, 2019 07:50
ssh-repl

Embedding an SSH-accessible REPL in a Clojure process

N.B. This is now a library, thanks to the efforts of the wonderful @mtnygard. And the README does a good job of making clear just how terrible an idea it is to actually do this. :)

As any Clojurist knows, the REPL is an incredibly handy development tool. It can also be useful as a tool for debugging running programs. Of course, this raises the question of how to limit access to the REPL to authorized parties. With the Apache SSHD library, you can embed an SSH server in any JVM process. It takes only a little code to hook this up to a REPL, and to limit access either by public key or

@allgress
allgress / reagent_datascript.cljs
Last active February 16, 2023 21:16
Test use of DataScript for state management of Reagent views.
(ns reagent-test.core
(:require [reagent.core :as reagent :refer [atom]]
[datascript :as d]
[cljs-uuid-utils :as uuid]))
(enable-console-print!)
(defn bind
([conn q]
(bind conn q (atom nil)))
(in-ns 'eclj.core)
(defprotocol Fn
:on-interface clojure.lang.Fn
"Marker interface indicating invokeables that are explictly functions")
(defprotocol IFn
:on-interface clojure.lang.IFn
(^{:on :invoke} -invoke
[this]
(ns kleene)
;;
;; Inspired by "Regexes, Kleene Algebras and Real Ultimate Power"
;; http://plastic-idolatry.com/erik/oslo2014.pdf
;;
;; What do we want to do?...
;;
;; (def p1 (times (Var. "w") (Var. "o") (Var. "w"))
;; (matches? p1 "wow") ;; true
@ptaoussanis
ptaoussanis / transducers.clj
Last active December 17, 2021 13:54
Quick recap/commentary: Clojure transducers
(comment ; Fun with transducers, v2
;; Still haven't found a brief + approachable overview of Clojure 1.7's new
;; transducers in the particular way I would have preferred myself - so here goes:
;;;; Definitions
;; Looking at the `reduce` docstring, we can define a 'reducing-fn' as:
(fn reducing-fn ([]) ([accumulation next-input])) -> new-accumulation
;; (The `[]` arity is actually optional; it's only used when calling
;; `reduce` w/o an init-accumulator).