Skip to content

Instantly share code, notes, and snippets.

;; Example Machfile (https://github.com/juxt/mach)
;; Install: npm install -g @juxt/mach
;; Run: mach hibye
;; I'd like it to print hallo then bye, but it prints bye then hallo.
;; This is because it does a reverse topological sort. It would be
;; nice if it does a stable reverse topological sort instead, where
;; {depends [hallo bye]} would give a hint that the user wants hallo
;; to come before bye, even though there is no explicit dependency
{
### Keybase proof
I hereby claim:
* I am nberger on github.
* I am nberger (https://keybase.io/nberger) on keybase.
* I have a public key ASBeRgCRjkl58gDoHOR7-mRHVSh3dbVxa32dR48e0Nn4EAo
To claim this, I am signing this object:
@nberger
nberger / reagent_infinite_scroll.cljs
Last active May 6, 2024 16:15
Reagent infinite scroll
(ns views.infinite-scroll
(:require
[reagent.core :as r]))
(defn- get-scroll-top []
(if (exists? (.-pageYOffset js/window))
(.-pageYOffset js/window)
(.-scrollTop (or (.-documentElement js/document)
(.-parentNode (.-body js/document))
(.-body js/document)))))
(ns isorto.core-test
(:require [clojure.core.logic :as l :refer [run run*]]
[clojure.test :refer :all]
[isorto.core :refer [isorto]]))
(deftest isorto-test
(is (= [[]]
(run* [q] (isorto q ()))))
(is (= [[]]
@nberger
nberger / mustache.clj
Created July 22, 2015 19:19
mustache basic parser
(require '[instaparse.core :as insta])
(def parse
(insta/parser
"<moustache> = (tagged-block / word / sp)*
<tagged-block> = comment | section | var
comment = <tag-open> <'!'> (word | sp)* <tag-close>
section = section-block-open (current-item / var / comment / word / sp)* <section-block-close>
<section-block-open> = <tag-open> <'#'> name <tag-close>
section-block-close = tag-open '/' name tag-close
@nberger
nberger / gist:fc636d8c2712b38a39f5
Last active December 18, 2018 03:19
riemann - send email when there are more than 5 critical events every 30 seconds
; http://stackoverflow.com/questions/31269170/event-count-at-certain-time-interval-in-riemann
(let [email (mailer {:host "localhost"
:port 1025
:from "[email protected]"})]
(streams
(where (and (service "system_log")
(description "IE")
(not (expired? event)))
; we are interested in the event count, so let's fix to :metric 1
@nberger
nberger / recipes.clj
Created July 8, 2015 03:22
recipes with core.logic
(ns recipes.core
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]
[clojure.core.logic.pldb :as pldb]))
(db-rel in-larder i)
(db-rel recipe r)
(db-rel in-recipe r i)
(db-rel compound-ingredient i is)
@nberger
nberger / pre-commit
Created April 19, 2015 21:39
Pre-commit hook to enforce branch naming to play well with mercurial via git-remote-hg
#!/usr/bin/env ruby
def current_branch()
branches = `git branch --no-color`.split(/\n/)
branches.select{ |b| b =~ /\s*\*/ }.first.gsub(/[\*\s]/, "")
end
branch = current_branch
if branch != "master" && branch !~ /^branches\//
@nberger
nberger / property_with_shrink_test.rb
Last active August 29, 2015 14:10
Rantly - Towards improving shrinking
require 'test_helper'
require 'rantly/shrinks'
require 'rantly/testunit_extensions'
class PropertyShrinking < Test::Unit::TestCase
def setup
Rantly.gen.reset
end
should "be able to shrink an array of ints towards smaller int elements" do
@nberger
nberger / bench.clj
Last active August 29, 2015 14:10
core.logic - resource allocation - try 4
(ns server-cons.bench
(:require [server-cons.core :refer [allocate-machines allocate-machines*]]))
(def machines [{:id 1 :cpu-avg 22}
{:id 2 :cpu-avg 17}
{:id 3 :cpu-avg 6}
{:id 4 :cpu-avg 17}
{:id 5 :cpu-avg 6}
{:id 6 :cpu-avg 17}
{:id 7 :cpu-avg 6}