<?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"
	>

<channel>
	<title>Single Point of Failure</title>
	<atom:link href="http://www.singlepointoffailure.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.singlepointoffailure.net</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Sat, 05 May 2012 17:03:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
	<language>en</language>
			<item>
		<title>Aha! Excellent book&#8230;</title>
		<link>http://www.singlepointoffailure.net/2012/05/books/how-to-install-the-java-development-kit-and-set-java_home-2-2-3-3-2-2/</link>
		<comments>http://www.singlepointoffailure.net/2012/05/books/how-to-install-the-java-development-kit-and-set-java_home-2-2-3-3-2-2/#comments</comments>
		<pubDate>Sat, 05 May 2012 14:32:37 +0000</pubDate>
		<dc:creator>singlepointoffailure</dc:creator>
		
		<category><![CDATA[Books]]></category>

		<category><![CDATA[Algorithms]]></category>

		<category><![CDATA[Book]]></category>

		<category><![CDATA[Pearls]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.singlepointoffailure.net/2012/05/books/how-to-install-the-java-development-kit-and-set-java_home-2-2-3-3-2-2/</guid>
		<description><![CDATA[I&#8217;ve been reading some of the classics, including the amazing Jon Bentley&#8217;s Programming Pearls (2nd Edition). The book provides awesome insight to the mind of a programmer. Moreover, by providing an excellent list of problems the author incites the reader to experiment with the contents of the book.
Here&#8217;s my version of the anagram finder from [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been reading some of the classics, including the amazing Jon Bentley&#8217;s Programming Pearls (2nd Edition). The book provides awesome insight to the mind of a programmer. Moreover, by providing an excellent list of problems the author incites the reader to experiment with the contents of the book.</p>
<p>Here&#8217;s my version of the anagram finder from Column 2: &#8220;Aha! Algorithms&#8221;.</p>
<pre class="brush: cpp; gutter: true; highlight: []; first-line: 1; pad-line-numbers: true; toolbar: false;">
#include &lt;iostream&gt;
#include &lt;fstream&gt;

#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;unordered_map&gt;
#include &lt;algorithm&gt;

typedef std::vector&lt;std::string&gt; anagram_vector_t;

typedef std::unordered_map&lt;std::string, anagram_vector_t&gt; anagram_map_t;

void
load_words_from_stream(anagram_vector_t&amp; words, std::istream&amp; input)
{
  std::string word;

  while(input &gt;&gt; word)
  {
    words.push_back(word);
  }
}

void
load_words_from_file(anagram_vector_t&amp; words, const std::string&amp; filename)
{
  std::ifstream input(filename);

  load_words_from_stream(words, input);
}

void
process_anagrams(const anagram_vector_t&amp; words, anagram_map_t&amp; anagrams)
{
  std::for_each(std::begin(words),
                std::end(words),
                [&amp;anagrams](const std::string&amp; word) {

    // get key by sorting the string value
    std::string key = word;
    std::sort(key.begin(), key.end());

    // store (key, value)
    anagrams[key].push_back(word);
  });
}

void
print_anagrams(const anagram_map_t&amp; anagrams)
{
  for(auto i = std::begin(anagrams); i != std::end(anagrams); ++i)
  {
    const anagram_vector_t&amp; words = i-&gt;second;

    if( words.size() &gt; 1 )
    {
      std::for_each(std::begin(words),
                    std::end(words),
                    [&amp;anagrams](const std::string&amp; word) {

        std::cout &lt;&lt; word &lt;&lt; " ";
      });
      std::cout &lt;&lt; std::endl;
    }
  }
}

void do_anagrams(const std::string&amp; filename)
{
  anagram_map_t anagrams;
  anagram_vector_t words;

  load_words_from_file(words, filename);
  process_anagrams(words, anagrams);
  print_anagrams(anagrams);
}

int main(int argc, char *argv[])
{
  if( argc != 2 )
  {
    std::cout &lt;&lt; "Usage: " &lt;&lt; argv[0] &lt;&lt; " &lt;words-file&gt;" &lt;&lt; std::endl;
    return -1;
  }

  do_anagrams(argv[1]);

  return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.singlepointoffailure.net/2012/05/books/how-to-install-the-java-development-kit-and-set-java_home-2-2-3-3-2-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Spies and Sci-fi&#8230; for a cold weekend!</title>
		<link>http://www.singlepointoffailure.net/2012/04/tv/spies-and-sci-fi-for-a-cold-weekend/</link>
		<comments>http://www.singlepointoffailure.net/2012/04/tv/spies-and-sci-fi-for-a-cold-weekend/#comments</comments>
		<pubDate>Sun, 22 Apr 2012 15:23:56 +0000</pubDate>
		<dc:creator>singlepointoffailure</dc:creator>
		
		<category><![CDATA[TV]]></category>

		<category><![CDATA[Alien]]></category>

		<category><![CDATA[Falling]]></category>

		<category><![CDATA[Homeland]]></category>

		<category><![CDATA[Radicalism]]></category>

		<category><![CDATA[Skies]]></category>

		<category><![CDATA[Spies]]></category>

		<category><![CDATA[Survival]]></category>

		<guid isPermaLink="false">http://www.singlepointoffailure.net/2012/04/tv/spies-and-sci-fi-for-a-cold-weekend/</guid>
		<description><![CDATA[ 
]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img src="https://lh3.googleusercontent.com/-wX1cNCP8E04/T5QgMi8UhZI/AAAAAAABBgM/JWae-d-fU9A/s320/Falling.jpg" alt="" /> <img src="https://lh6.googleusercontent.com/-z1qznNUefWQ/T5Qgxan0iUI/AAAAAAABBgU/SrOeU-UDy0Q/s320/FallingSkies.jpg" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.singlepointoffailure.net/2012/04/tv/spies-and-sci-fi-for-a-cold-weekend/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Once Upon a Time&#8230;</title>
		<link>http://www.singlepointoffailure.net/2012/04/tv/once-upon-a-time/</link>
		<comments>http://www.singlepointoffailure.net/2012/04/tv/once-upon-a-time/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 13:23:44 +0000</pubDate>
		<dc:creator>singlepointoffailure</dc:creator>
		
		<category><![CDATA[TV]]></category>

		<category><![CDATA[Evil Queen]]></category>

		<category><![CDATA[Fair]]></category>

		<category><![CDATA[Jennifer Morrison]]></category>

		<category><![CDATA[Tales]]></category>

		<guid isPermaLink="false">http://www.singlepointoffailure.net/2012/04/tv/once-upon-a-time/</guid>
		<description><![CDATA[
Here&#8217;s some company from my vacations&#8230;
]]></description>
			<content:encoded><![CDATA[<p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://lh4.googleusercontent.com/-4bVFvQP5twU/T32a-gwkCVI/AAAAAAABASg/MYm3cjXAQQ0/s512/OnceUpenATime.png" alt="" width="510" height="512" /></p>
<p style="text-align: center;">Here&#8217;s some company from my vacations&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.singlepointoffailure.net/2012/04/tv/once-upon-a-time/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Type-Erasure to store heterogenous properties</title>
		<link>http://www.singlepointoffailure.net/2012/04/uncategorized/using-type-erasure-to-store-heterogenous-properties/</link>
		<comments>http://www.singlepointoffailure.net/2012/04/uncategorized/using-type-erasure-to-store-heterogenous-properties/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 09:21:00 +0000</pubDate>
		<dc:creator>singlepointoffailure</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.singlepointoffailure.net/2012/04/uncategorized/using-type-erasure-to-store-heterogenous-properties/</guid>
		<description><![CDATA[The objective was to implement a Property class composed of a key and a value. The class is designed to store heterogenous data, implemeting a non-template class to allow storing properties in a standard container.
Property p("zero", 0),

auto key = p.key();
auto value = p.value&#60; int &#62;();
auto tname = p.type();

Let&#8217;s start over with the simple stuff: the [...]]]></description>
			<content:encoded><![CDATA[<p>The objective was to implement a Property class composed of a key and a value. The class is designed to store heterogenous data, implemeting a non-template class to allow storing properties in a standard container.</p>
<pre class="brush: cpp; gutter: false; highlight: []; first-line: 1; pad-line-numbers: true; toolbar: false;">Property p("zero", 0),

auto key = p.key();
auto value = p.value&lt; int &gt;();
auto tname = p.type();
</pre>
<p>Let&#8217;s start over with the simple stuff: the class declaration and some public types.</p>
<pre class="brush: cpp; gutter: false; highlight: []; first-line: 1; pad-line-numbers: 3; toolbar: false;">class Property
{
    public: // public types

    typedef std::string     key_t;
    typedef std::string     type_t;
</pre>
<p>To provide internal storage for the property value, define a Placeholder abstract class.</p>
<pre class="brush: cpp; gutter: false; highlight: []; first-line: 1; pad-line-numbers: 3; toolbar: false;">private:

    class Placeholder
    {
    public:

        Placeholder(const key_t&amp; key) : key_(key) {}

        virtual ~Placeholder() {};

        virtual key_t key() { return key_; }
        virtual type_t type() const = 0;

    private:

        key_t key_;
    };
</pre>
<p>The Property class will store a pointer to Placeholder base class. This class provides for type-erasure since it does not mention the actual value type. The value is stored in the derived templated PlaceHolderStorage class.</p>
<pre class="brush: cpp; gutter: false; highlight: []; first-line: 1; pad-line-numbers: 3; toolbar: false;">    template &lt; typename T &gt;
    class PlaceholderStorage : public Placeholder
    {
    public:
        PlaceholderStorage(const key_t&amp; key, const T&amp; value):
            Placeholder(key), value_(value)
        {}

        virtual ~PlaceholderStorage() {}

        virtual type_t type() const
        {
            return typename_of&lt; T &gt;();
        };

        virtual const T&amp; value()
        {
            return value_;
        }

    private:
        T value_;
    };
</pre>
<p>The default constructor of property created an integer value 0 and &#8220;default&#8221; as key. Default construction is only available to allow for usage with map standard container. Construction is also enabled by a template with the type of the storage data.</p>
<pre class="brush: cpp; gutter: false; highlight: []; first-line: 1; pad-line-numbers: 3; toolbar: false;">public:

    Property() :
        property_( new PlaceholderStorage&lt; int &gt;("default", 0) )
    {}

    template &lt; typename T &gt;
    Property(const key_t&amp; key, const T&amp; value) :
        property_( new PlaceholderStorage&lt; T &gt;(key, value) )
    {}
</pre>
<p>The Property allows access to the key and to the value. Access to the value requires a template type. A PropertyTypeInvalid exception is thrown if the requested type is not according to the stored value.</p>
<pre class="brush: cpp; gutter: false; highlight: []; first-line: 1; pad-line-numbers: 3; toolbar: false;">public:

    key_t key() const
    {
        return property_-&gt;key();
    }

    type_t type() const
    {
        return property_-&gt;type();
    }

    template &lt; typename T &gt;
    T value() const
    {
        PlaceholderStorage&lt; T &gt; *derived
            = dynamic_cast&lt;
                PlaceholderStorage&lt; T &gt;* &gt;(property_.get());

        if(derived == 0x0)
            throw PropertyTypeInvalid(
                std::string("Invalid property type, accessing \"")
                                + typename_of&lt; T &gt;()
                                + "\" value, but type is \""
                                + property_-&gt;type() + "\"");

        return derived-&gt;value();
    }
</pre>
<p>Internally, the Property stores the Placeholder for the data in a shared pointer.</p>
<pre class="brush: cpp; gutter: false; highlight: []; first-line: 1; pad-line-numbers: 3; toolbar: false;">private:

    std::shared_ptr&lt; Placeholder &gt; property_;
};
</pre>
<p>To access the complete example, access <a href="http://code.google.com/p/abyss/source/browse/#git%2Fcode%2Fregistry">abyss</a> source code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.singlepointoffailure.net/2012/04/uncategorized/using-type-erasure-to-store-heterogenous-properties/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to check for endianess?</title>
		<link>http://www.singlepointoffailure.net/2012/03/programming/how-to-install-the-java-development-kit-and-set-java_home-2-2-3-3-2/</link>
		<comments>http://www.singlepointoffailure.net/2012/03/programming/how-to-install-the-java-development-kit-and-set-java_home-2-2-3-3-2/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 11:00:00 +0000</pubDate>
		<dc:creator>singlepointoffailure</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[C/C++]]></category>

		<category><![CDATA[Endianness]]></category>

		<guid isPermaLink="false">http://www.singlepointoffailure.net/2012/03/programming/how-to-install-the-java-development-kit-and-set-java_home-2-2-3-3-2/</guid>
		<description><![CDATA[
bool platform_is_big_endian()
{
   long one = 1;
   return !(*((char *)(&#38;one)));
}

So, what&#8217;s going on?
A long takes more that 1 byte (usually 4 bytes).
In big-endian 1 is represented by {0&#215;00, 0&#215;00, 0&#215;00, 0&#215;01}, which is reversed for little-endian {0&#215;01, 0&#215;00, 0&#215;00, 0&#215;00}. The code above takes the address of the most significant byte of [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: cpp; gutter: true; highlight: []; first-line: 1; pad-line-numbers: true; toolbar: false;">
bool platform_is_big_endian()
{
   long one = 1;
   return !(*((char *)(&amp;one)));
}
</pre>
<p>So, what&#8217;s going on?</p>
<p>A long takes more that 1 byte (usually 4 bytes).<br />
In big-endian 1 is represented by {0&#215;00, 0&#215;00, 0&#215;00, 0&#215;01}, which is reversed for little-endian {0&#215;01, 0&#215;00, 0&#215;00, 0&#215;00}. The code above takes the address of the most significant byte of the long, and depending on the value of that byte returns true if big-endian, false if little endian.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.singlepointoffailure.net/2012/03/programming/how-to-install-the-java-development-kit-and-set-java_home-2-2-3-3-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>You Da One</title>
		<link>http://www.singlepointoffailure.net/2012/03/music/you-da-one/</link>
		<comments>http://www.singlepointoffailure.net/2012/03/music/you-da-one/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 10:38:16 +0000</pubDate>
		<dc:creator>singlepointoffailure</dc:creator>
		
		<category><![CDATA[Music]]></category>

		<category><![CDATA[Rihanna]]></category>

		<guid isPermaLink="false">http://www.singlepointoffailure.net/2012/03/music/you-da-one/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><iframe width="560" height="315" src="http://www.youtube.com/embed/b3HeLs8Yosw" frameborder="0"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.singlepointoffailure.net/2012/03/music/you-da-one/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Patience is a Virtue</title>
		<link>http://www.singlepointoffailure.net/2012/03/cartoon/patience-is-a-virtue/</link>
		<comments>http://www.singlepointoffailure.net/2012/03/cartoon/patience-is-a-virtue/#comments</comments>
		<pubDate>Sun, 04 Mar 2012 09:30:09 +0000</pubDate>
		<dc:creator>singlepointoffailure</dc:creator>
		
		<category><![CDATA[Cartoon]]></category>

		<category><![CDATA[Fuck]]></category>

		<category><![CDATA[Patience]]></category>

		<category><![CDATA[Virtue]]></category>

		<guid isPermaLink="false">http://www.singlepointoffailure.net/2012/03/cartoon/patience-is-a-virtue/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://lh5.googleusercontent.com/-RiyhiahIsaE/T1M1j0oSvZI/AAAAAAAA-hE/iygoktPX0gY/s800/PatienceIsAVirtue.jpg" alt="" width="420" height="294" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.singlepointoffailure.net/2012/03/cartoon/patience-is-a-virtue/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Map</title>
		<link>http://www.singlepointoffailure.net/2012/01/programming/map/</link>
		<comments>http://www.singlepointoffailure.net/2012/01/programming/map/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 13:18:00 +0000</pubDate>
		<dc:creator>singlepointoffailure</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[C++]]></category>

		<category><![CDATA[Map]]></category>

		<category><![CDATA[Picture]]></category>

		<guid isPermaLink="false">http://www.singlepointoffailure.net/2012/01/programming/map/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><a href="http://dl.dropbox.com/u/110729/Blog/Images/cppmap-2012.png"><img style="display: block; margin-left: auto; margin-right: auto;" src="https://lh5.googleusercontent.com/-AeJIvH_gzSs/TyPy3Mxxf9I/AAAAAAAA9z4/cmC7dcFVIl8/s400/cppmap-2012.png" alt="" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.singlepointoffailure.net/2012/01/programming/map/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Big Ball of Yarn</title>
		<link>http://www.singlepointoffailure.net/2012/01/work/big-ball-of-yarn/</link>
		<comments>http://www.singlepointoffailure.net/2012/01/work/big-ball-of-yarn/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 11:19:10 +0000</pubDate>
		<dc:creator>singlepointoffailure</dc:creator>
		
		<category><![CDATA[Work]]></category>

		<category><![CDATA[C/C++]]></category>

		<category><![CDATA[Fun]]></category>

		<category><![CDATA[include]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.singlepointoffailure.net/2012/01/work/big-ball-of-yarn/</guid>
		<description><![CDATA[New year, new project, right? Well&#8230; that not totally true for me this year! Let&#8217;s say that I&#8217;ve inherited a Big Ball of Yarn to play with. The goal is to &#8220;reuse&#8221; an existing project, remove unnecessary functionality (a.k.a. dead code), and plug-in some extra &#8220;algorithms&#8221;, but just lot at the #include dependencies of the [...]]]></description>
			<content:encoded><![CDATA[<p>New year, new project, right? Well&#8230; that not totally true for me this year! Let&#8217;s say that I&#8217;ve inherited a Big Ball of Yarn to play with. The goal is to &#8220;reuse&#8221; an existing project, remove unnecessary functionality (a.k.a. dead code), and plug-in some extra &#8220;algorithms&#8221;, but just lot at the #include dependencies of the &#8220;reusable&#8221; source code. This will be fun!</p>
<p style="text-align: center;"><a href="https://lh4.googleusercontent.com/-rwEwnHaT0P8/TwGM_mc0MlI/AAAAAAAA9zQ/EnJ0f90yZxQ/s800/BigBallOfYarn.png"><img src="https://lh4.googleusercontent.com/-rwEwnHaT0P8/TwGM_mc0MlI/AAAAAAAA9zQ/EnJ0f90yZxQ/s288/BigBallOfYarn.png" alt="" width="288" height="270" /></a></p>
<p style="text-align: center;">(<a href="https://lh4.googleusercontent.com/-rwEwnHaT0P8/TwGM_mc0MlI/AAAAAAAA9zQ/EnJ0f90yZxQ/s800/BigBallOfYarn.png">click</a> to enlarge)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.singlepointoffailure.net/2012/01/work/big-ball-of-yarn/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Caution: Highly Addictive</title>
		<link>http://www.singlepointoffailure.net/2011/12/tv/caution-highly-addictive/</link>
		<comments>http://www.singlepointoffailure.net/2011/12/tv/caution-highly-addictive/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 19:15:14 +0000</pubDate>
		<dc:creator>singlepointoffailure</dc:creator>
		
		<category><![CDATA[TV]]></category>

		<category><![CDATA[Bad]]></category>

		<category><![CDATA[Breaking]]></category>

		<category><![CDATA[Drugs]]></category>

		<category><![CDATA[Jesse Pinkman]]></category>

		<category><![CDATA[Methamphetamine]]></category>

		<category><![CDATA[Walter White]]></category>

		<guid isPermaLink="false">http://www.singlepointoffailure.net/2011/12/tv/caution-highly-addictive/</guid>
		<description><![CDATA[

]]></description>
			<content:encoded><![CDATA[<p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://lh5.googleusercontent.com/-x7RleQTNLzM/Tvy5TCG8MII/AAAAAAAA9ys/xL-ikMF9ph0/s400/breaking_bad.jpg" alt="" /></p>
<p><a href="https://lh5.googleusercontent.com/-7ZVLWqskt_k/Tvy5bD2gUbI/AAAAAAAA9y0/R30zIt5bhKI/s1600/breaking-bad-7827-1920x1200.jpg"><img style="display: block; margin-left: auto; margin-right: auto;" src="https://lh5.googleusercontent.com/-7ZVLWqskt_k/Tvy5bD2gUbI/AAAAAAAA9y0/R30zIt5bhKI/s400/breaking-bad-7827-1920x1200.jpg" alt="" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.singlepointoffailure.net/2011/12/tv/caution-highly-addictive/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

