Skip to content

Instantly share code, notes, and snippets.

@kurtharriger
kurtharriger / DragAndDrop.elm
Last active July 29, 2016 20:28
Drag and Drop
import Html exposing (text, div, Attribute)
import Html.Attributes exposing (style, draggable)
import Html.Events exposing (..)
import Signal exposing (map, mailbox)
import Json.Decode as Json exposing (value)
mb = mailbox "None"
messageOn : String -> Signal.Address a -> a -> Attribute
messageOn name addr msg =
(defn with-local-redefs-fn
[a-var its-new-value func]
(cast clojure.lang.IFn @a-var)
(alter-meta! a-var
(fn [m]
(if (::scope-count m)
(update-in m [::scope-count] inc)
(assoc m
::scope-count 1
::thread-local-var (doto (clojure.lang.Var/create @a-var)
@kurtharriger
kurtharriger / muxify
Created May 13, 2014 01:40
tmux helper script
#!/bin/bash
DNAME=$(basename $(pwd))
if [ -n "$1" ]; then
NAME="$1"
if [ "$NAME" != "$DNAME" -a -d ~/projects/"$NAME" ]; then
cd ~/projects/"$NAME"
fi
else
NAME=$(basename $(pwd))
@kurtharriger
kurtharriger / Gruntfile.js
Last active August 29, 2015 13:57
Livereload starter
// For clojurescript autorecompile: https://gist.github.com/johnbintz/9498860
module.exports = function(grunt) {
// Load Grunt tasks declared in the package.json file
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// Configure Grunt
grunt.initConfig({
// grunt-express will serve the files from the folders listed in `bases`
@kurtharriger
kurtharriger / strip_html.clj
Created March 23, 2014 02:52
Clojure script to strip classes from html
(require '[net.cgrand.enlive-html :as html])
(defn render [e] (apply str (html/emit* e)))
(defn strip-classes
"Remove class attribute from all elements"
[file]
(->
(html/html-resource file)
(html/at [(html/attr? :class)] (html/remove-attr :class))
(render)))
@kurtharriger
kurtharriger / emacs-customizations
Created February 3, 2014 23:00
emacs autosave, mouse, and OS X clipboard
;; autosave
(defun full-auto-save ()
(interactive)
(save-excursion
(dolist (buf (buffer-list))
(set-buffer buf)
(if (and (buffer-file-name) (buffer-modified-p))
(basic-save-buffer)))))
(add-hook 'auto-save-hook 'full-auto-save)
@kurtharriger
kurtharriger / gist:7667396
Created November 26, 2013 22:23
js module template
(function(exports){
// your code goes here
exports.test = function(){
return 'hello world'
};
})(typeof exports === 'undefined'? this['mymodule']={}: exports);
@kurtharriger
kurtharriger / recipe.rb
Created October 26, 2012 18:58 — forked from peplin/recipe.rb
S3 File Resource for Chef
# Source accepts the protocol s3:// with the host as the bucket
# access_key_id and secret_access_key are just that
s3_file "/var/bulk/the_file.tar.gz" do
source "s3://your.bucket/the_file.tar.gz"
access_key_id your_key
secret_access_key your_secret
owner "root"
group "root"
mode 0644
end
@kurtharriger
kurtharriger / gist:2395697
Created April 16, 2012 01:06
midje provides does not work in let bindings
(use 'midje.sweet)
(defn mocked [x] "ERROR: THIS SHOULDN'T HAVE BEEN CALLED")
(defn handler [r]
(let [body (mocked (get-in r [:params :id]))]
{:status (if (re-find #"ERROR" body) 500 200)
:body body
:content-type "text/plain"
}
@kurtharriger
kurtharriger / gist:2394051
Created April 15, 2012 17:36
Midje provided issue
(defn mocked [x] (Exception. "should not be called"))
(defn withmocked [x] (mocked (inc x)))
;.;. FAIL at (NO_SOURCE_FILE:1)
;.;. Expected: 3
;.;. Actual: #<Exception java.lang.Exception: should not be called>
(facts "Fails if mocked is called twice"
(let [x 2]
(mocked 3) => 3
(withmocked x) => 3