I will be in Portland, Oregon from Thursday, April 29 through Sunday, May 2 at UPS.
Monthly Archives: April 2010
My PC
I built a computer sometime in 2006 and then subsequently upgraded several times along the way. Here are the specifications:
- AMD Athlon 64 X2 Dual Core Processor 3800+ 2.01 Ghz
- ASUS A8N-SLI Deluxe 939 NVIDIA nForce4 SLI Motherboard
- CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM DDR 400 (PC 3200) TWINX2048-3200C2
- Western Digital Caviar SE16 WD3200KS 320GB 7200 RPM
- EVGA 256-P2-N363-TX GeForce 6600LE 256MB 128-bit DDR PCI Express x16 SLI
It’s been four years since then, and the machine still performs well and I can run all of the latest software that I use on a daily basis without difficulty.
Python Input/Output Idioms
Unlike the C programming language, Python assignments are statements, not expressions. Therefore the common C idiom of:
while (line = fgets(f)) {
/* do something with the line */
}
is not possible to implement directly.
However, effbot.org provides several alternatives using iterators or the while True idiom. I recently discovered the built-in iter() function as well:
for line in iter(f.readline, "END"):
... do something with line ...
Popcount in Python
While working a problem from the Waterloo Programming Contents, I found that the sample solution used the GCC internal function used the GCC internal function __builtin_popcount(unsigned int x).
This function returns the number of 1-bits in x, and we can emulate a similar operation in Python 2.6 (PEP 3127) or above using the quick and dirty snippet:
bin(x).count('1')
Command-Line Arguments in IDLE
Sometimes you want to be able to run a script through the interactive Python Shell that comes with IDLE, but using a different text editor (such as UltraEdit). In this case, you want to run IDLE from another program. To do so:
idle.py -r scriptname.py
or
idle.pyw -r scriptname.py
Strangely, the -r command-line argument doesn’t appear to be in the Python documentation for IDLE at all.
Note: The idle.py script is typically located at C:\Python31\Lib\idlelib, or very close to it.
Some other notes on specific to UltraEdit:
- An example Command Line is:
C:\Python31\Lib\idlelib\idle.pyw -r "%f". - For Program Type, set to Dos Program, not Windows Program.
- Do not capture any Command Output.
NetBeans 6.8 and Python 3 Unit Tests
It looks like the NetBeans IDE is unable to do unit tests if you are developing your code using a Python 3 interpreter. You’ll hit the following wall when trying to run a test:
File "C:\Program Files\NetBeans 6.8\python\
\nb_test_runner.py", line 216
except ValueError, e:
^
SyntaxError: invalid syntax
Finished in 0.0 seconds.
0 tests, 0 failures, 0 errors
Perhaps NetBeans 7.0 will address this issue.
MySQL Manually Remove Service Instance
How do you manually remove a MySQL Server Instance? I have MySQL Server 7.0 listed as one of the server instances when running the MySQL Server Instance Configuration Wizard.
HP C3180 and Envelope Printing
I have a standard Size 10 envelope (4 1/8 x 9 1/2 in). I can’t get it to work, and the text on the envelope always appears to be shifted. Changing the margins appears to be of no consequence.
Cisco VPN Client Download
You can download the Cisco VPN Client without registration here. The version on the site is 5.0.06.0160.
The latest actual released version on the Cisco site is 5.0.07.0290, having a file name of vpnclient-win-msi-5.0.07.0290-k9.exe. This file is available on RapidShare.