Skip to content

Instantly share code, notes, and snippets.

@danielsz
danielsz / pushState.cljs
Last active July 15, 2016 15:13
PushState (via Html5History from google closure) with secretary, a client-side routing library for clojurescript. Allows to map absolute urls with routes without the hash-bang hackery.
(def history (Html5History.))
(.setUseFragment history false)
(.setPathPrefix history "")
(.setEnabled history true)
(let [navigation (listen history EventType/NAVIGATE)]
(go
(while true
(let [token (.-token (<! navigation))]
(secretary/dispatch! token)))))
@pyrtsa
pyrtsa / exchange.clj
Created December 9, 2013 11:46
Exchange atom value in Clojure. This function seems like a common enough pattern in Clojure it should find its place in the standard library.
(defn exchange!
"Atomically set the value of `atom` to `(apply f @atom args)`,
and return the value of `@atom` just before the assignment.
(See also: `clojure.core/swap!`)"
[atom f & args]
{:pre [(instance? clojure.lang.Atom atom)]}
(loop [oldval @atom]
(if (compare-and-set! atom oldval (apply f oldval args))
oldval
(recur @atom))))
@DarrenN
DarrenN / canvas.html
Created December 7, 2013 16:42
Gnarly drag/drop with ClojureScript and core.async - http://cljsfiddle.net/fiddle/DarrenN.async.delta
<div id="canvas">
<h1>Click and drag boxes</h1>
<ul>
<li class="box"></li>
<li class="box"></li>
<li class="box"></li>
</ul>
</div>
@gonzalo-bulnes
gonzalo-bulnes / api_steps.rb
Last active February 3, 2021 16:49 — forked from aeden/api_steps.rb
A set of Cucumber steps to test and document API behaviour (with verbose and DRY step definitions for an example resource).Deeply inspired in @aeden API steps, see http://vimeo.com/30586709
# features/step_definitions/api_steps.rb
# These steps are very deeply inspired in the Anthony Eden (@aeden) API steps.
# See http://vimeo.com/30586709
# Given
Given /^I send and accept JSON$/ do
header 'Accept', 'application/json'
@nitaku
nitaku / README.md
Last active December 15, 2018 18:22
Gosper curve (L-system)
@emiller
emiller / yoga-auto-rotate
Last active April 22, 2024 15:44
Lenovo Yoga 13 tablet mode / auto rotation script (ubuntu/debian)
#!/bin/bash
#
# yoga-auto-rotate -- ghetto-style tablet mode, with keyboard and all.
#
# Simple little script that will detect an orientation change for a
# Lenovo Yoga 13 (very hackily) and adjust the active display's
# orientation and disable/enable the touchpad as necessary.
#
# The Yoga 13 will emit keycode `e03e` at one second intervals
# when the screen is flipped into tablet mode. Since this keycode
(ns blog.errors.core
(:require-macros
[cljs.core.async.macros :refer [go]]
[blog.utils.macros :refer [<?]])
(:require
[cljs.core.async :refer [>! <! chan close!]]))
;; convert Node.js async function into a something
;; that returns a value or error on a channel
(defn run-task [f & args]
@AaronLasseigne
AaronLasseigne / identicon.clj
Last active May 18, 2018 14:52
identicon.clj
(ns identicon.core
(:require [digest])
(:require [clojure.string :as str])
(import java.io.File)
(import java.awt.Color)
(import java.awt.image.BufferedImage)
(import javax.imageio.ImageIO))
(def tiles-per-side 6)
(def total-tiles
@jackrusher
jackrusher / blue-ball.clj
Last active December 20, 2015 07:49
Interacting with Leap Motion using Clojure from within emacs.
(ns blue-ball
(:use [seesaw core font graphics])
(:require [clojure-leap.core :as leap]
[clojure-leap.screen :as l-screen]))
;; these atoms contain the current x/y state from the Leap
(def x (atom 10))
(def y (atom 10))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Build the window/canvas
@pangloss
pangloss / xn.test.cljs
Last active January 23, 2020 05:45
ClojureScript XHR with core.async.
(ns xn.test
(:require-macros [cljs.core.async.macros :refer [go alts!]]
(:require [xn.core :as xn]
[xn.util :as u]
[cljs.core.async :refer [<! take!]]
[xn.xhr :refer [request-body request-records chain-req]]))
(def sample-app
(reify
xn/Application