Skip to content

Instantly share code, notes, and snippets.

View kputnam's full-sized avatar
💭
I have 478 browser tabs open

kputnam kputnam

💭
I have 478 browser tabs open
View GitHub Profile
@kputnam
kputnam / newrelic_httpi.rb
Created November 8, 2012 06:15
NewRelic Instrumentation for HTTPI
DependencyDetection.defer do
@name = :net
depends_on do
defined?(HTTPI)
end
executes do
NewRelic::Agent.logger.debug "Installing HTTPI instrumentation"
end
module L
( L
, empty
, single
, wrap
, unwrap
, cons
, append
, map
, foldl
@kputnam
kputnam / PrettyPrinter.hs
Created May 22, 2013 07:30
AST, parser, and pretty printer for JS-like language
{-# LANGUAGE OverloadedStrings #-}
module Example
( Term(..)
, pretty
, parse
, testReparse
, normalize
) where
@kputnam
kputnam / dtruss-vim-write.md
Created July 11, 2013 05:53
Vim system calls when saving a file

Using dtruss on vim's :w

Ever wonder what happens when you save a file in vim? There's quite a lot more happening than open, write, and close. I found this out while working on some code to monitor changed files using the node.js fs.watch API, which abstracts (or obscures) Mac OS X's kqueue API.

To find out exactly what vim is doing when saving a file, we'll use a tool included with DTrace that reports on another process's system calls. We need the process ID of vim, which is already open and editing my file:

@kputnam
kputnam / hmatrix.sh
Last active December 25, 2015 22:09
hmatrix
brew tap homebrew/science
brew tap homebrew/dupes
brew install lapack openblas gsl
cabal install hmatrix hmatrix-special hmatrix-tests \
--extra-lib-dirs=/usr/local/opt/lapack/lib --extra-include-dirs=/usr/local/opt/lapack/include \
--extra-lib-dirs=/usr/local/opt/gsl/lib --extra-include-dirs=/usr/local/opt/gsl/include \
--extra-lib-dirs=/usr/local/opt/openblas/lib --extra-include-dirs=/usr/local/opt/openblas/include
{-# LANGUAGE TemplateHaskell #-}
import Data.Monoid
import Data.DeriveTH
data Venn a =
Venn
{ both :: a -- number of elements in both t and p
, pNotT :: a -- number of elements in p but not t
, tNotP :: a -- number of elements in t but not p
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
-- http://michaelxavier.net/posts/2014-04-27-Cool-Idea-Free-Monads-for-Testing-Redis-Calls.html
import Control.Monad.State
import Control.Monad.Free
import Control.Monad.Free.TH
{-# LANGUAGE MonadComprehensions #-}
import Data.Maybe
import Data.Monoid
fizzBuzz :: [(Int, String)] -> Int -> String
fizzBuzz ds n = fromMaybe (show n) $ mconcat [[s | d `divides` n] | (d,s) <- ds]
where x `divides` y = y `mod` x == 0
main :: IO ()
@kputnam
kputnam / Test.java
Created May 10, 2014 03:13
Type parameter instantiation
package test;
public class Test {
public static class Generic<A, B> { }
public static class Instance extends Generic<String, String> { }
// OK
Class<? extends Generic<String, String>> w = Instance.class;
/**