Skip navigation

Author Archives: jkrez

I'm a student who's graduated with a degree in computer science at the University of Michigan.




Version control systems are important, and Git is one of the nicest one’s out there.  If you’re new to version control systems (VCS), or have mainly worked on small projects in the past, then it might not seem worth it to use one. However, once you start working on larger projects or need to collaborate with others, VCS’s become very important. Here’s a good explanation of Git and how it works that I wish I had found when I learned:

As Isaiah and I were hiking the Appalachian Trial this past July 4th weekend, he told me he had a fun riddle. Liking the logical nature of riddles and the thought process to solve them, I excitedly encouraged him to continue. The riddle is as follows:

There is a town with a small number (~200 but not really important) of married couples. Everyone in this town takes cheating very seriously. Once a woman cheats on her husband, everyone in the town will know except the husband. However, the day a husband catches his wife cheating he will kill her. One day, the Mayor of this town announces, “Some number of people in this town are cheating.” Note we do not know how many people are cheating, we only know that cheating is occurring. After this announcement no cheating occurs.

Seven day’s later, seven husbands kill their wives. Why did this happen?

Two hints and the answer are below spaced out by images [My photos from the Chattahoochee section of the Appalachian Trail in northern Georgia]:

Hint1: Think about the rules of the system. If cheating occurs, everyone in the town will know except the person who is being cheated on. What information does the Mayor give away? Also, It doesn’t matter if cheating or not occurs after the announcement, as long as no new cheating occurs.

Hint2: Review what happens after one day passes. The significance of the sentence “the day a husband catches his wife cheating he will kill her.” It might help to consider the other possible case of this riddle where if only one person is cheating. Then consider another case where two people are cheating: if the Mayor were to announce the cheating, and then two days later two husbands killed their wives. What happens after the first day that allows the husbands to know that their wives are cheating?

Answer: First let’s start with a single wife cheating with another husband. Say Alice cheats on Alan. If a Alice were to cheat, then upon hearing this announcement Alan would not know of any cheating going on and would be forced to kill her since he hasn’t heard of any cheating.

If we consider the case the second hint makes where if after two days two husbands kill their wives, then we can see what is learned after the first day. Consider two couples, Alice and Alan, and Bree and Bob. Say that Alice and Bree are both cheating on their husbands. If the Mayor announces the cheating, then both of their husbands will have knowledge of someone else cheating and not kill their wives after the first day. Then once this day passes, they will each realize that since no wife was killed like in the case above with one wife cheating, then there must be at least two people cheating. But they each only know of one person cheating, so the other must be their wives.

This process can be repeated up to seven days.  So the general form of this riddle would be told having N days pass and N wives killed. Pretty Sweet!
Related Riddle Links:

When I got my new T410s a couple of months ago, the first thing I did was pop in a live cd of 10.10 and check out the hardware support. I found that the Lenovo’s red pointing stick scrolling nor the two finger trackpad scrolling worked with a fresh version of Ubuntu. I relied on these navigational controls, so I set out to remedy this situation.

To fix the red pointing stick + middle button scrolling do the following:

create file /usr/share/X11/xorg.conf.d/20-thinkpad.conf and add:

Section "InputClass"
Identifier "Trackpoint Wheel Emulation"
MatchProduct "TrackPoint"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
Option "EmulateWheel" "true"
Option "EmulateWheelButton" "2"
Option "Emulate3Buttons" "false"
Option "XAxisMapping" "6 7"
Option "YAxisMapping" "4 5"

Restart X session
$>sudo service gdm restart

Now you should have middle button + trackpoint scrolling. Let’s get two finger scrolling back too:

Now /usr/share/X11/xorg.conf.d/20-thinkpad.conf looks like:

Section "InputClass"
Identifier "Trackpoint Wheel Emulation"
MatchProduct "TrackPoint"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
Option "EmulateWheel" "true"
Option "EmulateWheelButton" "2"
Option "Emulate3Buttons" "false"
Option "XAxisMapping" "6 7"
Option "YAxisMapping" "4 5"

Now append to it:

Section "InputClass"
Identifier "touchpad catchall"
MatchProduct "SynPS/2 Synaptics TouchPad"
MatchDevicePath "/dev/input/event*"
Option "VertTwoFingerScroll" "on"
Option "EmulateTwoFingerMinW" "8"
Option "EmulateTwoFingerMinZ" "40"

Save and close it. Now open a terminal (ctrl+alt+t) and type:

Now change desktop->gnome->peripherals->touchpad->scroll_method to 2.

Restart Gdm. Now you should have two finger scrolling and trackpoint scrolling.

Trackpoint info
Two-finger Scrooling method 1 (didn’t work for me)
Watch dmesg
Two-finger scrolling

The command:

