Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / enc.rb
Created February 7, 2015 13:18
Ruby Asymmetric Encryption
#!/usr/bin/env ruby
require 'base64'
require 'openssl'
common = {
:key_length => 4096,
:digest_func => OpenSSL::Digest::SHA256.new
}
@tuttlem
tuttlem / lcd.cpp
Created February 21, 2015 15:07
Double buffer arduino sketch
#include <Wire.h>
#include <LiquidCrystal.h>
#define LCD_WIDTH 16
#define LCD_HEIGHT 2
#define LCD_SIZE (LCD_WIDTH * LCD_HEIGHT)
class LCDDoubleBuffer {