Skip to content

Instantly share code, notes, and snippets.

View catharinejm's full-sized avatar
🐶

Catharine Manning catharinejm

🐶
View GitHub Profile
user=> (defn make-queue [elems] (into clojure.lang.PersistentQueue/EMPTY elems))
#'user/make-queue
user=> (make-queue [1 2 3])
#<PersistentQueue clojure.lang.PersistentQueue@7861>
user=> (set! *data-readers* {'p/q #'make-queue})
{p/q #'user/make-queue}
user=> (read-string "#p/q [1 2 3]")
#<PersistentQueue clojure.lang.PersistentQueue@7861>
user=> #p/q [1 2 3]
(ns asm-test.test-class
(:import [clojure.asm ClassWriter ClassVisitor Opcodes Type]
[clojure.asm.commons GeneratorAdapter Method]
[clojure.lang DynamicClassLoader Compiler RT]))
(def cw (ClassWriter. ClassWriter/COMPUTE_MAXS))
(. cw (visit Opcodes/V1_5 Opcodes/ACC_PUBLIC
"asm_test/test_class/TestClass" nil "java/lang/Object" (make-array String 0)))
(let [m (Method. "doit" Type/VOID_TYPE (into-array Type [(Type/getType String)]))
@catharinejm
catharinejm / bitwise.clj
Created November 19, 2014 14:23
bitwise op shorthand, with metadata (inline!) from originals
(defmacro bit-ops
[]
`(do
~@(for [[s l] '[[<< bit-shift-left]
[>> bit-shift-right]
[>>> unsigned-bit-shift-right]
[| bit-or]
[& bit-and]
[xor bit-xor]
[!b bit-not]]]
@catharinejm
catharinejm / dockerinit.zsh
Created February 17, 2015 23:07
faster boot2docker shellinit
# Docker
dockervars="$HOME/.dockervars"
function boot2docker {
case "$1" in
up|start|boot)
command boot2docker "$@"
command boot2docker shellinit > "$dockervars" 2> /dev/null
source "$dockervars"
;;
down|stop|halt)
@catharinejm
catharinejm / genseq.coffee
Last active August 29, 2015 14:16
genseq.coffee
isGen = (f) ->
f? and f.constructor.name is 'GeneratorFunction'
isIter = (f) ->
f? and f.constructor.name is 'GeneratorFunctionPrototype'
class Seq
constructor: (it) ->
if isGen it
@_it = it()
fs = require 'fs'
#request = require 'request'
#
request = ({uri}, done) ->
done null, uri
reqreq = (uris) ->
for uri in uris
yield ( (done) -> done null, uri )
@catharinejm
catharinejm / coffee
Last active August 29, 2015 14:18
Coffeescript Nave shim
#!/usr/bin/env zsh
set -e
function nave_version_file {
file="$(pwd)/.nave-version"
if [ -f "$file" ]; then
echo "$file"
elif `git rev-parse &>/dev/null`; then
file="$(git rev-parse --show-toplevel)/.nave-version"
@catharinejm
catharinejm / clojure-setup.md
Last active August 29, 2015 14:21
Clojure Setup

Getting Clojure set up

Leiningen

Leiningen is the de facto clojure project and package manager. It can be installed via homebrew on OS X

brew install leiningen

or just download the shell script and put it on your path. If ~/bin is on your path, then you would do:

@catharinejm
catharinejm / Concat.java
Created August 15, 2015 23:28
Clojure lazy concat without stack overflow
/**
* Copyright (c) Rich Hickey. All rights reserved.
* The use and distribution terms for this software are covered by the
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
* which can be found in the file epl-v10.html at the root of this distribution.
* By using this software in any fashion, you are agreeing to be bound by
* the terms of this license.
* You must not remove this notice, or any other, from this software.
**/
module Interpreter
import Data.Fin
import Data.Vect
data Ty = TyInt
| TyBool
| TyStr
| TyFun Ty Ty