Skip to content

Instantly share code, notes, and snippets.

View 3noch's full-sized avatar
🕯️

Elliot Cameron 3noch

🕯️
  • Indiana
View GitHub Profile
def match(fns):
def inner(x):
for cls, fn in fns:
if isinstance(x, cls):
return fn(x)
return inner
doformat = match(
[ (Literal, lambda x: x)
module Rules where
Schema ( "time" =: timestamp
, "enabled" =: bool )
data Value = VInt Int
| VString String
| VBool Bool
| VList [Value]
| VSchema [(String, Value)]
@3noch
3noch / Main.hs
Created August 20, 2014 18:19
TMQueue vs Chan
module Main where
import Control.Applicative
import Control.Concurrent (yield)
import Control.Concurrent.Async
import Control.Concurrent.Chan
import Control.Concurrent.STM (atomically)
import Control.Concurrent.STM.TMQueue
import Control.Monad (replicateM, forM_, forever)
import Data.Function (fix)
@3noch
3noch / Boxed.h
Last active August 29, 2015 14:06
Boxed
#pragma once
#include <cassert>
#include <memory>
/*
* A non-null shared pointer to some value (i.e. a shared reference).
*
@3noch
3noch / Atomic.hpp
Last active August 29, 2015 14:21
Atomic Variables in C++ (akin to Haskell's MVar)
#pragma once
#include <memory>
#include <boost/thread.hpp>
#include <boost/utility.hpp>
#include <CeFunctional.h>
#include <CeMemory.h>
#include <FunctionObject.h>
@3noch
3noch / alliteration.irclog
Last active August 29, 2015 14:21
Alliteration
(8:51:32 AM) matt_ribeiro: elliot1: I don't think we met, and have you seen elliot?
(8:54:01 AM) jared_burkeen: matt_ribeiro, check your email, elliot1 is a new hire that started this week
(8:54:10 AM) jared_burkeen: he's the anti-haskell elliot
(8:55:55 AM) matt_ribeiro: oh then.... PLEASED to meet you. :-)
(8:57:36 AM) jared_burkeen: he will greet you in return, he's just a little shy
(9:02:16 AM) matt_ribeiro: Unfortunately, I ran into some haskell woes last night, so I really need elliot, instead of elliot1.
(9:10:27 AM) jared_burkeen: I think he's off today
(9:10:31 AM) jared_burkeen: no that was yesterday
(9:10:41 AM) jared_burkeen: but it's usually tomorrow that he's off
(9:14:08 AM) matt_ribeiro: If yesterday was tomorrow, what does that make today?
@3noch
3noch / ResourceHandling.hpp
Last active August 29, 2015 14:21
RAII Encapsulation
#pragma once
#include <CePrelude.h>
#include <FunctionObject.h>
/**
* Encapsulates RAII by providing a safe interface to a scarce resource, closing it on destruction.
*/
template<typename T>
@3noch
3noch / Chan.hpp
Last active September 14, 2015 20:01 — forked from qzchenwl/Chan.hpp
Haskell's MVar and Chan in C++
#include <memory>
#include "MVar.hpp"
template <typename T>
struct Item;
template <typename T>
struct Stream
{
typedef MVar<Item<T>> type;
#pragma once
#include <boost/thread.hpp>
#include <CeBaseTypes.h>
#include <Maybe.h>
/**
* A concurrency primitive which may contain a single value or be empty.
import Shelly
import Prelude hiding (FilePath)
sudo_ com args = run_ "sudo" (com:args)
main = shelly $ verbosely $ do
apt_get "update" []
apt_get "install" ["haskell-platform"]
where
apt_get mode more = sudo_ "apt-get" (["-y", "-q", mode] ++ more)