<?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>Brett Terpstra &#187; Code</title> <atom:link href="http://brettterpstra.com/category/code/feed/" rel="self" type="application/rss+xml" /><link>http://brettterpstra.com</link> <description>Elegant solutions to complex problems.</description> <lastBuildDate>Wed, 28 Jul 2010 14:27:33 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=6792</generator> <item><title>Single-keystroke Instapaper in Google Reader</title><link>http://brettterpstra.com/2010/07/28/single-keystroke-instapaper-in-google-reader/</link> <comments>http://brettterpstra.com/2010/07/28/single-keystroke-instapaper-in-google-reader/#comments</comments> <pubDate>Wed, 28 Jul 2010 14:02:05 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[extension]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[safari 5]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=836</guid> <description><![CDATA[This was a quick plugin I put together last night when I got too frustrated to work on my actual jobs. It lets you define a single shortcut key which, after you input your Instapaper username and password, will let you send the currently-selected article in Google Reader straight to Instapaper. It works fine with themes like Helvetireader (Safari extension),&#8230;<ul><li><a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/" rel="bookmark">Instapaper Beyond for Safari!</a></li><li><a href="http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/" rel="bookmark">Instapaper Beyond: fix for text style controls</a></li><li><a href="http://brettterpstra.com/2010/03/20/updated-songza-lucky-link-service/" rel="bookmark">Updated: Songza Lucky Link Service</a></li></ul> ]]></description> <content:encoded><![CDATA[<p><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/07/greaderinstapapericon.jpg" alt="GReader Instapaper Icon" title="GReader Instapaper Icon" width="200" height="200" class="alignright size-full wp-image-838 noshadow" />This was a quick plugin I put together last night when I got too frustrated to work on my actual jobs. It lets you define a single shortcut key which, after you input your <a href="http://www.instapaper.com/">Instapaper</a> username and password, will let you send the currently-selected article in <a href="http://www.google.com/reader/">Google Reader</a> straight to Instapaper. It works fine with themes like <a href="http://helvetireader.com/">Helvetireader</a> (<a href="http://kirindave.tumblr.com/post/675464589/safari-5-port-of-helvetireader">Safari extension</a>), and functions in both list view and expanded view.</p><p>Click below to download, unzip the extension and double click it to install. Head for <strong>Preferences-&gt;Extensions</strong> and set up your Instapaper username and password, and pick a hotkey. The default hotkey is “i”, which doesn’t interfere with existing Google shortcuts. Tailor to taste.</p><p>The only issue I’m having right now is that it doesn’t fail properly if you have an incorrect user/pass combination. It tells you it succeeded, but doesn’t post to your account. I’ll have to add a verification step at some point in the process. For now, if things aren’t showing up in Instapaper for you, check your username and password in the Extensions preferences. Be sure to check out <a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/">Instapaper Beyond</a>, too!</p><h4>Download:</h4><p class="download_desc"><a href="http://brettterpstra.com/downloads/GReaderInstapaper.0.1.zip" title="Download GReader Instapaper (322)"><img src="http://cdn.brettterpstra.com/wp-content/uploads/downloads/thumbnails/2010/07/icon.png" alt="download image for GReader Instapaper" width="64" height="64" /></a><a href="http://brettterpstra.com/downloads/GReaderInstapaper.0.1.zip" title="Download GReader Instapaper (322)">GReader Instapaper</a> — Adds single-keystroke sending of the current article in Google Reader to your Instapaper account. <a href="http://brettterpstra.com/2010/07/28/single-keystroke-instapaper-in-google-reader/">More Info</a></p><ul><li><a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/" rel="bookmark">Instapaper Beyond for Safari!</a></li><li><a href="http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/" rel="bookmark">Instapaper Beyond: fix for text style controls</a></li><li><a href="http://brettterpstra.com/2010/03/20/updated-songza-lucky-link-service/" rel="bookmark">Updated: Songza Lucky Link Service</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/07/28/single-keystroke-instapaper-in-google-reader/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>Instapaper Beyond 1.8.9</title><link>http://brettterpstra.com/2010/07/26/instapaper-beyond-1-8-9/</link> <comments>http://brettterpstra.com/2010/07/26/instapaper-beyond-1-8-9/#comments</comments> <pubDate>Mon, 26 Jul 2010 13:31:29 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[extension]]></category> <category><![CDATA[instapaper]]></category> <category><![CDATA[instapaper beyond]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[safari 5]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=832</guid> <description><![CDATA[Instapaper Beyond version 1.8.9 is another small release with a couple of usability enhancements. Thanks to everyone who's been submitting ideas and bugs, I'll do my best to keep up! This release includes: Alphabetical sorting of the help HUD (A-Z,a-z) Edit a bookmark with "E" (Shift-E) you can tab through the fields and submit with Enter, returning you to your&#8230;<ul><li><a href="http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/" rel="bookmark">Instapaper Beyond: fix for text style controls</a></li><li><a href="http://brettterpstra.com/2010/07/25/instapaper-beyond-1-8-7/" rel="bookmark">Instapaper Beyond 1.8.7</a></li><li><a href="http://brettterpstra.com/2010/06/05/instapaper-beyond-1-3/" rel="bookmark">Instapaper Beyond 1.3</a></li></ul> ]]></description> <content:encoded><![CDATA[<p><a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/">Instapaper Beyond</a> version 1.8.9 is another small release with a couple of usability enhancements. Thanks to everyone who's been submitting ideas and bugs, I'll do my best to keep up!</p><p>This release includes:</p><ul><li>Alphabetical sorting of the help HUD (A-Z,a-z)</li><li>Edit a bookmark with "E" (Shift-E)<ul><li>you can tab through the fields and submit with Enter, returning you to your listing</li></ul></li><li>Scroll animation when navigating bookmark lists<ul><li>makes it more obvious which direction the page just scrolled you in when selecting a bookmark partially or entirely offscreen.</li></ul></li></ul><p><strong>Download:</strong></p><p class="download_desc"><a href="http://brettterpstra.com/downloads/InstapaperBeyond.1.8.10.zip" title="Download Instapaper Beyond for Safari 5 (94)"><img src="http://cdn.brettterpstra.com/wp-content/uploads/downloads/thumbnails/2010/06/instapaperbeyond95.png" alt="download image for Instapaper Beyond for Safari 5" width="64" height="64" /></a><a href="http://brettterpstra.com/downloads/InstapaperBeyond.1.8.10.zip" title="Download Instapaper Beyond for Safari 5 (94)">Instapaper Beyond for Safari 5</a> - Instapaper Beyond for Safari adds full keyboard navigation and Ajax loading of text views to Instapaper (http://www.instapaper.com). This extension is for Safari 5 with extensions enabled. <a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/">More Info</a></p><ul><li><a href="http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/" rel="bookmark">Instapaper Beyond: fix for text style controls</a></li><li><a href="http://brettterpstra.com/2010/07/25/instapaper-beyond-1-8-7/" rel="bookmark">Instapaper Beyond 1.8.7</a></li><li><a href="http://brettterpstra.com/2010/06/05/instapaper-beyond-1-3/" rel="bookmark">Instapaper Beyond 1.3</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/07/26/instapaper-beyond-1-8-9/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Instapaper Beyond 1.8.7</title><link>http://brettterpstra.com/2010/07/25/instapaper-beyond-1-8-7/</link> <comments>http://brettterpstra.com/2010/07/25/instapaper-beyond-1-8-7/#comments</comments> <pubDate>Sun, 25 Jul 2010 16:40:07 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[extension]]></category> <category><![CDATA[instapaper]]></category> <category><![CDATA[instapaper beyond]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[safari 5]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=825</guid> <description><![CDATA[Update: I just pushed out version 1.8.8 with a minor fix for some spacebar-in-forms issues. The download link and auto-update file have already been updated. Thanks to John P for the bug report! This is relatively minor update for Instapaper Beyond, the Safari extension which gives you full Ajax loading and keyboard control over Instapaper. It does, however, have one&#8230;<ul><li><a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/" rel="bookmark">Instapaper Beyond for Safari!</a></li><li><a href="http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/" rel="bookmark">Instapaper Beyond: fix for text style controls</a></li><li><a href="http://brettterpstra.com/2010/06/05/instapaper-beyond-1-3/" rel="bookmark">Instapaper Beyond 1.3</a></li></ul> ]]></description> <content:encoded><![CDATA[<p><strong>Update:</strong> I just pushed out version 1.8.8 with a minor fix for some spacebar-in-forms issues. The download link and auto-update file have already been updated. Thanks to John P for the bug report!</p><p>This is relatively minor update for <a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/">Instapaper Beyond</a>, the Safari extension which gives you full Ajax loading and keyboard control over <a href="http://www.instapaper.com">Instapaper</a>. It does, however, have one very cool new feature, and one often-requested fix.</p><p>The new feature is type-ahead folder selection in the popup HUDs for Move To and Go To Folder. When the HUD pops up, you can just start typing and it will find the first folder that matches the letters you've typed and select it. The arrow keys function as usual, and enter or right arrow will open the selected folder. If you type a few letters and then hit backspace or escape, it will clear the filter field. If you pause for a second, then start typing again, it will start a new filter, QuickSilver/Launchbar style.</p><p>The other noticeable change is that it works better with Greystyled now. It's not perfect, as Greystyled wants to do its own thing with the Ajax-loaded text versions and there's a major conflict. I check for Greystyled now, though, and give it a little leeway. The text view will not look like it does in Greystyled without IB loaded, but it will work for you.</p><p>If you have Instapaper Beyond loaded, it will either update automatically, or show up in your available updates if you have auto-updates turned off. If you haven't loaded it, download it below and give it a try!</p><p class="download_desc"><a href="http://brettterpstra.com/downloads/InstapaperBeyond.1.8.10.zip" title="Download Instapaper Beyond for Safari 5 (94)"><img src="http://cdn.brettterpstra.com/wp-content/uploads/downloads/thumbnails/2010/06/instapaperbeyond95.png" alt="download image for Instapaper Beyond for Safari 5" width="64" height="64" /></a><a href="http://brettterpstra.com/downloads/InstapaperBeyond.1.8.10.zip" title="Download Instapaper Beyond for Safari 5 (94)">Instapaper Beyond for Safari 5</a> - Instapaper Beyond for Safari adds full keyboard navigation and Ajax loading of text views to Instapaper (http://www.instapaper.com). This extension is for Safari 5 with extensions enabled. <a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/">More Info</a></p><ul><li><a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/" rel="bookmark">Instapaper Beyond for Safari!</a></li><li><a href="http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/" rel="bookmark">Instapaper Beyond: fix for text style controls</a></li><li><a href="http://brettterpstra.com/2010/06/05/instapaper-beyond-1-3/" rel="bookmark">Instapaper Beyond 1.3</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/07/25/instapaper-beyond-1-8-7/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Fixing Gleebox</title><link>http://brettterpstra.com/2010/07/17/fixing-gleebox/</link> <comments>http://brettterpstra.com/2010/07/17/fixing-gleebox/#comments</comments> <pubDate>Sun, 18 Jul 2010 00:11:14 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[css]]></category> <category><![CDATA[extension]]></category> <category><![CDATA[gleebox]]></category> <category><![CDATA[userstyle]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=778</guid> <description><![CDATA[If you haven’t tried it, gleeBox is an amazing extension. I have it installed in my Firefox and Chrome setups, and I’m more than thrilled that it’s finally available for Safari. It lets you do a lot of crazy (and useful) things with keyboard commands on any website. There’s a great writeup over at PimpMySafari.com, so I won’t go into&#8230;<ul><li><a href="http://brettterpstra.com/2010/06/19/textmate-drag-command-for-base64-encoding-images/" rel="bookmark">TextMate drag command for Base64 encoding images</a></li><li><a href="http://brettterpstra.com/2010/07/08/an-ode-to-twilight-and-a-textmate-tip/" rel="bookmark">An ode to Twilight, and a TextMate tip</a></li><li><a href="http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/" rel="bookmark">Instapaper Beyond: fix for text style controls</a></li></ul> ]]></description> <content:encoded><![CDATA[<p><a href="http://cdn.brettterpstra.com/wp-content/uploads/2010/07/defaultgleeboxhighlights.jpg" rel="lightbox[778]"><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/07/defaultgleeboxhighlights-150x150.jpg" alt="" title="defaultgleeboxhighlights" width="150" height="150" class="size-thumbnail wp-image-784 alignright" /></a>If you haven’t tried it, <a href="http://thegleebox.com/">gleeBox</a> is an amazing extension. I have it installed in my Firefox and Chrome setups, and I’m more than thrilled that it’s finally available for Safari. It lets you do a lot of crazy (and useful) things with keyboard commands on any website. There’s a <a href="http://www.pimpmysafari.com/extensions/gleebox-command-line-interface-for-safari">great writeup over at PimpMySafari.com</a>, so I won’t go into depth on the wonderful parts. I’ll concentrate on the one thing that bugs me about gleeBox: the highlight colors on found and selected elements. They are, in my opinion, a little obnoxious. <span id="more-778"></span></p><p>Fortunately, another Safari extension comes to the rescue. <a href="http://code.grid.in.th/">User CSS</a> is a pretty effective way to use slightly-modified <a href="userstyles.org/">userstyles</a> and generate your own CSS overrides. If you happen to have both extensions installed (or are on your way to get them right now), here’s a recipe for de-uglifying gleeBox (<a href="http://cdn.brettterpstra.com/wp-content/uploads/2010/07/UserCSSGleebox.jpg" rel="lightbox[778]">settings screenshot</a>):</p><ol><li>Create a new User CSS in the User CSS Manager</li><li>Name it Glee Highlight Override and set the Domains field to *</li><li>Add the code below in the Styles field:</li></ol><div markdown=0><pre><code>
body .GleeHL { 
    background-color:#eef49b !important;
    -webkit-box-shadow:none !important;
    border:solid 1px #dfec2c !important;
    padding:0 !important;
}
body .GleeReaped {
    background-color:#f6f9c9 !important;
    border:solid 1px #c0c660 !important;
}
</code></pre></div><p><a href="http://cdn.brettterpstra.com/wp-content/uploads/2010/07/adjustedGleeboxHighlights.jpg" rel="lightbox[778]"><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/07/adjustedGleeboxHighlights-150x150.jpg" alt="" title="adjustedGleeboxHighlights" width="150" height="150" class="size-thumbnail wp-image-782 alignright" /></a>The highlights should be prettier now, even if the change is fairly subtle. The style also removes the padding and shadow on the selected item so that, in most cases, selected items don’t jump around and move other elements as you tab through the page. Let me know if it doesn’t work for you. Obviously, the colors are adjustable to taste. You could even create special overrides for certain sites to match color schemes better… I mean, if you were crazy obsessive or something. If you come up with a better all-around color set, let me know!</p><p>By the way, the <a href="http://userstyles.org/styles/33647">Reddit Twitter</a> style is great in Safari! Here’s a <a href="http://img.skitch.com/20100717-mhhsdfh8194rhyg6imtp36byf4.jpg" rel="lightbox[778]">shot of it</a> with custom gleeBox highlights!</p><ul><li><a href="http://brettterpstra.com/2010/06/19/textmate-drag-command-for-base64-encoding-images/" rel="bookmark">TextMate drag command for Base64 encoding images</a></li><li><a href="http://brettterpstra.com/2010/07/08/an-ode-to-twilight-and-a-textmate-tip/" rel="bookmark">An ode to Twilight, and a TextMate tip</a></li><li><a href="http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/" rel="bookmark">Instapaper Beyond: fix for text style controls</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/07/17/fixing-gleebox/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Instapaper Beyond: fix for text style controls</title><link>http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/</link> <comments>http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/#comments</comments> <pubDate>Fri, 16 Jul 2010 09:00:08 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[extension]]></category> <category><![CDATA[instapaper]]></category> <category><![CDATA[instapaper beyond]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[safari 5]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=761</guid> <description><![CDATA[This is a bugfix release of Instapaper Beyond for Safari which brings the version up to 1.8.6. It fixes a few visual glitches, but most importantly it restores the functionality of the text style menu at the top of a read page, allowing you to set and remember the font, size, width and line spacing of your text view. I&#8230;<ul><li><a href="http://brettterpstra.com/2010/07/26/instapaper-beyond-1-8-9/" rel="bookmark">Instapaper Beyond 1.8.9</a></li><li><a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-bugs/" rel="bookmark">Instapaper Beyond Bugs (fixed)</a></li><li><a href="http://brettterpstra.com/2010/07/28/single-keystroke-instapaper-in-google-reader/" rel="bookmark">Single-keystroke Instapaper in Google Reader</a></li></ul> ]]></description> <content:encoded><![CDATA[<p>This is a bugfix release of Instapaper Beyond for Safari which brings the version up to 1.8.6. It fixes a few visual glitches, but most importantly it restores the functionality of the text style menu at the top of a read page, allowing you to set and remember the font, size, width and line spacing of your text view.</p><p>I actually ended up rewriting the existing javascript as a module in Instapaper Beyond, so there's the possibility of easily extending it to handle more options. Background color, more fonts, etc. We'll see how far I get with that. My next order of business is to get it to work with some of the existing userstyles out there, but time has been tight for me when it comes to these side projects. I'll keep you posted.</p><p>If you have Instapaper Beyond installed, it should show up in your updates (or be updated automatically, depending on your settings). If you want to download the extension, please use the link below. For more information on Instapaper Beyond, see the <a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/">original post for the Safari Release</a>.</p><p class="download_desc"><a href="http://brettterpstra.com/downloads/InstapaperBeyond.1.8.10.zip" title="Download Instapaper Beyond for Safari 5 (94)"><img src="http://cdn.brettterpstra.com/wp-content/uploads/downloads/thumbnails/2010/06/instapaperbeyond95.png" alt="download image for Instapaper Beyond for Safari 5" width="64" height="64" /></a><a href="http://brettterpstra.com/downloads/InstapaperBeyond.1.8.10.zip" title="Download Instapaper Beyond for Safari 5 (94)">Instapaper Beyond for Safari 5</a> - Instapaper Beyond for Safari adds full keyboard navigation and Ajax loading of text views to Instapaper (http://www.instapaper.com). This extension is for Safari 5 with extensions enabled. <a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/">More Info</a></p><ul><li><a href="http://brettterpstra.com/2010/07/26/instapaper-beyond-1-8-9/" rel="bookmark">Instapaper Beyond 1.8.9</a></li><li><a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-bugs/" rel="bookmark">Instapaper Beyond Bugs (fixed)</a></li><li><a href="http://brettterpstra.com/2010/07/28/single-keystroke-instapaper-in-google-reader/" rel="bookmark">Single-keystroke Instapaper in Google Reader</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>EverSave revisited, now with session restore!</title><link>http://brettterpstra.com/2010/07/15/eversave-revisited-now-with-session-restore/</link> <comments>http://brettterpstra.com/2010/07/15/eversave-revisited-now-with-session-restore/#comments</comments> <pubDate>Fri, 16 Jul 2010 01:50:46 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[applescript]]></category> <category><![CDATA[evernote]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[service]]></category> <category><![CDATA[snow leopard]]></category> <category><![CDATA[System Service]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=744</guid> <description><![CDATA[Safari 5 has brought several solutions for managing lists of open tabs, from the simple (like my TabLinks extension) to full session-management capabilities (see the beautiful Sessions extension). However, I've found I still like using my EverSave script in many situations, primarily because it allows me to annotate, tag and sync my important sessions for later retrieval. One thing's been&#8230;<ul><li><a href="http://brettterpstra.com/2010/03/06/saving-safari-browsing-sessions-to-evernote/" rel="bookmark">Saving Safari browsing sessions to Evernote</a></li><li><a href="http://brettterpstra.com/2010/06/18/tablinks-safari-extension/" rel="bookmark">TabLinks Safari Extension</a></li><li><a href="http://brettterpstra.com/2010/06/06/fun-with-marsedit-part-i/" rel="bookmark">Fun with MarsEdit, part I</a></li></ul> ]]></description> <content:encoded><![CDATA[<p>Safari 5 has brought several solutions for managing lists of open tabs, from the simple (like my <a href="http://brettterpstra.com/2010/06/18/tablinks-safari-extension/">TabLinks extension</a>) to full session-management capabilities (see the beautiful <a href="http://dl.dropbox.com/u/8247646/sessions/index.html">Sessions extension</a>). However, I've found I still like using my <a href="http://brettterpstra.com/2010/03/06/saving-safari-browsing-sessions-to-evernote/">EverSave script</a> in many situations, primarily because it allows me to annotate, tag and sync my important sessions for later retrieval. One thing's been bugging me, though, and that's the inability to do a mass restore on a tab list (i.e. open them all at once).</p><p>When I decided to fix this, the first issue was that when EverSave creates the Evernote note, it lets Evernote convert the list from HTML to Rich Text. Once it's stored in Rich Text Format (RTF), manipulating it via any shell language, including AppleScript, becomes quite difficult. It's not impossible, but I quickly decided it wasn't a route I wanted to wander down. Here's what I <strong>did</strong> do... <span id="more-744"></span></p><h3>Saving tabs to Evernote</h3><p>What I ended up doing was modifying what EverSave stored, and including the actual URL in the visible text of the note. It's not the prettiest solution, but it's the only way that this particular system will work. I did my best to minimize the visual presence of the URL using the rudimentary markup that Evernote actually pays attention to. The final product looks like this:</p><p><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/07/EverSaveRevisedBookmarks.jpg" alt="EverSaveRevisedBookmarks.jpg" border="0" width="650" height="93" /></p><p>The actual layout is still fully controlled by the _template property in the first line, which is the only line that's changed from the original script. I'm posting the whole thing again, with this minor revision, for convenience. With a little bit of HTML (remember to escape your double quotes), you can modify the template to look however you like. Just keep in mind that Evernote strips 90% of markup out when it creates the note from your HTML, so stick with basic tags. See the <a href="http://brettterpstra.com/2010/03/06/saving-safari-browsing-sessions-to-evernote/">original EverSave post</a> for a breakdown of the script.</p><p>Be sure to continue reading after the script to see how we handle the "restore" functionality.</p><div markdown=0><pre><code>
property _template : &quot;&lt;li&gt;&lt;strong&gt;&lt;a href=\&quot;%url\&quot;&gt;&amp;uArr;&lt;/a&gt; %name&lt;/strong&gt; &lt; &lt;small&gt;%url&lt;/small&gt; &gt;&quot;

