Skip to content

Instantly share code, notes, and snippets.

View crdueck's full-sized avatar

Chris Dueck crdueck

View GitHub Profile
@crdueck
crdueck / Mandlebrot
Created December 26, 2012 00:29
Parallel Mandlebrot set generator using Repa
import Data.Array.Repa
data Complex a = Complex { re, im :: !a }
instance Num a => Num (Complex a) where
(Complex a b) + (Complex c d) = Complex (a + c) (b + d)
(Complex a b) - (Complex c d) = Complex (a - c) (b - d)
(Complex a b) * (Complex c d) = Complex (a*c - b*d) (a*d + b*c)
abs _ = undefined
signum _ = undefined
@crdueck
crdueck / bb.c
Created December 26, 2012 00:32
BrickBreaker in C
#include <stdlib.h>
#include <math.h>
//#include <SDL/SDL.h>
#define WIDTH 640
#define HEIGHT 420
#define BLK_W WIDTH
#define BLK_H HEIGHT / 3
struct l_node
@crdueck
crdueck / xresources
Last active December 11, 2015 04:09
Xresources
! Xft settings
Xft.dpi: 96
! URxvt settings
URxvt*scrollBar: off
URxvt*foreground: #DDCCBB
URxvt*background: #101010
URxvt*font: xft:terminus:size=12:antialias=true
URxvt.perl-ext-common: default,matcher
URxvt.urlLauncher: /usr/bin/firefox
{-# LANGUAGE QuasiQuotes #-}
import Control.Monad
import Data.Array.Repa (Array, DIM2, All(..), Any(..), (:.)(..), U)
import qualified Data.Array.Repa as R
import Data.Array.Repa.Stencil
import Data.Array.Repa.Stencil.Dim2
import Data.Monoid (Endo(..), mappend, mconcat)
import System.Random
@crdueck
crdueck / tmux.conf
Created August 27, 2013 02:22
tmux.conf
## KEYBINDS
set -g prefix C-a
unbind C-b
set -g status-keys vi
setw -g mode-keys vi
unbind l
unbind s
unbind w
unbind v
@crdueck
crdueck / client.scala
Created August 30, 2013 18:14
akka remote
// client conf
akka {
loglevel = "DEBUG"
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
transport = "akka.remote.netty.NettyRemoteTransport"
log-sent-messages = on
log-received-messages = on
@crdueck
crdueck / Actor.hs
Created November 26, 2013 13:08
actors in haskell
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverlappingInstances #-}
import Control.Applicative
import Control.Concurrent
import Control.Concurrent.STM
import Data.Dynamic
import Data.Monoid
import Data.Word
import qualified Data.Foldable as F
@crdueck
crdueck / Par.hs
Created April 6, 2014 18:45
Self optimizing Par Arrow
{-# LANGUAGE Arrows, GADTs #-}
data Par a b where
Pure :: (a -> b) -> Par a b
Seq :: Par a b -> Par b c -> Par a c
Par :: (a -> (a1, a2)) -> Par a1 b1 -> Par a2 b2 -> ((b1, b2) -> b) -> Par a b
instance Category Par where
id = Pure id
@crdueck
crdueck / Signal.hs
Last active August 29, 2015 14:01
Signal
import Control.Applicative
import Control.Monad
import Data.Monoid
data SignalT m a
= Skip (m (SignalT m a))
| Emit a (m (SignalT m a))
instance Monad m => Functor (SignalT m) where
fmap f = go
@crdueck
crdueck / jump_consistent_hash.c
Created August 6, 2014 01:35
jump consistent hash
int32_t JumpConsistentHash(uint64_t key, int32_t num_buckets)
{
int64_t b = -1, j = 0;
while (j < num_buckets) {
b = j;
key = key * 2862933555777941757ULL + 1;
j = (b + 1) * (double(1LL << 31) / double((key >> 33) + 1);
}
return b;
}