Skip to content

Instantly share code, notes, and snippets.

@alex-dixon
alex-dixon / index.html
Created January 23, 2015 08:26
Eloquent Javascript - Chapter 3 // source http://jsbin.com/cuxina
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Eloquent Javascript - Chapter 3" />
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@alex-dixon
alex-dixon / index.html
Created January 23, 2015 08:26
Eloquent Javascript - Chapter 3 // source http://jsbin.com/cuxina
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Eloquent Javascript - Chapter 3" />
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
// Chapter 3 Exercises
onDrop: function(e) {
e.preventDefault();
this.setState({
isDragActive: false
});
var files;
if (e.dataTransfer) {
files = e.dataTransfer.files;
@alex-dixon
alex-dixon / 0_reuse_code.js
Created October 11, 2015 03:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@alex-dixon
alex-dixon / ns-interns.cljs
Created July 11, 2017 16:00
Confusion about symbols, quoting
(def my-ns 'precept.app-ns)
my-ns ;; => precept.app-ns
(ns-interns my-ns) ;; nth not supported on Symbol
(ns-interns 'precept.app-ns) ;; works
(ns-interns (quote precept.app-ns)) ;; works
'precept.app-ns ;; => precept.app-ns
(quote precept.app-ns) ;; => precept.app-ns
(ns myapp.typeahead
(:require [reagent.core :as r]
[goog.functions :as gf]
[myapp.api :as api]))
(defn input-control [props]
(let [value (r/atom (:default-value props ""))
local-change #(reset! value (.. % -target -value))]
(fn [{:keys [on-change] :as props}]
(defmacro deflet [bindings & body]
`(do ~@(for [[sym expr] (partition 2 (destructure bindings))]
(list 'def sym expr))
~@body))
(defmacro defbindings [bindings]
`(do ~@(for [[sym expr] (partition 2 (destructure bindings))]
(list 'def sym expr))))
(defmacro deflast [sym]

Stupid Spec Tricks

Problem: I want to spec a coll of maps. I know I can use s/coll-of and specify :kind vector? or :kind list?, but either is fine, so I've omitted it. When I call s/explain for this spec with a map it fails properly, but I get explain data for each map entry that says "x" isn't a map. I'd prefer it say it's not a collection and stop there.

Solution:

(s/def ::example (s/coll-of (s/keys :req-un [::foo]) 
@alex-dixon
alex-dixon / README.md
Last active July 28, 2018 14:53 — forked from bhb/README.md
Clojure cool mode

Stay cool Clojurists 😎

Usage:

clj -Sdeps '{:deps {cool {:git/url "https://gist.github.com/alex-dixon/bf2218ed3d3c633ed0602e23ae76c420" :sha "a9859300b5af48a18c88bdec2feb28bc91bd9d80"}}}' -m cool