Skip to content

Instantly share code, notes, and snippets.

@bhauman
bhauman / README.md
Last active December 3, 2019 16:43
ClojureScript minimal dev and prod setup.

Recent improvements to the ClojureScript compiler have greatly simplified setting up development versus production outputs.

This example uses Figwheel as something that you want to exclude for production, but the pattern is general.

With this simple setup you only need one html file/view and it will work for developement and production.

@bhauman
bhauman / index.html
Last active October 20, 2015 01:00
Dynamic source map test
<html>
<head>
<script src="modifyme.js"></script>
</head>
<body>
<h1>Testing source map reloading.</h1>
<h3>Open Dev Tools and look in the console.</h3>
<p>Execute the <code>test_sm()</code> function and follow the source links.</p>
</body>
</html>
@bhauman
bhauman / core.cljs
Last active August 29, 2015 14:01
The code from the Devcards introduction video
(ns hello-there.core
(:require
[devcards.core :as dc :include-macros true]
[sablono.core :as sab :include-macros true]
[om.core :as om :include-macros true])
(:require-macros
[devcards.core :refer [defcard is are= are-not=]])
)
(devcards.core/start-devcard-ui!)
@bhauman
bhauman / checking_safari_mem_leak.clj
Last active January 4, 2016 00:49
This runs fine in Chrome. But the channels seem to be accumulating something in Safari Version 6.1 (7537.71) The standard browser for Lion. This code crashes my browser running it quickly up to 1.7G of memory usage. This also may be a problem in Safari on iOS7. So far I have learned that it's the ->> threading operator. Comp and partial work fine.
;; in project.clj
;; [org.clojure/clojurescript "0.0-2138"]
;; [org.clojure/core.async "0.1.267.0-0d7780-alpha"]
(ns checking-safari-leak.core
(:require
[cljs.core.async :as async
:refer [<! map< put! chan]])
(:require-macros [cljs.core.async.macros :as m :refer [go alt! go-loop]]))
@bhauman
bhauman / screw_you_zerigo.rb
Last active January 2, 2016 00:49
Zerigo's recent rate increase will raise my yearly cost 5000% so I created this lovely little script to help you leave Zerigo behind. It relies on the excellent fog library http://fog.io/dns/ It is currently targeting DNSimple but fog supports many other providers. Using it is very satisfying. After setting the correct connection settings just t…
require 'rubygems'
require 'fog'
require 'zerigo_dns'
# A simple script to help you leave zerigo behind
# it relies on the excellent fog library http://fog.io/dns/
# It copies all of your Zerigo zones to DNSimple
# It is currently targeting DNSimple but fog supports many other
(defn partition-chan
([start-pred in] (partition-chan start-pred (complement start-pred) in))
([start-pred end-pred in]
(let [out (chan)]
(go
(loop []
(if-let [val (<! in)]
(if (start-pred val)
(let [next-chan (chan)]
(>! out next-chan)
(defn partition-chan
([start-pred in] (partition-chan start-pred (complement start-pred) in))
([start-pred end-pred in]
(let [out (chan)]
(go
(loop []
(if-let [val (<! in)]
(if (start-pred val)
(let [next-chan (chan)]
(>! out next-chan)
@bhauman
bhauman / tictactoe.clj
Last active December 22, 2015 15:09
This is a tic tac toe implementation by Jeff Dik
(ns tic-tac-toe)
(defn empty-board [size]
(let [row (vec (repeat size nil))]
(vec (repeat size row))))
(defn prn-board [board]
(dorun (map prn board)))
(defn place [board row col marker]
def assert(phrase, val)
puts (val && "p #{phrase}" || "FAIL #{phrase}")
end
@offsets = [[0,1], [1,0], [-1,1], [1,-1], [-1, 0], [0, -1], [1,1], [-1,-1]]
world = {}
def neighbors_coordinates(coord)
x,y = coord
@bhauman
bhauman / gist:5897002
Created June 30, 2013 21:31
dataflow question for pedestal
(ns ^:shared continue-set-focus.behavior
(:require [clojure.string :as string]
[io.pedestal.app :as app]
[io.pedestal.app.messages :as msg]
[io.pedestal.app.util.log :as log]))
(defn set-value-transform [old-value message]
(:value message))
(defn init-emitter [inputs]