Skip to content

Instantly share code, notes, and snippets.

View rampion's full-sized avatar

Noah Luck Easterly rampion

  • Mercury Technologies
View GitHub Profile
@rampion
rampion / DocumentWindow.nib
Last active June 9, 2017 09:33
How to make TextEdit.app fullscreen

Why Are Haskell Package Versions Numbers?

#Semantic Versioning is great.

Let me start by answering a different question. Why do Haskell packages have versions?

  • For support: when users report problems, knowing which version they're using allows the package support team to trace the problem through the package code accurately.
  • For compatibility:
@rampion
rampion / LazyLength.hs
Last active May 24, 2021 12:34
The Lazy Length monoid allows you to compare two lists by length without calculating the full length of both lists (unless they are of equal length). Though `lazyLength :: [a] -> LazyLength` is O(n), two `LazyLength` values for lists of length n and m may be compared in time O(min(log n, log m)).
{-# LANGUAGE BangPatterns #-}
module LazyLength (
LazyLength(),
fromLazyLength,
toLazyLength,
lazyLength,
-- QuickCheck properties
prop_invariant,
prop_invertible,
prop_addition,
module Main where
import Criterion.Main
import qualified Data.List.Ordered as O
import qualified Data.List as L
import qualified Data.Set as S
import qualified Data.IntSet as IS
repeatsTail, orderedIntersect, listIntersect, setIntersect :: [Integer] -> [Integer] -> [Integer] -> [Integer]
intsetIntersect :: [Int] -> [Int] -> [Int] -> [Int]
@rampion
rampion / alexa_invert.rb
Created December 8, 2012 01:36
quick and dirty ruby solution
#!/usr/bin/env ruby -I .
require 'file_status'
per_url = Hash.new { |h,k| h[k] = [] }
File.open( ARGV[0], 'r:UTF-8' ) do |f|
FileStatus.status( "processing scrapings", :file => f ) do |update|
update[]
line = f.gets
while line
cat = line.chomp
@rampion
rampion / AlexaTranspose.hs
Created December 7, 2012 23:08
Details for SO question 13735640
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Main where
import Control.Applicative ((<$>), (<*>), (<|>))
import Control.Monad (forM_, (>>), return)
import Control.Monad.Trans (lift)
@rampion
rampion / HuluQueueButtons.user.js
Created November 13, 2012 03:59
A greasemonkey script to add queue buttons to Hulu's "Watch [...] online" pages. Click the "raw" link to install (if you have greasemonkey).
// ==UserScript==
// @name HuluQueueButtons
// @namespace rampion.github.com
// @description Add buttons to Hulu's "Watch [...] online" pages to let you queue/dequeue videos
// @include http://www.hulu.com/watch/*
// @version 1
// @grant none
// ==/UserScript==
$(function(){
#!/usr/bin/env ruby
# only tested with ruby-1.9 so far - you may have issues w/o that
=begin
INPUT
top-1m.csv - from http://s3.amazonaws.com/alexa-static/top-1m.csv.zip
content.rdf.u8 - from http://rdf.dmoz.org/rdf/content.rdf.u8.gz
OUTPUT
domain-topics.csv
@rampion
rampion / RedBlackTree.hs
Created May 11, 2012 13:55
red-black trees in haskell, using GADTs and Zippers
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
module RedBlackTree where
data Zero
data Succ n
type One = Succ Zero
data Black