Prints out the driver message buffer in Linux. If you want to catch device events (eg. when inserting new hardware like a usb stick), dmesg is one way to print out these events. To watch them in real-time, use the watch command:

watch "dmesg | tail -20"

Step 1: Tethering

Running Android? Install azilink
Something else? Find a way to tether…

Make note of the device you’re using to connect (e.g. azilink –> tun0, “real tethering” –> usb0, etc)

Step 2: Ad-Hoc Network

— Server side (the tethered device) —

# Set up ad-hoc network:
iwconfig wlan0 mode ad-hoc
iwconfig wlan0 essid Jkrez # <-- network name here
ifconfig wlan0

# Some quick permissions…
echo 1 > /proc/sys/net/ipv4/ip_forward
vi /etc/sysctl.conf
net.ipv4.ip_forward = 1

# Make me a router! (note -o “output” device, -i “input” device)
iptables -A FORWARD -o tun0 -i wlan0 -s -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -j MASQUERADE

— DHCP Server —

Don’t want to manually configure clients? Time for a little dhcp3d server action:

sudo apt-get install dhcp3-server

edit /etc/default/dhcpd3-server

INTERFACES="tun0" #<-- same interface name as above

edit /etc/dhcpd3/dhcpd.conf
Add/change the following:


option domain-name “Jkrez”; #essid from before
option domain-name-servers #Google dns, or your favorite dns

