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 |
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 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
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
(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
(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
#!/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
""" | |
From the man page for ssh: | |
-f Requests ssh to go to background just before command execution. This is useful if ssh is going to ask | |
for passwords or passphrases, but the user wants it in the background. This implies -n. The recommended way | |
to start X11 programs at a remote site is with something like ssh -f host xterm. | |
If the ExitOnForwardFailure configuration option is set to “yes”, then a client started with -f will wait | |
for all remote port forwards to be successfully established before placing itself in the background. |
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
-- Fiddling around with STM and shell processes. | |
-- Carlo Hamalainen <[email protected]> | |
import Control.Concurrent | |
import Control.Concurrent.MVar | |
import Control.Concurrent.STM | |
import Control.Concurrent.STM.TChan | |
import Control.Exception |
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 -x | |
set -e | |
module load python/2.7.3 | |
mkdir -p /opt/src | |
cd /opt/src |
OlderNewer