Skip to content

Instantly share code, notes, and snippets.

View rcampbell's full-sized avatar

Robert Campbell rcampbell

View GitHub Profile
/*** ground ***/
ha = 33.3; // hill angle in degrees
hl = 1600; // hill length in cm
hw = 2821; // hill width in cm
hh = sin(ha)*hl; // hill height in cm
hd = cos(ha)*hl; // hill depth in cm
color("ForestGreen")
union() {
@RequestMapping("zencoder.htm")
public void zen(final HttpServletRequest request, final HttpServletResponse response) throws AttachSystemFileException, IOException {
final String body = IOUtils.toString(request.getReader());
logger.info("Received Zencoder notification:\n" + body);
final Notification notification = zen.notification(body);
final Job job = notification.getJob();
final Output output = notification.getOutput();
final String filename = decodeLabel(output.getLabel());
if (job.isFinished()) {
logger.debug("zen CALL downloader.execute filename: " + filename);
@rcampbell
rcampbell / gist:213ee1a7ab490c576d3a
Created September 4, 2014 16:05
Readable WPA2-PSK generator
(defn- char-range [start end]
(map char (range (int start)
(inc (int end)))))
(def ^:private
dirty
(char-range \! \~))
(def ^:private
clean
(defn- with-index
"Maps a token's sequential position to its
entry."
[{:keys [count] :as accum} x]
(-> accum
(update-in [:by-index] assoc (inc count) x)
(update-in [:count] inc)))
(defn- with-key
"Maps a token's normalized string-based key
@rcampbell
rcampbell / s3.clj
Created May 11, 2011 10:14
Storing and retrieving Clojure data structures as GZIP compressed JSON in Amazon S3
(ns aws.s3
(:refer-clojure :exclude [get])
(:use [clojure.walk :only (keywordize-keys stringify-keys)]
[clojure.contrib.def :only (defonce-)]
[clojure.contrib.json :only (read-json write-json)])
(:import [java.io PrintWriter InputStreamReader ByteArrayInputStream ByteArrayOutputStream]
[java.util.zip GZIPInputStream GZIPOutputStream]
[com.google.common.base Charsets]
[com.amazonaws.services.s3 AmazonS3Client]
[com.amazonaws.services.s3.model Region CreateBucketRequest ObjectMetadata
@rcampbell
rcampbell / coordinate.clj
Created May 10, 2011 17:59
Conversion from Decimal Degree to DMS (Degrees, Minutes, Seconds) in Clojure
;; See http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
(defn dms [type degrees]
{:pre [(#{:latitude :longitude} type)]}
"Conversion from Decimal Degree to DMS (Degrees, Minutes, Seconds)"
(let [total-sec (Math/round (* (Math/abs degrees) 60 60))
total-min (quot total-sec 60)
sec (rem total-sec 60)
min (rem total-min 60)
deg (quot total-min 60)]
@rcampbell
rcampbell / lexer.js
Created May 5, 2011 10:12
Lexical Analyzer for Scheme R5RS in JavaScript
//
// Lexical Analyzer for Scheme R5RS
//
// TODO: numbers, better error reporting
//
// Depends on Functional Javascript: http://osteele.com/sources/javascript/functional/
//
Functional.install();
insertTemplate :: Template -> IO ()
insertTemplate (Template _ src) = do
conn <- connectPostgreSQL "hostaddr=127.0.0.1 dbname=sandbox user=postgres password="
insertTemplateStmt <- prepare conn "INSERT INTO templates VALUES (?, ?)"
pk <- friendlyId 6
execute insertTemplateStmt [toSql pk, toSql src]
commit conn
disconnect conn
@rcampbell
rcampbell / monte-carlo-pi.clj
Created August 20, 2010 13:46
Monte Carlo calculation of Pi
(ns mc.core
(:use [clojure.contrib.seq-utils :only [separate]]))
; http://math.fullerton.edu/mathews/n2003/MonteCarloPiMod.html
(defn- square [x]
(* x x))
(defn- distance [[x y]]
(Math/sqrt (+ (square x)
@rcampbell
rcampbell / gist:459278
Created June 30, 2010 21:56
Ninety-Nine Clojure Problems
;; http://aperiodic.net/phil/scala/s-99/
; last
(defn p01 [[x & xs]]
(if xs (recur xs) x))
(defn p02 [xs]
(p01 (butlast xs)))
; nth