Skip to content

Instantly share code, notes, and snippets.

Avatar

Martin Sugioarto nakal

View GitHub Profile
@nakal
nakal / tcpserver.hs
Last active Aug 29, 2015
Threaded TCP-Server in Haskell (IPv4/IPv6)
View tcpserver.hs
import Network.Socket as N
import Control.Concurrent
serverPort :: PortNumber
serverPort = 8080
main = do
sock <- N.socket N.AF_INET6 N.Stream N.defaultProtocol
N.setSocketOption sock N.ReuseAddr 1
N.setSocketOption sock N.ReusePort 1
@nakal
nakal / Lockpattern.hs
Created Dec 8, 2014
Generate a random 3x3 unlock pattern for Android devices
View Lockpattern.hs
{-
File: Lockpattern.hs
This programm calculates a pattern for the 3x3 lock screen in Android
devices. It outputs the path in form of a matrix with numbered
finger positions.
-}
import System.Random
@nakal
nakal / PamTest.hs
Created Jan 14, 2015
PAM authentication test in Haskell
View PamTest.hs
import System.Posix.PAM
main = do
res <- authenticate "system" "user" "pass"
case res of
Left a -> putStrLn $ "error: " ++ pamCodeToMessage a
Right () -> putStrLn "success"
@nakal
nakal / hdm.hs
Last active Aug 29, 2015
First try for hdm
View hdm.hs
import System.IO.Error
import System.Posix.Process
import Graphics.X11.Xft
import Graphics.X11.Xlib.Context
import Graphics.X11.Xlib.Display
import Graphics.X11.Xlib.Event
import Graphics.X11.Xlib.Misc
import Graphics.X11.Xlib.Screen
import Graphics.X11.Types
import Graphics.X11.Xlib.Window
@nakal
nakal / mbox-split.sh
Created Sep 11, 2015
Split a single MBOX into many small email files
View mbox-split.sh
# generates mails 1.eml, 2.eml,... from a single mbox file
# when (e.g.) procmailrc is flawed and everything was delivered
# locally
#
# then you can feed these files into the LDA one-by-one
awk '/^From / {nr += 1; getline }; { print $0 >> ( nr".eml" ) }' /var/mail/$USER
@nakal
nakal / fibonacci.hs
Created Sep 11, 2015
Fibonacci stuff
View fibonacci.hs
-- return the nth fibonacci number
fib n = fst $ (foldr1 (.) (replicate n $ \(f1, f2) -> (f2, f1 + f2) )) (0,1)
View vimrc_local
" ***** Start project directory local vimrc files
let s:start_dir=getcwd()
while s:start_dir != '/' && empty(glob(s:start_dir . '/.git'))
let s:start_dir=fnamemodify( s:start_dir, ':h')
endwhile
if s:start_dir != '/'
let s:vimrc_path = s:start_dir . '/.vimrc'
@nakal
nakal / endian.c
Created Oct 31, 2015
Endianness test for C (untested)
View endian.c
#include <stdio.h>
int is_little_endian(void)
{
char buf[sizeof(unsigned int)];
*(unsigned int *)buf = 1u;
return (int)buf[0];
}
@nakal
nakal / is_ascii.c
Created Dec 30, 2015
C program that checks if the given STDIN stream is standard ASCII
View is_ascii.c
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int found_non_ascii = 0;
while (!ferror(stdin) && !feof(stdin)) {
size_t s;
View phabricator_sshd
#!/bin/sh
#
# $FreeBSD$
# PROVIDE: phabricator_sshd
# REQUIRE: DAEMON
# KEYWORD: shutdown
. /etc/rc.subr