Pages
Categories
Archives
- September 2010 (2)
- August 2010 (1)
- May 2010 (1)
- April 2010 (2)
- March 2010 (1)
- February 2010 (1)
- December 2009 (2)
- November 2009 (1)
- September 2009 (1)
- August 2009 (3)
Pipe Viewer (pv) is Pretty Swell
A pretty common task in my workflow is updating my development database to what's currently on the live servers. The database isn't too large, but it does take about 30 seconds to import -- and I do positively loathe not knowing what's going on. Enter pipeviewer! I remembered reading a post that was linked off reddit some number of internet decades ago.
With this mighty tool in hand, I set to apply it to those 30 seconds of terrifying mystery that MySQL was plaguing my dreams with.
pv databasedump.sql | mysql -uDATABASEUSER -p databasename
And like magic, a beautiful progress bar was rendered. Life had incrementally improved.
I'd also recently used pv to watch the progress of dd-ing an ISO onto a USB stick, like so:
pv -ptre ubuntu-10.04-desktop-i386.iso | dd of=/dev/disk1 bs=1mb
- The "-ptre" turns on all the rate monitors and progress bars and such.
- /dev/disk1 is where OSX had my USB stick mounted.
- bs=1mb sets the blocksize of dd to 1 megabyte, which made the copying process go a lot faster (minutes instead of hours.)
Django TestCase Comedy
Here's a little snippet that'll entertain the vast throngs of people who are interested in both Rock Paper Scissors strategy and Django unit testing.
def test_desperate_futility_of_avalanche(self):
for futile_attempt in range(100):
Round.objects.create(game=self.normal_game,
initiator_choice=self.rock,
opponent_choice=self.rock)
self.failUnlessEqual(self.normal_game.result(), UNRESOLVED)
for futile_attempt in range(100):
Round.objects.create(game=self.normal_game,
initiator_choice=self.rock,
opponent_choice=self.rock)
self.failUnlessEqual(self.normal_game.result(), UNRESOLVED)
Posted in Comedy, Messing With Stuff Tagged code, django, python, unittesting, wellithinkitsfunny 1 Comment



An interesting visualization demonstrating why not to use floating point calculations to determine if large integers are perfect squares
I've been working through The Art and Craft of Problem Solving, and there's been a few problems in it based on Pascal's Triangle. After some hours of scribbling numbers on paper, I got lazy and wrote up a generator for it in Python. The book wants the reader to examine some of the properties of the triangle, so I had my triangle renderer (renderer? ha, it's text!) take a function that'd return a boolean to determine if something should be shown or not. While scribbling odd and even values of the triangle on paper, I noticed that it kind of resembled Sierpinski's triangle, so I started with that.
Now this looked pretty neat to me, so I was thinking of another easy pattern I could look for. Perfect squares came to mind; just check to see if the square root of a number is an integer and you're all setup, right? I tried passing that function into the triangle renderer and beheld an interesting result.
It appeared as if perfect squares formed a kind of parabola past 100 rows of the triangle! What a discovery! Of course, I'm really doubting my naive perfect square test at this point, so I googled up a better one and tried that out. A less interesting result awaited me:
Even though I hadn't made the amazing discovery that perfect squares existed, buried within Pascal's triangle in an almost perfect parabola, I had learned to distrust floating point tests on gigantic integers. So there's that.
Code Follows:
Read More »