Skip to content

Instantly share code, notes, and snippets.

View dermesser's full-sized avatar
🐢
a bit of time :-)

Lewin Bormann dermesser

🐢
a bit of time :-)
View GitHub Profile
@dermesser
dermesser / Url.hs
Last active August 29, 2015 13:56
A small URL parser, including URL-encoded arguments
module Url where
import Data.List
import Text.Parsec
import Text.Parsec.String
data Proto = HTTP | FTP
data URL = URL {
@dermesser
dermesser / roman_converter.hs
Created July 6, 2014 18:36
A simple Roman2Decimal2Roman converter. Bugs: Dec2Rom converter uses four consecutive I (like in VIIII); romanToDecimal /may/ be simplified.
import Data.Char (toLower)
rdToDec :: Char -> Int
rdToDec 'i' = 1
rdToDec 'v' = 5
rdToDec 'x' = 10
rdToDec 'l' = 50
rdToDec 'c' = 100
rdToDec 'd' = 500
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <stdbool.h>
_Bool find(const char* haystack, const char* needle)
{
size_t hlen = strlen(haystack);
size_t nlen = strlen(needle);
unsigned int found = 0;
@dermesser
dermesser / uint64encode.go
Created January 31, 2015 16:17
Encode and Decode uint64 values for sending them over the network or similar use cases. Fast (30 ns per number for both functions)
// Converts a number to a little-endian byte array
func lengthToBytes(l uint64) [8]byte {
var sizebuf [8]byte
var i int = 7
for ; i >= 0; i-- {
// The commented implementation is 5 times slower but equivalent
/*
var divisor uint64 = 1 << (uint(i) * 8)
sizebuf[i] = uint8(l / divisor)
@dermesser
dermesser / test.c
Created February 13, 2012 17:07
Use of localtime()
# include <stdio.h>
# include <time.h>
# include <locale.h>
int main(void)
{
time_t currtime = time(NULL); // time_t time(time_t *timep)
struct tm *local, *gmt;
local = localtime(&currtime);
@dermesser
dermesser / chan.hpp
Created October 7, 2015 19:16
Golang-like channels. Not *entirely* threadsafe yet, but almost (a.k.a. quick sketch)
# ifndef _CHAN_HPP
# define _CHAN_HPP
# include <deque>
# include <mutex>
# include <condition_variable>
# include <utility>
template<typename T>
class Chan {
@dermesser
dermesser / .gitignore-latex
Last active December 10, 2015 01:48 — forked from kogakure/.gitignore
*.aux
*.glo
*.idx
*.log
*.toc
*.ist
*.acn
*.acr
*.alg
*.bbl
@dermesser
dermesser / downcode.sh
Created December 27, 2012 11:50
Little bash script to clean up file names of ogg files and transcode them to 64 kbit/s for my phone
#!/bin/bash
# Usage:
#
# Go to the directory you want to contain the transcoded files and
# call this script: $ downcode.sh /path/to/ogg/files/to/be/transcoded
# The transcoded ogg files containing the old tags are placed in $PWD.
# --> Spaces are replaced by underscores (_) in both the file names of the
# ogg files being transcoded and the new ogg files!
@dermesser
dermesser / gist:6145931
Last active December 20, 2015 14:19
Attendance tracking with pg/SaS in Haskell
{-# LANGUAGE OverloadedStrings #-}
import System.IO
import System.IO.Error
import System.Locale
import System.Exit
import Control.Monad
import Control.Exception
@dermesser
dermesser / dec2bin2dec.hs
Created August 7, 2013 18:46
Haskell code to convert decimal numbers to a digital representation ([Digital]) and vice versa.
-- Dec2Bin
--
data Digital = D1 | D0
instance Show Digital where
show D1 = "1"
show D0 = "0"
instance Eq Digital where