Skip to content

Instantly share code, notes, and snippets.

@joinr
joinr / ncproject.clj
Created September 9, 2017 18:08
nightcode project that builds on windows - but still has a broken repl
(defproject nightcode "2.3.8-SNAPSHOT"
:description "An IDE for Clojure and Java"
:url "https://github.com/oakes/Nightcode"
:license {:name "Public Domain"
:url "http://unlicense.org/UNLICENSE"}
:source-paths #{"src/clj" "src/cljs"}
:resource-paths #{"resources"}
:dependencies [[org.clojure/test.check "0.9.0" :scope "test"]
[adzerk/boot-cljs "1.7.228-2" :scope "test"]
; cljs deps
@joinr
joinr / wierd.clj
Last active December 12, 2017 10:27
bizarre destructuring behavior
(def m {:a ["a" [1 2 3]] :b ["b" [4 5 6]]})
(for [[k v] m
[l xs] v]
[l xs])
;;returns...
;;([\a nil] [1 2] [\b nil] [4 5])
;;Wat?
;;Why are strings being destructured this way?
;;Expected
@joinr
joinr / heatwierd.clj
Created February 3, 2018 18:03
incanter heat-map artifact example
(ns heat
(:require [incanter [core :as i] [charts :as c]]))
(defn f [x y] (i/minus (i/sq x) (i/sq y)))
;;looks good
(i/view (c/heat-map f -10 10 -10 10))
;;boxes for xyblock renderer are too small,
;;leaving gaps that show the grey background
;;behind, giving the appearance of "lines"
;;all over the plot.
@joinr
joinr / demo.lisp
Last active March 22, 2018 07:49
error demo
(defpackage :err-demo
(:use :common-lisp))
(in-package :err-demo)
(defun str (x &rest xs)
(format nil "~{~a~}" (cons x xs)))
(defun show-excuse (excuse)
((print (str excuse " is no excuse for poor errors!"))))
@joinr
joinr / Clojure.java
Last active March 30, 2018 20:52
output from Common Lisp Clojure Compiler, Clojure Java RT Front-end, circa May 2006
/* Generated by Clojure */
package org.clojure;
import org.clojure.runtime.*;
public class Clojure{
/* Generated by Clojure from the following Lisp:
(defn* f0 (NIL))
*/
static public class f0 extends AFn{public Object invoke(ThreadLocalData __tld) throws Exception
{return null;}}
/* Generated by Clojure from the following Lisp:
@joinr
joinr / deepmap.clj
Created May 8, 2018 20:40
building a deep nested map without blowing the stack
(defn children [item coll]
(-> (filter #(= (:parent %) (:id item)) coll)
seq))
(defn item-children
([get-children item coll]
(if-let [xs (get-children item coll)]
(map #(lazy-seq (cons item (item-children get-children % coll))) xs)
(list [item nil])))
([item coll] (item-children (memoize children) item coll)))
@joinr
joinr / specproblem.clj
Created May 22, 2018 08:19
spec problem?
(ns spec-problem)
;;This is a smalle example of some circa clojure 1.7 code I found
;;that spec seemed to dislike when I was trying to port it.
;;It comes from the fn-fx library by way of the freactive.core
;;library fyi.
;;dumb function pre-defined...
(defn my-fn [x] (+ x 2))
;;dumb macro that just builds an anonymous fn that
@joinr
joinr / incdebug.clj
Created July 26, 2018 19:38
error in incanter's delegation to core.matrix for building datasets from xls due to sparse data
(ns incdebug.core
(:require [incanter [excel :as xls] [core :as i]]
[clojure.core.matrix.impl.dataset :as ds]
[clojure.core.matrix.protocols :as mp]))
;;this is what incanter is doing....we'll tease it apart
;;to debug.
#_(defn- read-sheet [rows-it header-keywords]
(let [colnames (incanter.excel.cells/read-line-values (first rows-it))
rows (->> (rest rows-it)
@joinr
joinr / asyncpromise.clj
Created August 9, 2018 07:30
example of hacky promise implementation in core.async
(ns blah
(:require [clojure.core.async :as a]))
(defn error [x] {:error x})
(defn success [x] {:success x})
(defmacro maybe [expr]
`(->> (try (success ~expr)
(catch ~'Exception e# (error e#)))))
@joinr
joinr / spectruncate.clj
Created August 18, 2018 10:50
example of using spec to truncate keys....
;;So for my incoming API boundary, I only would retain keys defined in
;;spec after receiving data from client (to wholesale limit potentially
;;dangerous crafting of json/edn payload).
;;Likewise, at my outgoing boundary, I would similarly only retain keys
;;defined in spec (sending absolute minimum data necessary).
(ns incoming
(:require [clojure.spec.alpha :as s]))