--search and replace function for template
on snr(tofind, toreplace, TheString)
    set ditd to text item delimiters
    set text item delimiters to tofind
    set textItems to text items of TheString
    set text item delimiters to toreplace
    if (class of TheString is string) then
        set res to textItems as string
    else -- if (class of TheString is Unicode text) then
        set res to textItems as Unicode text
    end if
    set text item delimiters to ditd
    return res
end snr

set prettyDate to do shell script &quot;date &#x27;+%A, %B %d, %Y at %l:%M %p&#x27;&quot;
set theTitle to &quot;Bookmarks &quot; &amp; prettyDate
set urlList to &quot;&lt;ul&gt;&quot;

tell application &quot;Safari&quot;
    set tabList to every tab of front window
    repeat with aTab in tabList
        set aLink to _template
        set aLink to my snr(&quot;%name&quot;, name of aTab, aLink)
        set aLink to my snr(&quot;%url&quot;, URL of aTab, aLink)
        set urlList to urlList &amp; aLink &amp; return
    end repeat
end tell
set urlList to urlList &amp; &quot;&lt;/ul&gt;&quot;

tell application &quot;Evernote&quot;
    set theNote to create note with html urlList title theTitle notebook &quot;Bookmarks&quot;
end tell
</code></pre></div><p><a href="applescript://com.apple.scripteditor?action=new&amp;script=property%20_template%20%3A%20%22%3Cli%3E%3Cstrong%3E%3Ca%20href%3D%5C%22%25url%5C%22%3E%26uArr%3B%3C%2Fa%3E%20%25name%3C%2Fstrong%3E%20%3C%20%3Csmall%3E%25url%3C%2Fsmall%3E%20%3E%22%0A%0A%2D%2Dsearch%20and%20replace%20function%20for%20template%0Aon%20snr%28tofind%2C%20toreplace%2C%20TheString%29%0A%09set%20ditd%20to%20text%20item%20delimiters%0A%09set%20text%20item%20delimiters%20to%20tofind%0A%09set%20textItems%20to%20text%20items%20of%20TheString%0A%09set%20text%20item%20delimiters%20to%20toreplace%0A%09if%20%28class%20of%20TheString%20is%20string%29%20then%0A%09%09set%20res%20to%20textItems%20as%20string%0A%09else%20%2D%2D%20if%20%28class%20of%20TheString%20is%20Unicode%20text%29%20then%0A%09%09set%20res%20to%20textItems%20as%20Unicode%20text%0A%09end%20if%0A%09set%20text%20item%20delimiters%20to%20ditd%0A%09return%20res%0Aend%20snr%0A%0Aset%20prettyDate%20to%20do%20shell%20script%20%22date%20%27%2B%25A%2C%20%25B%20%25d%2C%20%25Y%20at%20%25l%3A%25M%20%25p%27%22%0Aset%20theTitle%20to%20%22Bookmarks%20%22%20%26%20prettyDate%0Aset%20urlList%20to%20%22%3Cul%3E%22%0A%0Atell%20application%20%22Safari%22%0A%09set%20tabList%20to%20every%20tab%20of%20front%20window%0A%09repeat%20with%20aTab%20in%20tabList%0A%09%09set%20aLink%20to%20_template%0A%09%09set%20aLink%20to%20my%20snr%28%22%25name%22%2C%20name%20of%20aTab%2C%20aLink%29%0A%09%09set%20aLink%20to%20my%20snr%28%22%25url%22%2C%20URL%20of%20aTab%2C%20aLink%29%0A%09%09set%20urlList%20to%20urlList%20%26%20aLink%20%26%20return%0A%09end%20repeat%0Aend%20tell%0Aset%20urlList%20to%20urlList%20%26%20%22%3C%2Ful%3E%22%0A%0Atell%20application%20%22Evernote%22%0A%09set%20theNote%20to%20create%20note%20with%20html%20urlList%20title%20theTitle%20notebook%20%22Bookmarks%22%0Aend%20tell%0A">Open this script in Script Editor</a></p><p>I have this script saved as "EverSave.scpt" in my <code>~/Library/Scripts/Applications/Safari</code> folder (create it if you don't have it), and launch it using <a href="http://www.red-sweater.com/fastscripts/">FastScripts</a> with a Command-Shift-S shortcut. Safari doesn't have anything bound to that key-combo, and it's easy to remember (Save As in most programs).</p><h3>Restoring tabs</h3><p>This solution makes a few assumptions, but the script is easily customized to handle any differences in your setup. I went with a System Service (Snow Leopard) for the restore function, primarily because it allows me to act directly on selected text in Evernote. It's a very simple Ruby script that parses the selected text for urls, and then opens any that it finds in sequential order using your default browser. There's a commented out line if you want to always target Safari directly when opening them, which may be useful in some situations. I use <a href="http://www.choosyosx.com/">Choosy</a>, and have a rule that just directs all of these to Safari. If you have Safari set as your default browser, and that's where you want to open your links, this will just work as is.</p><p>To set up the service:</p><ol><li>Open Automator and select "Service" as the new file type.</li><li>On the right hand side, tell it that "Service receives selected" <strong><em>text</em></strong> in <strong><em>Evernote.app</em></strong> (choose Other... and select Evernote).</li><li>Find "Run Shell Script" in the list on the left and drag it into the area on the right.</li><li>Set the Shell dropdown to /usr/bin/ruby</li><li>Insert the following code, and feel free to modify</li><li>Save the result as "EverRestore"</li><li>Assign a shortcut key, if desired, in System Preferences > Keyboard > Keyboard Shortcuts > Services</li></ol><p>Here's the code for the service:</p><div markdown=0><pre><code>
ARGF.each do |f|
    links = f.scan /&lt; (https?:\/\/.*?) &gt;/mi
    # The above scans specifically for the angle brackets in my template. 
    # If you remove those from the output of EverSave, be sure to update
    # the regular expression accordingly.
    if links.empty? then
        exit
    else
        links.each {|link| %x{osascript -e &#x27;open location &quot;#{link[0]}&quot;&#x27;}}
        # links.each {|link| %x{osascript -e &#x27;tell application &quot;Safari&quot; to open location &quot;#{link[0]}&quot;&#x27;}   }
    end
end
</code></pre></div><p>The simple regular expression in line 2 does scan specifically for the angle brackets I used in the new EverSave template. That just relieves some complexity. If you want a regular expression that doesn't require the angle brackets, try replacing line 2 with this:</p><div markdown=0><pre><code>
links = f.scan /(https?:\/\/([^\s&quot;,;]+)\..{2,4}(\/[^\s&quot;,;!]+))/mi
</code></pre></div><p>Once it's saved in Automator, it should be available when you select text in Evernote. If there are visible URLs in the selected text, running this Service will open them in tabs in Safari (or your default browser). You can selectively open certain urls by only selecting the lines that contain the ones you want to open. Non-contiguous selections will require a little text editing, of course.</p><h3>Not as hard as it looks... really.</h3><p>The explanation got a little long, and probably seems unnecessarily complex. The fact is, I can save a Safari browsing session with one key combo, edit, annotate and tag it (if I want to), then restore it later by highlighting and typing a new command combination. It's actually quite convenient, and fairly bulletproof. I'd love to hear how you use it, or what you're doing instead!</p><ul><li><a href="http://brettterpstra.com/2010/03/06/saving-safari-browsing-sessions-to-evernote/" rel="bookmark">Saving Safari browsing sessions to Evernote</a></li><li><a href="http://brettterpstra.com/2010/06/18/tablinks-safari-extension/" rel="bookmark">TabLinks Safari Extension</a></li><li><a href="http://brettterpstra.com/2010/06/06/fun-with-marsedit-part-i/" rel="bookmark">Fun with MarsEdit, part I</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/07/15/eversave-revisited-now-with-session-restore/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Better WordPress security through comment filters</title><link>http://brettterpstra.com/2010/07/01/better-wordpress-security-through-comment-filters/</link> <comments>http://brettterpstra.com/2010/07/01/better-wordpress-security-through-comment-filters/#comments</comments> <pubDate>Thu, 01 Jul 2010 11:57:22 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[comments]]></category> <category><![CDATA[functions.php]]></category> <category><![CDATA[hacks]]></category> <category><![CDATA[Wordpress]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=727</guid> <description><![CDATA[I have an admin username (it's not admin) which I use to manage my WordPress blog, and an editor user with which I write posts and leave comments. Sometimes, though, I get confused, lazy or both, and end up leaving comments as my admin user. This rather defeats the purpose of using a non-default admin username, which is generally done&#8230;<ul><li><a href="http://brettterpstra.com/2010/04/17/adding-a-tinymce-button/" rel="bookmark">Adding a TinyMCE button to WordPress</a></li><li><a href="http://brettterpstra.com/2010/07/24/notes-on-cleaning-up-the-mediatemple-hack-johnnya/" rel="bookmark">Notes on cleaning up the MediaTemple hack (JohnnyA)</a></li><li><a href="http://brettterpstra.com/2010/05/26/auto-lightboxing-image-links/" rel="bookmark">Auto-lightboxing image links</a></li></ul> ]]></description> <content:encoded><![CDATA[<p><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/07/wordpresssecuritycommentfiltersheader.jpg" alt="Wordpress security comment filters header image" border="0" width="650" height="187" class="headerimg" /></p><p><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/07/combolock200.jpg" alt="Combination Lock" border="0" width="200" height="200" class="alignright" />I have an admin username (it's not <em>admin</em>) which I use to manage my WordPress blog, and an editor user with which I write posts and leave comments. Sometimes, though, I get confused, lazy or both, and end up leaving comments as my admin user. This rather defeats the purpose of using a non-default admin username, which is generally done for security purposes (if they can't guess the admin's username, it makes it that much harder to hack the admin account).</p><p>More out of laziness than anything else (we can call it efficiency, right?), I dropped the functions below into my <code>functions.php</code> file. They filter my admin username out of any comments I leave. WordPress also adds the user's name in a class for the list item of the comment, so I needed to remove that as well. If you're in a similar situation, feel free to grab the code and place it in your own theme's <code>functions.php</code> file, replacing the adminuser and regularuser placeholders with your own admin and editor usernames. The comment class code is modified from a hack <a href="http://www.wprecipes.com/wordpress-hack-remove-admin-name-in-comments-class">found at WPRecipes</a>.</p><div markdown=0><pre><code>
// change the class that wordpress assigns to the comment
function change_comment_author_class( $classes ) {
    foreach( $classes as $key => $class ) {
        // change adminuser to your admin username
        if(strstr($class, "comment-author-adminuser")) {
            // change regularuser to the user you comment with
            $classes[$key] = 'comment-author-regularuser';
        }
    }
    return $classes;
}
// substitute a user name for the admin name
function change_comment_author($author)
{
    // change this to the admin username
    if(strstr($author,"adminuser")) { 
        // change this to the name of the user you comment with
        return "regularuser"; 
    }
    return $author;
}
// apply the filters
add_filter( 'comment_class' , 'change_comment_author_class' );
add_filter( 'get_comment_author' , 'change_comment_author' );
</code></pre></div><ul><li><a href="http://brettterpstra.com/2010/04/17/adding-a-tinymce-button/" rel="bookmark">Adding a TinyMCE button to WordPress</a></li><li><a href="http://brettterpstra.com/2010/07/24/notes-on-cleaning-up-the-mediatemple-hack-johnnya/" rel="bookmark">Notes on cleaning up the MediaTemple hack (JohnnyA)</a></li><li><a href="http://brettterpstra.com/2010/05/26/auto-lightboxing-image-links/" rel="bookmark">Auto-lightboxing image links</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/07/01/better-wordpress-security-through-comment-filters/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Minor TabLinks update</title><link>http://brettterpstra.com/2010/06/26/minor-tablinks-update/</link> <comments>http://brettterpstra.com/2010/06/26/minor-tablinks-update/#comments</comments> <pubDate>Sat, 26 Jun 2010 14:01:17 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[extension]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[safari 5]]></category> <category><![CDATA[tablinks]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=708</guid> <description><![CDATA[I just posted version 1.3 of TabLinks. It doesn't fix all of the things I eventually want to fix, but it does do some rudimentary entity encoding that allows you to actually use HTML tags in the templates. I had said that &#60;a href="%u"&#62;%t&#60;/a&#62; would work as a template, but it didn't. Now it does. The automatic update is functioning,&#8230;<ul><li><a href="http://brettterpstra.com/2010/07/25/instapaper-beyond-1-8-7/" rel="bookmark">Instapaper Beyond 1.8.7</a></li><li><a href="http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/" rel="bookmark">Instapaper Beyond: fix for text style controls</a></li><li><a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/" rel="bookmark">Instapaper Beyond for Safari!</a></li></ul> ]]></description> <content:encoded><![CDATA[<p><a href="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/TabLinksWithHTML.jpg" rel="lightbox[708]"><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/TabLinksWithHTML-150x150.jpg" alt="TabLinks With HTML Template" title="TabLinks With HTML Template" width="150" height="150" class="alignright size-thumbnail wp-image-709" /></a>I just posted version 1.3 of <a href="http://brettterpstra.com/2010/06/18/tablinks-safari-extension/">TabLinks</a>. It doesn't fix all of the things I eventually want to fix, but it <em>does</em> do some rudimentary entity encoding that allows you to actually use HTML tags in the templates. I had said that <code>&lt;a href="%u"&gt;%t&lt;/a&gt;</code> would work as a template, but it didn't. Now it does.</p><p>The automatic update is functioning, so anyone with TabLinks already installed should see it show up in their updates, or just update automatically if you have that option enabled. This version should show up as 1.3. If you're looking for the initial install, you can find it below.</p><p class="download_desc"><a href="http://brettterpstra.com/downloads/TabLinks1.3.zip" title="Download TabLinks Safari Extension (381)"><img src="http://cdn.brettterpstra.com/wp-content/uploads/downloads/thumbnails/2010/06/Icon.png" alt="download image for TabLinks Safari Extension" width="64" height="64" /></a><a href="http://brettterpstra.com/downloads/TabLinks1.3.zip" title="Download TabLinks Safari Extension (381)">TabLinks Safari Extension</a> - TabLinks gathers all of the link information from every open tab and presents them for copying based on a user-defined template. <a href="http://brettterpstra.com/2010/06/18/tablinks-safari-extension/">More Info</a></p><ul><li><a href="http://brettterpstra.com/2010/07/25/instapaper-beyond-1-8-7/" rel="bookmark">Instapaper Beyond 1.8.7</a></li><li><a href="http://brettterpstra.com/2010/07/16/instapaper-beyond-fix-for-text-style-controls/" rel="bookmark">Instapaper Beyond: fix for text style controls</a></li><li><a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/" rel="bookmark">Instapaper Beyond for Safari!</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/06/26/minor-tablinks-update/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Visually differentiating your development site</title><link>http://brettterpstra.com/2010/06/20/visually-differentiating-your-development-site/</link> <comments>http://brettterpstra.com/2010/06/20/visually-differentiating-your-development-site/#comments</comments> <pubDate>Sun, 20 Jun 2010 16:50:49 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[css]]></category> <category><![CDATA[php]]></category> <category><![CDATA[web design]]></category> <category><![CDATA[web dev]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=689</guid> <description><![CDATA[I have most of the websites I work on set up with separate development (usually local1) and production/deployment servers. It’s pretty easy to keep straight when I’m first designing a site, but going back later and making changes can cause some confusion with all the refreshing and dealing with caches and all. So I’ve been using a trick to make&#8230;<ul><li><a href="http://brettterpstra.com/2010/05/26/auto-lightboxing-image-links/" rel="bookmark">Auto-lightboxing image links</a></li><li><a href="http://brettterpstra.com/2010/06/06/multimarkdown-in-marsedit/" rel="bookmark">MultiMarkdown in MarsEdit</a></li><li><a href="http://brettterpstra.com/2010/04/17/adding-a-tinymce-button/" rel="bookmark">Adding a TinyMCE button to WordPress</a></li></ul> ]]></description> <content:encoded><![CDATA[<p><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/devdifferentheader.jpg" alt="devdifferentheader.jpg" border="0" width="650" height="187" class="headerimg" /></p><p><a href="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/devbadgeonbrettterpstracomwithcallout.jpg" rel="lightbox[689]"><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/devbadgeonbrettterpstracomwithcallout-300x205.jpg" alt="" title="devbadgeonbrettterpstracomwithcallout" width="300" height="205" class="alignright size-medium wp-image-698 noshadow" /></a></p><p>I have most of the websites I work on set up with separate development (usually local<sup id="fnref:localdev"><a href="#fn:localdev" rel="footnote">1</a></sup>) and production/deployment servers. It’s pretty easy to keep straight when I’m first designing a site, but going back later and making changes can cause some confusion with all the refreshing and dealing with caches and all. So I’ve been using a trick to make it clear which version I’m loading at any given time.</p><p>All of my local development sites are mapped to .dev addresses, e.g. brettterpstra.dev. I use php to scan the current SERVER_NAME variable for .dev and insert an unobtrusive div at the top of the content if it’s found. At the very top of the page (in the header file, assuming the site is modular), I insert this line:</p><div markdown=0><pre><code>
&lt;?php $dev = preg_match(&quot;/\.dev/&quot;,$_SERVER[&#x27;SERVER_NAME&#x27;]) ? true : false; ?&gt;
</code></pre></div><p>As a side note for those not familiar with this syntax: it’s a ternary conditional operator, meaning that <code>$dev</code> is set to either true or false based on the result of the condition. The format here is [variable] = [condition] ? [evaluate true] : [evaluate false];. Think of the question mark as “if” and the colon as “else.” It’s just all on one nifty line.</p><p>Now we use the <code>$dev</code> variable to determine whether or not we’re inserting an extra element in the markup. Right after my body tag, I have this logic:</p><div markdown=0><pre><code>
&lt;?php if ($dev) {
    echo &quot;&lt;div id=\&quot;development\&quot;&gt;\n&quot;;
    echo &quot;&lt;/div&gt;\n&quot;;
} ?&gt;
</code></pre></div><p>Yep, it just inserts a div if the $dev is true (SERVER_NAME contained .div). You can change the condition above to find whatever differentiates your development server from your production and/or deployment servers.</p><p>Lastly, I style the div with some CSS:</p><div markdown=0><pre><code>
#development {
    position: fixed;
    bottom: 0;
    left: 0;
    background: transparent url(http://d33frhdcafae93.cloudfront.net/images/devsticker.png);
    text-indent: -99999px;
    width: 150px;
    height: 150px;
    z-index: 9999999;
}
</code></pre></div><p>That sticks a dogear image I made into the lower left corner of the site, in a fixed position that is always visible but rarely in the way (you’re welcome to <a href="http://brettterpstra.com/share/devsticker.png" rel="lightbox[689]">steal the image</a>, if you want it). It’s an easy trick, but I’ve found it saves me a lot of frustration when I get too obsessed with a minor detail to bother looking at the URL and realizing I’m not even refreshing the right version of the site. Maybe you never have that problem, in which case I applaud your level, collected personality. People like me, though, can always use a little extra help.</p><div class="footnotes"><hr /><ol><li id="fn:localdev"><p>I run a full dev site in Snow Leopard with a custom build of PHP5 and MySQL. I use <a href="http://www.mamp.info/de/index.html">MAMP</a> or <a href="http://bitnami.org/stack/rubystack">RubyStack</a> when I need an alternate configuration, and map all of my dev addresses with <a href="http://clickontyler.com/virtualhostx/">VirtualHostX</a>. <a href="#fnref:localdev" rev="footnote">↩</a></p></li></ol></div><ul><li><a href="http://brettterpstra.com/2010/05/26/auto-lightboxing-image-links/" rel="bookmark">Auto-lightboxing image links</a></li><li><a href="http://brettterpstra.com/2010/06/06/multimarkdown-in-marsedit/" rel="bookmark">MultiMarkdown in MarsEdit</a></li><li><a href="http://brettterpstra.com/2010/04/17/adding-a-tinymce-button/" rel="bookmark">Adding a TinyMCE button to WordPress</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/06/20/visually-differentiating-your-development-site/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>TextMate drag command for Base64 encoding images</title><link>http://brettterpstra.com/2010/06/19/textmate-drag-command-for-base64-encoding-images/</link> <comments>http://brettterpstra.com/2010/06/19/textmate-drag-command-for-base64-encoding-images/#comments</comments> <pubDate>Sat, 19 Jun 2010 14:00:29 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[base64]]></category> <category><![CDATA[bash]]></category> <category><![CDATA[commands]]></category> <category><![CDATA[css]]></category> <category><![CDATA[drag command]]></category> <category><![CDATA[shell]]></category> <category><![CDATA[textmate]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=659</guid> <description><![CDATA[Just a quick hit on this one... when hacking away at the styles of things one probably shouldn't be hacking away at, embedding images right in the CSS is a handy trick. It's done by Base64 encoding the image, removing line breaks from the resulting string, and using it to set the background property for the CSS rule. It looks&#8230;<ul><li><a href="http://brettterpstra.com/2009/11/14/fk-a-useful-bash-function/" rel="bookmark">fk: a useful bash function</a></li><li><a href="http://brettterpstra.com/2010/07/09/new-safari-extensions-give-good-source/" rel="bookmark">New Safari Extensions give good source</a></li><li><a href="http://brettterpstra.com/2010/06/17/antique-1-6-final-release/" rel="bookmark">Antique 1.6, final release</a></li></ul> ]]></description> <content:encoded><![CDATA[<p>Just a quick hit on this one... when hacking away at the styles of things one probably shouldn't be hacking away at, embedding images right in the CSS is a handy trick. It's done by <a href="http://en.wikipedia.org/wiki/Base64">Base64</a> encoding the image, removing line breaks from the resulting string, and using it to set the background property for the CSS rule.</p><p>It looks something like this (truncated):</p><p><code>background:url(data:image/png;base64,iVBORw0KG...AAAAASUVORK5CYII=);</code></p><p>The image/png changes depending on the filetype that's encoded, becoming image/jpg or image/gif, etc. Anyway, I got tired of shelling out to encode the images, so here's a very simple command I set up in TextMate which allows me to drag any JPEG, PNG or GIF file into a CSS rule and get the background property with encoded image all at once. Don't try it with <em>big</em> images, but for the kind of thing you'd actually put into a CSS file, it works great.</p><p>The command itself is this (it's a one-liner):</p><div markdown=0><pre><code>
# Drag command set to handle: jpg,png,gif
# scoped to: text.html.basic source.css.embedded.html, source.css meta.scope.property-list.css

openssl base64 -in "$TM_DROPPED_FILE" | awk -v ext="${TM_DROPPED_FILE#*.}" '{ str1=str1 $0 }END{ print "background:url(data:image/"ext";base64,"str1");" }'
</code></pre></div><p>It uses the <code>openssl</code> command that's on a Mac by default. It encodes the file and outputs it to STDOUT, which is passed to awk. The extension of the dropped file is grabbed via Bash parameter substitution (<code>${TM_DROPPED_FILE#*.}</code>) and passed to awk where it's subbed in and all of the line breaks are removed. Presto.</p><p>Here's the actual TextMate command if you want to try it out and aren't sure how to create a new one. Assuming you're running TextMate (kind of a prerequisite for a TextMate command), just unzip and double click the file.</p><p class="download_desc"><a href="http://brettterpstra.com/downloads/InsertBase64image.tmDragCommand.zip" title="Download Base64 Image Encoder TextMate Drag Command (17)"><img src="http://cdn.brettterpstra.com/wp-content/uploads/downloads/thumbnails/2010/06/TextMateIcon.png" alt="download image for Base64 Image Encoder TextMate Drag Command" width="64" height="64" /></a><a href="http://brettterpstra.com/downloads/InsertBase64image.tmDragCommand.zip" title="Download Base64 Image Encoder TextMate Drag Command (17)">Base64 Image Encoder TextMate Drag Command</a> - Encodes a dropped image and inserts a CSS background property with the result in TextMate. Works in embedded CSS and in CSS files. <a href="http://brettterpstra.com/2010/06/19/textmate-drag-command-for-base64-encoding-images/">More Info</a></p><hr style="clear:both;visibility:hidden" /><ul><li><a href="http://brettterpstra.com/2009/11/14/fk-a-useful-bash-function/" rel="bookmark">fk: a useful bash function</a></li><li><a href="http://brettterpstra.com/2010/07/09/new-safari-extensions-give-good-source/" rel="bookmark">New Safari Extensions give good source</a></li><li><a href="http://brettterpstra.com/2010/06/17/antique-1-6-final-release/" rel="bookmark">Antique 1.6, final release</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/06/19/textmate-drag-command-for-base64-encoding-images/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>RedirectBuster, another late night Safari Extension</title><link>http://brettterpstra.com/2010/06/18/redirectbuster-another-late-night-safari-extension/</link> <comments>http://brettterpstra.com/2010/06/18/redirectbuster-another-late-night-safari-extension/#comments</comments> <pubDate>Fri, 18 Jun 2010 14:28:49 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Code]]></category> <category><![CDATA[Misc]]></category> <category><![CDATA[experiments]]></category> <category><![CDATA[extension]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[safari 5]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=649</guid> <description><![CDATA[Okay, this one has a little refining left to go, but it seems to be working pretty flawlessly. I ported most of the code from a greasemonkey script. All I really want to add is a toolbar item that lets you easily turn it on and off, and maybe a whitelist feature. There are actually legitimate uses for a plugin&#8230;<ul><li><a href="http://brettterpstra.com/2010/07/09/new-safari-extensions-give-good-source/" rel="bookmark">New Safari Extensions give good source</a></li><li><a href="http://brettterpstra.com/2010/05/26/auto-lightboxing-image-links/" rel="bookmark">Auto-lightboxing image links</a></li><li><a href="http://brettterpstra.com/2010/04/17/adding-a-tinymce-button/" rel="bookmark">Adding a TinyMCE button to WordPress</a></li></ul> ]]></description> <content:encoded><![CDATA[<p><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/RedirectBusterHeaderImage.jpg" alt="RedirectBusterHeaderImage.jpg" border="0" width="650" height="187" class="headerimg" /></p><p>Okay, this one has a little refining left to go, but it seems to be working pretty flawlessly. I ported most of the code from a <a href="http://userscripts.org/scripts/show/72535">greasemonkey script</a>. All I really want to add is a toolbar item that lets you easily turn it on and off, and maybe a whitelist feature.</p><p>There are actually legitimate uses for a plugin like this. Seriously.</p><p class="download_desc"><a href="http://brettterpstra.com/downloads/RedirectBuster.safariextz.zip" title="Download RedirectBuster (417)"><img src="http://cdn.brettterpstra.com/wp-content/uploads/downloads/thumbnails/2010/06/Icon1.png" alt="download image for RedirectBuster" width="64" height="64" /></a><a href="http://brettterpstra.com/downloads/RedirectBuster.safariextz.zip" title="Download RedirectBuster (417)">RedirectBuster</a> — Removes redirects from urls. Pretty simple. <a href="">More Info</a></p><hr style="clear:both;height:0;border:none" /><ul><li><a href="http://brettterpstra.com/2010/07/09/new-safari-extensions-give-good-source/" rel="bookmark">New Safari Extensions give good source</a></li><li><a href="http://brettterpstra.com/2010/05/26/auto-lightboxing-image-links/" rel="bookmark">Auto-lightboxing image links</a></li><li><a href="http://brettterpstra.com/2010/04/17/adding-a-tinymce-button/" rel="bookmark">Adding a TinyMCE button to WordPress</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/06/18/redirectbuster-another-late-night-safari-extension/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>TabLinks Safari Extension</title><link>http://brettterpstra.com/2010/06/18/tablinks-safari-extension/</link> <comments>http://brettterpstra.com/2010/06/18/tablinks-safari-extension/#comments</comments> <pubDate>Fri, 18 Jun 2010 06:28:17 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[Featured]]></category> <category><![CDATA[extension]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[safari 5]]></category> <category><![CDATA[tablinks]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=641</guid> <description><![CDATA[TabLinks is a quick experiment, designed to meet my own needs. It needs some work, but it does the trick: it copies the link information for every tab open in Safari, and outputs them as a list, based on a user-defined template. You set up your template in the Extension settings, and use the following variables to define your link&#8230;<ul><li><a href="http://brettterpstra.com/2010/05/07/textexpander-experiments/" rel="bookmark">TextExpander experiments</a></li><li><a href="http://brettterpstra.com/2010/06/26/minor-tablinks-update/" rel="bookmark">Minor TabLinks update</a></li><li><a href="http://brettterpstra.com/2010/03/06/saving-safari-browsing-sessions-to-evernote/" rel="bookmark">Saving Safari browsing sessions to Evernote</a></li></ul> ]]></description> <content:encoded><![CDATA[<p><a href="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/TabLinksScreenshot.jpg" rel="lightbox[641]"><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/TabLinksScreenshot-150x150.jpg" alt="" title="TabLinksScreenshot" width="150" height="150" class="alignright size-thumbnail wp-image-644" /></a></p><p>TabLinks is a quick experiment, designed to meet my own needs. It needs some work, but it does the trick: it copies the link information for every tab open in Safari, and outputs them as a list, based on a user-defined template. You set up your template in the Extension settings, and use the following variables to define your link style:</p><ul><li>%u = URL</li><li>%t = title</li><li>%w = window index</li><li>%n = tab index (within window)</li></ul><p>That’s all there is for now. The default link format is a Markdown reference list, with the references being window#-tab#, so they come out as <code>[0-12]: yourlink.com "and its title"</code>. If you dig Markdown, you can easily modify this to make a list of titles linked to their respective pages by changing the template to <code>* [%t](%u)</code>. If you’d rather get plain HTML, try <code>&lt;a href="%u"&gt;%t&lt;/a&gt;</code>. Maybe you just want a list of URLs, in which case your template would just be <code>%u</code>.</p><p>Like I said, it’s pretty simple right now, and may stay that way while I go back to tidy up and improve on <a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/">InstapaperBeyond</a>. I do plan to add a checkbox to the settings that lets you decide whether clicking the toolbar button copies just the current window’s tabs, or all tabs as it does now. I would have liked to add a “copy to clipboard” button, but (as far as I know), Safari doesn’t allow access to the clipboard in any fashion, even with something like <a href="http://code.google.com/p/zeroclipboard/">ZeroClipboard</a>.</p><p>The popup window could use some classing up, too… a little CSS3 animation/transition and some more consistent styling that isn’t constantly being overridden by site styles. However, it’s quite useful to me as is, so I’m sharing it in the hopes that others will find it as helpful as I do. Personally, I use it when I write posts, especially <a href="http://www.tuaw.com/bloggers/brett-terpstra">on TUAW</a>, where there are a lot of links to deal with. I pop open the links I know, run searches in new tabs for the ones I need, then copy the whole bunch as references to paste into the top of my post.</p><p class="download_desc"><a href="http://brettterpstra.com/downloads/TabLinks1.3.zip" title="Download TabLinks Safari Extension (381)"><img src="http://cdn.brettterpstra.com/wp-content/uploads/downloads/thumbnails/2010/06/Icon.png" alt="download image for TabLinks Safari Extension" width="64" height="64" /></a><a href="http://brettterpstra.com/downloads/TabLinks1.3.zip" title="Download TabLinks Safari Extension (381)">TabLinks Safari Extension</a> — TabLinks gathers all of the link information from every open tab and presents them for copying based on a user-defined template. <a href="http://brettterpstra.com/2010/06/18/tablinks-safari-extension/">More Info</a></p><hr style="clear:both;visibility:hidden" /><ul><li><a href="http://brettterpstra.com/2010/05/07/textexpander-experiments/" rel="bookmark">TextExpander experiments</a></li><li><a href="http://brettterpstra.com/2010/06/26/minor-tablinks-update/" rel="bookmark">Minor TabLinks update</a></li><li><a href="http://brettterpstra.com/2010/03/06/saving-safari-browsing-sessions-to-evernote/" rel="bookmark">Saving Safari browsing sessions to Evernote</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/06/18/tablinks-safari-extension/feed/</wfw:commentRss> <slash:comments>14</slash:comments> </item> <item><title>Antique 1.6, final release</title><link>http://brettterpstra.com/2010/06/17/antique-1-6-final-release/</link> <comments>http://brettterpstra.com/2010/06/17/antique-1-6-final-release/#comments</comments> <pubDate>Thu, 17 Jun 2010 15:24:57 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[Featured]]></category> <category><![CDATA[antique]]></category> <category><![CDATA[hacks]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[reader]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[safari 5]]></category> <category><![CDATA[typography]]></category> <category><![CDATA[widont]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=624</guid> <description><![CDATA[This will be the last release of Antique, I think, barring a few minor fixes (follow @ttscoff for updates on this and other projects). You can download it here. The code is completely open source, if anyone wants to continue the project feel free (credit would be swell, where it's due). I'll be putting my free time into Instapaper Beyond&#8230;<ul><li><a href="http://brettterpstra.com/2010/06/13/antique-1-5-for-safari-reader/" rel="bookmark">Antique 1.5 for Safari Reader</a></li><li><a href="http://brettterpstra.com/2010/06/12/safari-reader-antique-hack/" rel="bookmark">Safari Reader Antique hack</a></li><li><a href="http://brettterpstra.com/2010/06/12/antique-safari-reader-hack-update-with-evernote-goodness/" rel="bookmark">Antique Safari Reader hack update with Evernote goodness</a></li></ul> ]]></description> <content:encoded><![CDATA[<p><a href="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/AntiqueImageLinking.jpg" rel="lightbox[624]"><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/AntiqueImageLinking-150x150.jpg" alt="" title="AntiqueImageLinking" width="150" height="150" class="alignright size-thumbnail wp-image-628" /></a></p><p>This will be the last release of Antique, I think, barring a few minor fixes (follow <a href="http://twitter.com/ttscoff">@ttscoff</a> for updates on this and other projects). You can download it <a href="http://brettterpstra.com/downloads/Antique1.6.zip" title="Antique Reader 1.6">here</a>. The code is completely open source, if anyone wants to continue the project feel free (credit would be swell, where it’s due). I’ll be putting my free time into <a href="http://brettterpstra.com/2010/06/09/instapaper-beyond-for-safari/">Instapaper Beyond</a> and other more “legitimate” projects now (although I really would like to do a nice, high-contrast, Helvetica version…). In deference to <a href="http://farukat.es/journal/2010/06/456-stop-hacking-safari-reader">Faruk Ateş</a>, I’d like to clearly state that this <em>is</em> a hack, and you run a risk (albeit very minimal) of breaking your Safari install if you don’t know what you’re doing. I also won’t be posting further simplified instructions for installation, but they’re not hard to find. For advanced users, you simply need to know that you’re replacing <code>Reader.html</code> in <code>Contents/Resources</code>.</p><p><a href="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/AntiqueHeadlineSplit.jpg" rel="lightbox[624]"><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/AntiqueHeadlineSplit-150x150.jpg" alt="" title="AntiqueHeadlineSplit" width="150" height="150" class="alignright size-thumbnail wp-image-627" /></a></p><p>The coolest changes, in my opinion, are an <strong>amped-up Widon’t</strong> for headlines, and <strong>improved image linking</strong>. On the Widon’t end, if a title exceeds the width of the headline area, it’s actually split in the middle to provide more equal-length lines. It’s neat-o. And for the images: I had it only lightboxing images which were too large for the style and which <em>weren’t</em> already linked somewhere else, resulting in the user never knowing what would happen when they clicked an image. Now, if an image is linked to an external site, that link is extracted and placed on a line below the image. If an alt or title attribute are present in the image or the link, they’re preferred over the source attribute for naming the link, which should provide a decent idea of where you’re going, in most cases. Images which are linked, then, are always linked to the Colorbox effect, and will never take you out of the Reader page. Ah, consistency.</p><p>Here’s what else is new in this version.</p><ul><li>I swapped out the scrollbar images, shifted the colors a little, and included them in the HTML file.</li><li>Some style changes, including a darker background and slightly heavier gradient</li><li>Massively fixed up the <a href="http://brettterpstra.com/2010/06/14/ampersands-javascript/">ampersand code</a>. Also shifted ampersands 1 pixel left for better kerning within non-italicized text.</li><li>Improved smashing of empty paragraphs in bad markup to avoid huge spaces between paragraphs.</li><li>Fixed a CSS mistake I had introduced which caused the background and drop shadow to be visible before the content slid up from the bottom.</li><li>Set up an onscroll check for new elements. Every time the page is scrolled, Antique checks for new elements (i.e. additional pages that were inserted after initial load) and applies the default functions to them.</li><li>did I mention 12px Droid Sans Mono for code blocks? 12px seems reasonable, and doesn’t change when zooming/shrinking the rest of the text.</li></ul><p>Are there too many buttons in the HUD for your taste? They’re there as an example, but you can remove them easily by commenting out the “button” lines at the bottom of the Reader.html file. The HUD will adjust size and position automatically based on the number of buttons you have in there, so just remove the ones that aren’t of use to you.</p><p>If you’re playing with Reader styles, here’s a tip: you can set up a “sandbox” page to speed up development (at least with css). Once Reader has loaded a page that has elements you want to style, right click and choose “Inspect Element” (obviously, you have to have the developer menu enabled in preferences). Then, right click on the doctype declaration in the element inspector and choose “Copy as HTML.” That will give you the full HTML of the <em>rendered</em> document, which you can save to a new HTML file. Extract the inline stylesheets and link them into external stylesheets, and you can edit in CSSEdit or Firebug. It’s handy, given that, in order to change the live styles, you have to restart Safari every time you edit Reader.html.</p><p>I had started working on smart quotes and other javascript-based typography changes, but decided it wasn’t worth the time to try to come up with regular expressions that covered every possible circumstance. If anyone wants to pick up where I left off, I’d love to see what you come up with.</p><p class="download_desc"><a href="http://brettterpstra.com/downloads/Antique1.6.zip" title="Download Antique 1.6 for Safari Reader (1569)"><img src="http://brettterpstra.com/wp-content/plugins/download-monitor/page-addon/thumbnail.gif" alt="download image for Antique 1.6 for Safari Reader" width="64" height="64" /></a><a href="http://brettterpstra.com/downloads/Antique1.6.zip" title="Download Antique 1.6 for Safari Reader (1569)">Antique 1.6 for Safari Reader</a> — Version 1.6 of the Antique hack for Safari 5. Adds pleasant styling to Reader, with many additional features. <a href="http://brettterpstra.com/2010/06/17/antique-1-6-final-release/">More Info</a></p><hr /><ul><li><a href="http://brettterpstra.com/2010/06/13/antique-1-5-for-safari-reader/" rel="bookmark">Antique 1.5 for Safari Reader</a></li><li><a href="http://brettterpstra.com/2010/06/12/safari-reader-antique-hack/" rel="bookmark">Safari Reader Antique hack</a></li><li><a href="http://brettterpstra.com/2010/06/12/antique-safari-reader-hack-update-with-evernote-goodness/" rel="bookmark">Antique Safari Reader hack update with Evernote goodness</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/06/17/antique-1-6-final-release/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Ampersands &amp; Javascript</title><link>http://brettterpstra.com/2010/06/14/ampersands-javascript/</link> <comments>http://brettterpstra.com/2010/06/14/ampersands-javascript/#comments</comments> <pubDate>Mon, 14 Jun 2010 16:18:31 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[antique]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[typography]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=613</guid> <description><![CDATA[While playing around with Antique1, I decided I really wasn't in love with the ampersands that were included in any of the fonts I was working with. Normally, I'd just run everything through Typogrify2 and get some handy CSS classes to work with. Working in Safari's Reader, though, I only had access to Javascript (and jQuery, now). I set out&#8230;<ul><li><a href="http://brettterpstra.com/2010/06/17/antique-1-6-final-release/" rel="bookmark">Antique 1.6, final release</a></li><li><a href="http://brettterpstra.com/2010/05/16/targeting-and-filtering-ie-with-relative-ease-2/" rel="bookmark">Targeting and filtering IE with relative ease</a></li><li><a href="http://brettterpstra.com/2010/05/26/auto-lightboxing-image-links/" rel="bookmark">Auto-lightboxing image links</a></li></ul> ]]></description> <content:encoded><![CDATA[<p><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/ampersandjavascriptheader.jpg" alt="Ampersands and Javascript" border="0" width="650" height="187" class="headerimg" />While playing around with Antique<sup id="fnref:antique"><a href="#fn:antique" rel="footnote">1</a></sup>, I decided I really wasn’t in love with the ampersands that were included in any of the fonts I was working with. Normally, I’d just run everything through Typogrify<sup id="fnref:typogrify"><a href="#fn:typogrify" rel="footnote">2</a></sup> and get some handy CSS classes to work with. Working in Safari’s Reader, though, I only had access to Javascript (and jQuery, now).</p><p><a href="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/AntiqueAmpersands.jpg" rel="lightbox[613]"><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/AntiqueAmpersands-300x58.jpg" alt="" title="Antique - Ampersands" width="300" height="58" class="alignright size-medium wp-image-614" /></a>I set out on a search for an easy, all-purpose solution, but nothing worked as well as I wanted it to. So I did a little scavenging and put together a couple of functions that do the job pretty well. They use jQuery, but could just as easily be done with pure Javascript, if you really wanted to.</p><p><span id="more-613"></span></p><p>Here are the two functions I’m using in the latest (unreleased, at this moment) version of Antique:</p><div markdown=0><pre><code>
function fixAmpersands() {
    // entity encodes only ampersands that aren&#x27;t already encoded
    $(&quot;h1,h2,h3,p:contains(&#x27;&amp;&#x27;)&quot;, document.body).each(function() {
        if( this.nodeType == 3 ) {
            // regex from Stack Overflow http://bit.ly/aJZVCG
            $(this).html( $(this).html().replace( /&amp;(?![a-zA-Z]{2,6};|#[0-9]{2,4};)/g, &quot;&amp;amp;&quot; ) );
        }
    });
}
function dressUpAmpersands() {
    // adds a span with class &#x27;amp&#x27; to the entity-encoded ampersands
    $(&quot;h1,h2,h3,p:contains(&#x27;&amp;&#x27;)&quot;, document.body).each(function() {
        $(this).html( $(this).html().replace( /&amp;amp;/g, &quot;&lt;span class=&#x27;amp&#x27;&gt;&amp;amp;&lt;/span&gt;&quot; ) );
    });
}
$(document).ready(function() {
    fixAmpersands();
    dressUpAmpersands();
});
</code></pre></div><p>They seem to work pretty well, so far. I accompany them with some CSS I nicked from <a href="http://simplebits.com/notebook/2008/08/14/ampersands-2/">SimpleBits</a> and <a href="http://patrickhaney.com/thinktank/2008/08/19/automatic-awesompersands">Patrick Haney</a>:</p><div markdown=0><pre><code>
.page span.amp { 
    font-family: Baskerville, Palatino, Constantia, "Book Antiqua", "URW Palladio L", serif;
    font-style: italic;
}
</code></pre></div><p>In my situation, it doesn’t really matter if ampersands are captured within code blocks, but just to keep styling consistent, I also force any .amp-wrapped ampersands within pre and code blocks to match the pre/code styling:</p><div markdown=0><pre><code>
#article .page pre,#article .page code,.page code span.amp, .page pre span.amp {
    font-family: 'Droid Sans Mono', 'Andale Mono', 'Courier New', Courier, monospace !important;
    font-style: normal;
}
</code></pre></div><p>Of course, this is all really better handled server-side with, say, PHP, but if you’re looking for spicy typography and are limited to client-side solutions, give it a shot! I’m running these right before my rather wicked new version of widon’t which splits long titles into nearly equal-length lines… more on that soon.</p><div class="footnotes"><hr /><ol><li id="fn:antique"><p><a href="http://brettterpstra.com/2010/06/13/antique-1-5-for-safari-reader/">http://brettterpstra.com/2010/06/13/antique-1–5-for-safari-reader/</a> <a href="#fnref:antique" rev="footnote">↩</a></p></li><li id="fn:typogrify"><p><a href="http://code.google.com/p/typogrify/">http://code.google.com/p/typogrify/</a> <a href="#fnref:typogrify" rev="footnote">↩</a></p></li></ol></div><ul><li><a href="http://brettterpstra.com/2010/06/17/antique-1-6-final-release/" rel="bookmark">Antique 1.6, final release</a></li><li><a href="http://brettterpstra.com/2010/05/16/targeting-and-filtering-ie-with-relative-ease-2/" rel="bookmark">Targeting and filtering IE with relative ease</a></li><li><a href="http://brettterpstra.com/2010/05/26/auto-lightboxing-image-links/" rel="bookmark">Auto-lightboxing image links</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/06/14/ampersands-javascript/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Antique 1.5 for Safari Reader</title><link>http://brettterpstra.com/2010/06/13/antique-1-5-for-safari-reader/</link> <comments>http://brettterpstra.com/2010/06/13/antique-1-5-for-safari-reader/#comments</comments> <pubDate>Sun, 13 Jun 2010 21:19:16 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[antique]]></category> <category><![CDATA[hacks]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[safari 5]]></category><guid isPermaLink="false">http://brettterpstra.com/?p=592</guid> <description><![CDATA[There is a new version of Antique available! Check out version 1.6! Version 1.5 1.6 of Antique (originally posted here) is officially available for download. Here's what's new! jQuery: added the jQuery library via Google's Ajax API to make some of the other additions much easier to implement. Colorbox: links to images are automatically opened in a "lightbox" so you&#8230;<ul><li><a href="http://brettterpstra.com/2010/06/12/safari-reader-antique-hack/" rel="bookmark">Safari Reader Antique hack</a></li><li><a href="http://brettterpstra.com/2010/06/12/antique-safari-reader-hack-update-with-evernote-goodness/" rel="bookmark">Antique Safari Reader hack update with Evernote goodness</a></li><li><a href="http://brettterpstra.com/2010/06/17/antique-1-6-final-release/" rel="bookmark">Antique 1.6, final release</a></li></ul> ]]></description> <content:encoded><![CDATA[<p><strong>There is a new version of Antique available! <a href="http://brettterpstra.com/2010/06/17/antique-1-6-final-release/">Check out version 1.6</a>!</strong></p><p><a href="http://brettterpstra.com/downloads/Antique1.6.zip" title="Download Antique 1.6">Version <del datetime="2010-06-18T16:36:40+00:00">1.5</del> <ins datetime="2010-06-18T16:36:40+00:00">1.6</ins> of Antique</a> (<a href="http://brettterpstra.com/2010/06/12/safari-reader-antique-hack/">originally posted here</a>) is officially available for download. Here’s what’s new!</p><hr style="visibility:hidden;clear:both" /><ul><li><a href="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/Antique1.5.1screenshot.jpg" rel="lightbox[592]"><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/Antique1.5.1screenshot-150x150.jpg" alt="" title="Antique1.5.1screenshot" width="150" height="150" class="alignright size-thumbnail wp-image-609" /></a> <strong>jQuery:</strong> added the <a href="http://jquery.com/">jQuery</a> library via Google’s Ajax API to make some of the other additions much easier to implement.</li><li><strong>Colorbox:</strong> links to images are automatically opened in a “lightbox” so you don’t have to leave the page. Uses jQuery <a href="http://colorpowered.com/colorbox/">Colorbox</a> and automatically applies the effect to links ending in ‘.jpg’ or ‘.png’.</li><li><strong>Widon’t:</strong> headlines and paragraphs have a widon’t function applied to them, preventing “widows” (short words alone on a line). This was mostly annoying me in the top-level headings of the page, but it’s a nice touch throughout. It ignores words longer than 8 characters. They’ll do just fine on their own.</li><li><strong>New HUD buttons:</strong> in addition to the Evernote web clipper button in the floating HUD, there are new buttons for <a href="http://www.devon-technologies.com/products/devonthink/devonthink2.html">DEVONthink</a>, <a href="http://delibarapp.com/">Delibar</a> and <a href="http://www.celmaro.com/webbla/">Webbla</a>. These are mostly to show how to pull it off, and are easily edited. See the instructions below to remove buttons from the HUD.</li><li><strong>Pass text selections:</strong> unlike using bookmarklets, clicking on a HUD icon makes you lose your text selection. Any service that accepts a selection as a note or description (Evernote, DEVONthink, Webbla, etc.) won’t normally work. By storing the selected text in an HTML5 sessionStorage key every time your mouse enters the HUD, Antique is able to pass what <em>was</em> selected before you clicked the button. <em>Still working on making this function with Evernote.</em></li><li><a href="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/antiqueColorBoxScreenshot.jpg" rel="lightbox[592]"><img src="http://cdn.brettterpstra.com/wp-content/uploads/2010/06/antiqueColorBoxScreenshot-150x150.jpg" alt="" title="Antique with ColorBox" width="150" height="150" class="alignright size-thumbnail wp-image-595" /></a> <strong>Smarter image resizing:</strong> when you load a page, Antique shrinks the larger images. It’s smarter now, though: wide, centered images are only reduced slightly and left centered, and any floated images that are reduced (and aren’t already linked somewhere) are now linked to the full size version of themselves, which will display in-page using Colorbox. Floated images also have bottom margin and clear:left applied to them to prevent horizontal stacking when images are close to each other in the layout.</li><li><strong><em>Minor Update:</em></strong> <em>(version 1.5.1)</em> I just swapped out Crimson Text for OFL Sorts Mill Goudy TT, primarily because I like the quotation marks much better. I also added hanging quotes (image-based) to blockquotes, and improved code blocks and bulleted lists wrapped around images.</li></ul><h3>Installation</h3><p>If you want to try out the style, <a href="http://brettterpstra.com/downloads/Antique1.6.zip">download it here</a> and open the archive. Inside you’ll find a file called Reader.html. The file you’re going to replace (back it up somewhere safe first) is <code>/Applications/Safari.app/Contents/Resources/Reader.html</code>. If you don’t know how to do this from Terminal, you can just do it in Finder: go to your Applications folder and locate Safari, then right click on it and choose “Show Package Contents.” That will open a new window with the inner workings of Safari inside it. Open the folder called Contents, and then the Resources folder inside of that. Locate the file Reader.html and drag it out to your desktop (that’s your original, keep it safe). Then drag the new Reader.html file you downloaded into the Resources folder. Restart Safari and try it out!</p><p>There are lots of minor efficiency and style tweaks, but those are the major changes. If you’re interested in modifying the HUD (removing unnecessary buttons), read on…</p><p><span id="more-592"></span></p><h3>Removing HUD buttons</h3><p>This part is a cinch, even if you don’t know anything about Javscript or HTML. The HUD buttons are in the HTML body section of the Reader.html file, and you can just edit them out in a text editor. If you open the file (Reader.html) in a your editor of choice (as plain text, not rich text), and scroll all the way to the bottom, you’ll see a series of “<code>&lt;button id="hud... &gt;</code>” lines. It will be pretty obvious what each one is for, and you can simply comment out or delete the lines for buttons you don’t need. Antique will automatically resize and reposition the HUD based on the number of buttons in it, so that’s all you have to worry about.</p><h3>Adding HUD buttons</h3><p>Adding buttons is a different story, depending on what you want the button to do. So far, I’ve mostly been converting existing bookmarklets. You can set the function to call right in the button definition (just copy an existing button and edit it), then add the appropriate function to the script section above. Note that any bookmarklet that uses <code>window.location</code>, <code>location.href</code> or any means of getting the page title attribute are going to break. Reader overrides all of that, but thankfully, it stores the info in an object called ReaderJS. You can access the original page url with <code>ReaderJS.originalURL</code> and the title with <code>ReaderJS.displayTitle</code>. Those two make it pretty easy to cover 90% of bookmarklets you’d want to use.</p><p>I’m including most external javascript plugins and libraries directly in the html page. Standard rules don’t apply, this is all being served locally and the fewer files you have to keep track of, the easier it is to distribute. If your needs are different, you can reference external files in the <code>Safari.app/Contents/Resources</code> folder with <code>safari-resource:/filename.ext</code>, where filename.ext is the name of the file.</p><p>Antique handles the resizing of the HUD automatically, but if you’re doing it from scratch you’ll need to adjust the width and left-margin of #hud in the css section. The buttons are 48x48px PNG files, with the icon occupying approximately 36x36px of that space. White and transparent pixels only, if you want to fit the aesthetic, and the “inactive” version should be saved at about 70% opacity. I’ve been encoding all of my PNG files in base64 and including them inline in the CSS to make it easier to distribute, but you can reference them as mentioned above.</p><p>You also can’t use <code>document.location</code> when Reader.html is loaded, so most bookmarklets need to be modified. You can use <code>window.open</code> and immediately close the new window, like this:</p><div markdown=0><pre><code>
function sendToWebbla() {
    var wlWindow = window.open(&#x27;webbla:url=&#x27;+encodeURIComponent(ReaderJS.originalURL)+&#x27;&amp;mode=modify&amp;title=&#x27;+encodeURIComponent(ReaderJS.displayTitle))+&#x27;&amp;textSelection=&#x27;+encodeURIComponent(sessionStorage.getItem(&#x27;textSelection&#x27;));
    wlWindow.close();
    self.focus();
}
</code></pre></div><p>I have the <code>self.focus()</code> in there because I have <a href="http://haoli.dnsalias.com/Saft/index.html">Saft</a> running and restoring focus to the last active tab, which somehow is missing and leaving me on the wrong tab when I execute the above sequence. So this just brings me back to the right tab. When it runs, you can just <em>barely</em> see that it’s even opening a new window/tab. Should be pretty seamless for most folks.</p><p>I think that covers the process in a general sense. Each button I’ve added has had its own quirks and issues, so it would take a lot longer to detail every possible problem you’d run in to.</p><p class="download_desc"><a href="http://brettterpstra.com/downloads/Antique1.6.zip" title="Download Antique 1.6 for Safari Reader (1569)"><img src="http://brettterpstra.com/wp-content/plugins/download-monitor/page-addon/thumbnail.gif" alt="download image for Antique 1.6 for Safari Reader" width="64" height="64" /></a><a href="http://brettterpstra.com/downloads/Antique1.6.zip" title="Download Antique 1.6 for Safari Reader (1569)">Antique 1.6 for Safari Reader</a> — Version 1.6 of the Antique hack for Safari 5. Adds pleasant styling to Reader, with many additional features. <a href="http://brettterpstra.com/2010/06/17/antique-1-6-final-release/">More Info</a></p><hr style="visibility:hidden;clear:both" /><ul><li><a href="http://brettterpstra.com/2010/06/12/safari-reader-antique-hack/" rel="bookmark">Safari Reader Antique hack</a></li><li><a href="http://brettterpstra.com/2010/06/12/antique-safari-reader-hack-update-with-evernote-goodness/" rel="bookmark">Antique Safari Reader hack update with Evernote goodness</a></li><li><a href="http://brettterpstra.com/2010/06/17/antique-1-6-final-release/" rel="bookmark">Antique 1.6, final release</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://brettterpstra.com/2010/06/13/antique-1-5-for-safari-reader/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using xcache
Database Caching 90/444 queries in 4.943 seconds using xcache
Object Caching 2280/4363 objects using xcache
Content Delivery Network via Amazon Web Services: CloudFront: Amazon Web Services: S3: cdn.brettterpstra.com

Served from: brettterpstra.com @ 2010-08-01 03:24:36 -->