Skip to content

Instantly share code, notes, and snippets.

View dlundquist's full-sized avatar

Dustin Lundquist dlundquist

  • Tempered Networks
  • Seattle, WA
View GitHub Profile
# Returns a new hash applying the supplied transform to all values
class Hash
def copy_and_transform(&transform)
rv = self.class.new
self.each do |k,v|
case transform.arity
when 1
rv[k] = yield(v)
when 2
rv[k] = yield(k,v)
@dlundquist
dlundquist / shuffle.rb
Created July 8, 2010 22:43
Faro Shuffle
#!/usr/bin/ruby
MAX_ROUNDS = 50
# Splits the deck of cards into two equal parts
# in the case of an odd deck size, the extra card goes in the first part
def cut(cards)
b_size = cards.length / 2
a_size = cards.length - b_size
#!/usr/bin/perl
# Generates a random IPv6 address in the same subnet as the machine is currently in
# Written by Dustin Lundquist <dustin@null-ptr.net>
use strict;
use warnings;
sub getglobaladdress {
#!/usr/bin/perl
# $Id$
# This script enables IPv6 proxy arp for each address assigned to a container
# on this host. It also enables the nessacary sysctls for neighbor
# advertisments to be sent for container addresses.
#
# Written by Dustin Lundquist <dustin@null-ptr.net>
use warnings;
use strict;
@dlundquist
dlundquist / gist:1448796
Created December 8, 2011 21:54
DNS round robin in perl LWP
#!/usr/bin/perl
use strict;
use warnings;
use LWP;
use LWP::Protocol::http; # So we can manipulate EXTRA_SOCK_OPTS
use HTTP::Request::Common;
# LWP DNS round Robin
@dlundquist
dlundquist / .vimrc
Created September 21, 2012 14:56
vimrc
set ai " auto indenting
set history=100 " keep 100 lines of history
set ruler " show the cursor position
set et
set shiftwidth=4
set tabstop=4
set modeline
set spell
highlight constant ctermfg=lightblue
set background=dark
@dlundquist
dlundquist / .gitignore
Created October 3, 2012 03:08
Makefile for Latex assignments
*.aux
*.log
*.dvi
*.ps
*.pdf
@dlundquist
dlundquist / memory.c
Created October 22, 2012 18:23
Explaining different memory types
#include <string.h>
#include <stdio.h>
void print_maps();
char *foo = "This string is allocated in the string pool within the text segment which is read and execute only so it should be considered a const char *\n";
char bar[] = "This string is allocated in the initialized data section of the data segement\n";
char *baz;
int
#!/usr/bin/perl
use strict;
use warnings;
use LWP;
# $prerequisites->{course}->{requirement}
my $prerequisites = {};
my $ua = LWP::UserAgent->new();
@dlundquist
dlundquist / compilingsteps
Created January 25, 2013 03:55
Compiling steps
#Compiling step
gcc -std=c99 -Wall -Wextra -Wfatal-errors -pedantic-errors -O3 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L -c sni_proxy.c
gcc -std=c99 -Wall -Wextra -Wfatal-errors -pedantic-errors -O3 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L -c config.c
gcc -std=c99 -Wall -Wextra -Wfatal-errors -pedantic-errors -O3 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L -c cfg_parser.c
gcc -std=c99 -Wall -Wextra -Wfatal-errors -pedantic-errors -O3 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L -c cfg_tokenizer.c
gcc -std=c99 -Wall -Wextra -Wfatal-errors -pedantic-errors -O3 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L -c util.c
gcc -std=c99 -Wall -Wextra -Wfatal-errors -pedantic-errors -O3 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L -c server.c
gcc -std=c99 -Wall -Wextra -Wfatal-errors -pedantic-errors -O3 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L -c listener.c
gcc -std=c99 -Wall -Wextra -Wfatal-errors -pedantic-errors -O3 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L -c table.c
gcc -std