Skip to content

Instantly share code, notes, and snippets.

@ztmr
ztmr / cluster_bootserver.erl
Last active December 19, 2015 01:19
Erlang network boot example
tmr@dev:~$ erl -sname boot
Erlang R15B (erts-5.9) [source] [64-bit] [smp:2:2] [async-threads:0] [kernel-poll:false]
Eshell V5.9 (abort with ^G)
(boot@dev)1>
(boot@dev)1>
(boot@dev)1> erlang:get_cookie().
'HAKAZNCDECSZGWFBJSGC'
(boot@dev)2>
(boot@dev)2>
@ztmr
ztmr / ns_exec.c
Last active December 28, 2015 22:19
Spawn a new Linux process by inheriting all the kernel namespaces of the existing process specified by PID
/*
* Module : ns_exec
* Created : 20-NOV-2013 20:50
* Author : Tomas Morstein (www.IDEA.cz)
* Description : Spawn a new process by inheriting all the kernel
* namespaces of the existing process specified by PID
* Prereqs : Linux >=3.8 built with kernel namespace support;
* Older kernels does not implement all the namespaces
* and even the 3.8 shipped by Ubuntu does not come
* with CONFIG_USER_NS enabled:
@implementation CalendarView: CPView
{
}
-(id)init {
self = [super initWithFrame:CGRectMake(0, 0, 200, 200)];
if (self) {
[self loadData];
}
return self;
@ztmr
ztmr / free.c
Created January 19, 2014 20:11
OpenBSD equivalent of `free' Linux command. Shows memory usage.
/*
* $Id: $
*
* Module: free -- description
* Created: 15-SEP-2008 17:56
* Author: tmr
*/
#include <stdio.h>
#include <unistd.h>
@ztmr
ztmr / addInt.c
Created January 19, 2014 20:17
Add a new record to the OpenVMS intrusion database. Uses a $SCAN_INTRUSION system service. http://h71000.www7.hp.com/doc/82final/4527/4527pro_097.html#jul93_317
/*
* addInt.c, v0.1 -- Manually add an intrusion database record
*/
#include <stdio.h>
#include <stdlib.h>
#include <descrip.h>
#include <ssdef.h>
#include <jpidef.h>
#include <ciadef.h>
@ztmr
ztmr / inf.c
Created January 19, 2014 20:19
Inf and NaN values handling in C.
/*
* $Id: $
*
* Module: inf -- description
* Created: 18-DEC-2007 19:17
* Author: tmr
*/
#define INF (1.0 / 0.0)
#define NAN (0.0 / 0.0)
@ztmr
ztmr / gist:9009442
Created February 14, 2014 21:16
LuvvieScript build issues
tmr@gersemi:~/src/erl/misc$ git clone https://github.com/hypernumbers/LuvvieScript Cloning into 'LuvvieScript'...
remote: Reusing existing pack: 784, done.
remote: Total 784 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (784/784), 1.01 MiB | 546 KiB/s, done.
Resolving deltas: 100% (405/405), done.
tmr@gersemi:~/src/erl/misc$ cd LuvvieScript/
tmr@gersemi:~/src/erl/misc/LuvvieScript$ rebar get-deps
==> LuvvieScript (get-deps)
Pulling mochiweb from {git,"git://github.com/mochi/mochiweb.git","master"}
Cloning into 'mochiweb'...
@ztmr
ztmr / ztmr.fs
Created March 12, 2014 20:24
F# command line arguments parsing, factorial, lambdas, and pipe operator fun
// Build:
// $ fsharpc ztmr.fs
// Use:
// $ mono ztmr.exe 5
open System
let rec factorial n =
match n with
| 0 -> 1
@ztmr
ztmr / unix_login_records.erl
Created March 13, 2014 20:51
UNIX Login Records (utmp/wtmp) Parser in Erlang
%% UNIX Login Records (utmp/wtmp) Parser
%% Only GNU/Linux on x86_64 is supported at the moment.
-module (unix_login_records).
-export ([
read_utmp/0, read_wtmp/0,
parse_file/1, parse/1,
record_to_proplist/1
]).
-type utmp_type_code () :: integer ().
@ztmr
ztmr / spotify-adkiller.pl
Last active August 29, 2015 14:03
Spotify AdKiller written in Perl. It will simply mute Spotify's PulseAudio sink once the current track is about to end (= running over its official length) and unmute once a new track has started playing. What a naive solution to cut the advertisement injected at the end of the track!
#!/usr/bin/env perl
#
# $Id: $
#
# Module: spotify-adkiller -- Naive Spotify AdKiller
# Created: 03-JUL-2014 19:54
# Author: tmr
#
# TODO: