Fletch's Journal http://use.perl.org/~Fletch/journal/ Fletch'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:24:13+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 Fletch's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~Fletch/journal/ Textmate command line launcher for zsh http://use.perl.org/~Fletch/journal/38670?from=rss <p> Because I really miss being able to <tt>gnuclient +23 foo</tt> (for which there at least is <tt>mate --line 23 foo</tt>) or <tt>vim +/pat bar</tt> (which <tt>mate</tt> can't do) I whipped this up. Maybe someone will find it useful. </p><blockquote><div><p> <tt>##<br>## ma -- textmate launcher that works like 'vi +line file' or 'vi +/re file'<br>##<br>ma () {<br>&nbsp; emulate -L zsh<br>&nbsp; setopt extended_glob<br> <br>&nbsp; local line="" column="" url="txmt://open?url=" term=""<br>&nbsp; local usage="usage: ma [+line[:col]] file"<br> <br>&nbsp; if (( # == 0 )) ; then<br>&nbsp; &nbsp; print "$usage"<br>&nbsp; &nbsp; return 1<br>&nbsp; fi<br> <br>&nbsp; if [[ "$1" = (#b)+([0-9]##)(:([0-9]##)#)# ]] ; then<br>&nbsp; &nbsp; shift ## eat $1<br>&nbsp; &nbsp; line="$match[1]"<br>&nbsp; &nbsp; [[ -n "$match[3]" ]] &amp;&amp; column="$match[3]"<br>&nbsp; elif [[ "$1" = (#b)+/(*) ]] ; then<br>&nbsp; &nbsp; shift<br>&nbsp; &nbsp; local term="$match[1]"<br>&nbsp; fi<br> <br>&nbsp; if [[ -z "$1" ]] ; then<br>&nbsp; &nbsp; print "$usage"<br>&nbsp; &nbsp; return 1<br>&nbsp; fi<br> <br>&nbsp; file="$1" ; shift<br>&nbsp; [[ "$file" !=<nobr> <wbr></nobr>/* ]] &amp;&amp; file="${PWD}/$file"<br> <br>&nbsp; if [[ -n "$term" ]] ; then<br>&nbsp; &nbsp; local -a maybe_line<br>&nbsp; &nbsp; maybe_line=( "${(s,:,)$(perl -lne 'BEGIN{$p=shift;$p=qr/($p)/}if(<nobr> <wbr></nobr>/$p/ ){$c=$-[1]+1;print "$.:$c";exit 0}END{exit 1;}' -- "$term" "$file")}" )<br>&nbsp; &nbsp; if [[ -z "$maybe_line" ]] ; then<br>&nbsp; &nbsp; &nbsp; print "No match for '$term' found in '$file'"<br>&nbsp; &nbsp; &nbsp; return 1<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; line="$maybe_line[1]"<br>&nbsp; &nbsp; &nbsp; column="$maybe_line[2]"<br>&nbsp; &nbsp; fi<br>&nbsp; fi<br> <br>&nbsp; url="${url}file:///$file"<br> <br>&nbsp; [[ -n "$line" ]] &amp;&amp; url="${url}&amp;line=$line"<br>&nbsp; [[ -n "$column" ]] &amp;&amp; url="${url}&amp;column=$column"<br> <br>&nbsp; open "$url"<br>}<br> <br>ma "$@"</tt></p></div> </blockquote> Fletch 2009-03-20T15:13:46+00:00 journal 4 years, 3 months, 6 days http://use.perl.org/~Fletch/journal/37156?from=rss <p>Give or take, as the rough DateTime::Duration calculation flies.</p><p>Long time, no post.</p><p>So . . . here's a post.</p> Fletch 2008-08-11T17:15:03+00:00 journal Class::DBI::Pg and multi-column primary keys http://use.perl.org/~Fletch/journal/18634?from=rss <p>This will let <tt>Class::DBI::Pg</tt> deal with tables which have a primary key consisting of more than one column (<i>e.g.</i> <tt>CREATE TABLE foo ( a integer, b integer, PRIMARY KEY ( a, b ) )</tt>) </p><p> Patch sent to author as well, but just in case anyone else is interested . . . </p><blockquote><div><p> <tt>---<nobr> <wbr></nobr>/usr/lib/perl5/site_perl/5.8.0/Class/DBI/Pg.pm&nbsp; &nbsp; &nbsp; 2003-09-10 03:59:40.000000000 -0400<br>+++ Class/DBI/Pg.pm&nbsp; &nbsp; &nbsp;2004-05-05 13:53:57.000000000 -0400<br>@@ -23,7 +23,7 @@<br> WHERE relname = ?)<br> SQL<br>&nbsp; &nbsp; &nbsp;$sth-&gt;execute($table);<br>-&nbsp; &nbsp; my $prinum = $sth-&gt;fetchrow_array;<br>+&nbsp; &nbsp; my @prinums = split(<nobr> <wbr></nobr>/\s+/, ( $sth-&gt;fetchrow_array )[0] );<br>&nbsp; &nbsp; &nbsp;$sth-&gt;finish;<br> <br>&nbsp; &nbsp; &nbsp;# find all columns<br>@@ -50,17 +50,17 @@<br>&nbsp; &nbsp; &nbsp;$sth-&gt;finish;<br>&nbsp; &nbsp; &nbsp;my($sequence) = $nextval_str =~ m/^nextval\('"?([^"']+)"?'::text\)/;<br> <br>-&nbsp; &nbsp; my(@cols, $primary);<br>+&nbsp; &nbsp; my(@cols, @primary);<br>&nbsp; &nbsp; &nbsp;foreach my $col(@$columns) {<br>&nbsp; &nbsp; &nbsp; &nbsp; # skip dropped column.<br>&nbsp; &nbsp; &nbsp; &nbsp; next if $col-&gt;[0] =~<nobr> <wbr></nobr>/^\.+pg\.dropped\.\d+\.+$/;<br>&nbsp; &nbsp; &nbsp; &nbsp; push @cols, $col-&gt;[0];<br>-&nbsp; &nbsp; &nbsp; &nbsp;next unless $prinum &amp;&amp; $col-&gt;[1] eq $prinum;<br>-&nbsp; &nbsp; &nbsp; &nbsp;$primary = $col-&gt;[0];<br>+&nbsp; &nbsp; &nbsp; &nbsp;next unless @prinums &amp;&amp; grep $col-&gt;[1] eq $_, @prinums;<br>+&nbsp; &nbsp; &nbsp; &nbsp;push @primary, $col-&gt;[0];<br>&nbsp; &nbsp; &nbsp;}<br>-&nbsp; &nbsp; _croak("$table has no primary key") unless $primary;<br>+&nbsp; &nbsp; _croak("$table has no primary key") unless @primary;<br>&nbsp; &nbsp; &nbsp;$class-&gt;table($table);<br>-&nbsp; &nbsp; $class-&gt;columns(Primary =&gt; $primary);<br>+&nbsp; &nbsp; $class-&gt;columns(Primary =&gt; @primary);<br>&nbsp; &nbsp; &nbsp;$class-&gt;columns(All =&gt; @cols);<br>&nbsp; &nbsp; &nbsp;$class-&gt;sequence($sequence) if $sequence;<br> }</tt></p></div> </blockquote> Fletch 2004-05-05T20:12:10+00:00 journal Changing OS X Location from the command line http://use.perl.org/~Fletch/journal/18070?from=rss <p> Found out about <tt>scselect</tt> yesterday from <a href="http://www.kernelthread.com/mac/osx/tools.html">here</a>. A couple of minutes effort on the train and I now can change from a shell without having to mouse up to the apple menu. </p><p> <a href="http://www.zsh.org/"> <tt>zsh</tt> </a>++</p><blockquote><div><p> <tt>##<br>## _scselect -- Completion for OS X Network Location utility<br>##<br>_scselect () {<br>&nbsp; &nbsp; local locs<br>&nbsp; &nbsp; locs=( $( scselect |&amp; \<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; perl -lne 'next if/^\S/;/\(([^)]+)\)/&amp;&amp;print qq{"$1"}' ) )<br>&nbsp; &nbsp; _arguments -C "*:Network Location Set:($locs)"<br>}</tt></p></div> </blockquote> Fletch 2004-03-26T12:58:03+00:00 journal iLife 04 first impressions http://use.perl.org/~Fletch/journal/16866?from=rss <ul> <li>GarageBand Consumer grade <a href="http://www.propellerheads.se/products/reason/index.cfm">Reason</a>; looks interesting. </li><li>iPhoto <em>Much</em> more responsive (loading pictures, rotating).</li><li>iDVD Neat new themes, the new slideshow transitions look neat (haven't burned to look on TV yet but . .<nobr> <wbr></nobr>.), and the map/overview looks like it'll be useful.</li><li>iMovie Didn't really poke at this yet. Pulling in the holiday video's the weekend project.</li></ul> Fletch 2004-01-17T04:18:33+00:00 journal Mac::Carbon on Panther http://use.perl.org/~Fletch/journal/15415?from=rss <p> Just to save some other person some googling: </p><p> <a href="http://groups.google.com/groups?q=I_POLL+group:perl.macosx&amp;hl=en&amp;lr=&amp;ie=UTF-8&amp;oe=utf-8&amp;group=perl.macosx&amp;selm=487F4EE0-0580-11D8-987A-000A95AF9180%40apple.com&amp;rnum=1">You need to undef <tt>I_POLL</tt> </a> </p> Fletch 2003-10-27T17:34:18+00:00 journal Waiting for Panther http://use.perl.org/~Fletch/journal/15389?from=rss <p> Memo to myself: Next OS release bring chair. Mall tile floor is not the most comfortable. </p> Fletch 2003-10-24T23:27:19+00:00 journal nosleep 'till Brooklyn http://use.perl.org/~Fletch/journal/14582?from=rss <p> Or at least until that long running <tt>wget</tt> completes. This will temporarily set the OS X energy saver sleep timer to `never', run the specified command, and then restore the sleep time. </p><blockquote><div><p> <tt>#!/usr/bin/perl<br>##<br>## nosleep -- Disable sleep while command runs (OS X)<br>##<br>use warnings;<br>use strict;<br> <br>my @pm_set_cmd = qw( pmset sleep );<br> <br>unshift @pm_set_cmd, 'sudo' unless $&gt; == 0; ## Setting needs root privs<br> <br>## Figure out what sleep's set to<br>my $old_sleep = undef;<br> <br>open( GET, "pmset -g live |" ) or die "Can't open pipe from pmset -g: $!\n";<br> <br>while( &lt;GET&gt; ) {<br>&nbsp; if(<nobr> <wbr></nobr>/sleep\s+(\d+)/ ) {<br>&nbsp; &nbsp; $old_sleep = $1;<br>&nbsp; &nbsp; last;<br>&nbsp; }<br>}<br> <br>close( GET );<br> <br>die "Couldn't determine current sleep setting.\n" unless defined $old_sleep;<br> <br>my $ret;<br> <br>## Set sleep to 0 (never)<br>$ret = system( @pm_set_cmd, 0 );<br>die "Problem setting sleep: @{[ $? &gt;&gt; 8 ]}\n" unless $ret == 0;<br> <br>## Run command passed as argument<br>$ret = system( @ARGV );<br>warn "Problem running command: @{[ $? &gt;&gt; 8 ]}\n" unless $ret == 0;<br> <br>## Revert to old sleep value<br>$ret = system( @pm_set_cmd, $old_sleep );<br>die "Problem setting sleep: @{[ $? &gt;&gt; 8 ]}\n" unless $ret == 0;<br> <br>exit 0;<br> <br>__END__<br>You may wish to add something along these lines to your<nobr> <wbr></nobr>/etc/sudoers:<br> <br>Cmnd_Alias&nbsp; &nbsp; &nbsp; PMSET =<nobr> <wbr></nobr>/usr/bin/pmset sleep [0-9]*<br>%admin&nbsp; ALL=(ALL) ALL, NOPASSWD: PMSET</tt></p></div> </blockquote> Fletch 2003-09-08T15:16:25+00:00 journal Handy SSL CA Articles http://use.perl.org/~Fletch/journal/10938?from=rss <p> Two handy ORA onlamp.com articles you may not have seen: </p><ul> <li> <a href="http://www.onlamp.com/pub/a/onlamp/2003/02/06/linuxhacks.html"> Creating your own Certificate Authoritiy</a> </li><li> <a href="http://www.onlamp.com/pub/a/onlamp/2003/02/20/linuxhacks.html"> Getting browsers to recognize same</a> </li></ul><p>Now I don't have to remember what box I book marked those on . . .<nobr> <wbr></nobr>:)</p> Fletch 2003-03-07T16:00:17+00:00 journal Socks http://use.perl.org/~Fletch/journal/9882?from=rss <p> Last night I bought some socks at <a href="http://www.bjs.com/">a warehouse store</a> because the wife has been complaining about the lack of structural integrity of my present hosiery. </p><p> At any rate; 12 pair, 9$US, in a plastic bag. A plastic bag with a recloseable zipper seal. </p><p> Socks. In a ziplock bag. This means something. Possibly that ziplock bags are available off the shelf and were the most convenient way to package 12 socks. Or that I should be keeping my socks in the vegetable crisper in the fridge. </p> Fletch 2003-01-10T14:43:57+00:00 journal Interesting Web Services Application http://use.perl.org/~Fletch/journal/8773?from=rss <p> <a href="http://allconsuming.net/">All Consuming</a> grobbles throughthe sites listed in <a href="http://weblogs.com/">weblogs.com</a> for links to books on Amazon and then makes lists of the most blog'd about ones. </p><p> See the site for <a href="http://allconsuming.net/#whatisthis"> a more complete explanation.</a> </p> Fletch 2002-11-05T18:53:41+00:00 journal My mind is going, Dave . . . http://use.perl.org/~Fletch/journal/8682?from=rss <p>I've now forgotten my headphones at home for the third day in a row. Usually they stay at work, but last week someone was using my office and I was working from home so I took them home. I keep remembering that I've forgotten them when I'm sitting in the car or when I've already gotten to the office. </p> Fletch 2002-10-30T14:51:53+00:00 journal Testing from Emacs http://use.perl.org/~Fletch/journal/8601?from=rss <p>Just trying out the <a href="/article.pl?sid=02/10/25/007222">new toy</a> which <a href="/~jjohn/">Mr. Johnston</a> has provided. </p><p> Maybe now I might even write more often. Heh. </p> Fletch 2002-10-25T15:34:07+00:00 journal Testing new upj_post http://use.perl.org/~Fletch/journal/7785?from=rss <p>I'm sure Pudge loves me now that I've created and deleted about 5-6 quick garbage entries trying to get this working. </p><p>At any rate, now I can just run <tt>upj_post -s Subject -e</tt> and it'll pop up an emacs window with a template post. </p><p> <b>Update:</b> Fooie on <tt>upj_post</tt>, long live <tt>journal_client</tt>. </p> Fletch 2002-09-17T18:27:39+00:00 journal zoo.pl + GraphViz = useless neat maps http://use.perl.org/~Fletch/journal/7654?from=rss <p>ISAGN. OK, maybe not a <b>great</b> need, but it'd be interesting to map out friends and fans. If only there were a SOAP interface to grab things (not that I need an excuse to justify having bought Torgo's book). </p> Fletch 2002-09-10T14:27:33+00:00 journal Clicks-and-mortar gripe http://use.perl.org/~Fletch/journal/5794?from=rss <p> <a href="http://www.compusa.com/">CompUSA</a> gets it, but <a href="http://bn.com/">B&amp;N</a> doesn't. </p><p> At the former, when looking at a product you can enter a zip code and it'll show you the nearest <i>n</i> stores and if they have it in stock or not. Really annoying, since the store closes in about 30 minutes and I'd really like to see if they have <a href="http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?isbn=0312890184">what I'm interested in</a> in stock before bothering running over there (as for why not just order it, I'm on vacation and it wouldn't get here before I left). </p> Fletch 2002-06-20T01:24:28+00:00 journal Test journal entry http://use.perl.org/~Fletch/journal/4250?from=rss <p>Just checking out the SOAP interface</p><p>These aren't the droids you're looking for.</p><p>rjray++</p> Fletch 2002-04-16T17:12:50+00:00 journal Ancient code still (mostly) works http://use.perl.org/~Fletch/journal/3348?from=rss <p> I just got the four year old code from <a href="http://www.samag.com/documents/s=1287/sam03030011/"> my TPJ article</a> working with only one (cosmetic) bug and a few configuration tweaks. Woohoo. </p> Fletch 2002-03-07T15:22:24+00:00 journal Foop. http://use.perl.org/~Fletch/journal/17?from=rss <p>This is my first journal entry.</p><p>There are many like it, but this one is mine.</p> Fletch 2001-04-09T16:59:08+00:00 journal