da's Journal http://use.perl.org/~da/journal/ da's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:21:12+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 da's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~da/journal/ Practical application of an artistic idea http://use.perl.org/~da/journal/36555?from=rss Four years ago, I read about <a href="http://www.complexification.net/gallery/machines/nineblock/">9-block quilt patterns</a> and I <a href="http://kw.pm.org/wiki/index.cgi?NineBlocksPerlReview">turned it into a perl program and article</a>, purely for amusement-value. And a Christmas present. <p> Someone else has taken the original idea and made them into a <a href="http://www.docuverse.com/blog/donpark/2007/01/20/identicon-third-party-implementations">security feature</a> for web discussion-boards to prevent spoofing. It's a one-way hash from someone's IP address into a unique picture. Quite a clever idea, I think. </p><p> I noticed a few weeks ago when these shapes started showing up on wordpress blogs. It seems they've added it as a standard wordpress plugin option. It will take me a while before I don't do a double-take each time I see them though.</p> da 2008-05-30T20:32:16+00:00 journal The Leaves of Dianetics Personality Test http://use.perl.org/~da/journal/26778?from=rss So, last Friday when I was chatting with friends on IRC, one silly thought led to another, which I just brought to an obvious (?) conclusion, <a href="http://coder.com/daniel/mashup/"> <em>The Leaves of Dianetics Personality Test</em> </a>, a mashup Markov Chain program featuring Walt and L. Ron, together (hopefully) for the first time.<br> <br>Some sample output:<br> <br> <em>Do you consider that you read? When recounting some amusing incident can you easily pleased? <br> <br>When met with direct opposition would you really take the trouble to see the soul? See, your own inferiority? <br> <br>Do people enjoy being in your demands on your past illnesses or painful experiences? Do you consider the best points of most people and only rarely speak slightingly of them? Do you have little regret on past misfortunes and failures? Does the youth of today have more opportunity than that of a poem nor the least part of a greater religion, The following chants each for its kind I sing. My comrade! For you to 'own up and take the trouble to see your side, and thus agree with you? Do you openly and sincerely admire beauty in other people? Do you sometimes completely unable to enter the spirit of things? Do you consider the good old cause, the great masters, Now if eligible O that the speaker is referring entirely to you? </em> <p> The code is a <a href="http://www.postcognitive.com/tools/babelize">Markov chain program</a> by <a href="http://www.perlmonks.org/index.pl?node_id=22308">Dave Smith</a>.</p> da 2005-09-19T14:35:48+00:00 journal YAPC Day 3 http://use.perl.org/~da/journal/25428?from=rss Glad to be home. <p> First this morning, I went to the MVC talk by Perrin Harkins. He compared three web-app frameworks: CGI::Application, Catalyst, and Open Interact 2; his slides may cover other MVCs he didn't have time to discuss too. This talk felt like it should've been longer than 40 minutes, given the content. He was able to illustrate a bit of sample code, but wasn't really able to compare and contrast as deeply as he has in his online writings. I'm left wanting to learn more, but not knowing if I actually have any more additional knowlege than the little bit I wrote below. </p><p> So: briefly: </p><ul> <li>Catalyst features include very flexible URL handling, which you won't get in OI2 (without hacking). There are tools to generate lots of stub methods, for easy startup. However, documentation on this is shaky; perrin had to read sourcecode for 3-4 modules to get that to work. There are good plugins available, which will illustrate ideomatic code for you. Data relationships are stored in perl modules, such as via Class::DBI::Loader::Relationships perhaps.</li> <li>CGI::Application is the most skeletal framework of the three; you end up rolling things yourself or at least, writing enough to piece together some of the (many) good plugins available.</li> <li>Open Interact is quite automatic. You turn it on (it runs its own webserver at the outset), click a few buttons, and you have a MVC. There is more abstraction, for those plusses and minuses (he described one level which he found quite irritating; I didn't catch what it was called...) OI is quite appropriate for large-scale projects, where it will be worth the effort to learn. OI uses lots of configuration files (which I believe is where data relationships can be defined).</li> </ul><p> So, I have some information to go on for my next web app project. It's frustrating; the last MVC I used was Maypole, which I never quite got working well enough to do anything beyond the examples; since then I've re-invented wheels a few times on small db-backed projects, and I'm loathe to do the same again, but at the same time it's not completely clear that the existing frameworks will satisfy either. Guess I need to dive in and try them... </p><p> I skipped the next time-slot to check out and chat with people a bit; I was unhappy about missing Casey West's talk on development tools, but luckily (?) he got bumped due to over-runs and got to give a shorter version to everybody in the afternoon. Which was an awesome talk. He ended up with nine wonderful development tools I am pretty excited to learn about: </p><ul> <li>SQL::Translator - goes from any DBD to any other; and will even make images, too.</li> <li>HTTP::Server::Simple::Static - lets you run a no-muss, no-fuss HTTP server in your web directory, for quick testing.</li> <li>Devel::Cover - How much code are your tests covering? Not only provides answers, but spits out very pretty HTML tables of modules and functions which you can drill down into.</li> <li>podwebserver - another standalone POD database, but looks quite fully-featured. Will show you the source, and tidy/colourize it for you, too.</li> <li>perltidy - speaking of which, perltidy will allow your coding team write using each person's own preferred style, then you can run it through the (highly customizable) perltidy script to make it all standardized.</li> <li>Test::Pod::Coverage - self-evident?</li> <li>DBI::Shell - command-line tool, db equivalent of perl -e (or possibly perl -de1), with handy switches.</li> <li>Module::Refresh - nit sure what this one did</li> <li>CPAN::Mini - 600MiB of current CPAN goodness, as opposed to however many GiB are actually available.</li> </ul><p> After the morning break, I watched Ingy discurse about Data Driven Testing (so, writing tests in "0 lines of code" which actually means writing config files in a very easy to understand format) and Perldoc, his ideas for making POD suck less. I said "discurse" because he has an amazing ability to go off on tangents that are both trival and very important, and if you're not paying at least as much attention as he is, you might miss what he actually said. For example, I completely failed to take notes during them because they were so entertaining. On the other hand, he wrote the URLs for us to follow along; but I missed it. (Edit: and Autrejus told me what it is, below.) </p><p> Lunch was with other KW Mongers, down at the Bon Marche on Bay Street. We debriefed a bit about the morning, but I'm not confident enough about what people said to repeat it here. (See what I did when I echoed Allison on Monday?) </p><p> What else. Oh, lightning talks. Of particular note for me to look up [this is not meant as a slight against those I don't mention!]: </p><ul> <li>The list of all 16 talks is <a href="http://justanotherperlhacker.org/lightning/yapcna2005.shtml">here</a>.</li> <li>Regexp::Compost does automatic Regexp decomposition to make them predict<nobr> <wbr></nobr>/future/ matches as well. Sounds crazy but the demo seemed cool enough that it might just work for some applications (eg., monitoring web logs). By shields@cpan.org.</li> <li>SPF was invented at YAPC::NA Florida (03)? I had no idea. Anyway, Meng Wong, the creator, is working on two new projects, Domain Keys and "The Karma Project" for improving site-to-site trust, and "RSS email" as a complete reversal of the ideas behind SMTP. URL: somewhere <a href="http://spf.pobox.com/">here</a> and possibly <a href="http://www.mengwong.com/rssemail/">here</a>.</li> <li>annocpan.org</li> <li>Not Just Another Perl Hacker: The Perl Foundation is soliciting nominations for the best technical innovations in perl. talk to dha.</li> <li>wikis and cities: cityguides.com</li> <li>the talk of reimplementing CPAN for javascript has found a home; openjsan.org is live, today.</li> <li>there was entertaining juggling. As opposed to lame juggling, which would've happened in other fora, but never at YAPC. <p> Must go eat dinner now; more later (for some value of later) when I have a chance to look for stuff I only hinted at above... Comments welcome of course; it might be a few weeks before I respond though, because I'm off to the wilds of Virginia till the 12th. [edit: fixed URLs, 6/30] </p><p> Thanks to all the people who made YAPC possible this year (from the organizers to the speakers to...) It was a lot of fun to help out behind the scenes, such as I was able to. Looking forward to next year.</p></li></ul> da 2005-06-30T01:05:38+00:00 journal Yapc day 2 http://use.perl.org/~da/journal/25411?from=rss Well aren't I psyched, because I've gotten the oomph to follow day 1 with day 2. Ha, we'll see about day 3 tomorrow. Today I pretty much followed the databases track, with a detour at the beginning for 1.5 hours of perl 6 and Pugs. I'm quite impressed with how the perl 6 projects are coming along, though, as Eric/fishbot just told me, he was excited to see how the specs for Grammars have changed since he last looked at them. Now, I'll be excited to learn them when the design is finalized, and I'm excited for neat design development happening, but I'm not a language designer so I'll leave those discussions for those who are competent at such things. <p> In the database track, I saw a total of 4 Class::DBI talks of various sorts; I'm not convinced it's as useful as some claim, but I'm not actually warned away by the equally strong warnings I've heard from other smart people. Class::DBI seems just right for projects that can deal with a simple model. I suppose the first time I hit a wall with it, it'll be clear where the limitations are. But it seems it can handle many-to-many relationships, the thing I was most concerned about. </p><p> I need to look at Shawn Sorichetti's weblog, which will have interesting notes about IMA::DBI, and also I should track down the wiki for Class::DBI. </p><p> Casey West's talk about advanced Class::DBI included a number of modules to look at; which will shorten the amount of code you write, even further. </p><ul> <li> <b>Database-specific extensions</b>: there are subclasses of Class::DBI for each of the major DBDs; each has a 'set_up_table' method which will semi-automatically create the tables you need, at compile time (for better and worse).</li> <li> <b>Automatic Class creation</b>: Class::DBI::Loader has a method 'find_class' to shorten class-creation code...</li> <li> <b>Automatic Relationships</b>: Class::DBI::Loader::Relationships will set up simple cases of relationships. Also, Loader has a 'relationships' flag to look into.</li> <li> <b>Globally Unique Keys</b>:<nobr> <wbr></nobr>::Loader has parameter for 'additional_classes =&gt; [qw [Class::DBI::UUID]] whih uses/adds UUID field for able; it's DB independent and creates 16-character string UUIDs.</li> <li> <b>Automatic XML Serialization</b>: Class::DBI::AsXML (I think this was written by Casey): has 'to_xml_columns' method which will dump XML definitions for your data (non-recursively, I think; it might need more work)</li> <li> <b>Automatic CGI Input</b>: Class::DBI::FromCGI : the name is a misnomer; it can be used for many things besides CGI inputs. It will allow you to define columns/form-entries to untaint (as per type; you can specify integer, printable, etc... Pseudocode:<blockquote><div><p> <tt>use CGI::Untaint;<br># create handler<br>my $h = CGI::Untaint-&gt;new(CGI-&gt;new-&gt;Vars):<br>my $a = $camoose-&gt;create_from_cgi($h);</tt></p></div> </blockquote><p> Class::DBI::AsForm creates populated or empty form.</p></li> </ul><p> Advice: <b>Don't</b>: write a Class::DBI subclass; that namespace is already too populated. Don't reinvent classes already on CPAN.</p><p> <b>Do</b>: write a Class::DBI mixin; use exporting to provide your plugin; and use Class::DBI internals. </p><p> I need to read up in the docs, and possibly ask Casey what he meant for the last two Do's. </p><p> Dan Friedman's talk on Class::DBI::DataMigration describes a framework for basically building a better database programatically, but mostly just requiring a YAML config file that will do the translations. Which certainly sounds easy. </p><p> As for non-Class::DBI talks: I enjoyed the Yahoo tlak on high-volume databases and the high-availability talk which suggests corporate appropriateness for MySQL (hm...). Finally, I got a little bit of graph theory schoolin' with Walt Makowski's talk on Graph Theory and one instance when to use trees instead of sets to describe data so it can be combined more quickly. </p><p> Gotta go run and catch a boat-cruise.<nobr> <wbr></nobr>:) </p><p> [edit: back. Boy that was a long auction. Why did I think it would feel shorter if it were on a 4-hour boat-cruise? The conversations were excellent, though.]</p> da 2005-06-28T21:31:07+00:00 journal YAPC day 1 http://use.perl.org/~da/journal/25403?from=rss A review of YAPC day 1. <p>Larry Wall's keynote was quite high-level and syncretic. He enthused about tensegrity, the engineering design principle that opposing forces properly balanced can provide tension and integrity at the same time. The talk was based on one he was invited to give in Russia, on how to build an open-source community. </p><p>Allison Randal's "state of the carrot" was a snapshot of where perl 5 and perl 6 design are right now. I didn't take notes, but there were some perl6 milestones released the day before, and everything seems to be progressing. PUGs has 80% of perl6 features, wow. [edit: This should be corrected to &lt;30% or 10% (based on fraction of design that has test cases to cover it; see Autrijus's note below!)] </p><p> When we all split up, I started off in the "Enterprise Workflow" talk by Jim Brandt, which described how he and his group at the U of Buffalo used a few modules to save their University lots of time and money. The modules were: Class::DBI, Data::FormValidator, and CGI::Prototype. I've not actually done coding with Class::DBI, though I've read about it. Some people seem to dislike it intensely, for any sort of difficult projects, because it creates as much work as it saves. But for simple database lookups and manipulation, it seems like a timesaver. </p><p> Then, becasue we were running late and I was hungry, I ducked out and got lunch instead of going to the second talk... </p><p> For the afternoon, I took the easiest route and went for the session on Kwiki with Brian Ingerson. I probably would've decided differently if all of the talks weren't being recorded, but as it is, the other talks looked more formal and his looked more freeform. Sure enough, he started off by saying he was going to one-up Autrijus who wrote the first half of a talk on the train to the client's site, then wrote the second half during the intermission. </p><p>Ingy's talk had the first half written last night at 4am, and the second half was going to be written by us.</p><p> Sure enough, the first half he presented <a href="http://yapc.kwiki.org/kwiki-tutorial/start.html">slides</a> on the architecture of his freeform wiki. </p><p> The thing is entirely plugins based, and has interesting abilities to make plugins interact and do the Right Thing with the least amount of code. He invented a number of techniques from scratch, he says because he's too lazy to research how other people have done things. TIMTOWTDI, right? Yeah. The plan is for the design to be a lego set for perl hackers. </p><p>Stuff he wrote that he thinks is cool: 'spiffy': a source-filter that adds 'use warnings' and 'strict' and a trailing '1' to each package file, and 'my $self=shift' to each method (this is turned on if you 'use Spiffy qw( -Base )'. -base won't include those. mixins: anonymous class between base-class and current class. like in Ruby. allows for a simple inheritence chain. Allows you to wedge stuff to replace or enhance methods which were either defined or inherited from a parent-class. And, he wrote a program registry, which is shared between plugins, and has some funky interactions which make sense but I didn't write down how it works, sorry. </p><p> He decided, when the plugin modules started exploding in number (there are well over 100 now by over 10 main authors), that CPAN wasn't the optimal way to release, since dependencies and versions make things slow to install. Instead, he recommends checking out his svn.kwiki.org. </p><p> Interesting feature: 'kwiki -view [blah]' will create a new kwiki named blah, with its own configuration files, but whose data and metadata are symbolicly linked from the parent directory. So it's easy to set up an admin view with extra features. </p><p> Brian's not terribly excited by wikis; they were just a means to playing with these new ideas. Spiffy has universal improvements. Spoon is generic techniques that seem interesting outside Kwiki. and Kwiki is built on Spoon. </p><p> Spiffy has a function named 'xxx' which will die at that point and do a stack-trace and some sort of variable dump. </p><p> I asked about documentation, which is... sparse... and how one is to start learning this when everything is tied together so intimately. He pointed me at doolittle.kwiki.org, which is a wiki which incorporates all of the POD stripped from the live version; (and I believe, checks the POD back into the SVN for the files) when he releases to CPAN, he does a once-over of doolittle and it gets released along with. So the docs are written by the community. In theory. I haven't taken a look at it yet... </p><p> The second half was organized around a pair-programming session with him and Chris Dent, where they built a plugin to do tags, like Delicious. It seemed pretty straight-forward, though, I would have loved to have asked more questions about the bugs they worked through. However, I did learn a bunch about debugging kwiki. </p><p> Afterward, I met up with other kw.pm mongers, and agreed we'd meet at Simon's house later for beer and chat, and possibly coding. </p><p> I was going to precede that with an RT (request-tracker) BOF, which would've been useful for work, but they left before I could get myself sorted out. I'll have to meet Jesse Vincent later on. So instead, I rode around on a segway for a little bit. </p><p> So that was my afternoon. Listening to other peoples' afternoons, I'm glad I went for less-structured. Maybe I'll do the perl6 track on Tuesday. Dunno. </p><p> In the evening, Simon, Eric and I set up our laptops and started hacking on Bots and Kwiki. Shuchit, Arguile and Greg came a bit later, and we had really good pizza. </p><p> We saw a few Futurama episodes (including the Popplers one, yay) and took the train back.</p> da 2005-06-28T12:27:23+00:00 journal YAPC 05 http://use.perl.org/~da/journal/25383?from=rss OK, this will be an attempt to journal my thoughts about this year's YAPC. Non technical notes will go in my <a href="http://da-lj.livejournal.com/">livejournal</a>. Who knows whether I'll have time to keep up both; nor which one will get priority on a particular day. da 2005-06-27T16:58:49+00:00 journal Gig Grab Bag http://use.perl.org/~da/journal/22985?from=rss Since taking a full-time job last month, I've had a pile of smallish project-requests fall my way. I've been directing people to the perl jobs list, but I'd like to do better than that because these are all for friends or colleagues who I'd like to do the right thing by. <p> Please drop me email for contact information. Here's the top two gigs: </p><p> About one month's work cleaning up a batch of 20 scripts used by an IC fabrication plant. Lots of DBI. </p><p> Hand-holding and basic CGI for a website design firm in Vermont. Likely ongoing work in 10-20 hour chunks. My most recent project was building a mySQL membership directory, moving scripts from a windows to linux host, and "cleaning up" some awful CGI, but they didn't have time to pay me to rewrite the bad stuff from scratch.</p> da 2005-02-02T16:12:59+00:00 journal Nine Block Quilt Patterns http://use.perl.org/~da/journal/22024?from=rss I had fun today playing with GD.pm and quilting patterns. In "nine blocks" there are 9 squares, whose contents are limited to 16 basic patterns and radial symetry. <p> Here's a sample output: <a href="http://coder.com/daniel/photos/9block.png">3x3</a> </p><p> The idea comes from <a href="http://www.complexification.net/gallery/machines/nineblock/">this guy</a> who has done some amazing artistry with Flash programming. While he has open-sourced his code, I don't have access to Macromedia products so I built it from the specs on that web page. </p><p> I'm currently planning to print out a whole lot of them on a sheet of photographic paper, as a present for a quilter. </p><p> It's got problems with it, but it's a start.</p><blockquote><div><p> <tt>#!/usr/bin/perl<br># nineblocks.pl - create assorted quilt patterns using 16 graphical primitives<br>#&nbsp; &nbsp;and radial symetry.<br> <br>#&nbsp; &nbsp;Copyright (C) 2004 Daniel Allen.&nbsp; It is distributed under the same<br>#&nbsp; &nbsp;terms as Perl itself.&nbsp; See the "Artistic License" in the Perl<br>#&nbsp; &nbsp;source code distribution for licensing terms.<br> <br>#&nbsp; &nbsp;inspired by http://www.complexification.net/gallery/machines/nineblock/<br> <br>use warnings;<br>use strict;<br>use GD;<br> <br>my $XS = 20;&nbsp; &nbsp; # dimensions of squares in pixels<br>my $XN = $XS*5; # dimensions of nineblocks in pixels<br> <br>my $dim = 10;&nbsp; &nbsp; # number of squares wide/tall<br>my $border = $XN/2;<br> <br>my @squares = (<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;".5,1 1,1 1,.5",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;".5,.5<nobr> <wbr></nobr>.5,1 1,.5",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"0,0<nobr> <wbr></nobr>.5,.5 1,0",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"0,.5 1,.5,<nobr> <wbr></nobr>.5,0",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;".5,.5<nobr> <wbr></nobr>.5,1 1,1 1,.5",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;".25,.25<nobr> <wbr></nobr>.25,.75<nobr> <wbr></nobr>.75,.75<nobr> <wbr></nobr>.75,.25",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"0,1<nobr> <wbr></nobr>.5,1<nobr> <wbr></nobr>.5,.5 1,.5 1,0",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"0,.5 1,1<nobr> <wbr></nobr>.5,0",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"0,0<nobr> <wbr></nobr>.25,.5<nobr> <wbr></nobr>.5,0 1,0<nobr> <wbr></nobr>.75,.5<nobr> <wbr></nobr>.5,0",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # "0,0<nobr> <wbr></nobr>.25,.5<nobr> <wbr></nobr>.5,0 1,0<nobr> <wbr></nobr>.75,.5<nobr> <wbr></nobr>.5,0<nobr> <wbr></nobr>.5,1, +<nobr> <wbr></nobr>.25,.5<nobr> <wbr></nobr>.75,.5",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"0,0 0,.5 1,1<nobr> <wbr></nobr>.5,0",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;".5,0<nobr> <wbr></nobr>.5,1 1,1 1,0",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"0,.5<nobr> <wbr></nobr>.5,1 1,.5<nobr> <wbr></nobr>.5,0",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"0,0<nobr> <wbr></nobr>.5,1 1,0",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"0,1 1,1 1,0",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"0,0 1,0 1,1 0,1"<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);<br> <br>my @centers = (<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ".25,.25<nobr> <wbr></nobr>.25,.75<nobr> <wbr></nobr>.75,.75<nobr> <wbr></nobr>.75,.25",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "0,.5<nobr> <wbr></nobr>.5,1 1,.5<nobr> <wbr></nobr>.5,0",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "0,0 1,0 1,1 0,1"<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br> <br>my $image = new GD::Image($dim * $XN, $dim * $XN);<br>my $white = $image-&gt;colorAllocate(255,255,255); # background<br> <br>my $xpos = 0;<br>my $ypos = 0;<br> <br>OUT: while (1) {<br>&nbsp; &nbsp; my $block = &amp;nineblock(&amp;r(3), &amp;r(3), &amp;r(15), &amp;r(15), &amp;r(3));<br>&nbsp; &nbsp; $image-&gt;copy($block, $xpos, $ypos, 0, 0, $XN, $XN);<br>&nbsp; &nbsp; $xpos += $XN;<br>&nbsp; &nbsp; if ($xpos &gt; (($dim ) * $XN)) {<br>&nbsp; &nbsp; &nbsp; &nbsp; $xpos = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; $ypos += $XN;<br>&nbsp; &nbsp; &nbsp; &nbsp; if ($ypos &gt; (($dim ) * $XN)) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last OUT;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br> <br># nineblocks are at left-top corner of their background<br># (which might be useful for colored backgrounds, but not for white)<br>#<br># new background should be: + 2 * border - the total offset of each 9square<br> <br>my $background = new GD::Image($dim*$XN + 2*$border - 2*$XN/5,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$dim*$XN + 2*$border - 2*$XN/5);<br> <br>$white = $background-&gt;colorAllocate(255,255,255);<br>$background-&gt;copy($image, $border, $border, 0, 0, $dim * $XN, $dim * $XN);<br> <br>&amp;display($background);<br> <br>sub r {<br>&nbsp; &nbsp; my ($max) = @_;<br>&nbsp; &nbsp; int rand $max;<br>}<br> <br>sub nineblock {<br>&nbsp; &nbsp; # edgeRot&nbsp; &nbsp; &nbsp;= 0-3 ( times 90 degrees)<br>&nbsp; &nbsp; # cornerRot&nbsp; &nbsp;= 0-3<br>&nbsp; &nbsp; # edgeShape&nbsp; &nbsp;= 0-15<br>&nbsp; &nbsp; # cornerShape = 0-15<br>&nbsp; &nbsp; # centerShape = 0-3<br> <br>&nbsp; &nbsp; my ($edgeRot, $cornerRot, $edgeShape, $cornerShape, $centerShape) = @_;<br> <br>&nbsp; &nbsp; my $image = new GD::Image(3*$XS,3*$XS);<br>&nbsp; &nbsp; my $xpos = 0;<br> <br>&nbsp; &nbsp; my @face = (&amp;square($edgeRot,&nbsp; &nbsp;$squares[$edgeShape]),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;square($cornerRot, $squares[$cornerShape]));<br> <br>&nbsp; &nbsp; my $center = &amp;square(0, $centers[$centerShape]);<br> <br>&nbsp; &nbsp; $image-&gt;copy($center,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$XS, $XS, 0, 0, $XS, $XS);<br> <br>&nbsp; &nbsp; for (@face) {<br>&nbsp; &nbsp; &nbsp; &nbsp; my $square = $_;#6&amp;square($_);<br>&nbsp; &nbsp; &nbsp; &nbsp; # $destimage-&gt;copy(srcImage, destX, destY, srcX, srcY, width, height)<br>&nbsp; &nbsp; &nbsp; &nbsp; #<br>&nbsp; &nbsp; &nbsp; &nbsp; # $destimage-&gt;copyResized(srcImage, destX, destY, srcX, srcY,<br>&nbsp; &nbsp; &nbsp; &nbsp; #&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;destWidth, destHeight, srcWidth, srcHeight)<br> <br>&nbsp; &nbsp; &nbsp; &nbsp; my $max = (2*$XS - $xpos);<br>&nbsp; &nbsp; &nbsp; &nbsp; $image-&gt;copy($square, $xpos, 0, 0, 0, $XS, $XS);<br>&nbsp; &nbsp; &nbsp; &nbsp; $image-&gt;copy($square-&gt;copyRotate90, 2*$XS, $xpos, 0, 0, $XS, $XS);<br>&nbsp; &nbsp; &nbsp; &nbsp; $image-&gt;copy($square-&gt;copyRotate180, $max, 2*$XS, 0, 0, $XS, $XS);<br>&nbsp; &nbsp; &nbsp; &nbsp; $image-&gt;copy($square-&gt;copyRotate270, 0, $max, 0, 0, $XS, $XS);<br>&nbsp; &nbsp; &nbsp; &nbsp; $xpos += $XS;<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; return $image;<br>}<br> <br>sub square {<br>&nbsp; &nbsp; my ($rot, $points) = @_;<br> <br>&nbsp; &nbsp; my $image = new GD::Image($XS,$XS);<br> <br>&nbsp; &nbsp; my $polygon1 = new GD::Polygon;<br> <br>&nbsp; &nbsp; #my $white = $image-&gt;colorAllocate(&amp;r(255),0,&amp;r(255));<br>&nbsp; &nbsp; my $white = $image-&gt;colorAllocate(255,255,255);<br>&nbsp; &nbsp; my $black = $image-&gt;colorAllocate(&amp;r(255),0,&amp;r(255));<br>&nbsp; &nbsp; #my $black = $image-&gt;colorAllocate(0,0,0);<br> <br>&nbsp; &nbsp; &amp;add_points($polygon1, $points);<br> <br>&nbsp; &nbsp; $image-&gt;filledPolygon($polygon1, $black);<br>&nbsp; &nbsp; $image-&gt;flipVertical;<br>&nbsp; &nbsp; for (1<nobr> <wbr></nobr>.. $rot) {<br>&nbsp; &nbsp; &nbsp; &nbsp; $image = $image-&gt;copyRotate90;<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; return $image;<br>}<br> <br>sub add_points {<br>&nbsp; &nbsp; my ($poly, $points) = @_;<br> <br>&nbsp; &nbsp; foreach my $pair (split<nobr> <wbr></nobr>/\s/, $points) {<br>&nbsp; &nbsp; &nbsp; &nbsp; $pair =~<nobr> <wbr></nobr>/([\d.]+),([\d.]+)/;<br>&nbsp; &nbsp; &nbsp; &nbsp; $poly-&gt;addPt($1 * $XS, $2 * $XS);<br>&nbsp; &nbsp; }<br>}<br> <br>sub display {<br>&nbsp; &nbsp; my ($image) = @_;<br> <br>&nbsp; &nbsp; #&nbsp; &nbsp;'display' program provided with ImageMagick<br>&nbsp; &nbsp; open OUTFILE, "| display -" or die "couldn't open display";<br>&nbsp; &nbsp; print OUTFILE $image-&gt;png;<br>&nbsp; &nbsp; close OUTFILE;<br>}</tt></p></div> </blockquote> da 2004-11-27T03:59:26+00:00 journal I dodged a bullet today... http://use.perl.org/~da/journal/19080?from=rss This morning, I locked my keys in the car. On a hot day. With the dog also in the car. Due to Rover, though, I had the rear window cracked, so I successfully snagged the keys from the ignition with two coat-hangers attached together. <p> The timing was particularly bad, because I was on the way to pick up my sweetie at the airport, and was early enough that I figured I'd pick up lunch on the way. </p><p> Oops. </p><p> So, this evening, I feel I need to breathe a huge sigh of thanks that the first time I've ever done this, I did it with the window cracked open, so that I only inconvenienced myself for half an hour, instead of inconveniencing both of us for half a day while some tow-truck driver did their magick. </p><p> The learning experience this time seems to be: have backups. Preferably, a box with a good magnet stuck to the bottom of the car. And, of course, always check for keys before leaving the car.</p> da 2004-06-04T02:19:19+00:00 journal GD::Text::Arc http://use.perl.org/~da/journal/16964?from=rss <a href="http://search.cpan.org/~dallen/GD-Text-Arc-0.01/">GD::Text::Arc</a> is an addition to GD and GD::Text that simplifies drawing text on a curve. Sample output is <a href="http://coder.com/daniel/arc-sample.jpg">here</a>. It's not a terribly complicated module, in fact it's about 250 lines of code, but it does just what I want it to, so I'm happy. The most time-consuming part of the process was writing the 250 lines of documentation. <p> This was also my first foray into writing tests while I wrote code; that was just as useful as everyone says it is, so I think I'm a convert. Of course, I'm sure I need way more than 46 tests, but it's a fine first draft. </p><p> Now that I'm all puffed up with releasing my first CPAN module and stuff, I'd love for people to pick it apart and tell me what I did badly.<nobr> <wbr></nobr>:-)</p> da 2004-01-23T01:55:26+00:00 journal Can I get a stuffed bear too? http://use.perl.org/~da/journal/14671?from=rss I got some digital photos back from the local developer. On the inside flap of the Kodak envelope (emphasis added): <p> "Submitting any film, print, negative or <b> <em>digital image</em> </b> to our company<nobr> <wbr></nobr>... any damage or loss by our company<nobr> <wbr></nobr>... wlil only entitle you to <b> <em>replacement with a like amount of unexposed film and processing.</em> </b>" </p><p> Cool! No mention of digital media, just the image. Either that means they'll give me free reprints and a bunch of zeros, or they'll give me free reprints and a roll of film.</p> da 2003-09-12T14:00:40+00:00 journal Six signs http://use.perl.org/~da/journal/12126?from=rss <p>Signs that I should pass up on a project offer. This was a phone interview by the lead perl developer of $company.</p><p>1) He asked for a phone interview at 9:30pm (local timezone for both of us).</p><p>2) "We don't have funding for the project yet, but I'll know in the next two days. Can I interview you on Saturday?"</p><p>3) "We want to have this done in four weeks. How many hours are you available between now and then?"</p><p>4) $company was so secret he couldn't tell me the industry or size, "but it was big".</p><p>5) "how old are you?" (this interview question is still illegal in US and Canada).</p><p>At this point, I know I don't want the project, but maybe I knew somebody to recommend to him who likes this sort of atmosphere. Then comes:</p><p>6) "I'm thinking this could be a project for 3 people. But I might add a few more people if it looks like it isn't going fast enough."</p><p>As quickly and politely as I could, I removed myself from the conversation.</p> da 2003-05-12T02:42:35+00:00 journal Linux Journal http://use.perl.org/~da/journal/9774?from=rss Blah. Can't sleep, nervous energy. Been happening a lot lately. I can't say it's from job stress, since strictly speaking, I don't have one. (just a monotonically increasing number of projects). <p> This last week has been an interesting one, for the new projects I've added. </p><p> Last Monday I found myself volunteering to advise a Linux trainer who wants to host an "Intro to Linux" afternoon seminar for the larger local businesses, later this month. Ideally, I'll be useful during the Q&amp;A session afterward; and somebody will want to hire me for a software consulting gig. </p><p> Item number two- A while ago I sent an offer to the Linux Journal to write them a couple of articles, which I previously gave as talks to my local <a href="http://www.kwlug.org/">LUG</a> and <a href="http://kw.pm.org/">Perl Mongers</a> group. On Tuesday, much to my surprise, I got the go-ahead to write them. First is "11 Ssh Tricks". The second one is an intro article on the Perl Debugger. I probably have a month to write the first one.</p> da 2003-01-05T09:58:57+00:00 journal mapcar- not new, but new to me http://use.perl.org/~da/journal/8671?from=rss <tt>I overheard this on "Fun with Perl" today.&nbsp; The 'mapcar' ideom looks incredibly<br>useful for traversing more than one list at a time.<br><br>--------------<br>Date: Tue, 29 Oct 2002 14:24:13 -0500<br>From: Evan A. Zacks &lt;e@zacks.org&gt;<br>To: fwp@perl.org<br>Subject: Re: Iterating down two lists at the same time<br><br>On Tue, Oct 29, 2002 at 01:05:12 PM, Bernie Cosell wrote:<br><br>&gt; I was wondering if there's any fun to be found in elegant/clever ways to<br>&gt; traverse two lists at the same time...&nbsp; I envisioned something like:<br>&gt;&nbsp; &nbsp; map2 {stuff} \@list1, \@list2<br>&gt; where inside the map maybe you had $a and $b aliased appropriately<br>&gt; or something<br>&gt; like that.&nbsp; Or perhaps:<br>&gt;&nbsp; &nbsp; mapn {stuff} list-of-listrefs<br>&gt; where you aliased $1, $2, $3,<nobr> <wbr></nobr>... to the parallel entries from the different<br>&gt; lists...<br><br>Hello Bernie,<br><br>You may be interested in mapcar, a module written by Tye on Perlmonks:<br><br>&nbsp; &nbsp;http://www.perlmonks.org/index.pl?node_id=44763<br>&nbsp; &nbsp;http://www.perlmonks.org/index.pl?node_id=44763&amp;displaytype=displaycode<br><br>You call the mapcar function as you specified above:<br><br>&nbsp; &nbsp; use mapcar;<br><br>&nbsp; &nbsp; my @a= qw( foo bar baz&nbsp; );<br>&nbsp; &nbsp; my @b= qw( qux quux quo );<br><br>&nbsp; &nbsp; print mapcar { "@_\n" } \@a, \@b;<br><br>&nbsp; &nbsp; __END__<br>&nbsp; &nbsp; foo qux<br>&nbsp; &nbsp; bar quux<br>&nbsp; &nbsp; baz quo<br><br>Inside the block that you pass to mapcar, the two elements from<br>the lists you are traversing are stored in @_.<br><br>&gt;From Perlmonks:<br><br>&nbsp; &nbsp; mapcar is from lisp. It is like map but works on more than<br>&nbsp; &nbsp; one list. While map loops setting $_ to successive elements of a<br>&nbsp; &nbsp; list, mapcar loops setting @_ to successive elements of several<br>&nbsp; &nbsp; lists (but since you can only pass one list to a subroutine,<br>&nbsp; &nbsp; mapcar expects a list of references to one or more arrays). Both<br>&nbsp; &nbsp; map and mapcar collect the values returned by the code block or<br>&nbsp; &nbsp; subroutine and then return the collected values.<br><br>Hope this helps,<br>-E<br></tt> da 2002-10-30T01:47:41+00:00 journal Yapc 2002 photos http://use.perl.org/~da/journal/7146?from=rss Maybe better late than never, some <a href="http://coder.com/daniel/photos/yapc_2002">pictures from YAPC 2002</a>. See the knife-wielding Australian! See Pudge multitask, twice, once with a baby and once with a guitar! See me photograph R. Spier as he <a href="http://www.perl.org/yapc/2002/audio/interviews/day2/shuttle.wav.mp3">audio-records</a> us, while Gnat video-records me, and later R. Spier completes the cycle by impersonating Gnat in a well-received talk on optimization not meant for young ears. Be amazed and distressed at Larry Wall, much larger than life. <p> I guess that's all I've got to say. Sorry it took me 50 days, anyway.</p> da 2002-08-18T05:48:40+00:00 journal YAPC day 2 http://use.perl.org/~da/journal/6011?from=rss I don't have a journal entry for day one because day one, I spent my time hacking on some code that I promised would be done Monday. I like this wireless network. <p> Tuesday- </p><p> I actually left Brown 100; I went to Dave Rolsky's "Alzabo: Less SQL, more (Data Modelling and OO)" which is a project worth investigating. Alzabo is sort of an alternative to DBIx::RecordSet; it's a RBDMS data modeller, that also creates OO methods to manipulate the database. Cool looking stuff, and at least with HIS demos, it seemed to make hard stuff easy. Sort of worried by the program docs, where he says you should wrap Alzabo calls inside an 'eval'... </p><p> MJD's Tie::File talk is good. </p><p> Update after lunch... </p><p> "Something Something, Faster"- Robert Spier did an impression of gnat, which I have an excellent picture of (which I will upload tonight). </p><p> This was an Optimization talk gnat gave at OScon earlier this year. It took three hours then. Robert did it in 40 minutes. It was excellent. (more later).</p> da 2002-06-27T16:40:38+00:00 journal