Skip to content

Instantly share code, notes, and snippets.

View msgodf's full-sized avatar

Mark Godfrey msgodf

View GitHub Profile
@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 / 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 / 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 / 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 / intro-clojure.org
Created March 19, 2015 16:18
Clojure intro

Intro to Clojure

Overview

First three hours of Clojure.

Small (~3 people) group, Java experience, some Javascript and other dynamic language experience - no prior Clojure knowledge is assumed.

What can you learn?

@msgodf
msgodf / maximize-laptop.el
Created February 6, 2016 12:50
Function to maximize Emacs on my laptop display (Retina MacBook Pro 13", scaled for maximum space)
(defun maximize-laptop ()
"Resize to fill my laptop display, and hide menu bar"
(interactive)
(setq ns-auto-hide-menu-bar t)
(set-frame-position nil 0 -22)
(set-frame-size nil 1660 1046 'pixelwise))