Skip to content

Instantly share code, notes, and snippets.

@scottdw
scottdw / InToPbm.java
Last active July 14, 2016 14:50
A java class that reads text from stdin and outputs a pbm (Portable Bit Map) encoded QR Code on stdout.
/*
* Copyright 2010 Scott Douglas-Watson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@scottdw
scottdw / qr-encode.el
Created May 31, 2010 23:35
An elisp function for encoding a region into a QR code from emacs. Uses java class http://gist.github.com/420377 and core.jar from http://code.google.com/p/zxing/
;;; qr-encode.el ---
;;
;; Description: A function for encoding a region into a QR code from emacs.
;; Uses java class http://gist.github.com/420377 and core.jar from
;; http://code.google.com/p/zxing/
;;
;; URL: http://gist.github.com/420386
;;
;; Author: Scott Douglas-Watson
@scottdw
scottdw / gist:605354
Created September 30, 2010 21:29
Based on http://nakkaya.com/2010/08/17/visualising-the-wikileaks-war-logs-using-clojure using http://en.wikipedia.org/wiki/File:United_Kingdom_location_map.svg 500px png. Draws a red marker (16px square) at each of the long/latitude pairs provided to the
(import
[java.awt.geom Rectangle2D$Double]
[java.awt Dimension Color]
[javax.swing JFrame JLabel]
[java.io File]
[javax.imageio ImageIO])
(defn translate-scale-fn [min max target]
(let [scale-factor (/ target (- max min))]
(fn [v]
@scottdw
scottdw / capslock-as-control.reg
Created June 28, 2011 15:45
Remap caps lock to left control
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
(defn neighbours-fn [w h n]
(letfn [(has-w [i] (not (zero? (rem i w))))
(pos-w [i] (dec i))
(has-n [i] (>= i w))
(pos-n [i] (- i w))
(has-e [i] (not (zero? (rem (inc i) w))))
(pos-e [i] (inc i))
(has-s [i] (< i (* w (dec h))))
(pos-s [i] (+ i w))]
(let [pred-pos-m {:w [has-w pos-w]
@scottdw
scottdw / stats.clj
Created June 20, 2012 14:07
Some helper functions in Clojure for statistics
(ns stats)
(defn mode [vs]
(let [fs (frequencies vs)]
(first (last (sort-by second fs)))))
(defn quantile
([p vs]
(let [svs (sort vs)]
(quantile p (count vs) svs (first svs) (last svs))))
(ns scottdw.image
(:import
[java.awt Color Image Dimension]
[java.awt.image BufferedImage]
[java.io File]
[javax.imageio ImageIO]
[javax.swing JFrame JPanel])
(require [scottdw.stats :as stats]))
(defn read-image [^String filename]
(ns scottdw.plot.demo
(:import [java.util Random]
[org.jzy3d.analysis AnalysisLauncher AbstractAnalysis]
[org.jzy3d.chart Chart]
[org.jzy3d.chart.factories AWTChartComponentFactory]
[org.jzy3d.colors Color ColorMapper]
[org.jzy3d.colors.colormaps ColorMapRainbow]
[org.jzy3d.maths Coord3d Range]
[org.jzy3d.plot3d.builder Builder Mapper]
[org.jzy3d.plot3d.builder.concrete OrthonormalGrid]
(ns scottdw.mmgr.gl
(:import [javax.media.opengl DebugGL3 GL GL2 GL3 GLAutoDrawable GLCapabilities GLEventListener GLProfile]
[com.jogamp.newt NewtFactory]
[com.jogamp.newt.event WindowAdapter WindowEvent]
[com.jogamp.newt.opengl GLWindow])
(:require [clojure.java.io :as io]
[taoensso.timbre :as timbre :refer (trace debug error)]))
(defn create-shader [^GL3 gl resource type]
(let [source (slurp (io/resource resource))
@scottdw
scottdw / jpeg.clj
Last active December 24, 2015 14:29
Start of a clojure JPEG file decoder.
(ns scottdw.jpeg
(:import [clojure.lang Keyword]
[com.drew.imaging ImageMetadataReader]
[com.drew.metadata Directory Metadata Tag]
[java.net URI]
[java.nio ByteBuffer]
[java.nio.file Files Paths])
(:require [clojure.java.io :as io]))
(defn read-metadata [^String file-name]