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 / 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)
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 / 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
@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 / 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
"""
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Monad.Identity
import Control.Monad.Except
import Control.Monad.State.Strict
type SET s e m = StateT s (ExceptT e m)
type EST e s m = ExceptT e (StateT s m)
@hvr
hvr / gist:d9c08fe0e87075228e41
Last active August 29, 2015 14:06
CounterArray based on `fetchAddIntArray#`
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE BangPatterns #-}
module RingCounter
( CounterArray
, newCounterArray
, sizeofCounterArray
, readCounterArray
@hvr
hvr / gist:4b7b3074826ccc327a7d
Last active August 29, 2015 13:59
regen haddock docs
#!/bin/bash
set -e
PKGID="$1"
PKGN=$(echo "$PKGID" | sed 's,^\(.*\)-\([0-9.]*\)$,\1,')
PKGV=$(echo "$PKGID" | sed 's,^\(.*\)-\([0-9.]*\)$,\2,')
# EDIT ME XXX
CREDS="MyUser:MyPass"
@hvr
hvr / .gitignore
Last active August 29, 2015 13:57
Git server-side submodule reference validator
/dist/