This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o nounset # explode on undefined variables | |
set -e # explode if any command fails | |
# Best way to shrink a PDF of scanned pages without losing quality. Found on | |
# http://ubuntuforums.org/archive/index.php/t-1133357.html | |
# example: ./shrink_pdf.sh big_file.pdf 600 small_file.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns blerp | |
(:require [clojure.xml :as xml]) | |
(import (java.io ByteArrayInputStream))) | |
(def xml-data "<body> <myheader> <author> bob </author> </myheader> <data> d1 </data> <data>d2</data> <data>d3</data> </body>") | |
(def xml-parsed (let [input-stream (ByteArrayInputStream. (.getBytes xml-data))] | |
(xml-seq (xml/parse input-stream)))) | |
(let [name-blob (for [x xml-parsed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun blerp (x y) | |
"A closure that provides a linear interpolation of a function y = f(x). Attempts to evaluate f | |
at values of x below the minimum value of x result in zero, and attempts above the maximum | |
value of x result in the last value of y." | |
(assert (vectorp x)) | |
(assert (vectorp y)) | |
(let ((min-x (aref x 0)) | |
(max-x (aref x (1- (length x)))) | |
(interp-f (cl-numlib:make-interpolating-function x y))) | |
(lambda (x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ncInq :: NCID -> IO (Int, Int, Int, Int) | |
ncInq ncid = do | |
alloca $ \ndims_ptr -> do | |
alloca $ \nvars_ptr -> do | |
alloca $ \natts_ptr -> do | |
alloca $ \unlimdimid_ptr -> do | |
status <- nc_inq ncid ndims_ptr nvars_ptr natts_ptr unlimdimid_ptr | |
ndims <- peek ndims_ptr | |
nvars <- peek nvars_ptr | |
natts <- peek natts_ptr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns testing-netcdf | |
(:import ucar.ma2.Array) | |
(:import ucar.ma2.ArrayDouble) | |
(:import ucar.ma2.ArrayDouble$D2)) | |
(def a (Array/factory Double/TYPE (int-array [2 2]))) | |
(println (type a)) ; ucar.ma2.ArrayDouble$D2 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; http://carlo-hamalainen.net/blog/2011/08/04/ggplot2-from-clojure | |
; To dump the plot to a file: | |
(use '(com.evocomputing rincanter)) ; https://github.com/jolby/rincanter | |
(r-eval "library(ggplot2)") | |
(r-eval-raw "qplot(rating, data=movies, geom=\"histogram\")") ; see http://had.co.nz/ggplot2/geom_histogram.html | |
(r-eval "ggsave('histogram-example.png')") | |
; To display on your screen (Unix example; see rincanter docs for alternatives to x11() call) | |
(use '(com.evocomputing rincanter)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns date-example | |
(:import java.util.Date) | |
(:import java.text.DateFormat)) | |
(def df (DateFormat/getDateInstance)) | |
; Simon's bit | |
(defn weekdays-in-range [start-date end-date] | |
(let [one-day (* 1000 60 60 24) ; millisecs |
NewerOlder