Skip to content

Instantly share code, notes, and snippets.

@ato
ato / csvish-regex.clj
Last active August 29, 2015 14:02
CSV-ish regex parser
(map #(map second (re-seq #"((?:\"[^\"]*\"|[^ ]+)+)(?: |$)" (second %))) (re-seq #"((?:(?:\"[^\"]*\")+|[^\"\n]+)+)(?:\n|$)" input-string))
Working from the inside out:
(re-seq #"((?:(?:\"[^\"]*\")+|[^\"\n]+)+)(?:\n|$)" input-string)
Breaks down into:
(
(?:
;; Not useful as a generic HTTrack conversion tool as we don't bother trying to undo the URL-rewriting. PANDORA
;; crawls are often manually edited and sometimes collected with tools other than HTTrack.
;; Instead we just generate records with the URLs as they deliver in the PANDORA archive:
;; http://pandora.nla.gov.au/pan/...
;;
;; Example output:
;;
;; WARC/1.0
;; WARC-Type: resource
;; WARC-Target-URI: http://pandora.nla.gov.au/pan/85187/20080605-1425/www.tams.act.gov.au/__data/assets/pdf_file/0010/102250/Alcohol_and_Drugs_discussion_paper.pdf
@ato
ato / buggy.cpp
Last active August 29, 2015 14:03
RCSwitch receive bug
// "unsigned long" is 64-bit on x86_64 so changed to uint32_t to test this like it would be on a 32-bit platform
// commented out the delay logic so that it thinks it's just received all 1s
//
// output:
// $ g++ buggy.cpp -o buggy && ./buggy
// 7fffffff
#include <stdio.h>
#include <stdint.h>
@ato
ato / gist:212785
Created October 18, 2009 18:29
liverepl.sh
#!/bin/sh
# Starter script for Clojure liverepl
[ -z "$JDK_HOME" ] && JDK_HOME=/usr/lib/jvm/default-java
LIVEREPL_HOME="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
CLOJURE_JAR="$LIVEREPL_HOME/clojure.jar"
if [ ! -f "$JDK_HOME/lib/tools.jar" ]; then
echo 'Unable to find $JDK_HOME/lib/tools.jar'
echo "Please set the JDK_HOME environment variable to the location of your JDK."
@ato
ato / scroller.c
Created October 25, 2009 12:53 — forked from farcaller/scroller.c
// simplified and fixed bug where too many \b characters were printed
#include <stdio.h>
#include <unistd.h>
int main (int argc, const char *argv[])
{
int i;
const char scroller[] = "|/-\\";
for(i=0; i<20; ++i) {
printf("%c", scroller[i % (sizeof(scroller) - 1)]);
@ato
ato / wget.sh
Created October 27, 2009 22:58
# wget with notifications!
function wget() {
command wget "$@"
ret=$?
notify-send -i $HOME/.icons/down.svg "Download complete" "wget $*" &> /dev/null
return $ret
}
@ato
ato / fod.clj
Created November 1, 2009 12:38
(def randArray
(for [y (range 100)]
(persistent!
(reduce (fn [v _] (conj! v (rand)))
(transient []) (range (* 100 1000))))))
(def sums (map #(reduce + %) randArray))
(time (dorun (map println sums)))
(defn dostuff []
(couch/get document-id)
(couch/set document-id))
(defn dootherstuff []
(couch/get document-id))
(defn main []
(couch/with-couch host db
(dostuff)
@ato
ato / esj.clj
Created November 4, 2009 23:57
(defn esj-problem
[n limit s]
(if-not (seq s) ; reached end of input?
(when-not (zero? n) ; if there's anything left-over return it
(list n))
(if (>= n limit) ; have we reached the limit?
(lazy-seq ; if so, spit out a new output
(cons n (esj-problem 0 limit s)))
; haven't reached limit, gobble some more input
(recur (+ n (first s)) limit (next s)))))
(defmacro one []
"a one")
(defmacro two []
"and a two")
(defmacro whee [sym]
`(~sym))
(defmacro wheez [s]