subnet netmask {
option routers;
option subnet-mask
option time-offset -18000; #Eastern timezone

Then run:
sudo /etc/init.d/dhcpd3-server

Now clients should be able to auto connect. Enjoy!

— Don’t want to mess with a dhcp server? —

Set up a client (GUI edition!)

In NetworkManager try to connect to Jkrez (this will fail since no dhcp)
Right Click and “edit connections”, in Wireless tab select Jkrez and “Edit”
Go to IPv4 Settings and enter:
IP # Unique IP for each client

DNS # Or your favorite nameserver

These steps can also be done via CLI; setup ad-hoc wifi same way using iwconfig, ip/mask/gateway via ifconfig, and dns vi /etc/resolv.conf


Thanks to my friend Pat, and the following linux links for tips along the way:

Today I got tired of Rhythmbox and decided to do some investigation of the music players for ubuntu. Two of them popped out after reading some inital reviews: Songbird and Guayadeque. Both music players have some really cool features and they both use audio scrobbling through Here’s a quick rundown:


Songbird has a very nice iTunes like appearance but in a dark theme. So if you’re a fan of darker colors this player is for you. There are some very cool features in song bird such as the 7digital store, which gives you very easy access to buy music. It is also fairly customizable options menu with a very clean interface and supports tabs in the library display area. However, it’s not officially supported but you can still download the source code here. On some distributions it takes some additional setup and configuration. The code downloaded comes with some internal libraries (in the “libs” folder) which Songbird uses to decode various audio files types instead of using codec’s already installed on your system. I followed this link to fix these problems.

Note, the page above says to use the command
sh -c "export SB_GST_NO_SYSTEM=1 ; exec /usr/bin/songbird"

but the one that ended up working for me was:
sh -c "export SB_GST_SYSTEM=1 ; exec /usr/bin/songbird"


This player is very cool and has just about the same amount of customizability as Songbird, but also lets you completely customize the layout of the GUI. You can drag and drop the library, song queue, player controls, lyrics, etc.  Then once you’ve created a layout you like you can save it and create others. This is really cool IMO, but what really makes this player standout from any other I’ve used so far is the Smart Playlist. Once you choose a song, or search for an artists in your library, it will automatically use’s Audioscrobbler based music recommendation system to add and then play 3 (the default number) songs to your “current” song queue.  Once you’ve listed to all of these and reach the end, it will grab three more songs, all using what you have in your library and your listening preferences.  You can always remove songs, queue up new songs, delete songs it picks, or rearrange the order!  This is a feature you grow to love and will miss when trying to use other music players. Get Guayadeque here!

Other good overviews on the two players here:


This: ‘^(.(?<!(text i don't want)))*$' seems to work for me.

I’ve had networking issues on and off. The severity ranges from having my network manager disabled or having it drop out an be unable to connect randomly. I have a Dell XPS M1330, running Ubuntu 10.04.1 LTS with networking card:
Intel Corporation PRO/Wireless 4965 AG or AGN [Kedron] Network Connection (rev 61).

These are the things I have checked and or run when I’ve had networking issues and one of them has usually resolved the problem:

When your wired/wireless networking manager says it’s disabled:
The file “/var/lib/NetworkManager/NetworkManager.state” contains:


(make sure all these values are true)

you can edit it with simply:

sudo gedit /var/lib/NetworkManager/NetworkManager.state

then do:

sudo restart network-manager

Also check /etc/network/interfaces to verify an entry similar to:

auto eth1
iface eth1 inet dhcp

Sometimes this gets deleted.
I’ve even deleted this entire file, and restarted my computer and the networking issued fixed itself.

If the above steps aren’t working or your card has been dropping connections randomly it may be another issue with your driver or driver packages. If you know that restarting your computer will make it work for a little while longer then the fixes suggested below should help you out:

Use lspci to find your “Network Controller”

$ lspci
00:00.0 Host bridge: Intel Corporation Mobile PM965/GM965/GL960 Memory Controller Hub (rev 0c)
00:02.0 VGA compatible controller: Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller (rev 0c)
00:02.1 Display controller: Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller (rev 0c)
00:1a.0 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #4 (rev 02)
00:1a.1 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #5 (rev 02)
00:1a.7 USB Controller: Intel Corporation 82801H (ICH8 Family) USB2 EHCI Controller #2 (rev 02)
00:1b.0 Audio device: Intel Corporation 82801H (ICH8 Family) HD Audio Controller (rev 02)
00:1c.0 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 1 (rev 02)
00:1c.1 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 2 (rev 02)
00:1c.3 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 4 (rev 02)
00:1c.5 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 6 (rev 02)
00:1d.0 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #1 (rev 02)
00:1d.1 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #2 (rev 02)
00:1d.2 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #3 (rev 02)
00:1d.7 USB Controller: Intel Corporation 82801H (ICH8 Family) USB2 EHCI Controller #1 (rev 02)
00:1e.0 PCI bridge: Intel Corporation 82801 Mobile PCI Bridge (rev f2)
00:1f.0 ISA bridge: Intel Corporation 82801HEM (ICH8M) LPC Interface Controller (rev 02)
00:1f.1 IDE interface: Intel Corporation 82801HBM/HEM (ICH8M/ICH8M-E) IDE Controller (rev 02)
00:1f.2 SATA controller: Intel Corporation 82801HBM/HEM (ICH8M/ICH8M-E) SATA AHCI Controller (rev 02)
00:1f.3 SMBus: Intel Corporation 82801H (ICH8 Family) SMBus Controller (rev 02)
03:01.0 FireWire (IEEE 1394): Ricoh Co Ltd R5C832 IEEE 1394 Controller (rev 05)
03:01.1 SD Host controller: Ricoh Co Ltd R5C822 SD/SDIO/MMC/MS/MSPro Host Adapter (rev 22)
03:01.2 System peripheral: Ricoh Co Ltd R5C592 Memory Stick Bus Host Adapter (rev 12)
03:01.3 System peripheral: Ricoh Co Ltd xD-Picture Card Controller (rev 12)
09:00.0 Ethernet controller: Broadcom Corporation NetLink BCM5906M Fast Ethernet PCI Express (rev 02)
0c:00.0 Network controller: Intel Corporation PRO/Wireless 4965 AG or AGN [Kedron] Network Connection (rev 61)

and lsmod to find what drivers your network card uses (or you can google them if your internet is working):

$ lsmod
Module Size Used by
nls_iso8859_1 3249 2
nls_cp437 4919 2
vfat 8933 2
fat 47767 1 vfat
usb_storage 39425 2
iwl3945 68727 0
iwlagn 105694 0
iwlcore 105922 2 iwl3945,iwlagn
aes_i586 7268 2
aes_generic 26863 1 aes_i586
snd_hda_codec_intelhdmi 11622 1
snd_hda_codec_idt 51978 1
snd_hda_intel 21941 4
arc4 1153 2
snd_hda_codec 74201 3 snd_hda_codec_intelhdmi,snd_hda_codec_idt,snd_hda_intel
snd_hwdep 5412 1 snd_hda_codec
max6650 8042 0
snd_pcm_oss 35308 0
snd_mixer_oss 13746 1 snd_pcm_oss
psmouse 63245 0
snd_pcm 70662 4 snd_hda_intel,snd_hda_codec,snd_pcm_oss
coretemp 4289 0
snd_seq_dummy 1338 0
mac80211 205146 3 iwl3945,iwlagn,iwlcore
snd_seq_oss 26726 0
cfg80211 126517 4 iwl3945,iwlagn,iwlcore,mac80211
snd_seq_midi 4557 0
sdhci_pci 5470 0
sdhci 15462 1 sdhci_pci
snd_rawmidi 19056 1 snd_seq_midi
snd_seq_midi_event 6003 2 snd_seq_oss,snd_seq_midi
dell_wmi 1793 0
snd_seq 47263 6 snd_seq_dummy,snd_seq_oss,snd_seq_midi,snd_seq_midi_event
dell_laptop 6856 0
uvcvideo 56990 0
snd_timer 19098 2 snd_pcm,snd_seq
snd_seq_device 5700 5 snd_seq_dummy,snd_seq_oss,snd_seq_midi,snd_rawmidi,snd_seq
videodev 34361 1 uvcvideo
v4l1_compat 13251 2 uvcvideo,videodev
serio_raw 3978 0
snd 54148 20 snd_hda_codec_intelhdmi,snd_hda_codec_idt,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_seq_oss,snd_rawmidi,snd_seq,snd_timer,snd_seq_device
led_class 2864 3 iwl3945,iwlcore,sdhci
soundcore 6620 1 snd
snd_page_alloc 7076 2 snd_hda_intel,snd_pcm
joydev 8708 0
dcdbas 5422 1 dell_laptop
lp 7028 0
parport 32635 1 lp
fbcon 35102 71
tileblit 2031 1 fbcon
font 7557 1 fbcon
bitblit 4707 1 fbcon
softcursor 1189 1 bitblit
vga16fb 11385 0
vgastate 8961 1 vga16fb
usbhid 36110 0
hid 67032 1 usbhid
i915 285076 3
drm_kms_helper 29297 1 i915
drm 162409 4 i915,drm_kms_helper
ohci1394 26950 0
intel_agp 24119 2 i915
tg3 109324 0
ieee1394 81181 1 ohci1394
ahci 32200 1
i2c_algo_bit 5028 1 i915
video 17375 1 i915
output 1871 1 video
agpgart 31724 2 drm,intel_agp

Use either the Internet while it is working to find the main driver module for your network card or a driver name (or names) that looks like your cards name and do the following commands to stop and restart your driver:
(In my case my driver is iwlagn)

sudo service network-manager stop
sudo rmmod iwlgan
sudo rmmod iwl3945
sudo rmmod iwlcore
sudo modprobe iwlgan
sudo modprobe iwl3945
sudo modprobe iwlcore
sudo service network-manager start

Basically, rmmod pulls your dymanically linked driver and stops it and modprobe restarts it.

Sometimes that still doesn’t work. I found a bug fix posted by Brian Wu in this thread that fixed my problems recently. The method is outlined below:

$ sudo apt-get install --reinstall linux-backports-modules-wireless-lucid-generic
$ sudo apt-get install --reinstall linux-backports-modules-headers-lucid-generic

I did both, I wasn’t sure which would work. Note: replace ‘lucid’ with whatever distro/version of linux/ubuntu you are running, jaunty, karmic, gusty…etc.

If all else fails, try using live cds of various versions to verify that it isn’t a hardware failure.

Cool Commands:

Show the current date and time date
Show this month’s calendar cal
How much time did I spend at the computer uptime
Who are you? whoami
How much free RAM do I have? free
Where is that application I just installed whereis [app]
Disk space usage df -h

To shutdown:
sudo shutdown [-h] now

or restart:
sudo shutdown [-r] now


Python loggers are a good mechanism for printing to console or a log file when running any python file or especially useful when logging information from a server. Some of the useful things you can do are, logging to console and files at the same time, logging from different python packages, set logging filters to include timestamps and/or logging levels and/or handler information, and logging at different message levels weather an error is debug, information, a warning, an error, or critical level.

To create a logger:

import logging
LOG_FILENAME = 'mylog.log'
logging.debug('This message should go to the log file') #This is how to would print using the logger

or you can create a logger using:

LOG_FILENAME = 'mylog.log'

#Creating a logger
my_logger = logging.getLogger('MyLogger')

#Create handler - in this case a file handler
handler = logging.FileHandler(
LOG_FILENAME, mode='a')

#Set the format you want to log in
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')

#add format to the logging handler

#add logging handler to logger

Note the mode=’a’ line means that this logging handler is going to append to the file. The mode ‘w’ means it will create a new file each time.

To add a console logger to our previous example so that we can see output on the console we would add the following code:

# create console handler and set level to debug
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG) #sets default default level to debug

# create formatter -- this is format only prints the level of the debug message
formatter = logging.Formatter("%(levelname)s - %(message)s")

# add formatter to console_handler

# add console_handler to logger

Now we have a console logger. Whenever we call:

my_logger.debug("this is a debug level message")

This will be printed to the console, and the log file at the debug level, each in different formats. Note that in this example, we changed the format from the original File Handler so that it only prints the logging level to the console handler.

This example from shows the debug level:

import logging
import logging.config


# create logger
logger = logging.getLogger("simpleExample")

# "application" code
logger.debug("debug message")"info message")
logger.warn("warn message")
logger.error("error message")
logger.critical("critical message")

And this one is how to handle each logging in each package:

import logging


logger1 = logging.getLogger('package1.module1')
logger2 = logging.getLogger('package2.module2')

logger1.warning('This message comes from one module')
logger2.warning('And this message comes from another module')