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 / Linear.hs
Last active August 29, 2015 14:08
Gradient Descent Linear Regression
module Linear
where
import Prelude hiding (error)
import Control.Arrow
import Data.List
import Data.Vector (Vector)
import qualified Data.Vector as V
-- | Independent variables from a single observation
@kputnam
kputnam / Example.hs
Last active August 29, 2015 14:05
Demo of Union-Find algorithm used for solving type constraints
module Demo where
import Control.Applicative
import Control.Monad.ST
import UnionFind
import Weight
-- | Return the class label if the class is represented by a constructed type
con_ :: Class s (Weight a) b -> ST s (Maybe b)
con_ c = ((== Con) . tag <$> weight c) >>= if_
module Window
( Window
-- | Monoidal windows
, empty
, update
, shift
-- | Non-monoidal windows
, replicate
@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;
/**
{-# 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 ()
{-# 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 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
@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
@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: