February 14, 2011

Dirty, rotten scoundrels?

I don't normally like to write about politics because it often just leads to pointless and endless arguments. But, this idea has been rolling around in my head for a while and I wanted to check into it.

Basically, I've noticed the number of Republicans caught being hypocritical to their "family values" message and being forced to resign. I'll admit to being a bit biased and enjoying the
schadenfreude of the situation, so I wanted to look back at the historical data and see if it was just my biased view clouding my recollection.

So, I went to the cloud (cue music)... I found a source of resignations here http://www.rollcall.com/politics/casualtylist.html and then went to Wikipedia for the reasons that people resigned. Often I had to do a bit more googling when the reasons were not clear,
but hopefully I've captured the primary reasons in the spreadsheet I'm now publishing here:

http://spreadsheets.google.com/ccc?key=0AmVaLTr0TuSEdG4tRkstQWE1VW94dlFzQkU4Vk85b1E

So far, I've only gone back to the 101st Congress (1989-1990). Over time, I may add more data. If you want to help, just format the data as I have in this spreadsheet and send it on.

On the Summary tab, you'll find a rollup of the information. Here
are the things I found interesting:
  • Since 1989, exactly the same number, 9, Republican and Democratic congressmen have resigned for what I am calling "dishonorable" reasons.
  • The majority (5 or 56%) of Republican dishonorable resignations were due to sexual activity or allegations.
  • The majority (6 or 67%) of Democratic dishonorable resignations were money-related.
So, my recollection of Republicans being "caught with their pants down" was apparently a reasonable one. But, the Democrats are apparently just as dirty, but for greed rather than lust.

I suppose another cynical way to look at this is that both parties are sprinkled with dirty, rotten scoundrels. Its just that the Republicans are better at hiding bribery and graft, and Democrats are better at not getting caught cheating on their wives.

November 12, 2009

Disproving Dudeney's Dissection

I've written a document describing how the "Haberdasher Puzzle" was only apparently solved by "Dudeney's Dissection". This is a puzzle from 1902 where you are asked to transform an equilateral triangle into a perfect square.

EDIT: Ah, I finally figured out my mistake. Now I can see where I went wrong. I'll edit my document & republish soon.

See http://blog.makezine.com/archive/2009/09/dudeneys_dissection.html for the link that started me down this path. Googling the above quoted terms also turns up many interesting links.


July 02, 2009

Python Skeleton Code: base.py

I have a snippet of code I use whenever I start a new python commandline tool. Today, I read a post that added the use of the logging module to their skeleton code. I didn't realize how simple that module was. For some reason, I got bamboozled into thinking it was more complicated by earlier examples. So, I really appreciated that post. Then I thought I should put my skeleton out there for others to use if they want. My tiny addition is to add a configuration file. Optionally, you can create a config file based on the ConfigParser module to store default values for your tool in case you end up needing lots of commandline options. I'm sure this will continue to evolve, but here it is as of today.
#!/usr/bin/env python                                                                             
"""
base.py - a skeleton starting-point for python scripts by Roger Allen.
"""
import os
import sys
import logging
import ConfigParser
from optparse import OptionParser

# ======================================================================
# XXX extend this run function XXX
def run(options, args):
"""options is a dictionary of your commandline options, args is a list of the remaining commandline arguments
"""
# -v to see info messages
logging.info("Options: %s, Args: %s" % (options, args))
# -v -v to see debug messages
logging.debug("Debug Message")
# we'll always see these
logging.warn("Warning Message")
logging.error("Error Message")
print "Hello, World"
return 0

# ======================================================================
# XXX add your commandline arguments XXX
def parse_args(argv):
"""parse commandline arguments, but use config files to override
default values specified in the add_option calls
"""
config = Config()
parser = OptionParser()
parser.add_option("-v","--verbose",
action="store_true",dest="verbose",action='count',
default=config.get("options","verbose",0), # config file has verbosity level
help="Increase verbosity (specify multiple times for more)")
# XXX add more options here XXX
(options, args) = parser.parse_args(argv)
# adjust logging level based on verbosity flag
log_level = logging.WARNING # default
if options.verbose == 1:
log_level = logging.INFO
elif options.verbose >= 2:
log_level = logging.DEBUG
logging.basicConfig(level=log_level)
return (options, args)

