Skip to content

Instantly share code, notes, and snippets.

View hvr's full-sized avatar
🕶️
functional lazy

Herbert Valerio Riedel hvr

🕶️
functional lazy
  • Vienna, Austria, Europe, Earth, Solar System, Milky Way, ...
  • X @hvrgnu
View GitHub Profile
@hvr
hvr / gist:411780
Created May 24, 2010 11:50
Python prime number generator using "Sieve of Eratosthenes" algorithm
def primes(limit):
"""
generate lazy (finite) sequence of primes below limit
>>> list(primes(100))
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
>>> sum(primes(1000*1000))
37550402023
"""
@hvr
hvr / gist:608671
Created October 3, 2010 15:37
NFData instance for Text.JSON intermediate parse-tree types
import Text.JSON
import Text.JSON.Types
import Control.DeepSeq
instance NFData JSValue where
rnf JSNull = ()
rnf (JSBool _) = ()
rnf (JSRational b _) = rnf b
rnf (JSString s) = rnf s
rnf (JSArray a) = rnf a
@hvr
hvr / Setup.hs
Created October 31, 2010 15:44
Example CABAL Setup.hs file for automatic package versioning via `git describe`
import Control.Exception
import Control.Monad
import Data.Maybe
import Data.Version
import Distribution.PackageDescription (PackageDescription(..), HookedBuildInfo, GenericPackageDescription(..))
import Distribution.Package (PackageIdentifier(..))
import Distribution.Simple (defaultMainWithHooks, simpleUserHooks, UserHooks(..))
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..))
import Distribution.Simple.Setup (BuildFlags(..), ConfigFlags(..))
import Distribution.Simple.Utils (die)
@hvr
hvr / gist:662196
Created November 4, 2010 07:02
Show key fingerprints of public keys in .ssh/authorized_keys file
#!/bin/bash
( while read L
do echo $L > /tmp/pubkey
printf "%-16s => " $(cut -f 3 -d ' ' /tmp/pubkey)
ssh-keygen -l -f /tmp/pubkey
done
rm /tmp/pubkey
) < .ssh/authorized_keys
@hvr
hvr / aeson-vs-json-ghc-7.2.2-report.html
Created December 23, 2011 10:35
GHC-7.2 vs GHC-7.4 aeson/json performance
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>criterion report</title>
<!--[if lte IE 8]>
<script language="javascript" type="text/javascript">
if(!document.createElement("canvas").getContext){(function(){var z=Math;var K=z.round;var J=z.sin;var U=z.cos;var b=z.abs;var k=z.sqrt;var D=10;var F=D/2;function T(){return this.context_||(this.context_=new W(this))}var O=Array.prototype.slice;function G(i,j,m){var Z=O.call(arguments,2);return function(){return i.apply(j,Z.concat(O.call(arguments)))}}function AD(Z){return String(Z).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function r(i){if(!i.namespaces.g_vml_){i.namespaces.add("g_vml_","urn:schemas-microsoft-com:vml","#default#VML")}if(!i.namespaces.g_o_){i.namespaces.add("g_o_","urn:schemas-microsoft-com:office:office","#default#VML")}if(!i.styleSheets.ex_canvas_){var Z=i.createStyleSheet();Z
module Main where
import Control.DeepSeq
import Control.Exception (evaluate)
import Criterion.Main
import qualified Data.ByteString.Char8 as B
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified Data.Text.ICU.Convert as TI
@hvr
hvr / Raw.hs
Created August 5, 2013 09:15
Compact heap representation a `ByteString` can be converted to/from.
{-# LANGUAGE MagicHash #-}
module Data.ByteString.Raw (RawByteString, empty, fromByteString, toByteString) where
import qualified Data.ByteString as B
import Data.ByteString.Internal
import GHC.Prim
import GHC.ForeignPtr
import GHC.Types
import System.IO.Unsafe (unsafePerformIO)
@hvr
hvr / base-4.6.0.1-vs-4.7.0.0.md
Created September 21, 2013 08:29
API deltas for `base`

API Delta Report for version 4.7.0.0

Modules removed from API version 4.7.0.0:

- Control.Concurrent.SampleVar
- Data.HashTable

Modules added in API version 4.7.0.0:

@hvr
hvr / report.html
Last active December 27, 2015 11:59
tests & benchmarks for new integer-gmp import/export primitives
{-# LANGUAGE CPP, BangPatterns, MagicHash, UnliftedFFITypes, UnboxedTuples, ScopedTypeVariables #-}
-- | Tests/Benchmarks for new GHC.Integer.GMP.Internals.{import,export}Integer primitives
import Control.Monad
import Criterion.Main
import Data.Bits
import Data.ByteString.Short.Internal (ShortByteString(SBS))
import qualified Data.ByteString.Short.Internal as SBS
import Data.List
@hvr
hvr / .gitignore
Last active August 29, 2015 13:57
Git server-side submodule reference validator
/dist/