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
module Window
( Window
-- | Monoidal windows
, empty
, update
, shift
-- | Non-monoidal windows
, replicate
@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_
@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 / KMeans.hs
Last active August 29, 2015 14:08
Sequential and Parallel KMeans
{-# LANGUAGE ScopedTypeVariables #-}
module KMeans
( euclidean
, kMeans
, kMeansPar
, chunk
, random
) where
@kputnam
kputnam / Evaluation.hs
Created November 25, 2014 20:56
Evaluation of Predictive Ranking Algorithms
import Data.Ord
import Data.List
import Test.QuickCheck
-- | Quantify how "unsorted" a given list of elements is, by computing
-- at each position in the list: how many later elements are smaller?
--
-- e.g. cost "abc" == 0
-- cost "acb" == 1
-- cost "cba" == 2
@kputnam
kputnam / +jQuery.js
Last active December 29, 2015 20:22
jQuery Bookmarklet
(function() {
var otherLib = (typeof($) == 'function');
if (typeof(jQuery) != 'undefined') {
alert('jQuery already defined');
return;
}
function getScript(url, callback) {
var script = document.createElement('script');
@kputnam
kputnam / help-wanted.pl
Last active November 4, 2015 06:25
Formats and prints recent StackOverflow careers postings to console
#!/usr/bin/perl
use URI::Escape;
my $url = 'http://careers.stackoverflow.com/jobs/feed?searchTerm=';
# Either use search terms given as command-line arguments, or use default terms
my $q = join('+', map { uri_escape($_); } (@ARGV > 0) ?
@ARGV : ('-.net', '-css', '-c#', '-android', '-php', '-ios', '-vb.net', '-excel' ));
# Read XML from child process

Notes on Ruby's method refinement

The example below creates a refinement module which adds a method to instances of Integer. In the Test class, we bring it into scope by declaring using Refinements. Next, we create an instance method using def_delegators named Test#xxx that calls @k.xxx, which should resolve to the refinement method we added to Integer. Finally, we "manually" create essentially the same method, this time named yyy, but we define it "manually" without using def_delegators.

require "forwardable"

module Refinements
  refine Integer do
 def xxx
@kputnam
kputnam / example.hs
Created April 16, 2016 05:44
Covariant and contravariant functors
-- Covariate functor
class Fun f where
fun :: (a -> b) -> f a -> f b
-- Contravariate functor
class Con f where
con :: (b -> a) -> f a -> f b
-- Function parameterized over input type 'i'