Skip to content

Instantly share code, notes, and snippets.

View msgodf's full-sized avatar

Mark Godfrey msgodf

View GitHub Profile
@msgodf
msgodf / bots.clj
Last active December 19, 2015 00:19 — forked from cgrand/bots.clj
Tron bot, function is msgodf-random-indecisive
(ns tron.bots
(:require [tron.core :as tron]))
(defn empty-look
"A mock look function which just checks for the arena
boundaries."
[pos]
(when-not (tron/valid-pos? pos) :wall))
(defn mock-look
@msgodf
msgodf / gist:7003379
Created October 16, 2013 06:22
Bookmarklet to create a eval'ing text area and bootstrapping code to provide some styling/formatting niceties.
try {
var RIGHTCURLYBRACE="}",LEFTCURLYBRACE="{";
// bookmarklet to kick things off
//javascript:function%20runCode(e)%20%7Be.preventDefault();eval(document.getElementById(%22codearea%22).value);return%20false;%7D;(function()%7Ba=document.createElement(%22div%22);b=document.body.appendChild(a);b.style.background=%22%23eeeeee%22;b.style.width=%22100%25%22;b.style.height=%22100px%22;b.innerHTML='%3Ctextarea%20id=%22codearea%22%3E%3C/textarea%3E%3Cbutton%20id=%22runcodebutton%22%3ERun%3C/button%3E';document.getElementById('runcodebutton').addEventListener(%22click%22,runCode);a.style.position=%22absolute%22;a.style.top=%220px%22;document.getElementById(%22codearea%22).value=window.localStorage.getItem(%22codeMSG%22);a.style.zIndex=%221000%22%7D)();
function bootstrap() {
// get ourself
@msgodf
msgodf / gist:7048224
Last active December 25, 2015 22:18
Image upload control for Safari on iPad that pulls the selected image out of the control and renders it, all client side
function addUploadControl() {
if(document.getElementById("imageUpload")===null) {
var fileInputContainer=document.createElement("div");
var fileInput=document.createElement("input");
fileInputContainer.style.backgroundColor="white";
fileInputContainer.style.padding="10px";
fileInputContainer.style.borderColor="black";
fileInputContainer.style.borderRadius="10px";
@msgodf
msgodf / file1.txt
Created November 8, 2013 12:37
A test gist sent using XHR
Hello World
try {
var RIGHTCURLYBRACE = "}", LEFTCURLYBRACE = "{";
// bookmarklet to kick things off
//javascript:function%20runCode(e)%20%7Be.preventDefault();eval(document.getElementById(%22codearea%22).value);return%20false;%7D;(function()%7Ba=document.createElement(%22div%22);b=document.body.appendChild(a);b.style.background=%22%23eeeeee%22;b.style.width=%22100%25%22;b.style.height=%22100px%22;b.innerHTML='%3Ctextarea%20id=%22codearea%22%3E%3C/textarea%3E%3Cbutton%20id=%22runcodebutton%22%3ERun%3C/button%3E';document.getElementById('runcodebutton').addEventListener(%22click%22,runCode);a.style.position=%22absolute%22;a.style.top=%220px%22;document.getElementById(%22codearea%22).value=window.localStorage.getItem(%22codeMSG%22);a.style.zIndex=%221000%22%7D)();
function bootstrap() {
var startTheDance = 5000;
@msgodf
msgodf / rickshaw-full-demo.cljs
Created January 18, 2014 20:26
Full Rickshaw Example in Clojurescript
;; Original example (in Javascript) at: http://code.shutterstock.com/rickshaw/examples/lines.html
(def graph-with-legend
(let [series-data (array (array) (array) (array))
random (Rickshaw.Fixtures.RandomData. 150)]
(dotimes [i 150]
(.addData random series-data))
(doto
(Rickshaw.Graph. (clj->js {:element (.getElementById js/document "chart")
:renderer "line"
:width 960
@msgodf
msgodf / core.cljs
Created March 1, 2014 20:26
A Clojurescript port of the first of the Web Audio API examples from HTML5 Rocks (http://www.html5rocks.com/en/tutorials/webaudio/intro/)
(ns cljsaudio.core
(:require [goog.net.XhrIo]
[cljs.core.async :as async :refer [<! >! chan close!]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn decode-audio-data
[context data]
(let [ch (chan)]
(.decodeAudioData context
data
@msgodf
msgodf / async-merge.clj
Last active August 29, 2015 13:57
Just a quick demo of how the Clojure core.async merge function works. I wanted to check that the values from the input channels appear in the merged channel straight away.
(clojure.core.async/go
(let [sleepy-val (fn [v t] (clojure.core.async/go
(clojure.core.async/<! (clojure.core.async/timeout t))
v))
chans (clojure.core.async/merge (map #(sleepy-val % (rand-int 3000))
(range 10)))]
(while (when-let [v (clojure.core.async/<! chans)]
(prn v)
v))))
@msgodf
msgodf / core_async_merge_behaviour.clj
Created March 5, 2014 17:07
Some code to test the behaviour of Clojure core.async's merge function. Given two channels that produce values at a given intervals, merge them and see whether the two sequences are interleaved or concatenated.
(require '[clojure.core.async :as async refer [<! go timeout])
(defn sleepy-val
[v t]
(go (<! (timeout t)) v))
;; Will this produce [1 2 3 1.5 2.5 3.5] or [1 1.5 2 2.5 3 3.5]?
(go
(prn (<! (async/into []
(async/merge [(.async/merge [(sleepy-val 1 1000)
@msgodf
msgodf / gist:4f6ca8a1df5c65bb9483
Created July 17, 2014 10:46
Encode a bunch of FLAC files in the current directory to MP3
ls -1|sed -e "s/'/\\\'/g" -e "s/.flac//g"|xargs -I{} avconv -i {}.flac -c:a libmp3lame -b:a 256k {}.mp3