<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Matt Shelton &#187; perl</title>
	<atom:link href="http://www.mattshelton.net/tags/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattshelton.net</link>
	<description>scribbling geekery, things and stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 13:38:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Newseum: Today&#8217;s Front Pages</title>
		<link>http://www.mattshelton.net/2008/04/20/newseum-todays-front-pages/</link>
		<comments>http://www.mattshelton.net/2008/04/20/newseum-todays-front-pages/#comments</comments>
		<pubDate>Sun, 20 Apr 2008 21:42:31 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[lifehacks]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.mattshelton.net/?p=89</guid>
		<description><![CDATA[<p>Posted in <a href="http://www.mattshelton.net/topics/apple/" title="apple">apple</a><a href="http://www.mattshelton.net/topics/code/" title="code">code</a><a href="http://www.mattshelton.net/topics/lifehacks/" title="lifehacks">lifehacks</a></p>The other day, I caught a post on Signal Vs. Noise about using Automator in OS X to grab your favorite newspaper&#8217;s front pages from Newseum as PDFs and join them. This sounded like a great idea, so I set &#8230; <a href="http://www.mattshelton.net/2008/04/20/newseum-todays-front-pages/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The other day, I caught a <a href="http://www.37signals.com/svn/posts/970-newseum-todays-front-pages">post</a> on <a href="http://blogcabin.37signals.com/svn/">Signal Vs. Noise</a> about using <a href="http://www.apple.com/downloads/macosx/automator/">Automator</a> in OS X to grab your favorite newspaper&#8217;s front pages from <a href="http://www.newseum.org/todaysfrontpages/">Newseum</a> as PDFs and join them. This sounded like a great idea, so I set out to do just that.</p>
<p>Unfortunately for me, this particular workflow only works in OS X 10.5, and I have yet to upgrade my iMac past 10.4.11.</p>
<p>Undaunted, I replicated the same thing in perl. It turns out that the &#8220;Combine PDF Pages&#8221; automator action is a simple Python script. It looked semi-useful on its own, so I copied it from its normal home (<code>/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/</code>) to my personal bin directory for good measure. Perl source follows&#8230; please note that the &gt;&#8217;s are rendering as literal &amp;gt;&#8217;s. Silly Code Highlighter!</p>
<pre class="brush: perl; title: ; notranslate">#! /usr/bin/perl -w

use locale;
use strict;
use warnings;

#############################
#  [01-31]      [yyyy-mm-dd]
my ($day,       $date,      $tmpdir,              $tojoin) =
(`date +%d`, `date +%F`, '/Users/shelton/tmp', '');
chomp($day); chomp($date);

my ($join) =
(&quot;python /Users/shelton/bin/join.py -o '/Users/shelton/Desktop/$date.pdf'&quot;);

########################
# Define PDF Links Here
#
my (%papers) = (
# Boston Globe
0=&gt;&quot;http://www.newseum.org/media/dfp/pdf$day/MA_BG.pdf&quot;,
# Chicago Tribune
1=&gt;&quot;http://www.newseum.org/media/dfp/pdf$day/IL_CT.pdf&quot;,
# Buffalo News
2=&gt;&quot;http://www.newseum.org/media/dfp/pdf$day/NY_BN.pdf&quot;,
# NY Times
3=&gt;&quot;http://www.newseum.org/media/dfp/pdf$day/NY_NYT.pdf&quot;,
# Wall Street Journal
4=&gt;&quot;http://www.newseum.org/media/dfp/pdf$day/WSJ.pdf&quot;
);

######################################
# Loop through %papers
#  -&gt; Determine tmp output file
#  -&gt; Download the File
#  -&gt; Add file to string for join cmd
#
foreach my $page (sort(keys %papers)) {
my $output = &quot;&quot; . $tmpdir . &quot;/&quot; . $page . &quot;.pdf&quot;;
`wget -q -O $output $papers{$page}`;
$tojoin .= &quot;'&quot; . $output . &quot;' &quot;;
}

##################
# Join The Files!
#
`$join $tojoin`;

#############################
# Delete All Downloaded PDFs
#
foreach my $file (sort(keys %papers)) {
my $rm = &quot;&quot; . $tmpdir . &quot;/&quot; . $file . &quot;.pdf&quot;;
`rm -f $rm`;
}</pre>
<p>I suppose I could have picked more interesting papers (like, for instance, the <a href="http://www.newseum.org/todaysfrontpages/hr.asp?fpVname=BRA^PA_AH">Amazônia Hoje</a> from Belém, Brazil). I stuck to papers from my current and previous home towns (and the NYC area, because they have interesting papers). Boring? I know&#8230;</p>
<p>I run this daily from cron at about 7am. Of note, I also redirect all output of the script to /dev/null because the python script throws a ton of meaningless errors that don&#8217;t mar the output.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattshelton.net/2008/04/20/newseum-todays-front-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Perl Support for Google SyntaxHighlighter</title>
		<link>http://www.mattshelton.net/2008/01/28/testing-perl-support-for-google-syntaxhighlighter/</link>
		<comments>http://www.mattshelton.net/2008/01/28/testing-perl-support-for-google-syntaxhighlighter/#comments</comments>
		<pubDate>Mon, 28 Jan 2008 12:40:52 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[SyntaxHighlighter]]></category>

		<guid isPermaLink="false">http://www.mattshelton.net/2008/01/28/testing-perl-support-for-google-syntaxhighlighter/</guid>
		<description><![CDATA[<p>Posted in <a href="http://www.mattshelton.net/topics/code/" title="code">code</a></p>I&#8217;ve been enjoying playing with Google&#8217;s SyntaxHighlighter. Another user came up with a Perl brush file, so I thought I&#8217;d give it a shot. One note from the author of the brush file is that -&#62; gets converted to -&#38;gt; &#8230; <a href="http://www.mattshelton.net/2008/01/28/testing-perl-support-for-google-syntaxhighlighter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been enjoying <a href="http://www.mattshelton.net/2007/12/13/code-highlighting-with-googles-syntaxhighlighter/">playing with Google&#8217;s SyntaxHighlighter</a>. Another <a href="http://opticalgarbage.com/sh/">user</a> came up with a Perl brush file, so I thought I&#8217;d give it a shot. One note from the author of the brush file is that -&gt; gets converted to -&amp;gt; rather than being translated properly. It&#8217;s definitely the highlighter that does it, too, because when you disable the brush it shows up properly.</p>
<pre class="brush: perl; title: ; notranslate">#!/usr/bin/perl

use strict;
use Mail::Box::Manager;

#################################
# User Variables
#
# Set $password to your password (encoded):
# . only the low four bits of each character count
# . character 0x3f gets split into 0x?3 and 0x?f,
# . fill in the ?'s with anything you like
# . man ascii =)
#

my $server = 'pop.server.name';
my $username = 'username';
my $password = 'tSvx6!f&gt;v7V%d=fU'; # the word &quot;ChangeMe&quot; encoded

#################################
# Get em!
#

my $mgr = Mail::Box::Manager-&gt;new;
my $pop = $mgr-&gt;open(type =&gt; 'pop3',
username =&gt; $username,
password =&gt; decodePassword($password),
server_name =&gt; $server);

my @messages = $pop-&gt;messages;

print
&quot; 33[00;30;1m: 33[00;36m: 33[00;36;1m: &quot;, scalar @messages, &quot; messages in mailbox : 33[00;36m: 33[00;30;1m: 33[mn&quot;;

foreach my $message (@messages) {
	my $fr = $message-&gt;get('From');
	$fr =~ s/s+&lt; .*$//; $fr =~ s/&quot;//g;

	printf &quot; 33#7 33[1m %-28.28s %-45.45s 33[0mn&quot;, $fr, $message-&gt;get('Subject');
	my $lbls = $message-&gt;labels;
	while( my ($k, $v) = each %$lbls ) {
		print &quot;key: $k, value: $v.n&quot;;
	}
}

$pop-&gt;close;

#################################
# methods
#

sub decodePassword($) {
	my ($password_split) = @_;
	my $password = &quot;&quot;;
	my ($high, $low);

	$password_split = reverse($password_split);
	while (length($password_split) &gt; 1) {
		$high = (ord(chop($password_split)) &amp; 0xf) &lt; &lt; 4;
		$low = ord(chop($password_split)) &amp; 0xf;
		$password .= chr($high|$low);
	}

	return $password;
}</pre>
<p>About three years ago I was living in the shell. I had a script aliased to &#8216;m&#8217; that would run a perl script for each of my IMAP accounts and show me all of the unread messages. The script had been originally written by a fellow Help Desk supervisor at UB and then given colorization support by another fellow supervisor, <a href="http://drakkhen.net/">Doug</a>, who has since become a perl and python guru.</p>
<p>The trouble then was that, while this worked for my home email server, I had to change some of the socket code to work on all of the other IMAP servers I used. That wasn&#8217;t too tough since IMAP is a relatively straightforward protocol. Getting POP support to work looked to be a lot harder, however. I couldn&#8217;t find anyone that had written something similar for me to hack, so I wrote my own.</p>
<p>This script above uses the perl module Mail::Box which installs straight out of CPAN. It&#8217;s probably been updated since this was written, and I don&#8217;t even know if the script still works (who still uses POP??)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattshelton.net/2008/01/28/testing-perl-support-for-google-syntaxhighlighter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

