Skip to content

Instantly share code, notes, and snippets.

@starzia
starzia / netid_lookup.py
Last active September 10, 2020 16:29
Northwestern netid lookup script using LDAP
# reads netids from stdin and prints email addresses to stdout
# see http://ldap3.readthedocs.io/tutorial_searches.html
# and https://www.it.northwestern.edu/bin/docs/CentralAuthenticationServicesThroughLDAP.pdf
#
# prereq: pip install ldap3
# usage: echo abc2020@u.northwestern.edu | python netid_lookup.py
from ldap3 import Server, Connection, ALL, ALL_ATTRIBUTES
import sys
@starzia
starzia / test_project3.c
Last active May 13, 2019 19:41
A xv6 program that makes threads and then exits without cleaning them up.
#include "types.h"
#include "stat.h"
#include "user.h"
void run(void* id) {
printf(1, "hello\n");
volatile int i;
for(i=0; i<100000000; i++);
printf(1, "Child %d done\n", *(int*)id);
}
@starzia
starzia / parallel_swap.c
Created May 7, 2019 16:50
A buggy parallel swap program
#include <stdio.h>
#include <pthread.h>
static volatile char* person1;
static volatile char* person2;
static const int LOOPS = 1e4;
void* mythread(void* arg) {
printf("%s: begin\n", (char*)arg);
int i;
@starzia
starzia / parallel_count.c
Created May 6, 2019 21:32
A simple concurrency bug demo
#include <stdio.h>
#include <pthread.h>
static volatile int counter = 0;
static const int LOOPS = 1e7;
void* mythread(void* arg) {
printf("%s: begin\n", (char*)arg);
int i;
for (i=0; i<LOOPS; i++) {
@starzia
starzia / tcp_dns_client.py
Last active November 2, 2018 20:41
TCP DNS server test case
# Sends a TCP DNS request in two packets.
# First sends the message size, then sends the message.
# This behavior is similar to that of the Windows nslookup command.
import socket, binascii, sys, struct
def main(dns_server):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# disable Nagle's algorithm, to allow request to be sent in two pieces.
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
s.connect((dns_server, 53))
@starzia
starzia / convert_ogg_to_mp3.sh
Created April 11, 2012 02:19
convert ogg files to mp3 on mac for iTunes
#!/bin/bash
# Converts all ogg files in the current path to mp3 files.
# This is useful for moving a music libary to iTunes, which doesn't support ogg
find .|grep 'ogg$' > /tmp/ogg_files.txt
while read line; do
basepath=$(echo $line | sed 's/.ogg$//g')
echo $basepath
# get as much id3 tag information as possible from the path
trackAndSong=$(basename "$basepath")
@starzia
starzia / parallel_proc.sh
Created January 27, 2012 20:03
runs a queue of shell commands in parallel
#!/bin/bash
# Parallelization functions
# Maximum number of processes to run in parallel.
# A good value for this is one fewer than the number of cores available
NP=14
# wait until fewer jobs are running than number of processors
function queue {
@starzia
starzia / seq.sh
Created January 27, 2012 19:50
A bash implementation of the GNU seq command found on most unix systems. This is useful on AIX (which seems to lack seq)
#!/bin/bash
# Implements GNU seq functionality.
# Useful on IBM AIX systems which don't have GNU coreutils.
if [ -z "$3" ]; then
# if no third arg
incr=1
j=$2
else
incr=$2