Skip to content

Instantly share code, notes, and snippets.

@rsslldnphy
rsslldnphy / scrollbar.cljs
Last active August 29, 2015 14:17
Get the scrollbar width
;; Adapted from http://stackoverflow.com/a/8079681
(defonce scrollbar-width
(let [inner (.createElement js/document "p")
outer (.createElement js/document "div")]
(doto (.-style inner)
(aset "width" "100%")
(aset "height" "500px"))
(doto (.-style outer)
(aset "position" "absolute")
(aset "top" "0px")
@rsslldnphy
rsslldnphy / cursor-bug.cljs
Created February 4, 2015 15:36
cursor issue
ClojureScript:bugs-web.formatters> (def a (atom {}))
#<Atom: {}>
ClojureScript:bugs-web.formatters> (swap! a assoc :a 2 :b 3)
{:a 2, :b 3}
ClojureScript:bugs-web.formatters> (require '[reagent.core :as r])
ClojureScript:bugs-web.formatters> (def r (r/atom {}))
#<Atom: {}>
ClojureScript:bugs-web.formatters> (def rc (r/cursor [:x] r))
#<Cursor: [:x] #<Atom: {}>>
ClojureScript:bugs-web.formatters> (swap! rc assoc :y 3 :z 4)
@rsslldnphy
rsslldnphy / factorial.clj
Created January 20, 2015 22:16
Lazy factorials in Clojure
(ns factorial)
(defn factorials
"Generates an infinite sequence of factorials."
([]
(map first (factorials 1 2)))
([product counter]
(cons [product counter]
(lazy-seq (factorials (* product counter) (inc counter))))))
@rsslldnphy
rsslldnphy / clojure.vim
Created October 31, 2014 16:47
Prevent clojure-static.vim from clobbering your lispwords
"" This file needs to be at ~/.vim/after/ftplugin/clojure.vim
set lispwords+=as->,binding,bound-fn,case,catch,cond->,cond->>,condp,def,definline,definterface,defmacro,defmethod,defmulti,defn,defn-,defonce,defprotocol,defrecord,defstruct,deftest,deftest-,deftype,doseq,dotimes,doto,extend,extend-protocol,extend-type,fn,for,if,if-let,if-not,if-some,let,letfn,locking,loop,ns,proxy,reify,set-test,testing,when,when-first,when-let,when-not,when-some,while,with-bindings,with-in-str,with-local-vars,with-open,with-precision,with-redefs,with-redefs-fn,with-test,fact,facts,defproject,defroutes,context,GET,POST,PUT,UPDATE,DELETE,ANY,go-loop,go
@rsslldnphy
rsslldnphy / .tmux.conf
Created October 7, 2014 11:53
OSX, TMUX, VIM... *and* copy and paste
set-option -g default-command "reattach-to-user-namespace -l bash" # <- supposed to sort it globally, but doesn't always work for me
# Smart pane switching with awareness of vim splits
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-l) || tmux select-pane -R"
bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys 'C-\\') || tmux select-pane -l"
bind k confirm kill-session
(ns coins)
(def heads (repeat 50 :H))
(def tails (repeat 50 :T))
(def flip {:H :T :T :H})
(defn permutation [n]
[(concat (take n heads) (drop n tails))
(concat (drop n heads) (take n tails))])
@rsslldnphy
rsslldnphy / .tmux.conf
Last active August 29, 2015 14:06
TMUX stuff
set-option -g default-command "reattach-to-user-namespace -l bash"
# Smart pane switching with awareness of vim splits
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-l) || tmux select-pane -R"
bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys 'C-\\') || tmux select-pane -l"
@rsslldnphy
rsslldnphy / gist:491749d9f5b0afabd1c2
Last active August 29, 2015 14:06
Quick and dirty hacky script to test out many vim colorschemes quickly
for f in `ls -1 ~/.vim/colors`; do
echo colorscheme $(echo $f | awk -F'.' '{print $1}') >> ~/.vimrc
echo ";; $(echo $f | awk -F'.' '{print $1}')" >> example.clj
vim example.clj
echo "that was $f"
sed '$d' ~/.vimrc > .vimrc.new
sed '$d' example.clj > example.new
mv .vimrc.new ~/.vimrc
mv example.new example.clj
done
@rsslldnphy
rsslldnphy / annoy.txt
Last active August 29, 2015 14:06
Emacs/Evil-Mode annoyances
* 'p' pastes over lines rather than inserting new ones
* 'dd' doesn't work - it should call `evil-paredit-kill-line`
* can't map ad-hoc keybindings
* :e doesn't work from top-level of project, but level of current file
@rsslldnphy
rsslldnphy / help.js
Created July 29, 2014 13:34
Living the Jenn Schiffer dream!
(function() {
var d = document, body = d.querySelector('body'), popup = d.createElement('div');
popup.className = 'call-centre-help';
popup.style.visibility = 'hidden';
popup.style.position = 'fixed';
popup.style["z-index"] = 100000;
popup.style["background-color"] = "blue";
popup.style.color = "white";