# ======================================================================
# Should not have to edit below this line
class Config():
"""Read the <program_name>.cfg or ~/.<program_name>.cfg file for configuration options.
Handles booleans, integers and strings
"""
def __init__(self):
self.config = ConfigParser.ConfigParser()
program_name = os.path.basename(sys.argv[0].replace('.py',''))
self.config.read([program_name+'.cfg', os.path.expanduser('~/.'+program_name+'.cfg')])
def get(self,section,name,default):
"""in the config file, try to find the 'name' in the proper 'section'.
if not found, return the passed default value."""
try:
if type(default) == type(bool()):
return self.config.getboolean(section,name)
elif type(default) == type(int()):
return self.config.getint(section,name)
else:
return self.config.get(section,name)
except:
return default

def main(argv):
"""The main routine, taking in a commandline argv string sans the program name.
"""
options, args = parse_args(argv)
return run(options, args)

if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))

June 16, 2009

ramu

Just a link to my python code for playing around with music.

http://ramu.googlecode.com/

I thought that perhaps doing my (very slow) development in public might encourage me to keep at it. It's only barely usable, but it is a start.

Why do I do this instead of using another library?

http://www.graficaobscura.com/future/futman.html

July 29, 2008

A Trackball Camera for Pyglet

A week or so ago, I needed to write a simple OpenGL demonstration program. I decided to use pyglet since it is such a great utility. Of course, it is always nice to be able to move around your demo, so I looked for a "trackball" to control the camera. But, I came up empty.

So, to scratch that itch, I remembered & found the old GLUT example code in trackball.c and ported it to python. It wasn't that hard to do, but looking at how the code worked it brought back that in 1993 every cycle certainly counted. I refactored it significantly.

I also pushed the manipulation of the GL_MODELVIEW matrix into this class. It seemed a nice way to separate the code and make it into a proper camera. Anyway, a short while later and out popped my code and you can get it by going to


To use it, there are just a few public entrypoints.

Initialize the camera with a radius from the center/focus point:

tbcam = TrackballCamera(5.0)

After adjusting your projection matrix, set the modelview matrix.

tbcam.update_modelview()

On each primary mouse click, scale the x & y to [-1,1] and call:

tbcam.mouse_roll(x,y,False) # the final flag indicates this is a 'click' not a 'drag'

On each primary mouse drag:

tbcam.mouse_roll(x,y)

Mouse movements adjust the modelview projection matrix directly.

There is also a routine for mouse_zoom(x,y)

I hope you can find this useful.

May 25, 2008

wii2stdout

I few months ago, I wrote a simple commandline utility demonstrating how to use the WiiRemote Framework to connect to the Wii controller and capture events. Inspired and enabled by the darwiin-remote project. I just wanted something simpler to use as a starting point for my own projects.

This code is written using (and includes) the svn repository WiiRemote Framework 0.6 code.

Output is sent to stdout for all wii remote messages. Output to stderr for all other "informative" messages. This allows for easy use of unix pipes.

How to:

Build using xcode. Open a Terminal, type (without quotes)
  cd [where you put wii2stdout]
./build/Release/wii2stdout
then follow the instructions. When the wii remote is connected, you will see lots of accelerator events.

Press the "home" button to exit wii2stdout cleanly.

If you use it, drop me a line & let me know. Grab the code here: http://www.rogerandwendy.com/roger/code/wii2stdout-2008.05.25.tar.gz

Music/Midi & Mac Update

A comment on my earlier post reminded me that I should publish my latest Midi code.

I've updated my code a bit in the (gasp) 3 1/2 years since I posted that original code. In the meantime, I've taken to using a client/server model. It turns out that GarageBand doesn't seem to take kindly to a midi connection appearing and disappearing often. So, the server is started once per session and keeps the midi connection alive. The client connects over a socket to the server and translates from text input to a simple protocol. The client can appear & disappear without affecting GarageBand.

As a disclaimer, this is not my prettiest code--it basically works but is not all that robust. Get the code at http://rogerandwendy.com/roger/mac/mtl-2008.05.24.tar.gz

If you use it for anything, drop me a line or a comment to let me know.

January 24, 2006

Third Chimpanzee Species = Us?

Follow the link to some interesting research that seems to show that chimpanzees are more closely related to homo sapiens than other apes. Sienna & I were just chatting about this the other day & I didn't know the answer--apparently no-one did until now. :^)

The article also mentions that an earlier report had put us in the same genus as the chimpanzee and the bonobo. I think that's kind of a cool way to look at things...one is a war-crazy species, one is a sex-crazy species and then there's us--we got both kinds of crazies. ;^)