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.
November 12, 2009
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
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.
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
http://bitbucket.org/rallen/pyglet_trackball_camera [UPDATED LOCATION 2/14/2011]
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)
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
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]then follow the instructions. When the wii remote is connected, you will see lots of accelerator events.
./build/Release/wii2stdout
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.
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. ;^)
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. ;^)
December 03, 2005
Generation @
I saw the first reference to "Generation @" just now. Apparently, I'm a "Gen X"-er and my kids are part of "Generation @"--the 1st generation that will grow up online.
I wonder if this will stick. We'll just have to see...
I wonder if this will stick. We'll just have to see...
November 08, 2005
Wind Column
I wonder about random things. One of these things is wind power. I've never gotten past the idea that these 3-wing propeller-type generators seem to require a lot of engineering precision, complexity and cost to build. There has to be a simpler, better way. One way, it seemed to me would be to extend and stand the propeller up on its side, kind of like a silo with fins, instead of putting it on a big tower. Maybe this is a good idea, maybe not. At least, now, I can watch this company, TMA, to see if they succeed. I hope they do.
Opensource energy article.
Slashdot article
Opensource energy article.
Slashdot article
October 14, 2005
Mac DVD to iPod tutorial
Well isn't this a nicely done tutorial? I didn't even realize there was a GPL dvd ripper for the Mac and here's a tutorial on how to transcode a DVD to the new video ipod. AFAIK, this is completely legal and legitimate action when you own the DVD.
The programs used are:
Cheers.
osx
The programs used are:
- DVD extractor: MacTheRipper and
- VOB->MP4 transcoder: Handbrake
Cheers.
osx
October 08, 2005
tip: windows explorer view
I found this when I finally decided to bother to search for it. I wanted to always have the explorer folder view active in windows. As with most things Windows, it is something that makes little intuitive sense until it is explained. Gee, why couldn't this be part of the attributes that are saved with a normal "make these settings apply to all folders". Nah, that would make too much sense.
Open a folder,
Open a folder,
then go to View, Explorer Bar, Folders (or hold down Alt and type V,E,O) for short. To make it permanent, open My Computer and go to Tools, Folder Options, File Types and find the folder icon next to (none) and Folder. Click it, go to Advanced click Explore, then Set Default.
October 02, 2005
TGFG!
TGFG = Thank Goodness For Google.
Here is another reminder that no computer is truly "user friendly", not even the Mac.
My daughter couldn't login to the iMac anymore. The darn thing just hung up and didn't move. I'm lucky that I know how to
Plugging "MCXAppItems hang" into google found this hint, which worked for me.
TGFG!
Here is another reminder that no computer is truly "user friendly", not even the Mac.
My daughter couldn't login to the iMac anymore. The darn thing just hung up and didn't move. I'm lucky that I know how to
ssh
and ps -aux
from another computer so that I could see that it was hung up on this process: /System/Library/LoginPlugins/MCX.loginPlugin/Contents/MacOS/MCXAppItems -u My Applications
. Plugging "MCXAppItems hang" into google found this hint, which worked for me.
TGFG!
July 27, 2005
Violence, Sex & Video Games
The L.A. Times is running an editorial/open-letter to Hillary regarding the latest videogame probe. I recommend reading it.
I'm also quite amused that a little sex was what launched all this hoopla. I guess its okay for teenagers to simulate violence (the game features beat/rob/steal/kill/etc-ing), but for teenagers to simulate sex--that's over the line. I wonder what the arguments for/against this distinction would be...
Also, Take-Two predicted that they would need to take a write-off for all the returns & lost revenue they forsee. Anyone else think that maybe the direct opposite will happen?
I'm also quite amused that a little sex was what launched all this hoopla. I guess its okay for teenagers to simulate violence (the game features beat/rob/steal/kill/etc-ing), but for teenagers to simulate sex--that's over the line. I wonder what the arguments for/against this distinction would be...
Also, Take-Two predicted that they would need to take a write-off for all the returns & lost revenue they forsee. Anyone else think that maybe the direct opposite will happen?
July 12, 2005
Long Now
I rediscovered the Long Now website today and was really taken by the ideas that Brian Eno brings up in his Nov 02003 talk here (pdf) on the seminars page.
I'm struck by a couple thoughts so far:
1) the kind of "short now" thinking he attributes to the 1970s is alive and well in Silicon Valley. It might be a global epidemic.
2) I really should look at the book "The Evolution of Cooperation", by Robert Axelrod. The WWI example Eno relates about how generals had to rotate troops throught the frontlines to keep them from cooperating with the enemy made me think of how "big media" helps keep divisions like "the red states" and "the blue states" alive. Cooperation doesn't make for nearly as interesting TV. [See previous post.]
3) I really enjoyed his background on his ambient music. "Music for Airports" is one of Wendy & my all-time favorites.
A good lunchtime read.
I'm struck by a couple thoughts so far:
1) the kind of "short now" thinking he attributes to the 1970s is alive and well in Silicon Valley. It might be a global epidemic.
2) I really should look at the book "The Evolution of Cooperation", by Robert Axelrod. The WWI example Eno relates about how generals had to rotate troops throught the frontlines to keep them from cooperating with the enemy made me think of how "big media" helps keep divisions like "the red states" and "the blue states" alive. Cooperation doesn't make for nearly as interesting TV. [See previous post.]
3) I really enjoyed his background on his ambient music. "Music for Airports" is one of Wendy & my all-time favorites.
A good lunchtime read.
June 28, 2005
Google Earth
This software is now free for download. An EXCELLENT use of 3d graphics for something other than shooting people.
I'm a customer, I know people who work on the software and I recommend it highly.
I'm a customer, I know people who work on the software and I recommend it highly.
May 02, 2005
Pacific Coast Trail Hiker
My friend/co-worker Scott Heeschen is hiking the Pacific Coast Trail for the next 6 months. I thought I'd post this here to keep a link to his journal.
http://www.trailjournals.com/scoot2005
I'm all jealous. This sounds like an amazing and fun journey.
http://www.trailjournals.com/scoot2005
I'm all jealous. This sounds like an amazing and fun journey.
April 26, 2005
bugmenot
From Dan Gilmor's Blog. A site that gathers login/passwords for annoying sites on the web that force you to login, even when there is no charge. You tell it the site you want, it gives you the login.
Read the tutorial here.
Read the tutorial here.
April 11, 2005
gigapxl
Just heard about a company/project by a former co-worker Michael T. Jones--The Gigapxl project. An amazing camera & project built with (apparently) U2 Spy Plane cameras that take 4 gigapixel images. Woah.
March 03, 2005
Surreal Google...
So today I got in touch with someone I hadn't talked with for years. Googled her name, found a .Mac account, sent email and sure enough, that was her. During our email conversation she mentioned another name (Mac MacDougal) and I decided to google him, too. Well, apparently Mac worked at Amdahl in the early 80s (I worked there after meeting Mac at Apple) and this article mentions him: http://www.chipdesignmag.com/edanation/august2004/ [Seach for John Sanguinetti - A Profile it's a ways down the page]
Reading the article was interesting for me. It talks about places I've worked like Amdahl, Apple & NVIDIA. I remember being one of those engineers that knew that verilog would kill off VHDL. He's bringing up names & events that were all happening around me.
What a surreal google that was...
Reading the article was interesting for me. It talks about places I've worked like Amdahl, Apple & NVIDIA. I remember being one of those engineers that knew that verilog would kill off VHDL. He's bringing up names & events that were all happening around me.
What a surreal google that was...
March 01, 2005
Mac Home/End Keys
Reading slashdot today, I ran across this cool tweak for OS X and I'm really looking forward to trying it out. One bit of windows that I actually like is the way the Home & End keys work. But, on the Mac, the keys normally just do nothing--quite irritating. Hopefully, this gets things working...
/* put this in ~/Library/KeyBindings/DefaultKeyBinding.dict */
/* Home/End keys more like Windows */
{
"\UF729" = "moveToBeginningOfLine:";/* home */
"\UF72B" = "moveToEndOfLine:";/* end */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:";/* shift + home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:";/* shift + end */
"^\UF729" = "moveToBeginningOfDocument:";/* control + home */
"^\UF72B" = "moveToEndOfDocument:";/* control + end */
}
Subscribe to:
Posts (Atom)