Skip to content

Instantly share code, notes, and snippets.

@tuttlem
tuttlem / part.cpp
Last active August 29, 2015 14:13
Particle system
#include <alloc.h>
#include <conio.h>
#include <stdlib.h>
#define VIDEO_MODE_MCGA 0x13
#define VIDEO_MODE_TEXT 0x03
#define PARTICLE_COUNT 1000
@tuttlem
tuttlem / MVar.hs
Created March 19, 2014 04:49
MVar example
import Control.Concurrent
import Control.Concurrent.MVar
main :: IO ()
main = do
-- create an empty mvar
m <- newEmptyMVar
-- get another thread to put a value in it
forkIO $ putMVar m "A value"
@tuttlem
tuttlem / Lens.hs
Created March 18, 2014 14:29
Lens example
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
data Ball = Ball { _position :: (Double, Double), _velocity :: (Double, Double) }
deriving (Show)
-- create the accessors for the Ball type
makeLenses ''Ball
@tuttlem
tuttlem / StateMonad.hs
Created March 16, 2014 11:16
State Monad example
import Control.Monad.State
-- | Starts a value off.
-- This function doesn't perform any calculation at all, it just prepares an
-- initial value to start in the calculation pipeline
--
start :: Int -> State [String] Int
start x = do
put ["Starting with " ++ show x]
return x
@tuttlem
tuttlem / WriterMonad.hs
Created March 16, 2014 10:38
WriterMonad example
import Control.Monad.Writer
-- | Starts a value off.
-- This function doesn't perform any calculation at all, it just prepares an
-- initial value to start in the calculation pipeline
--
start :: Int -> Writer [String] Int
start x = do
tell (["Starting with " ++ show x])
return x
@tuttlem
tuttlem / ReaderMonad.hs
Created March 16, 2014 09:53
Reader monad example
import Control.Monad.Reader
-- | Shared configuration for this application.
-- Rather trivial (and useless), it just configures how our application will
-- address the user
--
data SalutationConfig = SalutationConfig { formal :: Bool }
-- | Returns a greeting
-- Takes in someone's name and returns a greeting string
@tuttlem
tuttlem / inotify1.hs
Created February 9, 2014 22:15
INotify example
module Main where
import Control.Concurrent (threadDelay)
import System.INotify
main :: IO ()
main = do
-- the paths that we'll monitor
let paths = [ "/tmp", "/home/user" ]
@tuttlem
tuttlem / WordCount.java
Created January 30, 2014 12:39
Map Reduce WordCount
package com.test.wordcount;
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
@tuttlem
tuttlem / fork1.hs
Created January 20, 2014 22:15
fork1.hs
module Main where
import Control.Concurrent
main :: IO ()
main = do
-- grab the parent thread id and print it
parentId <- myThreadId
putStrLn (show parentId)
@tuttlem
tuttlem / texture.cpp
Created January 13, 2014 11:11
Texture class
class texture {
public:
// manage the generated texture id
texture(const GLuint t) : _reference(t) { }
// cleanup of the allocated resource
virtual ~texture(void);
// provide access to the reference
const GLuint reference() const { return _reference; }