Skip to content

Instantly share code, notes, and snippets.

@jamesmacaulay
jamesmacaulay / Clojure.sublime-settings
Last active January 18, 2021 19:01
Clojure stuff for Sublime Text 2. Files live in ~/Application Support/Sublime Text 2/Packages/User
// installed Clojure packages:
//
// * BracketHighlighter
// * lispindent
// * SublimeREPL
// * sublime-paredit
{
"word_separators": "/\\()\"',;!@$%^&|+=[]{}`~?",
"paredit_enabled": true,
@jamesmacaulay
jamesmacaulay / profiles.clj
Last active November 15, 2023 01:18
My ~/.lein/profiles.clj at the moment.
{:user {:dependencies [[org.clojure/tools.namespace "0.2.3"]
[spyscope "0.1.3"]
[criterium "0.4.1"]]
:injections [(require '(clojure.tools.namespace repl find))
; try/catch to workaround an issue where `lein repl` outside a project dir
; will not load reader literal definitions correctly:
(try (require 'spyscope.core)
(catch RuntimeException e))]
:plugins [[lein-pprint "1.1.1"]
[lein-beanstalk "0.2.6"]
(ns jamesmacaulay.console)
(defn log [& xs] (.apply console/log js/console (apply array xs)))
(defn logjs [& xs] (.apply console/log js/console (clj->js xs)))
@jamesmacaulay
jamesmacaulay / gist:8264393
Created January 5, 2014 04:38
js notes 2014-01-04

wtfjs

wtf parens scope?

(function isBound() {return !!isBound}); isBound();
// ReferenceError: isBound is not defined

function isBound() {return !!isBound}; isBound();
// true
@jamesmacaulay
jamesmacaulay / debounce.clj
Last active January 25, 2016 09:29
debounce with core.async
(defn debounce
([input ms] (debounce (chan) input ms))
([output input ms]
(go
(loop [val (<! input)]
(let [t (timeout ms)
[next-val port] (alts! [input t])]
(if (= port t)
(do
(>! output val)
class Module
# Takes symbols representing instance methods defined in the module.
# Returns a new anonymous module with only those instance methods defined.
def slice(*methods)
src = self
Module.new do
methods.each do |sym|
define_method(sym, src.instance_method(sym))
end
end
@jamesmacaulay
jamesmacaulay / gist:375a1fc9eacded79bcdc
Created June 14, 2014 16:58
github.io https -> http redirect
$ curl -I https://shopify.github.io/dashing/
HTTP/1.1 200 OK
Date: Sat, 14 Jun 2014 16:57:15 GMT
Server: GitHub.com
Content-Type: text/html; charset=utf-8
Last-Modified: Wed, 07 May 2014 03:44:03 GMT
Expires: Sat, 14 Jun 2014 17:07:15 GMT
Cache-Control: max-age=600
Content-Length: 15154
Accept-Ranges: bytes
debounce : Time -> Signal a -> Signal a
debounce t sig = sig |> sampleOn (Time.since t sig |> keepIf not False)
import Mouse
import Array
buildAppDataMap delta pos history =
{ frameDelta=delta
, mousePosition=pos
, clickHistory=history }
arrayTakeLast n array =
let inputLen = Array.length array
module AttributeReaders
class <<self
# str = "foo"
# overrides = {
# another_reverse: :reverse,
# exclaimed: ->(str) { str + "!" },
# to_sym: ->(str) { str.reverse.to_sym }
# }
# reader = AttributeReaders.object_reader(str, overrides)
# [:reverse, :another_reverse, :exclaimed, :to_sym].map(&reader)