tag:blogger.com,1999:blog-47311302582911586302024-03-12T19:27:14.302-07:00Tech notes and tidbitsChristian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.comBlogger13125tag:blogger.com,1999:blog-4731130258291158630.post-44394982707228981342011-09-20T10:47:00.000-07:002012-05-21T12:32:08.053-07:00xinetd: restart vs reloadI'm running Ubuntu 11.04. When I change the configuration of xinetd, I have to use <br />
<code>sudo service xinetd reload</code><br />
rather than <br />
<code>sudo service xinetd restart</code><br />
Specifically, when I add a custom service to /etc/service and I do "restart", xinetd does not pick up the config changes.<br />
<br />
I was getting this error in /var/log/syslog
<br />
<code>service/protocol combination not in /etc/services: my-custom-service/tcp</code><br />
so I added this to /etc/services<br />
<code># Local services<br />my-custom-service 13082/tcp</code><br />
In this circumstance, "restart" did not make xinetd re-read the config files and change its behavior. However, "reload" did.<br />Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0tag:blogger.com,1999:blog-4731130258291158630.post-31051467295615234862011-05-13T21:25:00.001-07:002011-05-13T21:43:48.619-07:00Fabric and PageantHere's an example of using <a href="http://fabfile.org/">Fabric</a> with Pageant, the ssh key agent that comes with <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a>.<br /><br />We're using ssh keys in PuTTY (.ppk) format, not in OpenSSH format.<br /><br />It's a long example, but the work of connecting to Pageant happens in the _start_pageant_and_store_key function.<br /><br /><pre class="prettyprint"><br /># Regular Python imports<br />#<br /># Note: In the fabfile, don't do regular python imports like this<br />#<br />#from urllib import urlopen<br />#<br /># rather do them like this<br />#<br />#import urllib<br />#<br /># Any functions imported into this fabfile will be regarded as possible fabric<br /># tasks (in the example above, urlopen will show up when the user runs 'fab<br /># --list'), so instead of importing specific functions from modules, just import<br /># the whole module.<br /># http://docs.fabfile.org/en/1.0.1/usage/execution.html#imports<br />import os.path<br />import subprocess<br /><br /># Import Fabric<br />from fabric.api import env<br />from fabric.api import run<br />from fabric.api import sudo<br /><br /># To run the tasks defined in this file, use the 'fab' command line tool.<br /># cd \path\to\fabfile.py<br /># fab dev|prod task1 [task2]<br />#<br /># Note that you must specify dev or prod first, to set up the right server<br /># connection configuration.<br /><br /># Constants<br />KEY_DIR = r'\path\to\keys'<br />PUTTY_DIR = r'C:\Program Files\PuTTY'<br /><br /># These functions become tasks that can be executed from the command line using<br /># the 'fab' tool.<br /># Note: I couldn't find a more elegant way of specifying different connection<br /># parameters (such as key_filename) for each host, so I just made a 'dev' task<br /># and a 'prod' task.<br />def dev():<br /> """<br /> Set up for connection to the dev server<br /> """<br /> # Once DNS is set up for these hosts, I can use hostname instead of ip address<br /> env.user = 'admin_user'<br /> env.hosts = ['dev_server']<br /> _start_pageant_and_store_key('key2.ppk')<br /><br />def prod():<br /> """<br /> Set up for connection to the prod server<br /> """<br /> env.user = 'admin_user'<br /> env.hosts = ['prod_server']<br /> _start_pageant_and_store_key('key1.ppk')<br /><br />def install_all_all():<br /> """<br /> Install everything to all servers<br /> """<br /> dev()<br /> install_all_dev()<br /> prod()<br /> install_all_prod()<br /><br />def install_all():<br /> """<br /> Does all the installation.<br /> """<br /> ps()<br /> add_group('admins')<br /> # Note: put actual installation steps here.<br /><br /><br /># These utility functions are the building blocks of the install process. The<br /># can also be called individually on the command line, using the 'fab' tool, and<br /># specifying the target host and values for the arguments.<br />def ps():<br /> """<br /> Prints a process listing<br /> """<br /> run('ps -ef')<br /><br />def add_group(group_name):<br /> """<br /> Adds a linux user group.<br /> """<br /> # --force This option causes the command to simply exit with success<br /> # status if the specified group already exists.<br /> return sudo('groupadd --force %s' % group_name)<br /><br /><br /># These private python functions do not get exposed on the command line via the<br /># 'fab' tool. They will not show up when the user runs 'fab --list'<br />def _start_pageant_and_store_key(keyfile_name):<br /> """<br /> Starts the Pageant key agent, and loads the private key in to it, prompting<br /> for the passphrase if needed. Also sets the Fabric env.keyfile_name<br /> property.<br /> """<br /> keyfile_path = os.path.join(KEY_DIR, keyfile_name)<br /><br /> # Start pageant. Note that this works with the PuTTY key format (*.ppk), not<br /> # the OpenSSH format.<br /> path_to_pageant = os.path.join(PUTTY_DIR, 'pageant.exe')<br /> result = subprocess.call([path_to_pageant, keyfile_path])<br /> if result > 0:<br /> raise OSError, "Bad result %s" % result<br /><br /> # Store the path to the key file in fabric's global env dictionary<br /> env.key_filename = keyfile_path<br /></pre><br /><br />Thanks to Luka Marinko for his instructions for setting up <a href="http://lukabloga.blogspot.com/2008/10/to-test-new-highlighting.html">syntax highlighting on Blogger</a>.Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0tag:blogger.com,1999:blog-4731130258291158630.post-89480647391882718862011-05-11T11:32:00.000-07:002011-05-13T21:43:12.577-07:00Bash historyUse Ctrl-R to perform an incremental search on bash history. Press Ctrl-R again repeatedly to scroll backwards through matching commands.<br /><br /><a href="http://www.talug.org/events/20030709/cmdline_history.html">http://www.tahttp://www.blogger.com/img/blank.giflug.org/events/20030709/cmdline_history.html</a><br /><a href="http://superuser.com/questions/7414/how-can-i-search-the-bash-history-and-rerun-a-command">http://superuser.com/questions/7414/how-can-i-search-the-bash-history-and-rerun-a-command</a>Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0tag:blogger.com,1999:blog-4731130258291158630.post-61012150490095088012011-05-09T09:49:00.000-07:002011-05-13T21:42:19.641-07:00Line continuations and && in DOSNotes to myself:<br /><ul><br /><li>&& works in DOS too (only do step 2 if step 1 succeeded)</li><br /><li>Use ^ for line continuation</li><br /><li>Use %ERRORLEVEL%, labels, and goto, for some primitive flow control.</li><br /></ul><br />Here's an example<br /><br /><code><br />@echo off<br /><br />set basedir=Z:\path\to\dir<br /><br /><br />cd %basedir% && ^<br />hg fetch -R .\MRA && ^<br />hg fetch -R ".\Super common" && ^<br />hg fetch -R .\ServerKpf<br /><br />goto answer%ERRORLEVEL%<br />:answer0<br />echo hg fetch complete<br />komodo "%basedir%\ServerKpf\dev_util_nds_dev.kpf"<br />goto end<br />:answer1<br />echo Program had return code 1<br />pause<br />goto end<br />:end<br /></code><br /><br />References<br /><a href="http://www.dostips.com/DtCodeSnippets.php#Snippets.CommandsInSingleLine">Multiple Commands in Single Line</a><br /><a href="http://www.computerhope.com/if.htm">DOS IF command</a>Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0tag:blogger.com,1999:blog-4731130258291158630.post-2776427059402622262011-02-17T09:01:00.000-08:002011-05-13T21:41:49.361-07:00February 17I just got back from a rally on the steps of the Winnebago County Courthouse, organized by Rep. <a href="http://legis.wisconsin.gov/assembly/asm54/news/index.htm">Gordon Hintz</a> of Oshkosh. The rally was to protest Scott Walker's proposal to eliminate collective bargaining for state workers. Main theme: It's not about the money, it's about the disrespect Walker shows all working people when he takes away their right to have a say in their working conditions.<br /><br />There's another rally in support of state workers ** 5PM Today (Thursday 2/17)** in Opera House Square, downtown Oshkosh.Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0tag:blogger.com,1999:blog-4731130258291158630.post-22038249111832990502011-02-06T23:15:00.000-08:002011-05-13T21:46:58.511-07:00SSD Saga continuedSo I got my OCZ Vertex2 SSD some time ago, and I managed to get it <a href="http://christianlong.blogspot.com/2010/11/how-to-switch-windows-xp-from-ide-mode.html">running in AHCI mode</a> on my existing Windows XP pc. However, I had not yet transferred my windows system partition from hdd to ssd. A good job for Super Bowl Sunday, as it mirrored the highs and lows, the moments of elation and crushing despair, that I would have experienced had I watched the game itself.<br /><br />After many false starts, I arrived at this process:<br /><br />1) I <a href="http://www.ocztechnologyforum.com/forum/showthread.php?48366-How-to-Align-OCZ-SSD-in-XP-using-USB-SATA-and-Vista-recovery-disk">aligned the partition</a>, and formatted the whole ssd drive as one partition.<br /><br />2) I used <a href="http://clonezilla.org/">Clonezilla</a> to copy my C: drive partition on my hdd to the new empty partition on the ssd. I used the "device-device" (device to device) menu option, with the basic (not advanced) option.<br /><br />So far, so good. Here's where the fun began. Naturally, after such a cloning operation (operating on partitions, not the whole disk), the master boot record on the SSD was not set up properly to boot into windows.<br /><br />First, I unplugged the hdd, so the ssd would show up as C: (and so I wouldn't fat-finger it into oblivion). I booted from the XP install disk into the Recovery Console, and used the three classic incantations:<br /><code><br />fixmbr<br />fixboot C:<br />bootcfg /rebuild<br /></code><br />This is supposed to repair the mbr, and make the drive bootable. No dice. I just received the message "Error loading operating system" on a black screen.<br /><br />I turned to the old reliable, <a href="http://www.ultimatebootcd.com/">Ultimate Boot Cd</a> (not <a href="http://www.ubcd4win.com/">UBCD4win</a> <a href="http://christianlong.blogspot.com/2010/11/how-to-switch-windows-xp-from-ide-mode.html">this time</a>)<br /><br />It comes with several MBR tools. The one that worked for me was <a href="http://www.terabyteunlimited.com/downloads-free-software.htm">MBRWork</a> (version 1.07b)<br /><br />Here's how to use MBRWork, from <a href="http://www.computing.net/answers/windows-2000/how-to-use-mbrwork/54948.html">here</a> and <a href="http://members.shaw.ca/leesplace/mbrwork.htm">here</a><br /><blockquote>Steps to recover lost partitions<br />7> Change active hard drive. (ignore if you have only one hard drive)<br /><br />1> Backup first track<br /><br />4> Reset MBR to zero<br /><br />3> Reset EMBR area to zero.<br /><br />A> Recover MS Partitions (see fig 2)<br /><br />5> Install standard MBR code<br /><br />Reinstall your boot manager. (if used)<br /><br />See explanations below..<br /><br />Below view shows after 4> Reset MBR to zero. A> Recover MS Partitions has been<br />added to the list of options, also notice MBR Partition Information <hdo> is<br />now all zeros. There are no longer any partition boundaries, meaning the hard<br />drive is unbootable and you can't read any data. If you now try to use fdisk<br />or other utility to recreate the partitions, new file tables will mean all<br />your data will be inaccessible, except for data rescue efforts. MBRWork finds<br />the original partition boundaries and reconstructs them exactly as they were,<br />meaning your computer works again and the data is intact.<br /><br />MBRWork Menu<br /><br />1) Backup First Track This is your safety valve to put things back as they were<br />2) Restore First Track Appears as an option only after using 1)<br />3) Reset EMBR Clear extended partition area<br />4) Reset MBR Remove partitions<br />5) Install Std MBR Same as fdisk /mbr (removes any boot manager)<br />6) Set active partition Also can be done with fdisk<br />7) Change active HD<br />8) Only shows if DDO present Remove Dynamic Disk Overlay (i.e. EZDrive, Maxblast)<br />9) Capability Check Runs tests on your BIOS, makes no changes.<br />E) Exit<br />A) Recover partitions Appears only after running 3) (and/or 4)<br /></hdo></blockquote><br />Success! It boots, and is much much faster booting and loading programs. And, it's still aligned properly, according to this <a href="http://www.techpowerup.com/articles/other/157">ssd alignment calculator.<br /></a><br />However, if you're using XP, and thinking about transferring your existing install to an ssd, know that it is not an easy or straightforward operation. Newer versions of windows are apparently much smarter about the way they handle ssds.Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0tag:blogger.com,1999:blog-4731130258291158630.post-1766807141554843482011-01-18T13:05:00.000-08:002011-02-07T00:05:00.962-08:00Using the GNU tools for find and replace on WindowsThere are many ways to do find and replace in multiple files on Windows. I use the familiar GNU find | grep | sed tools.<br /><br />I use the GnuWin32 version of the unix utilities. I have used UnixUtils, but they are now outdated. The <a href="http://sourceforge.net/projects/getgnuwin32/">Automated gnuwin32 download tool</a> downloads and manages the gnuwin32 utilities. Read the Readme in the getgnuwin32 distribution folder for instructions.<br /><br />The use of GNU utilities in the windows command prompt environment is not without pitfalls. You use only double-quotes. There are problems with filenames containing spaces, and with path separators. We handle dodgy file names the same way we do on Linux, by passing around null-delimited lists of file names.<br /><br /><br />In this example, I'm replacing the <code>&frasl;</code> html character entity with the more common slash <code>&#47;</code>. I have broken it down in to smaller steps, and I save the intermediate results to temp files.<br /><br />First I find all the html files. I put all the file names in to a temp file. Passing <code>-print0</code> separates the file names with null strings.<br /><code><br />find "C:\The\windows\path to\my directory" -name "*.html" -type f -print0 > "C:\Temp\tmp.txt"<br /></code><br /><br />Next, I use xargs to read in all those null-delimited file names, and run grep over them looking for the <code>&frasl;</code> html character entity. I write out the names of files where grep found <code>&frasl;</code><br /><code><br />xargs --null --arg-file="C:\Temp\tmp.txt" grep --null -l "&frasl;" > "C:\Temp\tmp2.txt"<br /></code><br /><br />Then, I use sed to replace all instances of <code>&frasl;</code> with <code>&#47;</code>. Note that I have to eascape the & in the replacement.<br /><code><br />xargs --null --arg-file="C:\Temp\tmp2.txt" sed -i -e"s/&frasl;/\&#47;/g"<br /></code><br /><br />Now I check the results. This grep should now find nothing.<br /><code><br />xargs --null --arg-file="C:\Temp\tmp.txt" grep "&frasl;"<br /></code>Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0tag:blogger.com,1999:blog-4731130258291158630.post-44195152425994154882010-12-31T23:53:00.001-08:002011-01-01T00:01:22.512-08:00iTunes: How to share apps between different accounts on a single computerI've got multiple family user accounts on a Windows XP computer. I have my iTunes library set up the way I want, and my son has his playlists set up in iTunes under his own Windows login. All good. We even share the same iTunes music library, thanks to clear instructions <a href="http://support.apple.com/kb/ht1203">here </a><br /><br />To complicate matters slightly, he's using my iTunes account.<br /><br />To summarize:<br />2 windows accounts<br />1 iTunes account<br />shared iTunes media library<br />I sync the iPad when I'm signed in under my windows login<br />he syncs the iPod when he's signed in under his windows login<br /><br />This sounds complicated, but it all works remarkably well. His playlists and ratings are blessedly separate from mine, yet we can pull from the same underlying pool of music. I can listen to his Weird Al, and he can (hopefully, someday) learn to appreciate Elvis Costello and Gillian Welch.<br /><br />Now, one little problem was that the apps were not shared automatically the way the music was. I sync an iPad to mine, he an iPod. The apps I install, I can see in iTunes when I'm logged in to my PC as me. However, even though we are sharing the library across multiple PC accounts, the apps are not showing up in his iTunes.<br /><br />Instead of redownloading, here's what to do to get the apps to appear in his iTunes:<br /><br />Log in to windows under his account. Right-click on one app in the local iTunes Library, and choose "Show in Windows Explorer". This brings up an explorer window at "D:\Bla\Bla\iTunes\iTunes Music\Mobile Applications". This folder contains all the .ipa files that store the applications on the PC. Since we are sharing an iTunes library, this "Mobile Applications" folder contains all the apps I downloaded while I was logged in as me.<br /><br />I dragged the relevant .ipa files from the explorer window over to iTunes, and it added those apps. Now I can see the apps from his Windows login, and I can install them onto the iPod as well as the iPad.Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0tag:blogger.com,1999:blog-4731130258291158630.post-59170653373488648672010-11-18T20:24:00.000-08:002010-11-18T21:02:37.038-08:00How to switch Windows XP from IDE mode to AHCI mode.Many recent motherboards include AHCI-capable SATA controllers. However, if you have an existing installation of Windows XP, you can not easily switch from IDE to AHCI mode.<br /><br />If you are doing a fresh install of Windows XP, you can introduce the proper drivers with the old F6 method, or by slipstreaming the needed drivers on to you own custom install disk. However, for existing installations of XP, there's a catch-22.<br /><br />You can't switch to AHCI mode in the BIOS - that causes a Stop Error (BSOD) at the start of the boot process. This is because the Windows bootloader loads the existing IDE driver, but the motherboard is presenting an AHCI interface.<br /><br />Neither can you solve the problem by replacing the Windows driver first. The AHCI drivers won't install, since all Windows can see is an IDE controller.<br /><br />Some vigorous googling revealed nothing more than some <a href="http://forum.notebookreview.com/windows-os-software/217456-how-enable-ahci-after-xp-installation-guide.html">dubious</a> and <a href="http://forum.notebookreview.com/acer/186471-enabling-sata-mode-ahci-after-xp-install-applicable-most-laptops-systems.html">dated</a> <a href="http://forums.pcper.com/showthread.php?t=444831">registry hacks</a>, or the suggestion to do a <a href="http://www.howtofixcomputers.com/forums/storage/ahci-mode-xp-275910.html">Repair installation of XP</a>.<br /><br />I wasn't satisfied with any of those solutions. I thought, "Isn't this chicken-and-egg problem the kind of thing that Utility Boot CDs are supposed to solve?" Indeed. There is a little utility on the <a href="http://www.ubcd4win.com/">Ultimate Boot CD for Windows</a> called <a href="http://ubcd4win.com/forum/index.php?showtopic=12311">Fix HDC</a>, purported to "Fix the Hard Drive Controller when replacing your motherboard on an XP system" That sounds good to me.<br /><br />Now, the Ultimate Boot CD for Windows (UBCD4Win) is a decidedly do-it-yourself affair. You <a href="http://www.ubcd4win.com/howto.htm">build it yourself</a>, based on your own copy of the Windows XP install disk (I used an <a href="http://www.nliteos.com/">nLite</a> install disk, slipstreamed with SP3 and the <a href="http://h30434.www3.hp.com/t5/Operating-systems-and-software/SATA-drivers-for-XP/m-p/261043">right AHCI drivers</a>, but a plain Windows XP install CD should work fine too, since UBCD4Win comes with a bunch of drivers). I hit a snag caused by multiple copies of cygwin1.dll on my computer, but <a href="http://ubcd4win.com/forum/index.php?showtopic=7719">this post</a> helped me clear it up.<br /><br />So, burn a UBCD4Win cd, and put it in the drive. Boot the computer, and go in to your BIOS to make some changes. First, make sure that the CD player is first in the boot order. Also, change your SATA controller from IDE mode to AHCI mode in the BIOS. Note that many motherboards have two SATA controllers, so make sure you are changing the right one. Mine has a six-port Intel controller, and a four-port controller from Gigabyte.<br /><br />After a long boot process, UBCD4Win dumps you in to a bizarro-world version of Windows,with a zombie-colored, MS Serif Start menu. No matter, we didn't come here for the design. Under Start > Programs > Registry Utilities, you will find Fix HDC. Make sure you have changed your BIOS to AHCI mode beforehand, otherwise FixHDC will just install regular IDE drivers.<br /><br />In the Start Menu, Fix HDC is a folder, containing two items. The first allows you to set which Windows installation you want to modify. The second runs the actual Fix HDC utility. It runs in a dos window, and prompts you to back up your installation and/or modify your storage drivers. I chose Modify. UBCD4Win comes with a comprehensive selection of drivers, so Fix HDC will likely find the right driver for your hardware.<br /><br />If UBCD4Win does not have the right driver for your hardware, it may install a "close enough" driver that will at least allow you to boot into your hard-disk Windows in AHCI mode. Once there, you can upgrade the driver just as you would any other.<br /><br /><a href="http://h30434.www3.hp.com/t5/Operating-systems-and-software/SATA-drivers-for-XP/m-p/261043">This post</a> has a very clear explanation of which driver to use based on your motherboard.<br /><br />Anyway, the changes made by Fix HDC worked.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_-hMpHvtAP3Y/TOYB6la-I9I/AAAAAAAAFpQ/DF_VMt_CyuY/s1600/untitled.JPG"><img style="cursor: pointer; width: 329px; height: 81px;" src="http://1.bp.blogspot.com/_-hMpHvtAP3Y/TOYB6la-I9I/AAAAAAAAFpQ/DF_VMt_CyuY/s400/untitled.JPG" alt="" id="BLOGGER_PHOTO_ID_5541118497515250642" border="0" /></a>Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0tag:blogger.com,1999:blog-4731130258291158630.post-65562847611076547182010-10-26T12:14:00.000-07:002011-02-06T23:43:11.041-08:00Ctrl-Enter in ThunderbirdDid you know that Ctrl-Enter in Thunderbird sends your email message immediately? If you do, you probably learned it the hard way, by sending a half-written email, like I just did. Awkward . . .<br /><br />To get rid of this behavior, install the <a href="http://kb.mozillazine.org/Keyconfig_extension">keyconfig</a> extension. Once you have installed the extension and restarted Thunderbird, go to the Tools menu > Keyconfig. Choose "Send Now", and click the disable button.<br /><br />If you installed keyconfig, but you can't find the "Send Now" option:<br /><br />1) Open Thunderbird<br />2) Start composing a new message (in a new window)<br />3) In the main Thunderbird window, go to the Tools menu > Keyconfig<br />4) At the top of the Keyconfig window, there is a dropdown box, with one entry for each open Thunderbird window<br />for example:<br />- Inbox<br />- Write (no subject)<br />- Keyconfig<br />5) Choose the "Write . . ." window in the Keyconfig dropdown box<br />6) Send Now should now be listed in the Keyconfig listbox<br />7) Select Send Now, and click Disable<br />8) done!Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0tag:blogger.com,1999:blog-4731130258291158630.post-31042689672780065992010-07-20T12:05:00.000-07:002011-02-06T23:44:10.038-08:00Nested list comprehensions in PythonPython's nested list comprehensions often hover on the edge between elegance and obfuscation.<br /><br />I made some examples to show the order of evaluation, and the results of adding/removing the nested bracket symbols.<br /><br /><code class="prettyprint lang-py"><br />matrix = [<br /> [1, 2, 3],<br /> [4, 5, 6],<br /> [7, 8, 9],<br /> ]<br /><br /># This flattens and transposes the matrix.<br />c = [row[i] for i in range(len(matrix)) for row in matrix]<br />d = []<br />for i in range(len(matrix)):<br /> for row in matrix:<br /> d.append(row[i])<br />assert(c == d)<br />print c # [1, 4, 7, 2, 5, 8, 3, 6, 9]<br /><br /># This flattens the matrix.<br />e = [row[i] for row in matrix for i in range(len(matrix))]<br />f = []<br />for row in matrix:<br /> for i in range(len(matrix)):<br /> f.append(row[i])<br />assert(e == f)<br />print e # [1, 2, 3, 4, 5, 6, 7, 8, 9]<br /><br /># This transposes the matrix.<br />a = [[row[i] for row in matrix] for i in range(len(matrix))]<br />b1 = []<br />for i in range(len(matrix)):<br /> b2 = []<br /> for row in matrix:<br /> b2.append(row[i])<br /> b1.append(b2)<br />assert(a == b1)<br />print a # [[1, 4, 7], [2, 5, 8], [3, 6, 9]]<br /><br /># This returns the matrix unchanged.<br />g = [[row[i] for i in range(len(matrix))] for row in matrix]<br />h1 = []<br />for row in matrix:<br /> h2 = []<br /> for i in range(len(matrix)):<br /> h2.append(row[i])<br /> h1.append(h2)<br />assert(g == h1)<br />assert(g == matrix)<br />print g # [[1, 2, 3], [4, 5, 6], [7, 8, 9]]<br /><br /># This oddity builds up a nested list from simple lists.<br />k = [zip(j,j) for j in [range(i) for i in range(4)]]<br />m1 = []<br />for i in range(4):<br /> m1.append(range(i))<br />m2 = []<br />for j in m1:<br /> m2.append(zip(j,j))<br />assert(k == m2)<br />print k # [[], [(0, 0)], [(0, 0), (1, 1)], [(0, 0), (1, 1), (2, 2)]]<br /></code><br /><br />Thanks to Luka Marinko for his instructions for setting up <a href="http://lukabloga.blogspot.com/2008/10/to-test-new-highlighting.html">syntax highlighting on Blogger</a>.Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0tag:blogger.com,1999:blog-4731130258291158630.post-79599278153074029962009-03-30T09:47:00.000-07:002010-11-18T20:24:23.890-08:00Django on TwistedUpdate from the Twisted sprint - <a href="http://lackingcredibility.blogspot.com/">David Reid</a> is working on getting Django running on top of twisted. It's up and serving a simple app. Instructions <a href="http://lackingcredibility.blogspot.com/2009/03/twisted-django-it-wont-burn-down-your.html">here</a><br /><br />Here's the money line:<br /><code>twistd -no web --wsgi=myapp.application<br /></code>Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0tag:blogger.com,1999:blog-4731130258291158630.post-13933432583319812462008-02-04T09:10:00.001-08:002010-11-18T20:23:49.200-08:00Blogger wins!After years of holding a geek hard line on running my own server for my <a href="http://christianlong.com/">personal website</a>, I have decided to move to blogger. Another brick in the Google borg, I know; but I must admit that my poor server, starved of attention, too often fell prey to downtime, log overflows, and botched upgrades. For me, sysadmin is a chore, and if someone is willing to do it for me for free, then I (finally) say amen.<br /><br />I'll port posts here as time permits (i.e. never).Christian Longhttp://www.blogger.com/profile/12415511078862856599noreply@blogger.com0