Skip to content

Instantly share code, notes, and snippets.

@luelista
luelista / fgdi-dfautomaton.js
Last active August 29, 2015 14:00
Deterministic Finite Automata to search for the substrings '01', '010' and 'hallo'
#!/usr/bin/node
// A = (alphabet, states, q0, Delta, Z)
//--> Deterministic Finite Automaton
function Automaton(alphabet, Q, q0, Delta, Accept) {
this.alphabet = alphabet;
this.Q = Q;
this.q0 = q0;
@luelista
luelista / workingdays.c
Last active August 29, 2015 14:01
Workingdays - Calculate the number of business days in a given year
// Workingdays - Calculate the number of business days in a given year
// Copyright (c) 2014 Max Weller
// COMPILE AND RUN:
// $ gcc -o workingdays workingdays.c
// $ ./workingdays -h
// Tested with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) (x86_64-apple-darwin13.1.0)
// and gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) (x86_64-linux-gnu)
@luelista
luelista / gist:eba639ee62900ab41193
Created June 25, 2014 13:36
Parser for matching parentheses and strings
function check_parens(str) {
var br=0,skip=false,instr=false;
for(var i = 0, len = str.length; i<len; i++) {
if(skip) { skip=false; continue; }
var z = str[i];
switch(z) {
case "[":case "{":case "(": if(!instr)br++;break;
case "]":case "}":case ")": if(!instr)br--; if(br==0)return i; break;
case "\"":case "'": instr=!instr;
case "\\": skip=true; break;
@luelista
luelista / export_rsnapshot.sh
Last active August 29, 2015 14:07
export_rsnapshot
#!/bin/bash
RSNAPDIR=/.private/.snapshots
EXPDIR=$1
if [ -z "$EXPDIR" ]; then
echo Please give folder
exit 12
fi
@luelista
luelista / Makefile
Created January 28, 2015 19:00
Zone transfer to secondary name server via mysqldump...
zone.txt: last_change
pdnssec rectify-all-zones
echo "SELECT name,type,content from records;" | mysql pdns > new_zone.txt
diff zone.txt new_zone.txt > zone.diff
rm zone.txt
mv new_zone.txt zone.txt
gzip --stdout zone.diff > diffs/zone.diff.$(date +"%Y%m%d%H%M")
mysqldump pdns | ssh -i /root/.ssh/copydns_key ns3.teamwiki.net "mysql pdns"
#!/usr/bin/perl -w
open SHD, "<", "/etc/shadow" or die "cannot open /etc/shadow: $_";
while(<SHD>) {
@fields = split /:/;
print("\ndn: uid=$fields[0],ou=People,dc=fachschaft,dc=informatik,dc=tu-darmstadt,dc=de\n");
print("changetype: modify\n");
print("replace: userPassword\n");
print("userPassword: {crypt}$fields[1]\n");
}
#!/bin/sh
#Copyright (C) 2015 Max Weller
#This program comes with ABSOLUTELY NO WARRANTY. This is free
#software, and you are welcome to redistribute it under certain
#conditions; see LICENSE for details of the BSD 2-Clause License
if [ $# -eq 0 -o "-h" = "$1" -o "-help" = "$1" -o "--help" = "$1" ]; then
cat <<EOHELP
Usage: $0 MANIFEST PUBKEY...
@luelista
luelista / view_hexfile.pl
Created December 28, 2010 17:10
prints IBM hex files in a formatted way
#!/bin/perl
# view_hexfile.pl
# prints IBM hex files in a formatted way
# Max Weller, http://max-weller.de
while(<>) {
if($_=~/^\s*:([A-F0-9]+)\s*$/) {
my @data = unpack("(A2)*", $1);
print $_," " for (@data);
print " | ";
@luelista
luelista / mag_quad03.pl
Created December 28, 2010 17:14
mag_quad03.pl
#!/bin/perl
# mag_quad03.pl
# Max Weller, http://max-weller.de
my $count = $ARGV[0];
if(!$count || $count < 1 || $count % 2 == 0) {
print "Usage: perl $0 count\n\n";
print "Please specify a positive odd integer for count\n\n";
exit(1);
}
@luelista
luelista / durchschnitt.pl
Created December 28, 2010 23:03
Punkte-Durchschnittsberechner
#!/bin/perl
# durchschnitt.pl
use strict;
print "Punkte-Durchschnittsberechner\n";
print '(c) Max Weller <test@max-weller.de>',"\n\n";
die "Bitte gib den Punktespiegel absteigend ein\n" unless ($#ARGV>0);