Skip to content

Instantly share code, notes, and snippets.

View msgodf's full-sized avatar

Mark Godfrey msgodf

View GitHub Profile
@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
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 / file1.txt
Created November 8, 2013 12:37
A test gist sent using XHR
Hello World
@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 / 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 / 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:5656370
Last active December 17, 2015 18:49
Trying out Java 7 NIO2's FileVisitor, along with half of Guava to attempt a slightly functional style. This is still pretty verbose in Java.
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import org.apache.commons.lang3.StringUtils;
@msgodf
msgodf / concurrent_sieve.clj
Created May 20, 2013 12:03
Concurrent prime number sieve. I wanted something that took a while, so that the agent could be running in the background for some time. I used an atom so that I could monitor the sieve externally.
(def sieve (atom []))
(def siever (agent sieve))
(send-off siever
(fn [x test-set]
(doall
(map (fn [n]
(if (not (some
#(zero? (mod n %))
@msgodf
msgodf / counter_agent.clj
Created May 20, 2013 11:24
Messing around with Clojure agents
; A little function that adds its two parameters together
(defn addit [x y] (+ x y))
; This adds the value supplied in the second parameter to the atom in the first parameter, then returns the atom
(defn atom-adder [x y] (swap! x (partial addit y)) x)
(def value-atom (atom 1))
; Create an agent with a reference to the atom
(def counter-agent (agent value-atom))
@msgodf
msgodf / brisfunctional-ocr-kata-failures
Created April 10, 2013 08:03
Several attempts to get a sweet solution to getting digit parcel part of Brian Marick's Brisfunctional talk.
user=> (map #(partition 3 %) ["123---" "456---"])
(((\1 \2 \3) (\- \- \-)) ((\4 \5 \6) (\- \- \-)))
user=> (map #(map (partial apply str) (partition 3 %)) ["123---" "456---"])
(("123" "---") ("456" "---"))
user=> (map #(map (partial apply str) (partition 3 %)) s) ["123---" "456---"])
CompilerException java.lang.RuntimeException: Unable to resolve symbol: s in this context, compiling:(NO_SOURCE_PATH:1:1)
["123---" "456---"]
RuntimeException Unmatched delimiter: ) clojure.lang.Util.runtimeException (Util.java:219)