Skip to content

Instantly share code, notes, and snippets.

View nakal's full-sized avatar

Martin Sugioarto nakal

View GitHub Profile
@nakal
nakal / year_average.hs
Created November 3, 2016 16:57
Calculates a diagram of average usage per day from timestamp/value pairs
import qualified Data.ByteString.Char8 as C8
import Data.UnixTime
csvTableToTuple :: String -> (Int, Int)
csvTableToTuple line =
let date = takeWhile (/= ';') line
val = tail $ dropWhile (/= ';') line
in (fromEnum (utSeconds (parseUnixTime (C8.pack "%Y-%m-%d") (C8.pack date))), read val)
secondsInDay :: Int
@nakal
nakal / poudriere-cmd.sh
Created October 7, 2016 14:18
Command wrapper for poudriere
#!/bin/sh
JAIL=11amd64
FUN="$1"
DEST="$2"
shift 2
PKG="$@"
OPT_EXT=""
#!/usr/bin/env perl
use strict;
use warnings;
my $verbose = 0;
my ($senddiff) = @ARGV;
if (defined($senddiff)) {
$senddiff = 1;
@nakal
nakal / ssl-ca-check.c
Last active May 3, 2016 13:55
SSL self-made CA verification samples
const char * ca_pubkey =
{
"-----BEGIN CERTIFICATE-----\n"
...
"-----END CERTIFICATE-----"
};
void init(void)
{
/* these both are called only once for the entire application */
#!/bin/sh
IRCSERVER="$1"
CHANNEL="$2"
TEXT="$3"
WEECHAT_PID=`pgrep -U weechatuser weechat`
WEECHAT_PIPE="/home/weechatuser/.weechat/weechat_fifo_${WEECHAT_PID}"
if [ -p "$WEECHAT_PIPE" ]; then
echo "irc.$IRCSERVER.$CHANNEL *$TEXT" > "$WEECHAT_PIPE"
@nakal
nakal / is_ascii.c
Created December 30, 2015 09:47
C program that checks if the given STDIN stream is standard ASCII
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int found_non_ascii = 0;
while (!ferror(stdin) && !feof(stdin)) {
size_t s;
@nakal
nakal / endian.c
Created October 31, 2015 22:26
Endianness test for C (untested)
#include <stdio.h>
int is_little_endian(void)
{
char buf[sizeof(unsigned int)];
*(unsigned int *)buf = 1u;
return (int)buf[0];
}
@nakal
nakal / vimrc_local
Created October 20, 2015 07:24
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 / fibonacci.hs
Created September 11, 2015 23:49
Fibonacci stuff
-- return the nth fibonacci number
fib n = fst $ (foldr1 (.) (replicate n $ \(f1, f2) -> (f2, f1 + f2) )) (0,1)
@nakal
nakal / hdm.hs
Last active August 29, 2015 14:13
First try for hdm
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