Skip to content

Instantly share code, notes, and snippets.

/*
* $ gcc `pkg-config --libs --cflags libuv` libuv_tcp_echo.c -o tcp_echo
*/
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#include <sys/socket.h>
@EarlGray
EarlGray / memoize.cc
Last active August 29, 2015 14:20
Bartosz Milewsky category theory posts: exercises
#include <iostream>
#include <functional>
#include <unordered_map>
template<class Arg, class Res>
class memoize {
std::function<Res(Arg)> func;
std::unordered_map<Arg, Res> mem;
public:
{-# LANGUAGE GADTs #-}
module SafeList where
data Empty
data NonEmpty
class Emptiness e
instance Emptiness Empty
instance Emptiness NonEmpty
#!/bin/bash
#
# CMOS reader in Bash
#
# Copyright (C) 2015, ZOG Industries Inc, Dmytro S.
# Permission to use, copy, modify, and/or distribute this software
# for any purpose with or without fee is hereby granted, provided that
# the above copyright notice and this permission notice appear in all
# copies.
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <iterator>
#include <algorithm>
int main() {
std::string s;
std::getline(std::cin, s);
@EarlGray
EarlGray / SleepSort.hs
Last active August 29, 2015 14:12
sleepsort
module SleepSort (sleepsort) where
import Control.Concurrent
import Control.Concurrent.STM
worker chan timefun val = do
threadDelay $ timefun val
atomically $ writeTChan chan val
sleepsort :: (a -> Int) -> [a] -> IO [a]
@EarlGray
EarlGray / cleverptr.cpp
Last active January 1, 2016 13:19
C++ overloading
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
template <typename T>
class clever_ptr {
string log;
@EarlGray
EarlGray / bmpdiff.hs
Created October 6, 2013 09:42
A very primitive motion detection system using `fswebcam` utility for capturing images from webcam on Linux Dependencies: fswebcam, ImageMagic, GHC.
import Data.Binary.Get as BG
import Data.Binary.Put as BP
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Internal as BI
import qualified Data.ByteString.Lazy as BL
import Data.Word
import Data.Int
@EarlGray
EarlGray / hellohapp.hs
Created September 30, 2013 15:06
Happstack logging snippets for a wordpress blog
import Happstack.Server
import System.Environment
import Control.Monad (when)
main = do
args <- getArgs
when (length args < 2) $ error "Usage: ./HelloHTTP "
simpleHTTP nullConf $ serveDirectory EnableBrowsing ["index.htm"] (head args)
@EarlGray
EarlGray / tar-patch.sh
Created July 20, 2013 13:48
Patching binary files with bash and xxd
#!/bin/bash
export CHECKSUM_AT=148
function joinlines {
while read line ; do
echo -n "$line"
done
}