Skip to content

Instantly share code, notes, and snippets.

@blitzcode
blitzcode / gist:393c81115a32f7ac15e4
Created March 5, 2016 13:18
Rust parallel array
fn main() {
let data_in = (0..1000).collect::<Vec<i32>>();
let (_, mut data_in_slice) = data_in.split_at(0);
let mut data_out: Vec<i32> = Vec::with_capacity(data_in.len());
unsafe { data_out.set_len(data_in.len()); }
let (_, mut data_out_slice) = data_out.split_at_mut(0);
let nthreads = 5;
let threads: Vec<_> = (0..nthreads).map(|i| {
@blitzcode
blitzcode / gist:9d96be6eaea7dfd62742
Created March 5, 2016 13:16
Haskell Bin Tree to List
module Main where
data Tree a = Empty | Node a (Tree a) (Tree a)
tree :: Tree Int
tree = Node 4 (Node 2 (Node 1 Empty Empty) (Node 3 Empty Empty)) (Node 6 (Node 5 Empty Empty) (Node 7 Empty Empty))
toList :: Tree a -> [a]
toList root = go root []
@blitzcode
blitzcode / gist:038826010fdf75ada761
Created January 17, 2016 23:21
Haskell Tests, GADTs, TypeFamilies, MultiParamTypeClasses,
{-# LANGUAGE TemplateHaskell
, RankNTypes
, ExistentialQuantification
, GADTs
, MultiParamTypeClasses
, TypeFamilies #-}
module Main where
import Control.Monad.State
@blitzcode
blitzcode / Main.hs
Created January 17, 2016 23:17
monad-control type inferencence
{-# LANGUAGE ScopedTypeVariables, FlexibleContexts #-}
module Main where
import Control.Monad.Trans.Control
import Control.Exception
import Control.Monad.Trans.State
import Control.Monad.IO.Class
module Main (main) where
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad.State
import Control.Monad.Reader
import Control.Loop
main :: IO ()
main = do
let w = 1024
newtype Label r m = Label { runLabel :: ContT r m () }
label :: ContT r m (Label r m)
label = callCC $ \k -> return $ let x = Label (k x) in x
goto :: Label r m -> ContT r m b
goto lbl = runLabel lbl >> goto lbl
usesGoto :: (Monad m) => ContT r m r -> m r
usesGoto = flip runContT return
data Exp a where
Lit :: Int -> Exp Int
Add :: Exp Int -> Exp Int -> Exp Int
Mul :: Exp Int -> Exp Int -> Exp Int
Cmp :: Eq a => Exp a -> Exp a -> Exp Bool
If :: Exp Bool -> Exp a -> Exp a -> Exp a
deriving instance Show (Exp a)
eval :: Exp a -> a
@blitzcode
blitzcode / gist:8175735
Created December 29, 2013 22:55
Git RSync Backup Post Commit Hook
#!/bin/sh
if [ -d "/Volumes/Backup SD" ]; then
echo "rsync backup of .git to SD card..."
rsync $GIT_DIR --delete --times --recursive --checksum --compress --human-readable --stats /Volumes/Backup\ SD/
else
echo "SD card 'Backup SD' not inserted, NOT doing the rsync backup"
fi
@blitzcode
blitzcode / gist:8123168
Last active September 10, 2023 17:39
Haskell Hoogle Local Version Setup Steps
# Install a local copy of Hoogle (OS X 10.10, GHC 7.10.1)
# Download
cd
cabal unpack hoogle
cd hoogle-4.2.40/
# Use a sandbox
cabal sandbox init