Skip to content

Instantly share code, notes, and snippets.

#!/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.
{-# LANGUAGE GADTs #-}
module SafeList where
data Empty
data NonEmpty
class Emptiness e
instance Emptiness Empty
instance Emptiness NonEmpty
@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:
/*
* $ 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 / average.hs
Last active August 29, 2015 14:24
average.hs with timings
-- GHC 7.8.3, Core i5 1.3 GHz
{-# LANGUAGE BangPatterns #-}
import Data.List
{- naive sum over length -}
average0 xs = sum xs / fromIntegral (length xs)
-- ghc -O0 : real 6.392s, sys 0.758s
-- ghc -O3 : real 2.198s, sys 0.323s
-- ghci: 7.54s, 2_574_335_872 b
@EarlGray
EarlGray / deembed.erl
Created August 16, 2015 11:53
deembed: hs|erl
-module(deembed).
-export([main/1]).
read_bins(Data, 0) -> Data;
read_bins(<<NameSize, Name:NameSize/binary,
DataSize:32, _BinData:DataSize/binary,
Rest/binary>>, N) when N > 0 ->
io:format(" ~p (~p bytes)\n", [binary_to_list(Name), DataSize]),
read_bins(Rest, N - 1).
@EarlGray
EarlGray / bheap.py
Last active April 26, 2016 16:16
Algorithms playground
class BinHeap:
def __init__(self):
self.h = []
def __len__(self):
return len(self.h)
def _parent_index(self, i):
return (i - 1) / 2

Keybase proof

I hereby claim:

  • I am earlgray on github.
  • I am dmytrish (https://keybase.io/dmytrish) on keybase.
  • I have a public key ASCFfXNoKHKpVJirONi0Mnkonm24w197pX66YTH8gtcMLQo

To claim this, I am signing this object:

#!/bin/bash
PLAYER=mplayer
PLAYER_OPTIONS=-prefer-ipv4
while getopts "gch" opt; do
case $opt in
g) PLAYER=smplayer
export DISPLAY=:0
;;
(use-modules
(ice-9 hash-table)
(srfi srfi-1))
(define (for-each-file-line filepath thunk)
(with-input-from-file filepath (lambda ()
(let loop ((line (read-line)))
(if line
(begin
(thunk line)