<?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>&#60;&#60; shiftedbits</title>
	<atom:link href="http://shiftedbits.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://shiftedbits.org</link>
	<description>Shifty shifty shifty. Shifty.</description>
	<lastBuildDate>Sun, 29 Jan 2012 23:40:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Enable WordPress Automatic Updates on a Debian Server</title>
		<link>http://shiftedbits.org/2012/01/29/enable-wordpress-automatic-updates-on-a-debian-server/</link>
		<comments>http://shiftedbits.org/2012/01/29/enable-wordpress-automatic-updates-on-a-debian-server/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 23:39:30 +0000</pubDate>
		<dc:creator>Devin Lane</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://shiftedbits.org/?p=329</guid>
		<description><![CDATA[I attempted to get WordPress to update plugins automatically on my Debian server today, and found it a bit less than trivial due to the number of configuration gotchas. Assuming you&#8217;re running a Debian server (I have 6.0 Squeeze), on which WordPress is installed in /var/www/site/public_html: 1) Install required packages. I used vsftpd. sudo apt-get install vsftpd openssl 2) Configure vsftpd. I set the following options in /etc/vsftpd.conf # Enable only local users, no anonymous anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 # &#8230; <a href="http://shiftedbits.org/2012/01/29/enable-wordpress-automatic-updates-on-a-debian-server/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I attempted to get WordPress to update plugins automatically on my Debian server today, and found it a bit less than trivial due to the number of configuration gotchas.</p>
<p>Assuming you&#8217;re running a Debian server (I have 6.0 Squeeze), on which WordPress is installed in /var/www/site/public_html:</p>
<p>1) Install required packages. I used vsftpd.</p>
<p><pre>
sudo apt-get install vsftpd openssl
</pre></p>
<p>2) Configure vsftpd. I set the following options in /etc/vsftpd.conf</p>
<p><pre>
# Enable only local users, no anonymous
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022

# Allow only our special FTP user
userlist_enable=YES
userlist_deny=NO
userlist_file=/etc/vsftpd.allow_list

# Here&#039;s the security trick -- listen only on the local interface to 
# prevent external connections
listen_address=127.0.0.1

# Enable debugging until everything works :)
log_ftp_protocol=YES
</pre></p>
<p>3) Add a user for ftp access</p>
<p><pre>
# Add the user
sudo useradd ftpsecure -d /var/www

# Set a password. Since vsftpd is only listening on localhost, the 
# security of this password isn&#039;t too important.
sudo passwd ftpsecure
</pre></p>
<p>4) Turn on vsftpd:</p>
<p><pre>
sudo /etc/init.d/vsftpd restart
</pre></p>
<p>5) Set permissions for ftpsecure to access your wordpress files. I use access control lists (ACLs), but you could use chown/chmod if you want. These may seem like a bit to permissive &#8212; keep in mind that the only way ftpsecure can log in is <strong>from your server.</strong></p>
<p><pre>
setfacl -m u:ftpsecure:r-x /var/www/site/

# The updater needs access to the root site
setfacl -R -m u:ftpsecure:rwx /var/www/site/public_html
setfacl -R -d -m u:ftpsecure:rwx /var/www/site/public_html
</pre></p>
<p>7) Tell WordPress about your FTP credentials. In /var/www/site/public-html/wp-config.php:</p>
<p><pre>
define(&#039;FTP_HOST&#039;, &#039;localhost&#039;);
define(&#039;FTP_USER&#039;, &#039;ftpsecure&#039;);
define(&#039;FTP_PASS&#039;, &#039;&lt;password&gt;&#039;);
</pre></p>
<p>6) Run an update. If WordPress asks for the connection type, choose FTP. Try getting WordPress to update a plugin or the entire site. If it fails, view the log with</p>
<p><pre>
tail -f /var/log/vsftpd.log
</pre></p>
<p>and run the update again. You&#8217;ll be able to tell from the log if there was a permission problem.</p>
<p>7) Disable logging. Remove the line</p>
<p><pre>
log_ftp_protocol=YES
</pre></p>
<p>in /etc/vsftpd.conf</p>
<p>8) You&#8217;re done!</p>
<p>Comment below if these steps didn&#8217;t work for you.</p>
<p>For reference, I used:</p>
<ul>
<li><a href="https://www.ramgad.com/2009/09/19/updating-wordpress-via-installed-ssl-ftp-server-on-debian-ftps/" target="_blank">Updating WordPress via installed SSL FTP Server on Debian (FTPS)</a></li>
<li><a href="https://security.appspot.com/vsftpd/vsftpd_conf.html" target="_blank">vsftpd Configuration Manual</a></li>
<li><a href="http://www.619cloud.com/blog/configure-wordpress-to-remember-ftp-details/" target="_blank">How To Configure WordPress To Remember FTP Details</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://shiftedbits.org/2012/01/29/enable-wordpress-automatic-updates-on-a-debian-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When you need std::remove_const</title>
		<link>http://shiftedbits.org/2012/01/29/when-you-need-stdremove_const/</link>
		<comments>http://shiftedbits.org/2012/01/29/when-you-need-stdremove_const/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 01:38:10 +0000</pubDate>
		<dc:creator>Devin Lane</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://shiftedbits.org/?p=274</guid>
		<description><![CDATA[I ran across an interesting case where I needed to use std::remove_const to ensure a template parameter wasn&#8217;t const by default. I had something like this: const Matrix&#60;4&#62; m4 = Identity; Vector&#60;3&#62; v3 = project(m4[3]); With the library I was using, TooN 2.0.0 beta8, this resulted in a compile error. The error stated that when the vector returned from project() was being created, the compiler couldn&#8217;t invoke assign to a read only location. A simplified declaration of project() looks as &#8230; <a href="http://shiftedbits.org/2012/01/29/when-you-need-stdremove_const/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I ran across an interesting case where I needed to use <code>std::remove_const</code> to ensure a template parameter wasn&#8217;t const by default. I had something like this:</p>
<p><pre>
const Matrix&lt;4&gt; m4 = Identity;
Vector&lt;3&gt; v3 = project(m4[3]);
</pre></p>
<p>With the library I was using, <a href="http://www.edwardrosten.com/cvd/toon/html-user/index.html">TooN 2.0.0 beta8</a>, this resulted in a compile error. The error stated that when the vector returned from <code>project()</code> was being created, the compiler couldn&#8217;t invoke assign to a read only location. A simplified declaration of <code>project()</code> looks as follows:</p>
<p><pre>
template &lt;int Size, typename Precision, typename Base&gt;
Vector&lt;Size-1,Precision&gt; project(const Vector&lt;Size, Precision, Base&gt;&amp; v);
</pre></p>
<p>What the <code>project()</code> function returns is not important; what is important is the use of the template parameter <code>Precision</code> in both the argument type and the return type. When I invoke <code>operator[]</code> on a const Matrix object, the returned vector&#8217;s precision inherits the const.</p>
<p><pre>
template &lt;int Rows, int Cols, class Precision&gt;
class Matrix {
...
Vector&lt;Cols, const Precision, Slice&gt; Matrix::operator[](int row) const;
};
</pre></p>
<p>When this vector is passed to the <code>project()</code> function above, the function tries to create and return a <code>Vector&lt;3, const double&gt;</code> which can only be initialized with a constexpr. Assigning to it via operator= or a constructor will not work to copy the data from the other vector.</p>
<p>There are several ways one can fix this, all of them involving removing the const qualifier from the Precision type on the returned vector.</p>
<p>It may seem like a simple solution would work:</p>
<p><pre>
template &lt;int Size, typename Precision, typename Base, typename P2&gt;
Vector&lt;Size-1, P2&gt; project(const Vector&lt;Size, Precision, Base&gt;&amp; v);
</pre></p>
<p>Unfortunately, this requires the function be invoked as <code>project&lt;Size, Precision, Base, P2&gt;(v);</code> which is undesirable.</p>
<p><strong>Solution #1</strong></p>
<p>The first solution is simple, but tedious if you have several functions with similar signatures:<br />
<pre>
template &lt;int Size, typename Precision, typename Base&gt;
Vector&lt;Size-1, typename std::remove_const&lt;Precision&gt;::type &gt; 
project(const Vector&lt;Size, Precision, Base&gt;&amp; v);
</pre></p>
<p><code>std::remove_const&lt;T&gt;::type</code> is a type expression equal to the original type <code>T</code>, but with any const qualifiers removed. In this way, <code>const double</code> becomes simply <code>double</code>.</p>
<p><strong>Solution #2</strong></p>
<p>Another solution is to prevent the creation of a Vector object with a const precision, the idea that a non-slice vector with const data isn&#8217;t very useful &#8212; you can&#8217;t even construct one properly. Generally the only time you would actually want a vector with const data is when that data is pointing to some already existing area in memory (a slice).</p>
<p>Consider the following toy code for a vector class:</p>
<p><pre>
#define DECLARE_TYPES(T) \
    typedef typename std::remove_const&lt;T&gt;::type PlainType; \
    typedef const T ConstPlainType; \
    typedef typename std::remove_const&lt;T&gt;::type&amp; ReferenceType; \
    typedef const T&amp; ConstReferenceType

struct StackBase {
template &lt;int Size, typename P&gt;
class Layout { 
public:
    DECLARE_TYPES(P);
    PlainType data[Size];
};
};

struct SliceBase {
template &lt;int Size, typename P&gt;
class Layout {
public:
    P* data;
};
};

template &lt;int Size, typename P = double, typename B = StackBase &gt;
class Vector : public B::template Layout&lt;Size, P&gt; {
public:
    DECLARE_TYPES(P);
    using B::template Layout&lt;Size, P&gt;::data;

    ConstReferenceType operator[](int i) const { return data[i]; }
    ReferenceType operator[](int i) { return data[i]; }
};
</pre></p>
<p>When the Vector object is backed by owned storage (StackBase), the data is declared explicitly to be of a non-const type. Similarly, the return types of operator[] are defined to be the const and non-const reference types. The SliceBase, which handles references to un-owned data, retains the original templated type to allow pointing to constant data.</p>
<p>While this method prevents the creation of Vector objects with const owned data, it also means you don&#8217;t have to augment functions that interface with these objects to correct the return type.</p>
]]></content:encoded>
			<wfw:commentRss>http://shiftedbits.org/2012/01/29/when-you-need-stdremove_const/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Correcting Message Order with Courier</title>
		<link>http://shiftedbits.org/2012/01/03/correcting-message-order-with-courier/</link>
		<comments>http://shiftedbits.org/2012/01/03/correcting-message-order-with-courier/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 04:10:05 +0000</pubDate>
		<dc:creator>Devin Lane</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[courier]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Mail.app]]></category>

		<guid isPermaLink="false">http://shiftedbits.org/?p=261</guid>
		<description><![CDATA[Recently I moved some local messages from my machine (previously downloaded with pop3) onto the server so I could use imap. I used Mail.app on Mac OS X 10.5.8 to do this. For some reason, the messages in this example were uploaded in a way that caused them to be loaded in the wrong order on iOS 5.0.1. Since I run the mailserver myself, I took a look at the message files to see if I could deduce the cause &#8230; <a href="http://shiftedbits.org/2012/01/03/correcting-message-order-with-courier/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently I moved some local messages from my machine (previously downloaded with pop3) onto the server so I could use imap. I used Mail.app on Mac OS X 10.5.8 to do this. </p>
<p>For some reason, the messages in this example were uploaded in a way that caused them to be loaded in the wrong order on iOS 5.0.1. Since I run the mailserver myself, I took a look at the message files to see if I could deduce the cause of the issue. I noticed a series of messages on the mail server that looked like this:</p>
<p><pre>
1324697191.M91227P15574V000000000000CA00I0004B07D_556.hostname,S=5622:2,S
1324697192.M322096P15574V000000000000CA00I0004B07F_557.hostname,S=225691:2,RS
1324697196.M144018P15574V000000000000CA00I0004B081_558.hostname,S=7702:2,RS
1324697197.M715598P15574V000000000000CA00I0004B083_559.hostname,S=15741:2,S
1324697199.M327587P15574V000000000000CA00I0004B085_560.hostname,S=8744:2,RS
</pre></p>
<p>The received times of these messages, in the same order as listed above, are:</p>
<p><pre>
01/15/2010
01/09/2009
07/13/2010
02/21/2010
05/06/2010
</pre></p>
<p>It turns out that due to the messages in this example having a modification date that doesn&#8217;t match their receive timestamp the messages appear in the wrong order on an iOS device, where the mail application assumes the order of the messages it gets from the imap server is already sorted by date. This isn&#8217;t a problem with desktop mail clients &#8212; they simply fetch all the messages, sort them, and everything is fine. Several google searches on this subject yielded threads where people were trying to get their messages in the correct order and the suggested remedy was &#8220;sort them on the client side.&#8221;</p>
<p>To fix this, I <a href="/static/code/rename.pl">wrote a perl script</a> script to read the message headers, determine the receive time, and update the file name and modification date to match.</p>
<p>Use the script like this:</p>
<p><pre>
perl rename.pl cur/*
</pre></p>
<p>When you&#8217;re convinced it will do the right thing:</p>
<p><pre>
perl rename.pl cur/* --output-dir cur_renamed
</pre></p>
<p>After ensuring the rename was correct, I swapped the <code>cur</code> and <code>cur_renamed</code> directories, deleted the <code>courierimapuiddb</code> file, and restarted courier-imap. I also had to quit Mail.app on OS X and delete and read the mail account on the iOS device to get the messages to come in in the correct order.</p>
]]></content:encoded>
			<wfw:commentRss>http://shiftedbits.org/2012/01/03/correcting-message-order-with-courier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Authenticator Backup Woes</title>
		<link>http://shiftedbits.org/2011/12/29/google-authenticator-backup-woes/</link>
		<comments>http://shiftedbits.org/2011/12/29/google-authenticator-backup-woes/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 23:45:54 +0000</pubDate>
		<dc:creator>Devin Lane</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[google-authenticator]]></category>
		<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://shiftedbits.org/?p=257</guid>
		<description><![CDATA[Google Authenticator doesn't backup on iOS; before erasing your old device, make sure to re-configure Google Authenticator on your new one. <a href="http://shiftedbits.org/2011/12/29/google-authenticator-backup-woes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>TL;DR: <strong>Google Authenticator doesn&#8217;t backup on iOS; before erasing your old device, make sure to re-configure Google Authenticator on your new one.</strong></p>
<p>I use the Google Authenticator app on iOS for 2-factor authentication into Google&#8217;s services. Recently, I was transitioning to a new phone after giving my existing one to my mom for Christmas. I did the standard backup -> restore plan which put most of my settings on my new device without issues. Fortunately, before I erased the old device, I made sure all my apps worked, including the authenticator.</p>
<p>Apparently, the data the authenticator app stores is not backed up for whatever reason, which means that instead of being able to generate the keys needed to access my accounts, the authenticator was prompting me to set up a new account. The smart folks over <a href="http://cadince.com/3-ways-to-move-google-authenticator/">here</a> recommend taking a screenshot of the QR code Google&#8217;s site gives you when you set up 2-factor authentication. </p>
<p>Questions:</p>
<p>To Google: Why doesn&#8217;t the authenticator back up its data? Seems this could be a nasty surprise for someone.<br />
To Android users: Does this happen on Android as well?</p>
]]></content:encoded>
			<wfw:commentRss>http://shiftedbits.org/2011/12/29/google-authenticator-backup-woes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cubic Spline Interpolation</title>
		<link>http://shiftedbits.org/2011/01/30/cubic-spline-interpolation/</link>
		<comments>http://shiftedbits.org/2011/01/30/cubic-spline-interpolation/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 18:11:35 +0000</pubDate>
		<dc:creator>Devin Lane</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[interpolation]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[spline]]></category>

		<guid isPermaLink="false">http://shiftedbits.org/?p=191</guid>
		<description><![CDATA[Cubic spline interpolation is a simple way to obtain a smooth curve from a set of discrete points (knots). It has both C1 (first derivative) and C2 (second derivative) continuity, enabling it to produce a continuous piecewise function given a set of data points. From the algorithm detailed here I have implemented a clamped cubic spline class in C++. It is templated on the type of X and Y, allowing for use of scalar or vector types. It requires only &#8230; <a href="http://shiftedbits.org/2011/01/30/cubic-spline-interpolation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Cubic spline interpolation is a simple way to obtain a smooth curve from a set of discrete points (knots). It has both C1 (first derivative) and C2 (second derivative) continuity, enabling it to produce a continuous piecewise function given a set of data points.</p>
<p>From the algorithm detailed <a href="/spline-interpolation">here</a> I have implemented a clamped cubic spline class in C++. It is templated on the type of X and Y, allowing for use of scalar or vector types. It requires only that X and Y define the operators +, -, *, and /, and that Y have a constructor that takes a single scalar argument, initializing all elements to the supplied value. </p>
<p>Usage is very simple. For example, to interpolate a 2D location over time, try this:<br/><br/></p>
<p><pre>
#import &quot;glm.hpp&quot;
#import &lt;vector&gt;

std::vector&lt;float&gt; times;
std::vector&lt;glm::vec2&gt; points;
times.push_back(0);
points.push_back(glm::vec2(0));
times.push_back(.5f);
points.push_back(glm::vec2(-303, -572));
times.push_back(1);
points.push_back(glm::vec2(-250, -980));

/* Create the spline interpolating the position over time */
Spline&lt;float, glm::vec2&gt; sp(times, points);

/* Compute the interpolated position at time 0.75f */
glm::vec2 value(sp[.75f]);
</pre></p>
<p>The code for the spline class is below:</p>
<p><span id="more-191"></span></p>
<p><pre>
/* &quot;THE BEER-WARE LICENSE&quot; (Revision 42): Devin Lane wrote this file. As long as you retain 
 * this notice you can do whatever you want with this stuff. If we meet some day, and you
 * think this stuff is worth it, you can buy me a beer in return. */

#include &lt;vector&gt;
#include &lt;iostream&gt;

/** Templated on type of X, Y. X and Y must have operator +, -, *, /. Y must have defined
 * a constructor that takes a scalar. */
template &lt;typename X, typename Y&gt;
class Spline {
public:
    /** An empty, invalid spline */
    Spline() {}
    
    /** A spline with x and y values */
    Spline(const std::vector&lt;X&gt;&amp; x, const std::vector&lt;Y&gt;&amp; y) {
        if (x.size() != y.size()) {
            std::cerr &lt;&lt; &quot;X and Y must be the same size &quot; &lt;&lt; std::endl;
            return;
        }
        
        if (x.size() &lt; 3) {
            std::cerr &lt;&lt; &quot;Must have at least three points for interpolation&quot; &lt;&lt; std::endl;
            return;
        }
        
        typedef typename std::vector&lt;X&gt;::difference_type size_type;
        
        size_type n = y.size() - 1;
        
        std::vector&lt;Y&gt; b(n), d(n), a(n), c(n+1), l(n+1), u(n+1), z(n+1);
        std::vector&lt;X&gt; h(n+1);

        l[0] = Y(1);
        u[0] = Y(0);
        z[0] = Y(0);
        h[0] = x[1] - x[0];
            
        for (size_type i = 1; i &lt; n; i++) {
            h[i] = x[i+1] - x[i];
            l[i] = Y(2 * (x[i+1] - x[i-1])) - Y(h[i-1]) * u[i-1];
            u[i] = Y(h[i]) / l[i];
            a[i] = (Y(3) / Y(h[i])) * (y[i+1] - y[i]) - (Y(3) / Y(h[i-1])) * (y[i] - y[i-1]);
            z[i] = (a[i] - Y(h[i-1]) * z[i-1]) / l[i];
        }
            
        l[n] = Y(1);
        z[n] = c[n] = Y(0);
        
        for (size_type j = n-1; j &gt;= 0; j--) {
            c[j] = z[j] - u[j] * c[j+1];
            b[j] = (y[j+1] - y[j]) / Y(h[j]) - (Y(h[j]) * (c[j+1] + Y(2) * c[j])) / Y(3);
            d[j] = (c[j+1] - c[j]) / Y(3 * h[j]);
        }
        
        for (size_type i = 0; i &lt; n; i++) {
            mElements.push_back(Element(x[i], y[i], b[i], c[i], d[i]));
        }        
    }
    virtual ~Spline() {}
    
    Y operator[](const X&amp; x) const {
        return interpolate(x);
    }
    
    Y interpolate(const X&amp;x) const {
        if (mElements.size() == 0) return Y();
        
        typename std::vector&lt;element_type&gt;::const_iterator it;
        it = std::lower_bound(mElements.begin(), mElements.end(), element_type(x));
        if (it != mElements.begin()) {
            it--;
        }   
            
        return it-&gt;eval(x);
    }
    
    std::vector&lt;Y&gt; operator[](const std::vector&lt;X&gt;&amp; xx) const {
        return interpolate(xx);
    }
    
    /* Evaluate at multiple locations, assuming xx is sorted ascending */
    std::vector&lt;Y&gt; interpolate(const std::vector&lt;X&gt;&amp; xx) const {
        if (mElements.size() == 0) return std::vector&lt;Y&gt;(xx.size());
        
        typename std::vector&lt;X&gt;::const_iterator it;
        typename std::vector&lt;element_type&gt;::const_iterator it2;
        it2 = mElements.begin();
        std::vector&lt;Y&gt; ys;
        for (it = xx.begin(); it != xx.end(); it++) {
            it2 = std::lower_bound(it2, mElements.end(), element_type(*it));
            if (it2 != mElements.begin()) {
                it2--;
            }
                
            ys.push_back(it2-&gt;eval(*it));
        }

        return ys;
    }

protected:
    
    class Element {
    public:
        Element(X _x) : x(_x) {}
        Element(X _x, Y _a, Y _b, Y _c, Y _d)
        : x(_x), a(_a), b(_b), c(_c), d(_d) {}
        
        Y eval(const X&amp; xx) const {
            X xix(xx - x);
            return a + b * xix + c * (xix * xix) + d * (xix * xix * xix);
        }
        
        bool operator&lt;(const Element&amp; e) const {
            return x &lt; e.x;
        }
        bool operator&lt;(const X&amp; xx) const {
            return x &lt; xx;
        }
        
        X x;
        Y a, b, c, d;
    };
            
    typedef Element element_type;
    std::vector&lt;element_type&gt; mElements;
};
</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://shiftedbits.org/2011/01/30/cubic-spline-interpolation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Houses in Minecraft</title>
		<link>http://shiftedbits.org/2011/01/02/houses-in-minecraft/</link>
		<comments>http://shiftedbits.org/2011/01/02/houses-in-minecraft/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 04:11:56 +0000</pubDate>
		<dc:creator>Devin Lane</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[minecraft]]></category>
		<category><![CDATA[ocd]]></category>

		<guid isPermaLink="false">http://shiftedbits.org/?p=154</guid>
		<description><![CDATA[So I&#8217;ve been playing Minecraft, focusing mainly on the creative aspect, although I play the new Beta client and run my own server locally so I get the features added post-classic. I&#8217;ve turned off monster spawning and set the difficulty to Peaceful, so I can focus on bringing creations to life instead of running from scary monsters in the night. The first time I played with monsters, I found the sound of a zombie&#8217;s &#8220;murrrrrrrr&#8221; in a dark, endless cavern &#8230; <a href="http://shiftedbits.org/2011/01/02/houses-in-minecraft/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been playing <a href="http://minecraft.net">Minecraft</a>, focusing mainly on the creative aspect, although I play the new Beta client and run my own server locally so I get the features added post-classic. I&#8217;ve turned off monster spawning and set the difficulty to Peaceful, so I can focus on bringing creations to life instead of running from scary monsters in the night.</p>
<p>The first time I played with monsters, I found the sound of a zombie&#8217;s &#8220;murrrrrrrr&#8221; in a dark, endless cavern to be frightening enough that I never wanted to hear it again. /shivers.</p>
<p>I find the first-person building experience to be very satisfying to the OCD urge within me that wants to make everything <em>right</em>. As all blocks are destroyable (with the exception of Bedrock), any reality can be created given enough time. I&#8217;m fond of using the different kinds of blocks to vary the aesthetics &#8212; even if the blocks type is not practical.</p>
<p>My favorite activity is to visualize my buildings at night, as I find the lighting of torches, lava, and glowstone to create a very pleasing effect. I also make frequent use of glass to provide a sense of openness and to allow light to mix between areas.</p>
<p>Here&#8217;s some screenshots of a large house on top of a hill that I&#8217;ve been working on.<br />
<div id="attachment_166" class="wp-caption alignnone" style="width: 610px"><a href="http://shiftedbits.org/wp-content/uploads/2011/01/house_masterbed.png"><img src="http://shiftedbits.org/wp-content/uploads/2011/01/house_masterbed-600x357.png" alt="The master bedroom" title="Master bedroom" width="600" height="357" class="size-large wp-image-166" /></a><p class="wp-caption-text">The spacious master bedroom.</p></div></p>
<p><span id="more-154"></span></p>
<div id="attachment_162" class="wp-caption alignnone" style="width: 610px"><a href="http://shiftedbits.org/wp-content/uploads/2011/01/house_kitchen.png"><img src="http://shiftedbits.org/wp-content/uploads/2011/01/house_kitchen-600x357.png" alt="View of the kitchen" title="Kitchen" width="600" height="357" class="size-large wp-image-162" /></a><p class="wp-caption-text">The kitchen has a large worktable, oven/stove, sink, and storage.</p></div>
<div id="attachment_164" class="wp-caption alignnone" style="width: 610px"><a href="http://shiftedbits.org/wp-content/uploads/2011/01/house_sunset.png"><img src="http://shiftedbits.org/wp-content/uploads/2011/01/house_sunset-600x357.png" alt="Sunset seen from one of the western bedrooms" title="Sunset" width="600" height="357" class="size-large wp-image-164" /></a><p class="wp-caption-text">Sunset seen from one of the western bedrooms.</p></div>
<div id="attachment_160" class="wp-caption alignnone" style="width: 610px"><a href="http://shiftedbits.org/wp-content/uploads/2011/01/house_front.png"><img src="http://shiftedbits.org/wp-content/uploads/2011/01/house_front-600x357.png" alt="Front of house." title="House Front" width="600" height="357" class="size-large wp-image-160" /></a><p class="wp-caption-text">Front view of the house, looking down the walkway at the main entrance.</p></div>
<div id="attachment_169" class="wp-caption alignnone" style="width: 610px"><a href="http://shiftedbits.org/wp-content/uploads/2011/01/house_lava_livingroom.png"><img src="http://shiftedbits.org/wp-content/uploads/2011/01/house_lava_livingroom-600x357.png" alt="" title="Lava in the living room" width="600" height="357" class="size-large wp-image-169" /></a><p class="wp-caption-text">Lava provides heat and light to a central table in the living room, <a href='http://en.wikipedia.org/wiki/Kotatsu'>Kotatsu</a> style.</p></div>
<div id="attachment_181" class="wp-caption alignnone" style="width: 610px"><a href="http://shiftedbits.org/wp-content/uploads/2011/01/house_backside.png"><img src="http://shiftedbits.org/wp-content/uploads/2011/01/house_backside-600x357.png" alt="" title="Unfinished backside of the house" width="600" height="357" class="size-large wp-image-181" /></a><p class="wp-caption-text">The back side of the house is still in progress!</p></div>
]]></content:encoded>
			<wfw:commentRss>http://shiftedbits.org/2011/01/02/houses-in-minecraft/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Time Machine Exclusions &#8211; Snow Leopard</title>
		<link>http://shiftedbits.org/2011/01/02/time-machine-exclusions-snow-leopard/</link>
		<comments>http://shiftedbits.org/2011/01/02/time-machine-exclusions-snow-leopard/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 03:24:37 +0000</pubDate>
		<dc:creator>Devin Lane</dc:creator>
				<category><![CDATA[Leopard]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[snow-leopard]]></category>

		<guid isPermaLink="false">http://shiftedbits.org/?p=150</guid>
		<description><![CDATA[A bit late, but here&#8217;s an update of the Time Machine exclusion list for Snow Leopard.Here&#8217;s the full list of the excluded paths: Contents Excluded The contents of these paths are excluded, but the directories themselves are preserved as they are required for a successful restore. Remains the same as in Leopard. /Volumes /Network /automount /.vol /tmp /cores /private/tmp /private/Network /private/tftpboot /private/var/automount /private/var/run /private/var/tmp /private/var/vm /private/var/db/dhcpclient /private/var/db/fseventsd /Library/Caches /Library/Logs /System/Library/Caches /System/Library/Extensions/Caches These folders are excluded pre 10.5.something [Does anyone know &#8230; <a href="http://shiftedbits.org/2011/01/02/time-machine-exclusions-snow-leopard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A bit late, but here&#8217;s an update of the Time Machine exclusion list for Snow Leopard.<span id="more-150"></span>Here&#8217;s the full list of the excluded paths:</p>
<h4>Contents Excluded</h4>
<p>The contents of these paths are excluded, but the directories themselves are preserved as they are required for a successful restore. Remains the same as in Leopard.<br />
<pre>
/Volumes
/Network
/automount
/.vol
/tmp
/cores
/private/tmp
/private/Network
/private/tftpboot
/private/var/automount
/private/var/run
/private/var/tmp
/private/var/vm
/private/var/db/dhcpclient
/private/var/db/fseventsd
/Library/Caches
/Library/Logs
/System/Library/Caches
/System/Library/Extensions/Caches
</pre></p>
<p>These folders are excluded pre 10.5.something [Does anyone know when these came about?]<br />
<pre>
/private/var/log
/private/var/folders
/private/var/log/apache2
/private/var/log/cups
/private/var/log/fax
/private/var/log/ppp
/private/var/log/sa
/private/var/log/samba
/private/var/log/uucp
/private/var/spool
</pre></p>
<h4>Paths Excluded</h4>
<p>These directories and their contents are excluded completely. Remains the same as in Leopard.<br />
<pre>
/.Spotlight-V100
/.Trashes
/.fseventsd
/.hotfiles.btree
/Backups.backupdb
/Desktop DB
/Desktop DF
/Network/Servers
/Previous Systems
/Users/Shared/SC Info
/Users/Guest
/dev
/home
/net
/private/var/db/Spotlight
/private/var/db/Spotlight-V100
</pre></p>
<h4>User Paths Excluded</h4>
<p>These directories and their contents are excluded per-user. The path is relative to the user&#8217;s home folder.<br />
<pre>Library/Application Support/SyncServices/data.version
Library/Caches
Library/Logs
Library/Mail/Envelope Index
Library/Mail/AvailableFeeds
Library/Mirrors
Library/PubSub/Database
Library/PubSub/Downloads
Library/PubSub/Feeds
Library/Safari/Icons.db
Library/Safari/WebpageIcons.db
Library/Safari/HistoryIndex.sk
</pre></p>
<h4>File Contents Excluded</h4>
<p>These directories are not themselves excluded, but the files in them are. The directories will be recreated on restore. Remains the same as in Leopard.<br />
<pre>
/private/var/log
/private/var/spool/cups
/private/var/spool/fax
/private/var/spool/uucp
</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://shiftedbits.org/2011/01/02/time-machine-exclusions-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NSCopying and Mutability</title>
		<link>http://shiftedbits.org/2009/04/17/nscopying-and-mutability/</link>
		<comments>http://shiftedbits.org/2009/04/17/nscopying-and-mutability/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 19:43:12 +0000</pubDate>
		<dc:creator>Devin Lane</dc:creator>
				<category><![CDATA[Cocoa Yups and Nopes]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[objc]]></category>

		<guid isPermaLink="false">http://shiftedbits.org/?p=121</guid>
		<description><![CDATA[In the Cocoa frameworks, it is common to find mutable and immutable versions of classes that store data, such as strings, dictionaries, and arrays. Most of these classes also implement the NSCopying informal protocol, and those with mutable varients implement the NSMutableCopying protocol. These protocols specify methods for obtaining immutable and mutable copies of an object. These copying methods should be implemented such that the copy can return an instance of a subclass, to allow for subclasses to copy their &#8230; <a href="http://shiftedbits.org/2009/04/17/nscopying-and-mutability/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the Cocoa frameworks, it is common to find mutable and immutable versions of classes that store data, such as strings, dictionaries, and arrays. Most of these classes also implement the <code>NSCopying</code> informal protocol, and those with mutable varients implement the <code>NSMutableCopying</code> protocol. These protocols specify methods for obtaining immutable and mutable copies of an object. These copying methods should be implemented such that the copy can return an instance of a subclass, to allow for subclasses to copy their specific instance variables.</p>
<p>There are situations, however, that can result in the inability of a subclass to do so. Consider <code>NSURLRequest</code>:</p>
<p><pre>
@interface NSURLRequest : NSObject &amp;lt;NSCoding, NSCopying, NSMutableCopying&amp;gt;
</pre></p>
<p>An immutable class, but one that implements <code>NSMutableCopying</code>, it responds directly to the <code>-mutableCopyWithZone:(NSZone *)zone</code> method that returns a mutable url request, an instance of <code>NSMutableURLRequest</code>. While this isn&#8217;t a problem in itself, it becomes an issue when this method is not re-implemented in <code>NSMutableURLRequest</code>.</p>
<div class="yupnoperap">
<p class="nope"><strong>– Nope: </strong>Implement the <code>NSMutableCopying</code> protocol only in your immutable class.</p>
<div class="why">
<p>The implementation of <code>-mutableCopyWithZone:(NSZone *)zone</code> in the immutable class must certainly hard-code the name of the mutable class &#8212; it cannot be aware of any external subclasses of the mutable class. This means that asking for a mutable copy of the immutable class creates an instance of the known mutable subclass. Consider the following example:</p>
<p><pre>
@interface MyMutableURLRequest : NSMutableURLRequest {} @end

MyMutableURLRequest *request = [MyMutableURLRequest requestWithURL:url];
request = [request mutableCopy];
</pre></p>
<p>In this case, the object returned from <code>-mutableCopy</code><strong> will be an instance of <code>NSMutableURLRequest</code></strong> instead of the expected <code>MyMutableURLRequest</code>.
</div>
</div>
<div class="yupnoperap">
<p class="nope"><strong>– Nope: </strong>Hardcode class names in <code>-copyWithZone:</code> and <code>-mutableCopyWithZone:</code></p>
<div class="why">
<p>Hardcoding class names serves to block subclassers from subclassing the copy methods without dirty hacks.</p>
</div>
</div>
<div class="yupnoperap">
<p class="yup"><strong>+ Yup: </strong>[Re]Implement the <code>NSMutableCopying</code> protocol in your mutable class.</p>
<div class="why">
<p>By doing this, the class name doesn&#8217;t have to be hard-coded (in the mutable class), and so a subclasser can simply call <code>[super mutableCopy]</code> and then copy their specific instance variables.</p>
</div>
</div>
<div class="yupnoperap">
<p class="nope"><strong>+ Yup: </strong>Use <code>[self class]</code> in <code>-copyWithZone:</code> and <code>-mutableCopyWithZone:</code></p>
<div class="why">
<p>By using [self class], an object of the subclass type will be allocated.</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://shiftedbits.org/2009/04/17/nscopying-and-mutability/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Readable If Statements</title>
		<link>http://shiftedbits.org/2009/04/17/readable-if-statements/</link>
		<comments>http://shiftedbits.org/2009/04/17/readable-if-statements/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 18:10:17 +0000</pubDate>
		<dc:creator>Devin Lane</dc:creator>
				<category><![CDATA[Coding Yups and Nopes]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[style]]></category>

		<guid isPermaLink="false">http://shiftedbits.org/?p=66</guid>
		<description><![CDATA[To kick of the Coding Yups and Nopes section, I&#8217;ll start with something simple. There are a set of things to do, and a set of things to avoid. For each thing, there are one or more reasons justifying its classification. These reasons are ordered by descending importance and increasing subjectivity. – Nope: if (condition) doWork(); else doOtherWork(); If you&#8217;re stepping through with a debugger (I used gdb), it is difficult to tell when stepping over the line if the &#8230; <a href="http://shiftedbits.org/2009/04/17/readable-if-statements/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>To kick of the Coding Yups and Nopes section, I&#8217;ll start with something simple. There are a set of things to do, and a set of things to avoid. For each thing, there are one or more reasons justifying its classification. These reasons are ordered by descending importance and increasing subjectivity.</p>
<div class="yupnoperap">
<p class="nope"><strong>– Nope: </strong></p>
<p><pre>if (condition) doWork();
else doOtherWork();
</pre></p>
<div class="why">
<ul>
<li>If you&#8217;re stepping through with a debugger (I used gdb), it is difficult to tell when stepping over the line if the statement is executed. To do so you must determine the value of condition, or determine if the function was called based on its side effects.</li>
<li>If you add an additional statement to the false case, it&#8217;s possible that braces may be forgotten, leading to incorrect operation.</li>
<li>Assuming the reason for putting both condition and statement on one line was to use less lines, the benefits of this are negated by the decreased readability of such a statement. By putting both condition and statement on one line, searching for a specific condition becomes more difficult.</li>
<li>Assuming other parts of your code are scoped and indented, this breaks that pattern.</li>
</ul>
</div>
<p><pre>if (condition) {
    doWork();
} else doOtherWork();
</pre></p>
<div class="why">
<ul>
<li>Similar to the above case. Basically this is inconsistent and has none of the advantages of either method.</li>
</ul>
</div>
<p><pre>if(condition){
    doWork();
}
</pre></p>
<div class="why">
<ul>
<li>This is a pure spacing issue. <code>if</code> is not a function, please do not call it as one. Also, that brace is squashed against that parentheses, give it some room! Skimping on spacing issues like this while writing makes it harder to read later.</li>
</ul>
</div>
</div>
<div class="yupnoperap">
<p class="yup"><strong>+ Yup: </strong></p>
<p><pre>if (condition) {
    doWork();
} else {
    doOtherWork();
}
</pre></p>
<div class="why">
<ul>
<li>The perfect if-else statement. Well spaced, condition and statement on separate lines.</li>
</ul>
</div>
<p><pre>if (error) return;
if (error) break;
if (error) continue;
</pre></p>
<div class="why">
<ul>
<li>When used only for error/early exit conditions, these help to condense code so that the reader can quickly get to the meat of a function.</li>
<li>The statements and the condition are on one line because I do not consider the flow control statements return, break, and continue to contribute useful work, such that it should be scoped in braces and on its own line.</li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://shiftedbits.org/2009/04/17/readable-if-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Window Resizing on Resolution Change</title>
		<link>http://shiftedbits.org/2009/04/16/window-resizing-on-resolution-change/</link>
		<comments>http://shiftedbits.org/2009/04/16/window-resizing-on-resolution-change/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 18:35:43 +0000</pubDate>
		<dc:creator>Devin Lane</dc:creator>
				<category><![CDATA[App Yups and Nopes]]></category>

		<guid isPermaLink="false">http://shiftedbits.org/?p=96</guid>
		<description><![CDATA[This post kicks off the &#8220;App Yups and Nopes&#8221; section in which I&#8217;ll post both good and bad things I see applications doing. This differs from the other Yups and Nopes sections in that it talkes specifically about observed application behavior. My intent is to show why a specific behavior is undesirable, then present a solution. In this situation, I connect my laptop to a projector to watch a movie. My screen resolution changes to match that of the projector. &#8230; <a href="http://shiftedbits.org/2009/04/16/window-resizing-on-resolution-change/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This post kicks off the &#8220;App Yups and Nopes&#8221; section in which I&#8217;ll post both good and bad things I see applications doing. This differs from the other Yups and Nopes sections in that it talkes specifically about observed application behavior. My intent is to show why a specific behavior is undesirable, then present a solution.</p>
<p>In this situation, I connect my laptop to a projector to watch a movie. My screen resolution changes to match that of the projector. I see applications with the following behaviors:</p>
<div class="yupnoperap">
<p class="nope"><strong>–  Nope: </strong>Resize application windows to fit on screen, regardless of window or application visibility.
</p>
<div class="why">
<p>The goal of resizing an application window on screen resolution change is to make sure the window is placed so that the user is able to manipulate it (move and resize.) An application is only required to resize and reposition windows that are actually visible. If a window is offscreen or the application is hidden, the window size and position should not be modified. When an offscreen window or a window of a hidden application is modified in this way, useless computation results. If the window cannot be seen, what use is there in constraining its bounds?</p>
</div>
</div>
<div class="yupnoperap">
<p class="yup"><strong>+ Yup: </strong>Resize application windows as they are made visible, making only the smallest change necessary to satisfy visibility and interaction requirements.
</p>
<div class="why">
<p>A common trick I use before connecting an external monitor of smaller resolution is to hide all applications &#8212; for most applications this prevents their window state from being altered. In this way when I have finished using the projector, I can unhide these applications and continue using them with a window state identical to before the resolution change. This works great for applications that implement correct window resizing behavior. Most Cocoa applications do this correctly by default. Noted offenders are iTunes and iPhoto, both of which require me to pointlessly resize their windows after the resolution is restored.</p>
<p>Note also that only the height must be constrained to the visible screen height &#8212; windows are allowed to be wider than the screen. Furthermore, it is not necessary to reposition the window such that its entire contents are visible &#8212; windows can hang off the edge of the screen on the left and right sides. This, of course, becomes more complicated when multiple displays are attached as these restrictions change.</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://shiftedbits.org/2009/04/16/window-resizing-on-resolution-change/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.342 seconds -->
<!-- Cached page served by WP-Cache -->

