tags/perlbloghttp://blog.spang.cc/tags/perl/blogikiwiki2010-04-12T05:23:41Zshortening URLs in barnowlhttp://blog.spang.cc/posts/shortening_URLs_in_barnowl/Christine Spang2010-04-12T05:23:41Z2010-04-12T05:23:41Z
<p>I post to <a href="http://identi.ca/">identica</a> through
<a href="http://barnowl.mit.edu/">BarnOwl</a> using
<a href="http://github.com/nelhage/barnowl-twitter">Nelson's Twitter extension</a>.
This generally means I want to shorten URLs in my posts ("dents" as
they're called on identica) so it's easier to fit them into the
140-character limit.</p>
<p>Luckily, BarnOwl can be extended using Perl, which, combined with some
libraries from <a href="http://cpan.org/">CPAN</a>, makes this task simple.
Here's the snippet I wrote:</p>
<pre><code>package ShortenURLs;
use BarnOwl::Editwin qw(:all);
use Text::FindLinks;
use WWW::Shorten 'Bitly', qw(:short);
my $bitly_username = 'YOUR_BITLY_USERNAME_HERE';
my $bitly_apikey = 'YOUR_BITLY_APIKEY_HERE';
sub shorten_urls {
my $text = save_excursion {
move_to_buffer_start();
set_mark();
move_to_buffer_end();
get_region();
};
my $linkified_text = Text::FindLinks::markup_links(
text => $text,
handler => sub {
my ($url, $before, $after) = @_;
my $short_link = q{};
# hack around Text::FindLinks including trailing )
# characters in URLs, which 99% of the time I don't
# want, since it probably means I've surrounded the
# link in parens
if ($before =~ m/\($/ && $url =~ m/\)$/) {
$url =~ s/\)$//;
$short_link .= ")";
}
return short_link($url, $bitly_username, $bitly_apikey).$short_link;
},
);
move_to_buffer_start();
set_mark();
move_to_buffer_end();
replace_region($linkified_text);
}
BarnOwl::new_command('shorten-urls' => \&shorten_urls);
BarnOwl::bindkey(edit => 'C-l' => command => 'shorten-urls');
1;
</code></pre>
<p>You'll need a <a href="http://bit.ly">bit.ly</a> account, and to enter your username and
API key from that account in the relevant locations. Paste the snippet into
e.g. <code>~/.owl/barnowl-shortenurls.pl</code>, and add <code>require
"$ENV{HOME}/.owl/barnowl-shortenurls.pl";</code> to your
<code>~/.owlconf</code>.</p>
<p>It has a sort of ridiculous dependency chain that I am too lazy to cull,
which you'll need to install, probably using <code>cpan</code>. I
recommend using <code>local::lib</code> if you're installing without
root. (I found
<a href="http://perl.jonallen.info/writing/articles/install-perl-modules-without-root">this</a>
to be a pretty good walkthrough). Installing WWW::Shorten::Bitly and
Text::FindLinks should pull in all relevant dependencies.</p>
<p>And that's it! Hit C-l in the editwin and all the links in it will be
replaced with shortened versions.</p>
Prophet and SD 0.70http://blog.spang.cc/posts/Prophet_and_SD_0.70/2009-08-26T19:37:01Z2009-08-26T19:37:01Z
<p><a href="http://blog.fsck.com/">Jesse Vincent</a> and I just pushed a first release
of <a href="http://syncwith.us/">Prophet and SD</a> which is what I've been hacking
on for all of this summer and half of last.</p>
<p>Jesse summarises Prophet and SD well:</p>
<blockquote><p>Prophet is a lightweight schemaless database designed for peer to peer
replication and disconnected operation. Prophet keeps a full copy of
your data and (history) on your laptop, desktop or server. Prophet
syncs when you want it to, so you can use Prophet-backed applications
whether or not you have network.</p>
<p>SD (Simple Defects) is a peer-to-peer issue tracking system built on
top of Prophet. In addition to being a full-fledged distributed bug
tracker, SD can also bidirectionally sync with your RT, Hiveminder,
Trac, GitHub or Google Code issue tracker.</p></blockquote>
<p><a href="http://syncwith.us/">Website here</a>,
<a href="http://blog.bestpractical.com/2009/08/prophet-and-sd-07-cavil-are-now-available.html">full announcement here</a>
.</p>
<p>All the missing core dependencies have been uploaded to Debian and made
it through NEW; Prophet and SD packages will come shortly (1-2 days,
likely).</p>
<p>Debian folks may also be wondering when SD will support syncing with
debbugs (at least one of you have asked me already). The answer is
"eventually, but maybe sooner if you want to help". I started
sketching out a debbugs foreign replica type last summer, but it's
fallen off my radar since. I also spoke with <a href="http://liw.iki.fi/">Lars</a>
and <a href="http://www.donarmstrong.com/">Don</a> at DebConf9 about their
ideas for a
<a href="http://blog.liw.fi/posts/bug-exchange-format/">Bug exchange format</a>,
which might be worth waiting for debbugs to support.</p>
<p>However, this afternoon I felt inspired to poke around at the old
skeleton again and started making some changes. I'll hopefully push a
debbugs feature branch that is at least closer in the next couple days,
depending on how far I get. Talk to me if you're interested in lending a
hand.</p>