Skip to content

Instantly share code, notes, and snippets.

@carlohamalainen
carlohamalainen / gist:b540375f1fe7218dec8b
Last active August 29, 2015 14:01
The expression "give him the wall".
Quote from _At Day's Close: Night in Times Past Paperback_ (A. Roger Ekirch, 2006).
Courtiers took the place of knights, satin and silk replaced chain
mail. The growing power of nation states, marked by their
monopolization of military force, only broadened the scope of
this transformation. Well-understood rules of civility governed
social exchanges among friends and strangers. Hence, it was thought
inappropriate, if walking on a street, to ask questions of a stranger
or to touch, much less jostle, other pedestrians. Above all, persons
of quality required respect, lest their dignity be affronted. Besides
@carlohamalainen
carlohamalainen / Airports.hs
Created July 1, 2014 10:00
Airports for Blinco.
{-# LANGUAGE FlexibleInstances #-}
-- Airports for Blinco!
module Airports where
import Control.Monad (forM_)
airportsRaw :: [String]
airportsRaw = [ "BNE", "SYD", "ADL", "PER", "CNB", "NTL", "UDG", "CTL"
@carlohamalainen
carlohamalainen / TestWithHsJWT.hs
Created August 7, 2014 04:32
Trying to use hs-jwt to validate an AAF Rapid Connect assertion.
{-# LANGUAGE OverloadedStrings #-}
module TestWithHsJWT where
import qualified Data.Text as T
import qualified Crypto.JWT as JWT
import qualified Crypto.JOSE as JOSE
import qualified Data.HashMap.Lazy as HM
import Data.Aeson
@carlohamalainen
carlohamalainen / join.py
Created June 12, 2015 00:27
Join binary files.
#!/usr/bin/env python
from functools import partial
import sys
BLOCKSIZE = 1048576
# Similar to http://bugs.python.org/issue20992
# but with Python 2.x syntax.
def read_blocks(files):
@carlohamalainen
carlohamalainen / AddProjToBruker.hs
Created July 23, 2015 03:07
Add CAI project ID to Bruker file (demo)
module AddProjToBruker where
-- ##$SUBJECT_comment=( 2048 )
-- <CAI:10001>
import Control.Monad (when)
import Data.Either
import Data.List
import Data.Maybe
import System.Environment
@carlohamalainen
carlohamalainen / gist:1119348
Created August 2, 2011 00:40
weekdays in a range
(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
@carlohamalainen
carlohamalainen / gist:1124157
Created August 3, 2011 23:38
Run ggplot2 from Clojure using rincanter
; 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))
(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
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
(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)