Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jcromartie's full-sized avatar

John Cromartie jcromartie

View GitHub Profile
;; now with an escape hatch!
(deftest home-page-flow
(naturally
(navigate to "/")
(click link "Sign In")
(fill in "Username" with $username, "Password" $password)
(click button "Sign In")
(expect page to have content "Welcome, " $username)))
;;; MrMusAddict's original function
(def charge-max 100.0)
(def charge-min 0.0)
(def bright-max 0.9)
(def bright-min 0.0)
;;; float brightFinal = (brightMin-brightMax)*Math.Pow((chargeCurrent-chargeMax)/(chargeMax-chargeMin), 4)+brightMax;
(defn mr-mus-addict
(defn compile-unrolled
[f inputs]
(let [clauses (mapcat #(list % (f %)) inputs)]
`(fn [x#]
(case x#
~@clauses
(~f x#)))))
(defn unrolled
"Return a function with precomputed lookup for the given input domain."
(ns stackity.stack)
(defn compile-mode?
[stack]
(-> stack meta :mode (= :compile)))
(def interpret-mode? (complement compile-mode?))
(defn ->compile-mode
[stack]
@jcromartie
jcromartie / vignere.clj
Last active August 29, 2015 14:00
Vigenere cipher in a completely pointless (I mean, um, point-free) style
;; an appropriate prelude...
(def parpar (partial partial partial))
(def parapply (parpar apply))
(def parconj (parpar conj))
;; one convenient constant
(def char-offset (int \A))
class Integer
def to_a
(0..Math.log2(self).ceil).map {|idx| self[idx] }.reverse
end
end
@jcromartie
jcromartie / events.clj
Last active August 29, 2015 14:04
Totally naive event based system in Clojure
(defonce handlers (atom {}))
(defn- install-handler!
[topic-key f]
(swap! handlers assoc topic-key f))
(defmacro on
"Registers a global message handler for the given topic keyword. A
single handler can be registered at a time for a given topic
keyword. Handlers are dispatched based on the name portion of the
function arrayAssocIn(obj, keys, val) {
var m = obj;
for (var ii = 0; ii < keys.length - 1; ii++) {
var k = keys[ii];
m = m[k] = m[k] || [];
}
m[keys[keys.length - 1]] = val;
return obj;
@jcromartie
jcromartie / git-cleanup
Created April 3, 2015 19:24
git cleanup - delete branches that are fully merged relative to the current branch
#!/bin/bash
for branch in $(git branch --merged | grep -v '*')
do
read -n 1 -p "Delete ${branch} [y/N]? " answer
echo ""
if [[ "$answer" = "y" ]]
then
git branch -d "$branch"
fi
@jcromartie
jcromartie / uniq-live.rb
Created July 27, 2015 15:30
uniq live!
#!/usr/bin/ruby
# uniq-live
#
# Reads from stdin or a given file and counts the number of times a
# given line repeats as it is read.
last = nil
count = 1
while !ARGF.eof? && line = ARGF.readline.strip do