<?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>gnapse.com &#187; Programming</title>
	<atom:link href="http://gnapse.com/blog/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://gnapse.com/blog</link>
	<description>whatever comes to my mind</description>
	<lastBuildDate>Wed, 02 May 2012 15:08:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Unit Conversion for Alfred and Java</title>
		<link>http://gnapse.com/blog/2012/02/07/unit-conversion-for-alfred/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=unit-conversion-for-alfred</link>
		<comments>http://gnapse.com/blog/2012/02/07/unit-conversion-for-alfred/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 22:14:53 +0000</pubDate>
		<dc:creator>ernesto</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[alfredapp]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[extensions]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[offline]]></category>
		<category><![CDATA[search engine]]></category>
		<category><![CDATA[unit conversion]]></category>

		<guid isPermaLink="false">http://gnapse.com/blog/?p=335</guid>
		<description><![CDATA[Have you ever tried typing unit conversion queries in Google&#8217;s search box? You&#8217;ll get something like this. Imagine if you could that offline, or even be able to have this functionality available to incorporate it in scripts or other programs as well. Imagine you could have this functionality as an extension in Mac&#8217;s AlfredApp. Introducing Metric: [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever tried typing unit conversion queries in Google&#8217;s search box? You&#8217;ll get something like this.</p>
<div id="attachment_336" class="wp-caption aligncenter" style="width: 552px"><a href="http://gnapse.com/blog/wp-content/uploads/2012/02/google-unit-conversion.png"><img class="size-full wp-image-336" title="Google Unit Conversion" src="http://gnapse.com/blog/wp-content/uploads/2012/02/google-unit-conversion.png" alt="Google Unit Conversion" width="542" height="293" /></a><p class="wp-caption-text">Performing unit conversion queries using Google&#39;s search box.</p></div>
<p>Imagine if you could that offline, or even be able to have this functionality available to incorporate it in scripts or other programs as well. Imagine you could have this functionality as an extension in Mac&#8217;s <a title="Alfred App" href="http://www.alfredapp.com/" target="_blank">AlfredApp</a>.</p>
<h2>Introducing Metric: A Unit Conversion Library for Java</h2>
<p>I needed this functionality to develop an extension for Alfred, the most wonderful Mac launcher, and I wanted it to work offline, without having to retrieve the results from Google or another online source. So I created a Java library that&#8217;s capable of performing unit conversion queries expressed in natural English. I called it simply <strong>Metric</strong>, made it open source, and <a href="https://github.com/gnapse/metric" target="_blank">published it on Github</a>. You can clone it, fork it, play with it or contribute back if you will. The code is fairly well documented and organized. The library includes some supporting sub-libraries that may be used independently in other projects, including a plural/singular inflector for the English language.</p>
<h2>Metric meets Alfred</h2>
<p>The original goal of developing a library like <strong>Metric</strong> was to use it as an Alfred extension. Alfred (<a href="http://www.alfredapp.com/" target="_blank">http://www.alfredapp.com/</a>) is a wonderful productivity application for Mac, much like Quicksilver or Google&#8217;s Quick Search Box, but  a little bit better in my opinion. You can grab a copy of Metric as an Alfred extension <a title="Unit Conversion extension for AlfredApp" href="http://cl.ly/340O1y0n0p3c1b2D3n30" target="_blank">here</a>. After you install this extension, you can type unit conversion queries on Alfred using <code>cv</code> as keyword.</p>
<div id="attachment_337" class="wp-caption aligncenter" style="width: 658px"><a href="http://gnapse.com/blog/wp-content/uploads/2012/02/alfred-unit-conversion.png"><img class="size-full wp-image-337" title="Alfred Unit Conversion" src="http://gnapse.com/blog/wp-content/uploads/2012/02/alfred-unit-conversion.png" alt="Unit Conversion with Alfred" width="648" height="190" /></a><p class="wp-caption-text">Performing a unit conversion query with Alfred</p></div>
<p>This Alfred extension shows the results of the conversion using Growl, but I guess if you already have a Mac chances are that you Growl installed. If not, you can get it <a title="Growl" href="http://growl.info/" target="_blank">here</a>.</p>
<h2>Links and resources</h2>
<ul>
<li><a href="https://github.com/gnapse/metric" target="_blank">Metric source code repository on Github</a></li>
<li><a href="http://cl.ly/340O1y0n0p3c1b2D3n30" target="_blank">Unit Conversion extension for AlfredApp</a></li>
<li><a href="http://www.alfredapp.com/" target="_blank">Alfred App</a> and <a href="http://growl.info/" target="_blank">Growl</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://gnapse.com/blog/2012/02/07/unit-conversion-for-alfred/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Skip Lists (a.k.a. Balanced Trees are overrated)</title>
		<link>http://gnapse.com/blog/2011/05/18/skip-lists/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=skip-lists</link>
		<comments>http://gnapse.com/blog/2011/05/18/skip-lists/#comments</comments>
		<pubDate>Wed, 18 May 2011 13:37:38 +0000</pubDate>
		<dc:creator>ernesto</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Whatever]]></category>
		<category><![CDATA[balanced trees]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[skip lists]]></category>
		<category><![CDATA[sorting]]></category>
		<category><![CDATA[time complexity]]></category>

		<guid isPermaLink="false">http://gnapse.com/blog/?p=299</guid>
		<description><![CDATA[Programming computers is fascinating. A couple of days ago I was introduced to a new data structure I did not know before. It’s called a skip list. It’s a sorted linked list, where the nodes are linked at different levels, forming increasingly sparse chains, each of which skips more nodes, and therefore is faster to [...]]]></description>
			<content:encoded><![CDATA[<p>Programming computers is fascinating.</p>
<p>A couple of days ago I was introduced to a new data structure I did not know before. It’s called a <a class="print-href" href="http://en.wikipedia.org/wiki/Skip_list" target="_blank">skip list</a>. It’s a sorted linked list, where the nodes are linked at different levels, forming increasingly sparse chains, each of which <em>skips</em> more nodes, and therefore is faster to traverse, allowing search algorithms to hop over parts of the list when searching. That’s why they’re called <em>skip lists</em>.</p>
<p>The concept was shown to me during a job interview. They briefly introduced me to the concept of skip lists using an image. It is said that an image is worth a thousand words, and in this case the assertion holds:</p>
<div><a href="http://en.wikipedia.org/wiki/Skip_list"><img class="aligncenter" style="margin-top: 15px; margin-bottom: 20px;" title="A skip list" src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Skip_list.svg/470px-Skip_list.svg.png" alt="" width="470" height="110" /></a><span id="more-299"></span></div>
<p>After I finished the interview I went on to <a class="print-href" href="http://www.google.com/search?q=skip+list" target="_blank">find out more about skip lists</a>, and I was amazed on how I did not stumbled upon them before. Immediately my instinct was to try out the algorithm I came up with during my interview, and when I saw it worked, I ended up writing a whole new <code>SortedMap</code> subclass in Java, implemented with skip lists.</p>
<p>It is surprisingly amazing how easy it is to write the routines for all the basic operations on skip lists, like adding, updating, removing and querying on them, specially when you see it described as a probabilistic data structure, which you have to admit that looks scary at first glance.</p>
<h2>Performance</h2>
<table style="border-width: 1px; border-style: solid; border-collapse: collapse; margin-left: 10px; margin-bottom: 10px;" border="1" cellspacing="0" cellpadding="5" align="right">
<caption></caption>
<tbody>
<tr>
<th>Operation</th>
<th>Expected time complexity</th>
</tr>
<tr>
<td>Insert</td>
<td><em>O(log n)</em></td>
</tr>
<tr>
<td>Delete</td>
<td><em>O(log n)</em></td>
</tr>
<tr>
<td>Search</td>
<td><em>O(log n)</em></td>
</tr>
<tr>
<td>Item at index</td>
<td><em>O(log n)</em> with <a title="Indexable Skip Lists" href="http://en.wikipedia.org/wiki/Skip_list#Indexable_skiplist" target="_blank">some tweaking</a></td>
</tr>
<tr>
<td>Enumerate</td>
<td><em>O(n)</em></td>
</tr>
</tbody>
</table>
<div>
<p>Performance-wise they can behave similar to, or perhaps even better than, balanced binary trees, according to the assertions made by the inventor of this concept in his <a href="ftp://ftp.cs.umd.edu/pub/skipLists/skiplists.pdf" target="_blank">original paper</a> about them. They&#8217;re also easier to implement and comprehend, and the algorithms have a very little constant factor compared to the often recursive and complex algorithms on red-black, 2-3 trees, and other types of balanced trees.</p>
<h2>Indexing</h2>
<p>But the true killer feature of skip lists lie in its indexing capabilities. It&#8217;s possible, with some minor <a title="Indexable Skip Lists" href="http://en.wikipedia.org/wiki/Skip_list#Indexable_skiplist">tweaks</a>, to find the i<sup>th</sup> element in the list with an expected time complexity of <em>O(log n)</em>. With this you can have a data structure that can act as a sorted dictionary, but as an array or vector at the same time. <del>That&#8217;s not something you can do with self-balanced search trees, at least not that I&#8217;m aware of.</del> I&#8217;m not quite sure right now in what type of application could this be useful, but it is certainly quite amazing, and worth having in mind if one ever finds such a situation.</p>
<p><strong>Were you familiar with skip lists already? Do you know about any other cool and useful data structure that you would like to share?</strong></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://gnapse.com/blog/2011/05/18/skip-lists/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Five reasons to love Objective-C</title>
		<link>http://gnapse.com/blog/2010/10/06/five-reasons-to-love-objective-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=five-reasons-to-love-objective-c</link>
		<comments>http://gnapse.com/blog/2010/10/06/five-reasons-to-love-objective-c/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 20:35:04 +0000</pubDate>
		<dc:creator>ernesto</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[programming languages]]></category>

		<guid isPermaLink="false">http://gnapse.com/blog/?p=218</guid>
		<description><![CDATA[Objective-C was always a distant name for me, a blur memory from lists of languages read somewhere. I recall having a very subtle curiosity for the name. It&#8217;s like saying two things in one. First, it&#8217;s like adding objectivity to C, but also the objective word gives a hint that objects and Object-Oriented Programming are somehow [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Objective-C</strong> was always a distant name for me, a blur memory from lists of languages read somewhere. I recall having a very subtle curiosity for the name. It&#8217;s like saying two things in one. First, it&#8217;s like adding objectivity to <a class="print-href" title="The C language at Wikipedia" href="http://en.wikipedia.org/wiki/C_programming_language" target="_blank">C</a>, but also the <em>objective </em>word gives a hint that objects and Object-Oriented Programming are somehow involved. It&#8217;s a nice and insightful word play with the pun intended.</p>
<p><a class="print-href" title="Objective-C at Wikipedia" href="http://en.wikipedia.org/wiki/Objective-C" target="_blank">Objective-C</a> provides most of the benefits of <a class="print-href" title="C++ at Wikipedia" href="http://en.wikipedia.org/wiki/C%2B%2B" target="_blank">C++</a>, plus some more benefits that C++ does not provide at all. And I am not talking only about <a class="print-href" title="Simula at Wikipedia" href="http://en.wikipedia.org/wiki/Simula" target="_blank">Simula</a> vs. <a class="print-href" title="Smalltalk at Wikipedia" href="http://en.wikipedia.org/wiki/Smalltalk" target="_blank">Smalltalk</a> philosophical differences here, but about stuff that C++ could have actually had without breaking its Simula-like philosophy. Some of the features/reasons I will enumerate below fall under this category.<span id="more-218"></span></p>
<h2>Declared properties</h2>
<p>Objective-C provides a simple way to <a title="Declared Properties at the Objective-C Language Reference" href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html" target="_blank">declare properties</a> that define and describe the state of an object, as well as to implement the way we access these properties.</p>
<p>Properties ensure that we adhere to the principle of encapsulation, by which an object controls the way that other objects have access to query its own state. In Objective-C all instance variables are private to an object, and its values can only be accessed via properties defined in the object&#8217;s class.</p>
<p>Properties also play a big role in some of the core features of the runtime library, such as <a title="Key-Value Coding" href="http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/KeyValueCoding/KeyValueCoding.html" target="_blank">KVC</a>, <a title="Key-Value Observing" href="http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html" target="_blank">KVO</a>, <a href="http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/ModelObjects/Introduction.html" target="_blank">Model Objects</a>, etc. I wish C++ would have had this one.</p>
<h2>Protocols</h2>
<p><a title="Protocols in the Objective-C Programming Language" href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProtocols.html" target="_blank">Protocols</a> are similar to <a title="Java Interface at Wikipedia" href="http://en.wikipedia.org/wiki/Interface_(Java)" target="_blank">interfaces in Java</a>. When I started learning Java over twelve years ago, no one made a reference to Objective-C protocols as a similar feature of an existing language, even though protocols were introduced to Objective-C several years before Java appeared.</p>
<p>A protocol defines an abstract interface that classes can adhere to. This interface consists of a set of method definitions that implementing classes should provide.</p>
<p>As a plus, compared to Java interfaces, protocols can define some or all of its methods to be optional, so that implementing classes can opt to provide implementations for the optional methods or not. In this case when sending a message to invoke an optional method on an object that conforms to the protocol, the caller should ensure first, via reflection, that the object is able to respond to the message.</p>
<p><span style="font-weight: normal;">Compared to C++, protocols provide a way to circumvent the lack of multiple inheritance, although their use in the standard Cocoa library is mostly not related to this.</span></p>
<h2>Categories</h2>
<p><a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCategories.html" target="_blank">Categories</a> allow you to add methods to an existing class, but without subclassing. You can do this even with classes from the runtime library or classes to which you do not have the source. This is my favorite language feature. Ever since I became addicted to Ruby I believe I cannot stand a language that does not allow me to do this.</p>
<p>When you first think about it, it makes no sense. Subclassing should be fine. But what if you need to add a new functionality to an existing hierarchy of classes? The best example comes not from Objective-C itself, but from Ruby and the Ruby on Rails framework: Rails would not have been possible without Ruby having this feature. Another good example within the Objective-C realm is <a class="print-href" href="http://three20.info" target="_blank">the Three20 iPhone programming library</a>, that would have been harder to implement and maybe not too feature-wide if it were not for the language having this feature.</p>
<p>A more mundane but valid use for categories is to split the implementation of a class into separate source files, be it for organizational purposes, or because the class interface and implementation is too extensive and splitting it up makes it easier to understand and maintain, etc.</p>
<p>This is one of the features I believe that C++ could have had without breaking its philosophy, and it would have been great.</p>
<h2>Compatibility with C (and C++)</h2>
<p>Unlike C++, Objective-C is a proper superset of C, meaning that any C program or file is also Objective-C code. There&#8217;s no guideline of what to do and what not to do when using C code in Objective-C. The most evident advantage is that Objective-C programs can use any existing C library without the need for wrappers. Some notable examples of libraries that are used in iPhone programming are sqlite and OpenGL.</p>
<p>It should also be mentioned at this point as a side note, that Objective-C can be combined with C++ as well, although they are still different languages. In this case there&#8217;s a list of requirements or restrictions to observe. For more information refer to <a title="Using C++ with Objective-C" href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCPlusPlus.html" target="_blank">the official documentation about this feature</a>.</p>
<h2>Simpler, more flexible, and easier to master</h2>
<p>This one is a subjective reason, but I stand by it.</p>
<p>I have mastered more of Objective-C in six months than of C++ in years. I have also been more confortable learning it. I remember learning C++ as a necessary evil, and by contrast, I am happy that iPhone programming led me to this wonderful programming language.</p>
<p>The language is far from perfect, and there are certainly a few features from other languages that I miss a little bit. My perception of it has changed over time though. When you first start to use it, it appears to be cumbersome and bizarre. But sooner rather than later you start to love it (unless you are a C++ fanboy, of course).</p>
<p><strong>So what do you think about Objective-C? Are there any other features that you love or hate about it? Feel free to share you opinion without starting a war.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://gnapse.com/blog/2010/10/06/five-reasons-to-love-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Import your iPhone address book into the iPhone simulator</title>
		<link>http://gnapse.com/blog/2010/09/13/import-your-iphone-address-book-into-the-iphone-simulator/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=import-your-iphone-address-book-into-the-iphone-simulator</link>
		<comments>http://gnapse.com/blog/2010/09/13/import-your-iphone-address-book-into-the-iphone-simulator/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 18:11:00 +0000</pubDate>
		<dc:creator>ernesto</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[address book]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[iphone simulator]]></category>

		<guid isPermaLink="false">http://gnapse.com/blog/?p=214</guid>
		<description><![CDATA[When you are developing an iPhone application that works with the system-wide address book, it&#8217;s sometimes useful to have already some entries to play with when testing the app. Suppose then that you are testing in the simulator, which comes with no contacts at all. You cannot sync your simulator with iTunes, and the simulator [...]]]></description>
			<content:encoded><![CDATA[<p>When you are developing an iPhone application that works with the system-wide address book, it&#8217;s sometimes useful to have already some entries to play with when testing the app. Suppose then that you are testing in the simulator, which comes with no contacts at all. You cannot sync your simulator with iTunes, and the simulator is not integrated into your Mac Address Book, so you have to start creating some contacts manually.</p>
<p>Well, not exactly. If you have a real device (and you should anyway, if you are developing for the platform) and this device has lots of contacts in it, then you can copy the internal address book files into the simulator&#8217;s file system in your Mac. I actually got the tip from <a title="Using your own address book in the iPhone Simulator" href="http://0xced.blogspot.com/2009/01/using-your-own-address-book-in-iphone.html" target="_blank">this blog post</a> after searching on Google a little bit, but it did not worked for me exactly that way. I&#8217;ll let you know why.<span id="more-214"></span></p>
<p>First you have to extract the device&#8217;s address book sqlite files. There are two files actually, and according to their names, one is for the actual contacts, and the other one stores the contact images. Both files are located in <code>/var/mobile/Library/AddressBook/</code> inyour iPhone, so if you have a jailbroken device, then it is as simple as copying through ssh&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> mobile<span style="color: #000000; font-weight: bold;">@</span>iphone:Library<span style="color: #000000; font-weight: bold;">/</span>AddressBook<span style="color: #000000; font-weight: bold;">/*</span>  ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Application\ Support<span style="color: #000000; font-weight: bold;">/</span>iPhone\ Simulator<span style="color: #000000; font-weight: bold;">/</span>User<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>AddressBook</pre></div></div>

<p>If your device is not jailbroken then it is a bit more complicated. The solution involves extracting the sqlite files from the backups of your device created by iTunes in your Mac whenever you sync. The blog post linked above has a nice script for doing this, although I have not tested it.</p>
<p>But this did not work for me right away. I copied the files into the specified directory and started the simulation just to see the same empty list. So I wandered a bit through the vicinities of that location and I realized that along with the <code>User</code> directory inside <code>~/Library/Application Support/iPhone Simulator</code>, there are a few more directories whose names correspond to the versions of the <abbr title="Software Development Kit">SDK</abbr> installed in the simulator. Since I am running the simulator on iOS 4.0.2, then I copied the files into this directory structure instead, like below</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> mobile<span style="color: #000000; font-weight: bold;">@</span>iphone:Library<span style="color: #000000; font-weight: bold;">/</span>AddressBook<span style="color: #000000; font-weight: bold;">/*</span>  ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Application\ Support<span style="color: #000000; font-weight: bold;">/</span>iPhone\ Simulator<span style="color: #000000; font-weight: bold;">/</span>4.0.2<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>AddressBook</pre></div></div>

<p>So if the <code>User</code> directory don&#8217;t work for you either, then try looking for the one corresponding to the SDK version that you are running in the simulator.</p>
]]></content:encoded>
			<wfw:commentRss>http://gnapse.com/blog/2010/09/13/import-your-iphone-address-book-into-the-iphone-simulator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Selectively print link URLs in your wordpress blog</title>
		<link>http://gnapse.com/blog/2010/09/08/selectively-print-link-urls-in-your-wordpress-blog/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=selectively-print-link-urls-in-your-wordpress-blog</link>
		<comments>http://gnapse.com/blog/2010/09/08/selectively-print-link-urls-in-your-wordpress-blog/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 17:52:18 +0000</pubDate>
		<dc:creator>ernesto</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web programming]]></category>

		<guid isPermaLink="false">http://gnapse.com/blog/?p=202</guid>
		<description><![CDATA[Today I was trying to improve the print-view styles of this blog. This is useful not only to actually print on paper, but also when you print to PDF to keep a digital copy of the content. So besides the obvious hiding of sections not relevant on a printed media, like the sidebar, comments form, [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was trying to improve the print-view styles of this blog. This is useful not only to actually print on paper, but also when you print to PDF to keep a digital copy of the content.</p>
<p>So besides the obvious hiding of sections not relevant on a printed media, like the sidebar, comments form, etc., I started to look at what other improvements could be made for a printed version of a web page. I readily searched for and turned to an article I recall having read some time ago in <em>A List Apart</em> about exactly this matter: <a class="print-href" href="http://www.alistapart.com/articles/goingtoprint/" target="_blank">Going to Print</a>.</p>
<p>Following the article&#8217;s suggestions I started customizing margins, backgrounds, font type and size, etc. Then I stumbled upon a very tricky issue they mention: what to do with links? They are clearly of no direct use in printed media since users can&#8217;t click on a paper, but on the other hand it&#8217;s a pity that the extra information conveyed in a link (namely the referenced <abbr title="Uniform Resource Locator">URL</abbr>) gets lost.<span id="more-202"></span></p>
<h3>CSS selectors to the rescue</h3>
<p>The article suggests using an advanced <abbr title="Cascading Style Sheet">CSS2</abbr> technique. Using special selectors we can append after every link, the URL it refers to enclosed in parentheses. This will only be visible using modern and fully CSS2-compliant browsers (Yes, I am staring at you, Internet Explorer).</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#content</span> <span style="color: #6666ff;">.post</span> a<span style="color: #3333ff;">:after </span><span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot; (&quot;</span> attr<span style="color: #00AA00;">&#40;</span>href<span style="color: #00AA00;">&#41;</span> <span style="color: #ff0000;">&quot;) &quot;</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">90%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The above rule states that <strong>after</strong> any anchor tag within the post, the href attribute value should be added in parenthesis. It also additionally puts the link in a slightly smaller font so that the link text gets more attention.</p>
<p>However, when I actually tried this I didn&#8217;t like it. The resulting printed view is too cluttered, specially if you have a sizable amount of links in your post, or if some of them reference URLs that are too long and hard to read. It would be really nice if one could selectively apply this printed styling to certain links only.</p>
<p>An apparent solution would be to apply a certain CSS class to the links we want to have this behavior, and then specify in our style sheet that the rule above should only apply to links with this CSS class.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#content</span> <span style="color: #6666ff;">.post</span> a<span style="color: #6666ff;">.print-href</span><span style="color: #3333ff;">:after </span><span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot; (&quot;</span> attr<span style="color: #00AA00;">&#40;</span>href<span style="color: #00AA00;">&#41;</span> <span style="color: #ff0000;">&quot;) &quot;</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">90%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Note the <code>.print-href</code> class in the CSS selector. We now have to apply this class to all the links in a post that we want to be printed along with the referenced URL.</p>
<p>The problem is that there&#8217;s no straightforward way of doing this in WordPress&#8217; post editor. The link popup allows you to specify a style class to be selected from a predefined set of wordpress-specific classes, but not your own.</p>
<h3>Plugins to save the day</h3>
<p>The short story about how to solve this, involves installing the <a href="http://wordpress.org/extend/plugins/tinymce-advanced/" target="_blank">TinyMCE Advanced plugin</a> in WordPress, which enhances the post editor in several ways. One of the several enhancements is that the link popup is larger and has more options, even a few separate tabs grouping lots of different options. The last tab, the one labeled <em>Advanced</em>, allows you to arbitrarily specify the value for several possible attributes of the anchor tag, including the <code>class</code> attribute.</p>
<p><a href="http://gnapse.com/blog/wp-content/uploads/2010/09/wordpress-advanced-links.png"><img class="aligncenter size-full wp-image-204" title="Advanced links popup for WordPress" src="http://gnapse.com/blog/wp-content/uploads/2010/09/wordpress-advanced-links.png" alt="" width="486" height="423" /></a></p>
<p>Notice the classes text field in the picture above, where it is already filled with the class name. The actual class name doesn&#8217;t matter, as long as you use the same class name in both your links and the CSS rule in your stylesheet.</p>
<p>So now, if you <a href="javascript:window.print();">print this post</a>, you&#8217;ll notice how some links in it get printed along with the referenced web page, and others don&#8217;t. I hope this hint may helpful to anybody out there.</p>
<p><strong>Do you know any other helpful hints about making web pages and blog posts more printer-friendly?</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://gnapse.com/blog/2010/09/08/selectively-print-link-urls-in-your-wordpress-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gnapse.com goes mobile!</title>
		<link>http://gnapse.com/blog/2010/08/09/gnapse-com-goes-mobile/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gnapse-com-goes-mobile</link>
		<comments>http://gnapse.com/blog/2010/08/09/gnapse-com-goes-mobile/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 19:15:19 +0000</pubDate>
		<dc:creator>ernesto</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web programming]]></category>
		<category><![CDATA[gnapse.com]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://gnapse.com/blog/?p=185</guid>
		<description><![CDATA[It&#8217;s a tiny change, but I wanted to say it out loud. I recently updated this website to be mobile-friendly when visited from a handheld device such as an iPhone and other smart-phones. Go and see it for yourself and you&#8217;ll know what it&#8217;s like. Actually it was very simple and required almost no work. There&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a tiny change, but I wanted to say it out loud. I recently updated this website to be mobile-friendly when visited from a handheld device such as an iPhone and other smart-phones. Go and see it for yourself and you&#8217;ll know what it&#8217;s like.</p>
<p><a href="http://gnapse.com/blog/wp-content/uploads/2010/08/gnapse.com-mobile.png"><img class="aligncenter size-full wp-image-192" title="gnapse.com in mobile safari" src="http://gnapse.com/blog/wp-content/uploads/2010/08/gnapse.com-mobile.png" alt="" width="320" height="460" /></a></p>
<p>Actually it was very simple and required almost no work. There&#8217;s <a title="Wordpress Mobile Edition by Crowd Favorite" href="http://crowdfavorite.com/wordpress/plugins/wordpress-mobile-edition/" target="_blank">a wordpress plugin</a> for that already, which along with <a title="Carrington Mobile" href="http://crowdfavorite.com/wordpress/themes/carrington-mobile/" target="_blank">a custom mobile-friendly theme</a> gets the job done. Both the plugin and the theme are developed by <a href="http://crowdfavorite.com/" target="_blank">Crowd Favorite</a>, a web development company specializing in WordPress customization and enhancement. They also provide two great standard themes, including the one used in the blog&#8217;s standard interface.</p>
<p><strong>Do you know any other plugins or tools to make a WordPress blog friendly to handheld mobile devices?</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://gnapse.com/blog/2010/08/09/gnapse-com-goes-mobile/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Railscasts on text</title>
		<link>http://gnapse.com/blog/2010/07/28/railscasts-on-text/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=railscasts-on-text</link>
		<comments>http://gnapse.com/blog/2010/07/28/railscasts-on-text/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 18:50:37 +0000</pubDate>
		<dc:creator>ernesto</dc:creator>
				<category><![CDATA[Web programming]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[railscasts]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[screencasts]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://gnapse.com/blog/?p=158</guid>
		<description><![CDATA[Every Rails programmer out there should have heard about Railscasts. It&#8217;s a great blog that every monday posts a new short screencast about some topic related to Ruby on Rails programming. It can be about features of the upcoming or just released new version of Rails, about how to integrate other services and softwares with [...]]]></description>
			<content:encoded><![CDATA[<p>Every Rails programmer out there should have heard about <a title="About Railscasts.com" href="http://railscasts.com/about" target="_blank">Railscasts</a>. It&#8217;s a great blog that every monday posts a new short screencast about some topic related to Ruby on Rails programming. It can be about features of the upcoming or just released new version of Rails, about how to integrate other services and softwares with Rails, about hot plugins and gems that can be really useful, or anything related that you can think of. It&#8217;s been running for over three years and keeps its content amazingly up to date. The credits go for Ryan Bates.</p>
<p>But you probably haven&#8217;t heard of <a title="About ASCIIcasts.com" href="http://www.asciicasts.com/about" target="_blank">ASCIIcasts</a>, which is a text version of the original blog, including a transcript of Ryan&#8217;s voice from the original video, along with key code samples and screenshots of the main features explained. Think of it as a textual equivalent of the screencast. It can serve various purposes, including being search friendly (you can make a full text search on Ryan&#8217;s spoken words), but also for people like me with a slow connection, it can help me have a glimpse of any episode before actually downloading it, maybe even sparing me the effort and bandwidth. If any of these or other reasons are good for you, or even for the sake of it, take a look as <a href="http://www.asciicasts.com/" target="_blank">ASCIIcasts</a>. You&#8217;ll love it almost as much as the original.</p>
]]></content:encoded>
			<wfw:commentRss>http://gnapse.com/blog/2010/07/28/railscasts-on-text/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My new iPad nano (aka iPhone)</title>
		<link>http://gnapse.com/blog/2010/02/03/my-new-ipad-nano-aka-iphone/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=my-new-ipad-nano-aka-iphone</link>
		<comments>http://gnapse.com/blog/2010/02/03/my-new-ipad-nano-aka-iphone/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 17:54:10 +0000</pubDate>
		<dc:creator>ernesto</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Whatever]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://gnapse.com/blog/?p=116</guid>
		<description><![CDATA[Most people are going crazy these days talking about the most recent gadget announced by Apple. They&#8217;ve seen the video, they went to the announcement conference, they are wondering when will they get one in their hands. They simply can&#8217;t wait. Meanwhile I am enjoying a similar experience. Somebody noticed out there that there are [...]]]></description>
			<content:encoded><![CDATA[<p>Most people are going crazy these days talking about <a title="iPad" href="http://apple.com/ipad" target="_blank">the most recent gadget announced by Apple</a>. They&#8217;ve seen <a href="http://www.apple.com/ipad/includes/video-ipad.html#video" target="_blank">the video</a>, they went to the announcement conference, they are wondering when will they get one in their hands. They simply can&#8217;t wait.</p>
<p>Meanwhile I am enjoying a similar experience. <a href="http://www.buzzfeed.com/kellyh3/ipad-nano-q94" target="_blank">Somebody noticed out there</a> that there are many of us with an iPad already (kind of). The <a title="iPhone" href="http://apple.com/iphone" target="_blank">iPad nano</a> has been around for a couple of years now but with another name. And I recently got one and I am delighted with it. Why going crazy about the new one when you can have the nano version which fits in your pocket, has a camera and makes phone calls too!</p>
<div id="attachment_120" class="wp-caption aligncenter" style="width: 510px"><img class="size-full wp-image-120" title="ipad-nano" src="http://gnapse.com/blog/wp-content/uploads/2010/02/ipad-nano-18412-1264908879-85.jpg" alt="iPad nano" width="500" height="600" /><p class="wp-caption-text">iPad nano</p></div>
<p>Now seriously, after using the iPhone for some days I understand why people are crazy to experiment with its big but younger brother. Touch screens are seriously redefining how we interact with computers and from a developer standpoint it&#8217;s amazing the whole new set of possibilities that arise. And it&#8217;s not only touch screens and multi-touch, but also the ability to make a program adapt to different orientations of the device, to be able to access hardware services like a compass, accelerometer, GPS, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://gnapse.com/blog/2010/02/03/my-new-ipad-nano-aka-iphone/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>gitignore++</title>
		<link>http://gnapse.com/blog/2009/12/18/gitignore/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gitignore</link>
		<comments>http://gnapse.com/blog/2009/12/18/gitignore/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 21:31:14 +0000</pubDate>
		<dc:creator>ernesto</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[vcs]]></category>

		<guid isPermaLink="false">http://gnapse.com/blog/?p=108</guid>
		<description><![CDATA[I always wondered why Rails developers on the Mac keep adding those .DS_Store files into the .gitignore file of their project repo. It just doesn&#8217;t feel right. When I cloned some of these repos in ubuntu I always wondered what the hell that file has to do with me.  I also felt bad every time [...]]]></description>
			<content:encoded><![CDATA[<p>I always wondered why Rails developers on the Mac keep adding those <code>.DS_Store</code> files into the <code>.gitignore</code> file of their project repo. It just doesn&#8217;t feel right. When I cloned some of these repos in ubuntu I always wondered what the hell that file has to do with me.  I also felt bad every time I added my <code>nbproject</code> folders and <code>*.kpf</code> files to my <code>.gitignore</code> list back in the days when I used Netbeans and Komodo to program in Rails. People interested in my projects need not be seeing this when they clone my code.<span id="more-108"></span></p>
<p>It turns out that <a title="Git Version Control System" href="http://git-scm.com/" target="_blank">git</a> offers three mechanisms to specify which files to ignore. Most people know about the <code>.gitignore</code> files inside the working tree. But if you take a look at the <a href="http://www.kernel.org/pub/software/scm/git-core/docs/gitignore.html" target="_blank">gitignore documentation</a> you&#8217;ll find out that there&#8217;s a second file to specify ignore patterns that are specific to a given user&#8217;s work-flow, but that shouldn&#8217;t be cluttering the .gitignore files inside the repo, which are normally also versioned by git and thus shared by all the developers working in the project. Patterns like these should go in the <code>$GIT_DIR/info/exclude</code> file, where <code>$GIT_DIR</code> usually refers to the <code>.git/</code> directory inside your working tree.</p>
<p>Nobody cares what&#8217;s your favorite editor and you shouldn&#8217;t be cluttering the ignore files versioned inside the repo with the patterns of the files generated by your working environment. That way your buddies on a Mac won&#8217;t laugh at you when they notice you are stuck with Netbeans because you&#8217;re on Linux, or that you are geeky enough to use Emacs or Vim instead of the sexy TextMate.</p>
<p>But wait. We still have to repeat all those pesky private ignore patterns in every different project, when we should be able to tell git globally about the garbage we normally want to ignore. <a title="Don't Repeat Yourself" href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a> anybody?</p>
<p>You&#8217;re right. That sounds very stupid. We are programmers after all. We&#8217;re supposed to be clever and lazy. So is the guy who invented all this git thing. It turns out that you can specify a global <code>.gitignore</code> file via <code>git-config</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git-config</span> <span style="color: #660033;">--global</span> core.excludesfile <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>ernesto<span style="color: #000000; font-weight: bold;">/</span>.gitignore</pre></div></div>

<p>The file doesn&#8217;t have to be named <code>.gitignore</code> and it doesn&#8217;t have to be in your home directory. The <code>core.excludesfile</code> configuration directive is there precisely so that you can put this global ignore file anywhere you want. Also, beware of using <code>~/</code> to specify that the file is in your home directory. The documentation says that it works and expands it to the value of the <code>$HOME</code> environment variable, but it doesn&#8217;t work in my Mac.</p>
<p>So now you can go and edit that file and put the things that bother you privately. Mine for instance is something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.DS_Store
.svn
<span style="color: #000000; font-weight: bold;">*</span>~
<span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #7a0874; font-weight: bold;">&#91;</span>oa<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">*</span>.kpf
nbproject
Thumbs.db</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://gnapse.com/blog/2009/12/18/gitignore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AMP: One VCS to rule them all</title>
		<link>http://gnapse.com/blog/2009/11/30/amp-one-vcs-to-rule-them-all/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=amp-one-vcs-to-rule-them-all</link>
		<comments>http://gnapse.com/blog/2009/11/30/amp-one-vcs-to-rule-them-all/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 18:59:56 +0000</pubDate>
		<dc:creator>ernesto</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[bazaar]]></category>
		<category><![CDATA[distributed vcs]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[vcs]]></category>

		<guid isPermaLink="false">http://gnapse.com/blog/?p=95</guid>
		<description><![CDATA[If you are a programmer and you already know something about git, mercurial, bazaar or some other modern distributed version control system, you should give AMP a try. And no, it is not a VCS in the most strict sense of the concept, but a meta-tool for VCS ease of use. Currently it works as [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a programmer and you already know something about <a href="http://git-scm.com/" target="_blank">git</a>, <a href="http://mercurial.selenic.com/" target="_blank">mercurial</a>, <a href="http://bazaar-vcs.org/" target="_blank">bazaar</a> or some other modern distributed version control system, you should give <a href="http://amp.carboni.ca/" target="_blank">AMP</a> a try. And no, it is not a <abbr title="Version Control System">VCS</abbr> in the most strict sense of the concept, but a meta-tool for VCS ease of use.</p>
<p>Currently it works as a Ruby interface to Mercurial, but they are aiming high. According to their own definition, &#8220;[their] goal is to produce a piece of software that lets you forget that you&#8217;re working on git project one moment and a Mercurial project the next.&#8221; A sort of meta-interface for most modern distributed VCS&#8217;s out there, so that you can use them all with the same set of commands, or maybe even interact between different VCS&#8217;s. Although I haven&#8217;t had the time yet to truly play with it, It appears to be highly customizable.</p>
<p>BTW, they also mention svn and cvs as VCS&#8217;s they want to support, but I can&#8217;t see why to drain out resources into these dinosaurs. I still don&#8217;t get why people still use centralized-only VCS&#8217;s if they have the choice of distributed version control. But anyway, I wish them good luck with the project overall, and I will sure keep an eye on it for a while.</p>
]]></content:encoded>
			<wfw:commentRss>http://gnapse.com/blog/2009/11/30/amp-one-vcs-to-rule-them-all/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

