<?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>Record and Reverie &#187; Programming</title>
	<atom:link href="http://www.cod3r.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cod3r.com</link>
	<description>General things I find interesting</description>
	<lastBuildDate>Sat, 07 Jan 2012 15:44:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>What Objective-C can learn from Java, Part 3 (Single Source File)</title>
		<link>http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-3-single-source-file/</link>
		<comments>http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-3-single-source-file/#comments</comments>
		<pubDate>Thu, 30 Dec 2010 16:16:28 +0000</pubDate>
		<dc:creator>Graham Booker</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://www.cod3r.com/?p=422</guid>
		<description><![CDATA[This is the third is a series of blog posts I’m writing on things that Objective-C can learn from Java. The other parts can be found here: Part 1 (Generics) Part 2 (Abstract Classes) Part 3 (Single Source File) Part 4 (Namespace) Objective-C still retains a lot of its heritage from it&#8217;s C beginnings. This [...]]]></description>
			<content:encoded><![CDATA[<p>This is the third is a series of blog posts I’m writing on things that Objective-C can learn from Java.  The other parts can be found here:<br />
<a href="http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-1-generics/">Part 1 (Generics)</a><br />
<a href="http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-2-abstract-classes/">Part 2 (Abstract Classes)</a><br />
Part 3 (Single Source File)<br />
<a href="http://www.cod3r.com/2011/01/what-objective-c-can-learn-from-java-part-4-namespace/">Part 4 (Namespace)</a></p>
<p>Objective-C still retains a lot of its heritage from it&#8217;s C beginnings.  This includes using two files, a header and a source file, for each class.  In a strictly object oriented environment, the header file contains the class definition (super-class and instance variables), public property definitions, and any public function declarations.  The source file contains all of the function implementations, including synthesize statements.  In contrast, Java contains all the functions of both files in a single file.  To one who knows better, as in one who has used the single file environment, the two files for each class becomes a pain.</p>
<p>As to why this is a pain, one needs only to visit the following scenario:  Add a property called <code>name</code> to the <code>Person</code> object.  In Objective-C, one needs to add the instance variable to the class definition and the property declaration to the header file.  Then, add a <code>@synthesize</code> statement to the implementation and add <code>[name release];</code> in the dealloc (I&#8217;m neglecting Objective-C&#8217;s ability to create the instance variable in modern runtimes since it denies direct access to it in the code).  In contrast, Java needs the instance variable added to the class, and in the same file add the setters and getters (which if using Eclipse, can be auto-generated).  Java is able to accomplish this because it uses a two-pass compiler.  One pass parses the class definition and function declarations, and the second generates the actual code.  Any <code>import</code> statements only need the first pass of each file.</p>
<p>In Objective-C, some of this pain can be eliminated using my fork of <a href="https://bitbucket.org/gbooker/objectivecannotate/">ObjectiveCAnnotate</a>, but this is only part of the way to what should be done.  What Objective-C really needs is to use a single source file, and auto-generate the equivalent header file when the source file is saved (and save it only if it is different to reduce unnecessary re-compiles).  This serves as the equivalent of Java&#8217;s first complier pass.  Then, the actually compile step executes the second pass, using the generated header and the code within the source file.  Using the paradigm, several changes should be made to the source file.  The obvious is adding a public (or maybe @public) to functions that should be included in the header file.  Additionally, the property syntax can be combined with the instance variable declaration and possibly with synthesize to create something like <code>@property (nonatomic, retain, synthesize) NSString *name</code> to take the place of the instance variable declaration, the property declaration, and the synthesize statement.  Since this is by far the most common use case, why not simplify it to make things easier for the developer?  The instance variable still needs to be in dealloc, but now changes in instance variables has been reduced to two places.</p>
<p>This change doesn&#8217;t completely eliminate the need for header files.  The old C-style declarations, such as C-functions, structs, enums, externs, typedefs, and defines, would still need to be in a header file on their own.  Since most classes do not make these declarations, most classes wouldn&#8217;t need a distinct header file.  In the cases where such a definition is made, it is often better style to include all of the definitions in a single <em>types</em> header file for the framework/project.</p>
<p>This does necessitate a change to the import statements for a class.  In the two file environment, one can separate the import statements between the header and source files, but in a single file, this separation no longer exists.  However, the compiler could be made smart enough to track the locations of types it inserts in the generated header file, and include those location in the header file&#8217;s import statements.  This would mean the header file would contain the import statements for the super-class, and any C-style declarations only.  There is no need at all to include the import statements for other classes, as the existing <code>@class</code> declaration tells the compiler all it needs to know at this stage.  This would also eliminate the bad coding practice of including unnecessary import statements in the header file, a practice which I&#8217;ve seen too often by new programmers who were never taught of its dangers.</p>
<p>Impact on Runtime:<br />
None, this is pre-processor only</p>
<p>Impact on Code:<br />
Reduction in code complexity, ease in modification.  Reduction in need to reference two files to understand a single class.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-3-single-source-file/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>What Objective-C can learn from Java, Part 2 (Abstract Classes)</title>
		<link>http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-2-abstract-classes/</link>
		<comments>http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-2-abstract-classes/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 21:54:20 +0000</pubDate>
		<dc:creator>Graham Booker</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://www.cod3r.com/?p=412</guid>
		<description><![CDATA[This is the second is a series of blog posts I’m writing on things that Objective-C can learn from Java. The other parts can be found here: Part 1 (Generics) Part 2 (Abstract Classes) Part 3 (Single Source File) Part 4 (Namespace) When one is using object oriented design, a common practice is to lump [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second is a series of blog posts I’m writing on things that Objective-C can learn from Java.  The other parts can be found here:<br />
<a href="http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-1-generics/">Part 1 (Generics)</a><br />
Part 2 (Abstract Classes)<br />
<a href="http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-3-single-source-file/">Part 3 (Single Source File)</a><br />
<a href="http://www.cod3r.com/2011/01/what-objective-c-can-learn-from-java-part-4-namespace/">Part 4 (Namespace)</a></p>
<p>When one is using object oriented design, a common practice is to lump similar classes together with a common super-class and include the common functionality in that super-class.  In doing such design, a common problem is for the super-class to require some information that can only be computed by the sub-class.  The solution is for the super-class to make a function call on itself which the sub-class implements.  For example, I recently designed a class which simplifies storage of an object in a SQL row, but it knows nothing about the actual field names or values stored in the database.  In this case, I made a function, which subclasses implement, to retrieve this data.  In Java, this is simply done through an abstract method in an abstract class.</p>
<p>Objective-C has no concept of an abstract method or class.  Instead, the closest one can get is to provide an empty implementation for a function and then override that implementation in the sub-classes.  Unlike Java, there is no error, or even a warning, if the programmer of the subclass forgets to implement the function that must be overridden.  The landscape becomes more confusing when one considers properties.  Since Objective-C&#8217;s gives errors when an implementation doesn&#8217;t provide the property accessor methods, it provides a annotation <code>@dynamic</code> which silences the error.  Apple mentions this can be used when an implementation is dynamically provided at runtime, but considering the complexity of this technique, it&#8217;s more common use is to silence the error in the case where a subclass implements the accessor methods.  However, in the inconsistency with which Apple has treated properties, there is no error or warning, or any way to make the compiler throw one, if the sub-class programmer forgets the implementation.  This makes <code>@dynamic</code> really dangerous (just as ignoring warnings can be dangerous).</p>
<p>So, what is really required to make abstract classes work in Objective-C?  Again, all of the work is in the compiler and doesn&#8217;t affect runtime.  First, one needs to be able to define a class as abstract, which tells the complier that allocation of that class, such as <code>[AbstractClass alloc]</code>, should throw an error.  Second, properties and methods need to be able to be defined as abstract.  This will silence any errors and warnings about missing implementation in the abstract class and throw the errors and warnings about missing implementation in a non-abstract sub-class.  A few changes to the complier, and a programmer can do more advanced designs and avoid simple common mistakes at compile time rather than runtime.</p>
<p>Impact on Runtime:<br />
None, abstract classes and methods are syntax sugar only.</p>
<p>Impact on Code:<br />
Allows more advanced design, and sub-classes become less prone to error.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-2-abstract-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Objective-C can learn from Java, Part 1 (Generics)</title>
		<link>http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-1-generics/</link>
		<comments>http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-1-generics/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 22:38:29 +0000</pubDate>
		<dc:creator>Graham Booker</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://www.cod3r.com/?p=396</guid>
		<description><![CDATA[This is the first is a series of blog posts I&#8217;m going to write over the next several days on things that Objective-C can learn from Java. I&#8217;ve been programming in Java since 1997, and in Objective-C since 2001. The two languages have a lot of similarities, but there are a few design principles in [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first is a series of blog posts I&#8217;m going to write over the next several days on things that Objective-C can learn from Java.  I&#8217;ve been programming in Java since 1997, and in Objective-C since 2001.  The two languages have a lot of similarities, but there are a few design principles in which Java excels and Objective-C is left behind.  This is understandable considering that Objective-C is older than Java, and Java borrowed heavily from Objective-C when it was designed.  In this series I&#8217;m only going to discuss changes to the language; these items will have very little, if any, impact on the runtime.  For the purposes of this discussion, I&#8217;m going to use Java&#8217;s terminology since it is more familiar with the programming public.  This means I&#8217;ll talk about functions instead of selectors, and interfaces instead of protocols.</p>
<p>The other parts can be found here:<br />
Part 1 (Generics)<br />
<a href="http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-2-abstract-classes/">Part 2 (Abstract Classes)</a><br />
<a href="http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-3-single-source-file/">Part 3 (Single Source File)</a><br />
<a href="http://www.cod3r.com/2011/01/what-objective-c-can-learn-from-java-part-4-namespace/">Part 4 (Namespace)</a></p>
<p>The first item which Objective-C can learn from Java is Generics.  Objective-C is a weakly typed language, too weak for my tastes, whereas Java is strongly typed.  There are distinct advantages to a strongly typed language, but I&#8217;m not going to get into that here.  This means that Objective-C&#8217;s can make a function call on an object without knowing its type where as Java must have the object typed to an interface or class which defines that function.  This requires typecasting in Java before making function calls, where as Objective-C does not.  In some cases this throws a warning in Objective-C, and in some cases does not.  Missing warnings can lead to programming mistakes, and programmer ignored warnings leads to bad style.  In either case, typecasting will change the mistakes to warnings, and the warnings which are not mistakes to no warnings.</p>
<p>Java had the issue in requiring typecasting to make function calls.  This lead to numerous typecasts in code, which added to clutter.  Java&#8217;s solution to much of this clutter came through the use of generics.  One of the largest sets of typecasts resulting in fetches from a collection.  For example, if one had a list which contains objects of class <code>Person</code>, then it would be convenient if the complier just remembered that for you.  This was done by simply declaring the list as <code>List&lt;Person&gt;</code>.  Then, when fetching objects from the List, no typecast is necessary since the compiler already knows that all objects in that list are a <code>Person</code> in the first place.  I should add, for the C++ programmers out there, this is <strong>not a template</strong>.  Templates define a whole new set of code for that type, ballooning the object binary, where as generics can be thought of as automatic typecasting.</p>
<p>I have found many arguments that state Objective-C doesn&#8217;t need generics because it is a weakly typed language (just Google <em>Objective-C generics</em> to see them).  These arguments tend to forget one major piece of the language.  Consider the following code:</p>
<p><code><br />
@interface Person : NSObject {<br />
&nbsp; &nbsp; NSString &nbsp; *name;<br />
&nbsp; &nbsp; NSArray &nbsp; &nbsp;*siblings;<br />
&nbsp; &nbsp; Person &nbsp; &nbsp; *father;<br />
&nbsp; &nbsp; Person &nbsp; &nbsp; *mother;<br />
&nbsp; &nbsp; NSArray &nbsp; &nbsp;*children;<br />
}</p>
<p>@property (nonatomic, retain) NSString *name;<br />
@property (nonatomic, retain) NSArray *siblings;<br />
@property (nonatomic, retain) Person *mother;<br />
@property (nonatomic, retain) Person *father;<br />
@property (nonatomic, retain) NSArray *siblings;</p>
<p>@end<br />
</code></p>
<p>In this example, I&#8217;ve defined an Objective-C class called <code>Person</code> with a name, an array of siblings, a father, mother, and an array of children.  Now, say I wanted to get the first-born child&#8217;s name.  I could do this with <code>[children objectAtIndex:0].name</code>.  Except, this produces an error because <code>[children objectAtIndex:0]</code> returns an <code>id</code>, not a <code>Person *</code>, and properties, unlike functions, are strongly typed in Objective-C.  So, the recourse is to either use a temporary variable of type <code>Person *</code>, or to typecast on the same line like: <code>((Person *)[children objectAtIndex:0]).name</code>.  If Objective-C had generics, this would eliminate any need for the typecast or temporary variable since the compiler would already know the type of the object returned by the array.</p>
<p>This is a simple example of where generics become useful in the language, but there are far more.  I have actually found Objective-C&#8217;s lack of generics limiting my ability to design class hierarchies, and requiring a large amount of unnecessary typecasts or in some cases, additional function calls, which produces slower code.</p>
<p>Should Objective-C adopt all of Java&#8217;s generics?  I would contend the answer is no.  Java&#8217;s generics can get very convoluted very quickly, and the biggest source of the mess is in defining a generic function call.  While they add convenience, generics in function calls becomes very messy.  However, generics on a class level (and used in it&#8217;s functions) add so much benefit and cleaner code design that Objective-C is really suffering without them.  Additionally, Java produces warnings if a class containing generics does not have it&#8217;s generic type defined.  For example, <code>List children</code> will produce a warning because I didn&#8217;t define the type of object contained within list.  In these cases, since Objective-C is so weakly typed, it&#8217;d be most appropriate if its generics just defaulted to the base class allowed in the generic, which in the case of NSArray would be <code>id</code>.</p>
<p>Impact on Runtime:<br />
None, generics are <em>syntax sugar</em> only.</p>
<p>Impact on Code:<br />
Generics added where needed, changing the tracking of object type to the compiler instead of the programmer.  Cleaner code, and less prone to error.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cod3r.com/2010/12/what-objective-c-can-learn-from-java-part-1-generics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trac.fcgi Memory Usage</title>
		<link>http://www.cod3r.com/2010/10/trac-fcgi-memory-usage/</link>
		<comments>http://www.cod3r.com/2010/10/trac-fcgi-memory-usage/#comments</comments>
		<pubDate>Sat, 16 Oct 2010 18:06:28 +0000</pubDate>
		<dc:creator>Graham Booker</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Servers]]></category>

		<guid isPermaLink="false">http://www.cod3r.com/?p=388</guid>
		<description><![CDATA[I&#8217;ve been slowly transitioning to using nginx as the web front-end in an effort to reduce Apache&#8217;s memory usage. In keeping with this task, I&#8217;m moving more and more off of Apache. One piece I recently moved was trac, transitioning to using it directly by nginx by running it in fast-cgi mode where as previously [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been slowly transitioning to using nginx as the web front-end in an effort to reduce Apache&#8217;s memory usage.  In keeping with this task, I&#8217;m moving more and more off of Apache.  One piece I recently moved was trac, transitioning to using it directly by nginx by running it in fast-cgi mode where as previously it was running as cgi though Apache.  </p>
<p>While fast-cgi is faster, it has inherent issues, such as any memory leak can result in ever growing memory usage, which is exactly why Apache has a setting for each child to serve a limited number of requests before exiting.  Trac.fcgi has no such directive, and has the equivalent of a large memory leak, a non-expiring cache.  While it&#8217;s not as bad as a memory leak, which will indefinitely grow instead of reaching a limit, if the cache size is larger than the available memory for trac to use, it&#8217;s just as serious.  The only solution, without fixing trac&#8217;s caching mechanisms, is to restart trac periodically, but during the time trac is restarting, all requests are lost, causing bad gateway errors to the user.  Additionally, the restart needs to be done manually.  Clearly not an ideal solution.</p>
<p>The ideal solution would be for the trac process to be periodically restarted, but all requests be successfully completed.  This is what Apache accomplishes with its children, but trac has no such mechanism or even the support for one.  So, I had to build it in myself.</p>
<p><strong>My Solution:</strong><br />
First piece is to create a parent process, which holds the fcgi socket, and restarts a child trac process when it dies.  This ensures that all waiting requests will be served by either the old or new process.  Such a parent process absolutely must have no memory leaks, and so I created one that has only 1 explicit allocation, and it is executed only once.</p>
<p>The second piece, and one that&#8217;s considerably harder, is to make the trac process exit gracefully when it&#8217;s memory usage gets too big.  The first step was to create a subclass of WSGIServer and override its _mainloopPeriodic to run a periodic check.  In this check, I do a memory usage check, and if it&#8217;s over 90MB, set itself to exit.  The problem is there&#8217;s no easy way to figure out the memory usage on linux.  There is a function, getrusage, which is supposed to give resource usage information, such as memory, but linux gives all zeros (unlike a proper kernel).  The only way to get this is to read the information out of /proc, and parse that data.  Since this becomes a more expensive operation, I only conduct the test every 100 times.<br />
After doing this, I was still getting periodic bad gateway errors.  It turns out that trac spawns a thread to process the request, and that request hadn&#8217;t completed when the process exited, dropping the connection and causing the error.  In examining the documentation, Python is supposed to wait for the thread to complete before exit.  Since it wasn&#8217;t, I put in a mechanism to see if any threads are running before exit.  Here lies a big problem with Python.  I found out that the thread, while created, hasn&#8217;t actually started.  Since it hasn&#8217;t started, it isn&#8217;t running, which is why Python exited.  Furthermore, Python&#8217;s threading is so brain-dead, there seems to be no way at all to differentiate between a thread which hasn&#8217;t started and one that is exited but not freed.  This means there is no reliable way to detect if all threads have exited.  So instead, in order to work around Python, I created a thread-safe counter to count the number of threads.  I increment it when the thread is created (not started), and decrement it when the thread completes.  I then only allow the main thread to exit when this counter reaches zero (since the main thread does the allocations, this never lets the process die without starting all threads).  Given this glaringly bad threading model, I put in another protection mechanism so that the main thread will exit after 30 seconds even if the count isn&#8217;t zero, just in case.</p>
<p>With the above two pieces, trac&#8217;s memory usage is limited, and no connections are dropped, in the time between one process deciding to go down and when it actually does, nothing is processing requests.  So, the last piece is to make trac signal to the parent process that it has decided to exit, and then have the parent process launch a new trac to take over while the previous is exiting.  I did this with USR1 signal, where the parent process sends a HUP to the child (in case someone else sent it the USR1 signal), and start a new child.  With these modifications in place, trac has been humming along for nearly a month, being restarted about 2-3 times a day with no issues.</p>
<p>Files:<br />
<a href='http://www.cod3r.com/images/2010/10/launcher.c'>launcher.c</a> &#8211; Requires the environment variable WORKER_PATH to be set to know what process to launch.  Best run with something like spawn-fcgi<br />
<a href='http://www.cod3r.com/images/2010/10/trac.fcgi_.txt'>trac.fcgi</a> &#8211; Modified trac.fcgi to incorporate the above mentioned changes, complete with commented code for testing/experimentation.<br />
Enjoy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cod3r.com/2010/10/trac-fcgi-memory-usage/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google Link Redirection (cont.)</title>
		<link>http://www.cod3r.com/2010/10/google-link-redirection-cont/</link>
		<comments>http://www.cod3r.com/2010/10/google-link-redirection-cont/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 14:04:21 +0000</pubDate>
		<dc:creator>Graham Booker</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.cod3r.com/?p=383</guid>
		<description><![CDATA[Earlier I wrote about google&#8217;s link redirection. I have finally finished my testing of a Safari extension which kills this behavior. I didn&#8217;t want to release this extension until the updating mechanism worked and that is what took me so long. Anyway, here is the the extension. Enjoy, and let me know what you think.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cod3r.com/2010/08/googles-link-redirection/">Earlier</a> I wrote about google&#8217;s link redirection.  I have finally finished my testing of a Safari extension which kills this behavior.  I didn&#8217;t want to release this extension until the updating mechanism worked and that is what took me so long.  Anyway, here is the <a href="http://www.cod3r.com/download/get.php?name=BlockGoogleRwt.safariextz">the extension</a>.  Enjoy, and let me know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cod3r.com/2010/10/google-link-redirection-cont/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google’s Link Redirection</title>
		<link>http://www.cod3r.com/2010/08/googles-link-redirection/</link>
		<comments>http://www.cod3r.com/2010/08/googles-link-redirection/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 02:42:50 +0000</pubDate>
		<dc:creator>Graham Booker</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.cod3r.com/?p=370</guid>
		<description><![CDATA[Google, for quite some time, has been redirected clicks on links in their search results to www.google.com/url?&#8230;. While I don&#8217;t approve of such practices, I didn&#8217;t mind it so much since this is presumably an effort to improve their search results. That changed recently, when I noticed that my history in Safari was filled with [...]]]></description>
			<content:encoded><![CDATA[<p>Google, for quite some time, has been redirected clicks on links in their search results to www.google.com/url?&#8230;.  While I don&#8217;t approve of such practices, I didn&#8217;t mind it so much since this is presumably an effort to improve their search results.  That changed recently, when I noticed that my history in Safari was filled with entries containing that URL as the title.  Considering the fact that I often use the history to re-find a page with pertinent information, this is bordering on making my browser usage useless.  Note: I tend to cmd-click links so they show up in new tabs.  If you just click the link, the title in the history is correct.</p>
<p><strong>Edit:</strong> My solution that was here previously didn&#8217;t work properly.  I&#8217;ve developed a Safari Extension to correct this, and am currently testing it.  If it passes the tests, I&#8217;ll likely put it up here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cod3r.com/2010/08/googles-link-redirection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Text Compression Code Released</title>
		<link>http://www.cod3r.com/2010/07/text-compression-code-released/</link>
		<comments>http://www.cod3r.com/2010/07/text-compression-code-released/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 20:36:22 +0000</pubDate>
		<dc:creator>Graham Booker</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.cod3r.com/?p=363</guid>
		<description><![CDATA[After it&#8217;s original post, I got a request for the code I used in my text compression technique. I&#8217;ve not gotten around to cleaning up the code and separating it from it&#8217;s test environment so it can be distributed separately. You can read more about it in its own page. Sometime soon, I&#8217;ll get around [...]]]></description>
			<content:encoded><![CDATA[<p>After it&#8217;s <a href="http://www.cod3r.com/2009/07/text-compression-techniques/">original post</a>, I got a request for the code I used in my text compression technique.  I&#8217;ve not gotten around to cleaning up the code and separating it from it&#8217;s test environment so it can be distributed separately.  You can read more about it in its own <a href="http://www.cod3r.com/programming/text-compression/">page</a>.</p>
<p>Sometime soon, I&#8217;ll get around to releasing my code for fetching old Escape Pod episodes that I <a href="http://www.cod3r.com/2009/09/incorrect-podcast-order-on-my-ipod/">hinted at earlier</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cod3r.com/2010/07/text-compression-code-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Common Media Player Framework</title>
		<link>http://www.cod3r.com/2010/02/common-media-player-framework/</link>
		<comments>http://www.cod3r.com/2010/02/common-media-player-framework/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 19:27:43 +0000</pubDate>
		<dc:creator>Graham Booker</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Frontrow]]></category>
		<category><![CDATA[Sapphire]]></category>

		<guid isPermaLink="false">http://www.cod3r.com/?p=292</guid>
		<description><![CDATA[About 3 weeks ago, Kevin (developer of NitoTV) and I decided it was a bit silly how we were each writing playback mechanisms on the AppleTV with little to no collaboration between us. So, we decided to write a Common Media Player Framework, which is licensed using LGPL. Kevin sent me the code he used [...]]]></description>
			<content:encoded><![CDATA[<p>About 3 weeks ago, Kevin (developer of <a href="http://wiki.awkwardtv.org/wiki/NitoTV">NitoTV</a>) and I decided it was a bit silly how we were each writing playback mechanisms on the AppleTV with little to no collaboration between us.  So, we decided to write a Common Media Player Framework, which is licensed using LGPL.</p>
<p>Kevin sent me the code he used for DVD playback inside NitoTV as a place to start.  I stripped it down to a smaller piece, and started the framework.  After I had it doing basic playback, I worked on overlays to provide feedback to the user.  Now, hitting up and down changes the overlays between normal, chapter view, audio/subtitle selection, and zoom.<br />
<div id="attachment_294" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.cod3r.com/images/2010/02/Chapter-Overlay.png"><img src="http://www.cod3r.com/images/2010/02/Chapter-Overlay-300x168.png" alt="" title="Chapter Overlay" width="300" height="168" class="size-medium wp-image-294" /></a><p class="wp-caption-text">Chapter Overlay Sceenshot</p></div></p>
<p>Also, I added a pretty menu using a blurred image as the resume menu.  This is more consistent with Apple&#8217;s own playback<br />
<div id="attachment_296" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.cod3r.com/images/2010/02/Resume-Overlay.png"><img src="http://www.cod3r.com/images/2010/02/Resume-Overlay-300x168.png" alt="" title="Resume Overlay" width="300" height="168" class="size-medium wp-image-296" /></a><p class="wp-caption-text">Resume Overlay</p></div></p>
<p>In addition, I used my work on AC3 Passthrough in <a href="http://www.perian.org">Perian</a> to see if I could pull off the same in DVD Playback.  The issue is the AppleTV claims to only have a device which can play uncompressed audio, not one that can send Dolby Digital to a decoder.  So, I created an audio driver that claims to do exactly that and pipe the data through to the optical/HDMI port.  It was a lot of fun getting that working, and then I added support for DTS.</p>
<p>Anyway, now <a href="http://appletv.nanopi.net/">Sapphire</a> uses the common media player framework for DVD playback.  In the future, we&#8217;ll add other playback mechanisms as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cod3r.com/2010/02/common-media-player-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Text Compression Techniques</title>
		<link>http://www.cod3r.com/2009/07/text-compression-techniques/</link>
		<comments>http://www.cod3r.com/2009/07/text-compression-techniques/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 22:17:20 +0000</pubDate>
		<dc:creator>Graham Booker</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.cod3r.com/?p=264</guid>
		<description><![CDATA[A friend of mine develops on an Bible application for the iPhone, BibleXpress. Since his application includes several translations with the app, he once mentioned to me the possibility of compressing them to save space. Any compression that is done must achieve a good ratio, but more importantly, decompression must be fast. I took it [...]]]></description>
			<content:encoded><![CDATA[<p>A friend of mine develops on an Bible application for the iPhone, <a href="http://www.biblexpress.com/">BibleXpress</a>.  Since his application includes several translations with the app, he once mentioned to me the possibility of compressing them to save space.  Any compression that is done must achieve a good ratio, but more importantly, decompression must be fast.  I took it upon myself to find a compression algorithm that could fit the bill.</p>
<p>In my test case, I worked with the NASB translation of the Bible.  The raw text of this translation, minus formatting and book/chapter/verse identifiers is 3.965MB.  Since the iPhone already has zlib, using gzip compression is an obvious choice.  When compressed with gzip, the file size becomes 1.189MB, a significant savings.  Even though bzip2 is not readily available on the iPhone (at least not that I could find), I tested its compression which produced a file size of 0.8548MB.  While these mechanisms provide a significantly smaller file, when one desires a certain portion of the file, one must first decompress the entire file up to that point.  This is an expensive operation on a small device such as the iPhone.</p>
<p>One compromise is to compress each book individually.  This yields a file size of 1.242MB.  However, some books, such as Psalms, are still quite large, requiring a long decompression operation to read some of it&#8217;s chapters.  Since the application displays a chapter at a time, a logical compression block would be a single chapter which yields a file size of 1.628MB.  While this is a large increase in file size, a single chapter can be decompressed without requiring decompression of any other parts of the file.</p>
<p>I was not happy with these compression ratios and was determined to find a better way.  I looked into Huffman encoding, which uses a variable length string of bits to represent a symbol.  Its compression ratio does not change with the order of symbols, which typically means it won&#8217;t provide as high a compression ratio.  However, if you are told which bit is the start of a string, you may begin decompression without examining any of the file which precedes it.  In addition, the decompression scheme only requires walking a binary tree, which means it is also quite fast.  So, if Huffman encoding can be made to provide a good compression ratio, it will work well for this problem.</p>
<p>When using Huffman encoded, the question becomes how to decompose the string into symbols.  One typical decomposition is to make each character into a symbol.  While this is an easy representation, it doesn&#8217;t provide a good compression ratio.  Instead, I chose to make each word into a symbols.  After adding in punctuation, the tree contained 16,246 words.  This resulted in a dictionary size of 0.1364MB.  When compressed, the entire Bible was represented by a Huffman encoding of 0.9947MB, meaning a total of 1.131MB for the compressed stream and dictionary.</p>
<p>After this experiment, I concluded that Huffman encoding of words is the best for a large quantity of text.  It yielded a compression ratio that was better than gzip (though not as good as bzip2), but at the same time a scheme that could decompress individual parts of the file without having to read preceding parts.  In this scheme, a single chapter can be decompressed very quickly, and still have a high compression ratio.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cod3r.com/2009/07/text-compression-techniques/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using Newer Subversion in Xcode</title>
		<link>http://www.cod3r.com/2009/07/using-newer-subversion-in-xcode/</link>
		<comments>http://www.cod3r.com/2009/07/using-newer-subversion-in-xcode/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 20:05:47 +0000</pubDate>
		<dc:creator>Graham Booker</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.cod3r.com/?p=251</guid>
		<description><![CDATA[I use MacPorts to get a whole host of utilities. In addition, I&#8217;ve always used it to obtain later versions of subversion that the one provided with the OS. Xcode, on the other hand, is locked into using the version of Subversion which is installed in /usr (currently version 1.4.4 where as I have 1.6.3). [...]]]></description>
			<content:encoded><![CDATA[<p>I use <a href="http://www.macports.org/">MacPorts</a> to get a whole host of utilities.  In addition, I&#8217;ve always used it to obtain later versions of subversion that the one provided with the OS.  Xcode, on the other hand, is locked into using the version of Subversion which is installed in /usr (currently version 1.4.4 where as I have 1.6.3).  Since I often work in the command line, eventually I will use the newer version of Subversion on a directory which I also use in Xcode.  This causes a problem since the command line utility will upgrade the local repository format in such a way that old versions of Subversion (Xcode&#8217;s) cannot use it.</p>
<p>So, my options are:</p>
<ul>
<li>Only use the command line utility, or use Xcode, on a single repository checkout, but never both.</li>
<li>Use a horribly out of date version of Subversion</li>
<li>Hack Xcode&#8217;s plugin to work with newer versions of Subversion</li>
</ul>
<p>I chose the last, as it should give me the best of both worlds.  If you were to conduct a quick Google search, you would find a whole host of people posing a solution which involves <strong>moving around system libraries</strong>!!!!!  This is a horrible idea, as it breaks other things such as Apache.  Buried somewhere in the sea of bad ideas, I ran across a good one, written by <a href="http://lists.apple.com/archives/Xcode-users//2008/Sep/msg00525.html">Jean-Daniel Dupas and improved by Philippe Casgrain</a> which only changes the path location of libraries used by Xcode&#8217;s Subversion plugin.  This script worked well for Subversion 1.5, but recent versions of Subversion would cause Xcode to crash in libapr.  The solution is to add libapr and libaprutil to the script.  Here is the corrected script for your use.<br />
<code><br />
#!/bin/sh</p>
<p>if [ "$#" -lt "2" ]<br />
then<br />
  echo "Usage: xcode-svn-update.sh
<path to XcodeSubversionPlugin>
<path to svn base folder>"<br />
  echo "Example: xcode-svn-update.sh /Developer/Library/Xcode/Plug-<br />
ins/\c"<br />
  echo "XcodeSubversionPlugin.xcplugin/Contents/MacOS/<br />
XcodeSubversionPlugin /opt/local"<br />
  exit 1;<br />
fi</p>
<p># Save a backup copy, if necessary<br />
if [ -e "$1_Old" ]<br />
then<br />
  echo "Backup copy of \"$1\" exists."<br />
else<br />
  echo "Saving a backup copy of \"$1\"."<br />
  cp "$1" "$1_Old"<br />
fi</p>
<p>echo "Updating install path using svn libraries in \"$2\"..."<br />
install_name_tool -change \<br />
  /usr/lib/libapr-1.0.dylib \<br />
  $2/lib/libapr-1.0.dylib "$1"<br />
install_name_tool -change \<br />
  /usr/lib/libaprutil-1.0.dylib \<br />
  $2/lib/libaprutil-1.0.dylib "$1"<br />
install_name_tool -change \<br />
  /usr/lib/libsvn_client-1.0.dylib \<br />
  $2/lib/libsvn_client-1.0.dylib "$1"<br />
install_name_tool -change \<br />
  /usr/lib/libsvn_delta-1.0.dylib \<br />
  $2/lib/libsvn_delta-1.0.dylib "$1"<br />
install_name_tool -change \<br />
  /usr/lib/libsvn_diff-1.0.dylib \<br />
  $2/lib/libsvn_diff-1.0.dylib "$1"<br />
install_name_tool -change \<br />
  /usr/lib/libsvn_fs_fs-1.0.dylib \<br />
  $2/lib/libsvn_fs_fs-1.0.dylib "$1"<br />
install_name_tool -change \<br />
  /usr/lib/libsvn_fs-1.0.dylib \<br />
  $2/lib/libsvn_fs-1.0.dylib "$1"<br />
install_name_tool -change \<br />
  /usr/lib/libsvn_ra_local-1.0.dylib \<br />
  $2/lib/libsvn_ra_local-1.0.dylib "$1"<br />
install_name_tool -change \<br />
  /usr/lib/libsvn_ra_svn-1.0.dylib \<br />
  $2/lib/libsvn_ra_svn-1.0.dylib "$1"<br />
install_name_tool -change \<br />
  /usr/lib/libsvn_ra-1.0.dylib \<br />
  $2/lib/libsvn_ra-1.0.dylib "$1"<br />
install_name_tool -change \<br />
  /usr/lib/libsvn_repos-1.0.dylib \<br />
  $2/lib/libsvn_repos-1.0.dylib "$1"<br />
install_name_tool -change \<br />
  /usr/lib/libsvn_subr-1.0.dylib \<br />
  $2/lib/libsvn_subr-1.0.dylib "$1"<br />
install_name_tool -change \<br />
  /usr/lib/libsvn_wc-1.0.dylib \<br />
  $2/lib/libsvn_wc-1.0.dylib "$1"<br />
echo "Done!"<br />
</code></p>
<p>Now, how long till Xcode supports <a href="http://mercurial.selenic.com/wiki/">Mercurial</a>?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cod3r.com/2009/07/using-newer-subversion-in-xcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

