Skip to content

Instantly share code, notes, and snippets.

View 3noch's full-sized avatar
🕯️

Elliot Cameron 3noch

🕯️
  • Indiana
View GitHub Profile
@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.
@3noch
3noch / Functor.py
Last active December 20, 2021 21:41
Functors in Python
import types
global fmap_vtable
fmap_vtable = {}
def fmap_for(type):
def register_fmap(func):
fmap_vtable[type] = func
return func
@3noch
3noch / permissions.py
Last active November 25, 2015 19:10
permissions.py
import sqlalchemy as sa
import sqlalchemy.orm as saorm
from keg.db import db
permission_child_map = db.Table(
'permission_child_map',
sa.Column(
'permission_id',
sa.Integer(),
@3noch
3noch / install-ghcjs-for-stack.hs
Last active August 28, 2016 12:48
Install GHCJS for Stack
#!/usr/bin/env stack
-- stack --install-ghc runghc --package turtle --package wreq
{-# LANGUAGE OverloadedStrings #-}
import qualified Control.Foldl as Fold
import Control.Lens ((^.))
import Control.Monad (when)
import Data.ByteString.Lazy (hPut)
import Data.Maybe (fromMaybe)
@3noch
3noch / Geolocation.hs
Last active January 30, 2016 20:25
Reflex-DOM Geolocation
module Geoposition where
import Control.Concurrent (forkIO)
import Control.Monad.Exception (catch, throw)
import Control.Monad.IO.Class (liftIO)
import Reflex (Event)
import Reflex.Dom (MonadWidget)
import Reflex.Dom.Class (performEventAsync)
@3noch
3noch / keybase.md
Created February 7, 2016 04:52
keybase.md

Keybase proof

I hereby claim:

  • I am 3noch on github.
  • I am 3noch (https://keybase.io/3noch) on keybase.
  • I have a public key whose fingerprint is AEB7 54C9 7689 DDC8 1146 4303 6927 D7A5 B754 636C

To claim this, I am signing this object:

@3noch
3noch / test_assert.py
Created February 12, 2016 15:36
Python Optimization Tosses `assert` statements
def false():
print 'Bah humbug!'
return False
assert false()
print 'Done'
# run with python -O and 'Bah humbug!' is never printed.
@3noch
3noch / void.py
Last active February 17, 2016 03:46
Abstract, unambiguous nothingness in Python
class Void(object):
"""A placeholder object which never equals itself and always evaluates to False in
conditions.
This is useful when you want an abstract, unambiguous way to delineate a value as
being "not-set".
Ideally, you would subclass this in your context to create a "personal" void class
no one would ever use besides you. For example: