Dec 31, 2009
Released pydelatt
Need to strip attachments from from maildir formatted mail files? Surprisingly there doesn't seem to be a convenient command-line tool to do just this... So I wrote pydelatt.
My ramblings on technology, programming, art, theology and whatever else strikes my fancy...
Dec 31, 2009
Need to strip attachments from from maildir formatted mail files? Surprisingly there doesn't seem to be a convenient command-line tool to do just this... So I wrote pydelatt.
Jul 06, 2009
After the recent reorganization I realised I had a little problem with my comments. Comments on this blog are provided by Disqus using their Javascript integration method. Disqus was a Y Combinator funded startup that uses Django to provide remote hosting for comments. They have an API to provide more advanced integration options and provide plugins and templates for specific enviroments like Wordpress and Blogger, but it's easy to just step through the "Generic Integration" option and paste a few Javascript snippets in your HTML. Voila - comment counts on links to specific posts and comments and a comment submission box at the bottom of each post.
Until I moved my urls around. I know, I know - cool urls shouldn't change! In my defense I'm using HTTP 301 redirects to catch the old urls and redirect to the new locations. At any rate Disqus uses the URL as the key to load a comment thread - so change the URL and you lose the attached comments.
This was no good - I didn't want to lose all 17 comments this blog has received - but I did want to take numeric PK's out of the url for blog posts and separate my tech blog from my personal/theology blog. A quick poke through the Javascript disqus provides showed how to keep comments working at their new locations.
The generic installation instructions has you add some javascript where you want the comments widget to appear:
<div id="disqus_thread"></div>
<script type="text/javascript" src="http://disqus.com/forums/metapundit/embed.js"></script>
<noscript><a href="http://metapundit.disqus.com/?url=ref">View the discussion thread.</a>
</noscript>
<a href="http://disqus.com" class="dsq-brlink">blog comments powered by
<span class="logo-disqus">Disqus</span></a>
This code doesn't have any obvious dependencies on the current location (it's referenced in the embed.js file) so we can't fix our problem. Fortunately the team at Disqus anticipated our problem and provided a few variables to customise the Javascript embed (see the JSEmbed docs for details). Adding a quick line of javascript defining a variable to the template for individual blog posts allows me to refer back to the old PK-style urls:
<script type="text/javascript">
var disqus_url = "http://metapundit.net/sections/blog/242";
</script>
The other problem is getting the comment count to show up on links to individual blog posts. Disqus lets you display this data by adding an identifying anchor (#disqus_thread) to the links you want modified and than add some more javascript to your post list page:
<script type="text/javascript">
<script type="text/javascript">
//<![CDATA[
(function() {
var links = document.getElementsByTagName('a');
var query = '?';
for(var i = 0; i < links.length; i++) {
if(links[i].href.indexOf('#disqus_thread') >= 0) {
query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
}
}
document.write('<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/metapundit/get_num_replies.js' + query + '"></' + 'script>');
})();
//]]>
</script>
This injects your comment count into the text of the link. Now that my links aren't pointing to the canonical location (as far as Disqus is concerned) I needed to modify the Javascript. Adding the old numeric key value to the id element of the links allowed me to make a minor modification:
if(links[i].href.indexOf('#disqus_thread') >= 0) {
query += 'url' + i + '=' + encodeURIComponent('http://metapundit.net/sections/blog/' + links[i].id.split("_")[1]) + '&';
}
and build the old url to send back to Disqus...
Jun 10, 2009
Lately I've been getting enthused about a couple of Firefox plugins. They're both raw but I think they both point to the way forward for the programmable web.
Ubiquity is basically a command line for the web - a way to apply "verbs" to user input and web pages. Sample usage (and built in commands) include a "map" command to quickly build a googlemap and insert it into, say, the html in your webmail interface. What's cooler is that it provides infrastructure to quickly build additions to the browser that before would have to be packaged as bookmarklets or Firefox extensions. In the case of extensions it's frequently not worth the trouble and bookmarklets provide a lousy UI and development experience.
Ubiquity comes with a built in editor and commands can be tried out live in the editor or installed without any restarting required. To be honest the ease of writing commands made me think of emacs - executing code in the same tool you're writing it without any sort of compile->execute cycle. I even quickly whipped up an unwrap command when I was repetitively pasting sql statements from mysqlbinlog in a console to phpMyAdmin to restore some damaged data. Newlines inserted by the console were messing up the sql statements and visually scanning each statement was error prone. 30 seconds after thinking about it I had a two line Ubiquity command up in the editor that allows me to select some text in a textbox and unwrap it...
Along the same lines is the other Firefox extension Jetpack. This is even more alpha - but perhaps even cooler than Ubiquity. Similarly Jetpack comes with it's own editor that allows you to run code or install Jetpack features without a restart. While Ubiquity aims at interacting with webpages, Jetpack aims at interacting with the browser and exposes an API to let you play with notifications, the status bar, tabs and includes JQuery to easily slice and dice html and access web API's. Want to write an extension that shows your unread GMail message count in the status bar? The Jetpack tutorial does this in 45 lines of code and you can execute the code as part of the tutorial and immediately see the message count display. I can see Jetpack giving Firefox's conventional plugin infrastructure a serious challenge - I've already replaced one of my plugins with a few lines of javascript in Jetpack and I'll release it after I've added a couple of features.
Jetpack reminds me even more strongly of my Emacs environment. Emacs is famously "the programmable editor" and until you've taken advantage of that environment you don't know what an advantage that is. Firefox, with the new speed improvements to its Javascript engine, and new and easier methods of adding programmable functionality is becoming the programmable browser.
May 23, 2009
You may notice (if you're visiting the site) that things are moved about. New menu entries appear, old ones disappear - but fear not! All the great blog content you've come to expect from the virtual pen of the metapundit is still here - it's just been dusted off and moved around a bit.
As threatened a bit ago I've split my blog up into two separate streams: a Tech Only Blog and a personal blog. If you're visiting the old url or subscribed to the old RSS feeds than things will continue to just work, but if you'd rather not hear Baypiggies reports and rants about PHP you can now subscribe to the personal RSS feed and not get any of the tech stuff. And of course you can subscribe to the Tech-Only RSS feed if my theological ramblings are starting to annoy you...
Do poke around - I've put up an essays section to link to the longer writing I've done and I'll try to keep it updated as I write more. I've also got some UI changes in the works to make it easier to find related content...
May 10, 2009
I added curiousprogrammer.wordpress.com to my emacs feed in bloglines after finding a cool tip that helps me out particularly with Django programming in Emacs.
One of the cool things about Emacs is that it's not just a text-editor, it's a whole ecosystem of code (or as the joke goes - a pretty cool operating system with a crappy built-in text editor). In exploring all the extensibility though - the built in major and minor modes, the many external modes available - it's easy to forget how much can be customised by setting a few variables.
I didn't even realise how much it was annoying me but the default way Emacs handles duplicate buffer names is kind of dumb. If you have multiple files with the same names the first buffer gets the filename and subsequent buffers get an index value. This isn't a problem in most editing tasks - you occasionally see a choice of switching between foo.py and foo.py<1> and have to remember which is which.
In most code editing I do I don't have many identically named files. Django, however, makes this a little more annoying - each django app I have open has it's own models.py, views.py and likely a urls.py file. When I'm working simultaneously in several apps at once it's confusing every time I go to switch buffers... Thanks to this post, however, I added the following lines to my .emacs:
(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse)
(setq uniquify-separator "/")
(setq uniquify-after-kill-buffer-p t)
(setq uniquify-ignore-buffers-re "^\\*")
And now see a choice between views.py/app1, views.py/app2, and views.py/app3 when switching buffers. Uniquify is comes with Gnu Emacs so there's nothing you need to install to scratch this particular itch.
Update: thanks to commenter Van Gale Van Gale for the catch - I added the necessary require line above. I also should have noted that this is built in on my Emacs 23 packaged by Ubuntu 8.10 - YMMV.