Skip to content

Instantly share code, notes, and snippets.

@jacobstanley
jacobstanley / commutative.hs
Created September 21, 2015 01:47
Using `sbv` to detect if a fold is commutative
import Data.SBV
import Control.Applicative ((<$>))
import Prelude hiding (sum, count)
------------------------------------------------------------------------
main :: IO ()
main = do
x <- satWith z3 { timing = True, smtFile = Just "smt.txt" } program
@jacobstanley
jacobstanley / emojis.hs
Last active September 15, 2015 02:51
Generate a random set of GitHub emojis
#!/usr/bin/env runghc
import Data.List
import System.Environment
import System.Process
import System.Random
main :: IO ()
main = do
args <- getArgs
module Collect
export value collectInit : Nat# -> Unit;
export value collectHeap : Addr# -> Addr# -> Addr# -> Addr# -> Unit;
import foreign c value
malloc : Nat# -> Addr#;
import foreign c value
formatOfObject : [r : Region].Ptr# r Obj -> Nat#;
import foreign c value
{-# LANGUAGE GADTs
, FlexibleInstances
, RebindableSyntax
, DeriveFunctor
, RebindableSyntax
, OverloadedStrings #-}
import Control.Monad.Free
import Control.Monad
import Data.Monoid
-- Solve for the maximum/minimum number of menu items adding up to $15.05
-- http://xkcd.com/287/
xkcd :: Direction -> Program String String IntDouble
xkcd dir = program dir
( z1 mf .+.
z1 ff .+.
z1 ss .+.
z1 hw .+.
z1 ms .+.
z1 sp )
@jacobstanley
jacobstanley / VarInt.hs
Created October 9, 2014 11:46
hs-packer super inlinable varint decoding
getVarInt32 :: Unpacking Word32
getVarInt32 = go step (stepLast "getVarInt32: varint was larger than 32-bits") 0
where
go :: (Int -> b -> b) -> (Int -> b) -> b
go !s !sl = s 0 . s 7 . s 14 . s 21 $ sl 28
{-# INLINE go #-}
{-# INLINE getVarInt32 #-}
getVarInt64 :: Unpacking Word64
getVarInt64 = go step (stepLast "getVarInt64: varint was larger than 64-bits") 0
#!/bin/bash
# Options / Usage
# put this script in the same directory as your *.cabal file
# it will use the first line of "cabal info ." to determine the package name
# custom options for "cabal haddock" (cabal haddock --help,
# http://www.haskell.org/haddock/doc/html/invoking.html)
CUSTOM_OPTIONS=(--haddock-options='-q aliased')
# hackage server to upload to (and to search uploaded versions for)
<?xml version="1.0" encoding="utf-16"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark><name>Crosses itself</name><styleUrl>#S6</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-92.3941429892949,29.443662005645,0
public sealed class ImmutableList<T> : IList<T>, IList
{
private readonly T[] m_Items;
public ImmutableList(IEnumerable<T> source)
{
m_Items = source.ToArray();
}
public T[] ToArray()
@jacobstanley
jacobstanley / nyanicon.js
Created November 21, 2011 06:35 — forked from sphvn/nyanicon.js
Animooted Nyan Favicon
// *** First of all the Favicon.js ***
// Favicon.js - Change favicon dynamically [http://ajaxify.com/run/favicon].
// Copyright (c) 2006 Michael Mahemoff. Only works in Firefox and Opera.
// Background and MIT License notice at end of file, see the homepage for more.
// USAGE:
// * favicon.change("/icon/active.ico"); (Optional 2nd arg is new title.)
// * favicon.animate(new Array("icon1.ico", "icon2.ico", ...));
// Tip: Use "" as the last element to make an empty icon between cycles.