Skip to content

Instantly share code, notes, and snippets.

@gfredericks
gfredericks / rec-lazy-seq.clj
Last active August 29, 2015 14:05
Recursive lazy sequences in Clojure
(defmacro rec-lazy-seq
"Like lazy-seq, but also takes a single binding form that will be
a reference to the lazy seq object itself, so that the lazy seq can
be defined in terms of itself."
[[name] & body]
`(let [p# (promise)
ls# (lazy-seq
(let [~name (lazy-seq @p#)]
~@body))]
(deliver p# ls#)
@mrb
mrb / chords.clj
Last active August 29, 2015 14:05
core.logic db chords exercise
(ns chords.core
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :refer :all]
[clojure.core.logic.fd :as fd]
[clojure.core.logic.pldb :as pldb]
[fipp.edn :refer (pprint) :rename {pprint fipp}]))
(pldb/db-rel note-name ^:index p)
(pldb/db-rel octave ^:index p)
(pldb/db-rel note ^:index p1 ^:index p2)
@cgrand
cgrand / transmogrify.clj
Last active August 29, 2015 14:18
transmogrify->> rewrites last-threaded forms to use transducers.
(defmulti transmogrify
"Rewrites the last form of a thread-last to use transducer (if possible)."
(fn [f xform src & args] f))
(defmacro transmogrify->>
"Like ->> but uses transducers"
([x] x)
([src & xs]
(let [end (last xs)
xforms (butlast xs)

Reciprocal Needs in the Employment Relation

We can look at two sides of the management coin: What do the individuals get out of it? And what benefit does the whole system derive from it?

I will disregard any benefits that accrue to managers just by holding the position of managing. Those are just circular logic. Circular logic abounds in discussions of management and hierarchy. For example, consider status reports. It will be said that status reports are necessary so managers know what their employees are working on. It’s

(defn select-view
"Navigates to a sequence that is the result of a select on the
current structure. Has similar functionality of srange and filterer,
but can be used with arbitrary selectors making it vastly more
powerful."
[& path]
(fixed-pathed-path [late path]
(select* [this structure next-fn]
(next-fn (compiled-select late structure)))
(transform* [this structure next-fn]
@Engelberg
Engelberg / SantaClaus.clj
Created February 19, 2013 18:47
Santa Claus problem in Clojure
;; Ref-based Santa Claus solution, Written by Mark Engelberg
;; (start-simulation) to run
(def *num-elves* 10)
(def *num-reindeer* 9)
;; Santa is a ref containing either {:state :asleep} or {:state :busy, :busy-with <sequence-of-workers>}
(def santa (ref {:state :asleep}))
(defn waiting-room [capacity]
@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

@bhauman
bhauman / README.md
Last active December 3, 2019 16:43
ClojureScript minimal dev and prod setup.

Recent improvements to the ClojureScript compiler have greatly simplified setting up development versus production outputs.

This example uses Figwheel as something that you want to exclude for production, but the pattern is general.

With this simple setup you only need one html file/view and it will work for developement and production.

@swannodette
swannodette / om_data.cljs
Last active January 9, 2021 16:09
Om + DataScript
(ns om-data.core
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[datascript :as d]))
(enable-console-print!)
(def schema {})
(def conn (d/create-conn schema))
@bonifaido
bonifaido / oql_recipes.js
Last active January 21, 2022 08:00
VisualVM OQL Recipes
// The MIT License (MIT)
//
// Copyright (c) 2015 Nandor Kracser
//
// 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: