Skip to content

Instantly share code, notes, and snippets.

View thoughtpolice's full-sized avatar
👊
omae wa mou shindeiru

Austin Seipp thoughtpolice

👊
omae wa mou shindeiru
View GitHub Profile
@thoughtpolice
thoughtpolice / RC4.hs
Created April 4, 2011 22:15
RC4 via SBV library
-- | An RC4 implementation utilizing SBV.
{-# LANGUAGE ScopedTypeVariables, MultiParamTypeClasses #-}
module RC4
( -- * Types
S -- :: *
, Key -- :: *
, RC4 -- :: *
-- * Swapping array values
, swap -- :: SWord8 -> SWord8 -> S -> S
con meta t = { Label : string
, Show : t -> string }
fun mkTable [r ::: {Type}] (fl : folder r) (mr : $(map meta r)) (x : $r) =
@fold [fn r => $(map meta r) -> $r -> string]
(fn [nm :: Name] [t :: Type] [r :: {Type}] [[nm] ~ r] acc mr x =>
"<tr> <th>" ^ mr.nm.Label ^ "</th> <td>"
^ mr.nm.Show x.nm ^ "</td></tr>"
^ (acc (mr -- nm) (x -- nm)))
(fn _ _ => "") fl mr x
con meta t = { Label : string
, Show : t -> string }
fun mkTable [r ::: {Type}] (fl : folder r) (mr : $(map meta r)) (x : $r) =
@fold [fn r => $(map meta r) -> $r -> xtable]
(fn [nm :: Name] [t :: Type] [r :: {Type}] [[nm] ~ r] acc mr x =>
<xml><tr><th>{[ mr.nm.Label ]}</th><td>
{[ mr.nm.Show x.nm ]}</td></tr>
{ acc (mr -- nm) (x -- nm) }
</xml>)
I have a perl script like this:
$ cat foo.pl
... snip ...
# these functions are exposed to users
sub func1 {
say "func1 arg: " . $_;
...
}
@thoughtpolice
thoughtpolice / gist:1098790
Created July 22, 2011 02:50
IT LIIIIIIVESS, kinda
21:49:39 a@kratos ur-openid $ cat build.urpkg
# -*- Perl -*-
name 'openid';
version '0.0.0';
author 'Adam Chlipala <adam@chlipala.net>';
maintainer 'Adam Chlipala <adam@chlipala.net>';
license 'BSD3';
description 'OpenID authentication for Ur/Web';
homepage 'http://hg.impredicative.com/openid';
bug_tracker 'www.impredicative.com/mantis/';
@thoughtpolice
thoughtpolice / DotP.hs
Created October 3, 2011 23:59
GHC + llvm + acovea
{-# LANGUAGE ParallelArrays #-}
{-# OPTIONS_GHC -fvectorise #-}
module DotP (dotp_wrapper) where
import qualified Prelude
import Data.Array.Parallel
import Data.Array.Parallel.Prelude.Int
dotp_double :: [:Int:] -> [:Int:] -> Int
use std;
import std::io;
import std::uint;
import std::task;
import std::comm;
type d = { ch: comm::chan<uint>, i: uint };
fn runner(c: d) {
let z = c.i; // Satisfy move semantics for send
Q=@
E=@echo
PANDOC=$(Q)pandoc
FILES=$(shell ls *.md)
FILES_HTML=$(patsubst %.md,outdir/%.html,$(FILES))
all: outdir $(FILES_HTML)
outdir:
$(Q)mkdir -p outdir
@thoughtpolice
thoughtpolice / gist:1448869
Created December 8, 2011 22:06
static_assert omg
#if defined(COMPILER_GNUC) && \
(4 < __GNUC__ || (__GNUC__ == 4 && 6 <= __GNUC_MINOR__))
#define STATIC_ASSERT(cond,m) _Static_assert(cond, m)
#else
/* Not GCC 4.6 */
#define STATIC_ASSERT_NAME2(name, line) name ## line
#define STATIC_ASSERT_NAME(line) STATIC_ASSERT_NAME2(jas_assert_, line)
/* The unused 'm' is a transition into C1x _Static_assert */
#ifdef __COUNTER__
#define STATIC_ASSERT(cond,m) \
@thoughtpolice
thoughtpolice / bench.hs
Created December 12, 2011 01:22
Nonce benchmark
{-# LANGUAGE BangPatterns #-}
import Crypto.NaCl.Encrypt.PublicKey
import Crypto.NaCl.Nonce
import Data.List
import System.Environment
main = do
[f] <- getArgs
let n = createZeroNonce nonceLength
print n