<?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>The Squirrels Are Watching</title>
	<atom:link href="http://andrewfong.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewfong.com/blog</link>
	<description>Rants and Ramblings From a Programmer / Lawyer / Webcomic Artist</description>
	<lastBuildDate>Wed, 24 May 2017 17:30:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.7.5</generator>
	<item>
		<title>Javascript, React, This, and Programming Fundamentals</title>
		<link>http://andrewfong.com/blog/2017/05/13/javascript-react-this-and-programming-fundamentals/</link>
		<comments>http://andrewfong.com/blog/2017/05/13/javascript-react-this-and-programming-fundamentals/#respond</comments>
		<pubDate>Sat, 13 May 2017 04:44:05 +0000</pubDate>
		<dc:creator><![CDATA[Andrew Fong]]></dc:creator>
				<category><![CDATA[Code and Tech]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://andrewfong.com/blog/?p=500</guid>
		<description><![CDATA[A friend of mine was teaching herself React and got confused by how the this keyword worked in JavaScript. Someone told her it was like self in Python. It&#8217;s not. So I typed up a longish Gist on how this works and how it applies to React. It&#8217;s not the only explanation of this out &#8230; <p class="link-more"><a href="http://andrewfong.com/blog/2017/05/13/javascript-react-this-and-programming-fundamentals/" class="more-link">Continue reading<span class="screen-reader-text"> "Javascript, React, This, and Programming Fundamentals"</span></a></p>]]></description>
				<content:encoded><![CDATA[<p>A friend of mine was teaching herself React and got confused by how the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this"><code>this</code></a> keyword worked in JavaScript. Someone told her it was like <code>self</code> in Python. It&#8217;s not. So I typed up a <a href="https://gist.github.com/fongandrew/f28245920a41788e084d77877e65f22f">longish Gist on how this works and how it applies to React</a>. It&#8217;s not the only explanation of <code>this</code> out there, but I couldn&#8217;t find one that tied into React, so &#8230; there it is.</p>
<p>Anyhow, the bigger problem here is that she started learning React from a bunch of tutorials without a solid grasp of JavaScript fundamentals. My guess is that she wanted to learn React, learned just enough JavaScript to understand the React Hello World tutorial, but never got to the part about how <code>this</code> works and got really frustrated when she started running into weird behavior related to how React does (or used to do) auto-binding.</p>
<p>It&#8217;s not a new problem. Every so often, a new library or framework takes off and everyone goes, &#8220;Oh, I should learn that *thing* now.&#8221; And that *thing* is often built on other libraries or languages or abstractions but no one really wants to learn all of underlying fundamentals of the hot new thing, but the fundamentals aren&#8217;t really all that hot themselves. Like JavaScript and React, and before that, JavaScript and jQuery (cue all the Stack Overflow searches for &#8220;how do I do this in jQuery&#8221; when jQuery isn&#8217;t at all necessary, or useful). Or Python and Django. Ruby and Rails. Databases and ORMs.<br />
<span id="more-500"></span></p>
<p>Basically, folks read the tutorial for the new thing, and learn just enough of the old thing to get going with the new thing, but not enough of the old thing to really understand what&#8217;s happening behind the scenes of the new thing and get frustrated or bogged down when things stop working.</p>
<p>But I can&#8217;t really fault people for that. It&#8217;s tempting to say that everyone should understand every last intricacy of a foundation before moving on to a higher abstraction or interface. But that just isn&#8217;t realistic. I like to imagine I have a pretty strong grasp of how JavaScript works, but every so often I get the terminology wrong or encounter something new about the language myself. And while I might know JavaScript, I don&#8217;t really know how the various compilers out there work. I haven&#8217;t touched C or C++ in a really long time. And Assembly is a complete mystery. Understanding every last step from machine code to JavaScript would probably make me a better developer. But depending on the application I&#8217;m developing, it&#8217;s hard to say that it&#8217;s the most efficient use of my time to learn Assembly.</p>
<p>Which is all to say &#8212; it&#8217;s tempting to think of programming as this exercise in mathematics where we start with axioms and build up super fancy theories from there. But in practice, it&#8217;s more like archaeology. You start from the top and work your way down. You&#8217;ll probably never reach bottom. All you can do is just o reconstruct things and create theories of how everything works as you go along.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfong.com/blog/2017/05/13/javascript-react-this-and-programming-fundamentals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Property removals in TypeScript</title>
		<link>http://andrewfong.com/blog/2017/04/28/typing-property-removals-in-typescript/</link>
		<comments>http://andrewfong.com/blog/2017/04/28/typing-property-removals-in-typescript/#respond</comments>
		<pubDate>Fri, 28 Apr 2017 19:06:02 +0000</pubDate>
		<dc:creator><![CDATA[Andrew Fong]]></dc:creator>
				<category><![CDATA[Code and Tech]]></category>
		<category><![CDATA[TypeScript]]></category>

		<guid isPermaLink="false">http://andrewfong.com/blog/?p=498</guid>
		<description><![CDATA[A quick note about how to easily go from a broader type to a narrower one in TypeScript. Suppose you have the following two interfaces: interface ABC { a: number; b: string; c: boolean; } interface AB { a: number; b: string; } We want to convert a var from ABC to AB. Although ABC &#8230; <p class="link-more"><a href="http://andrewfong.com/blog/2017/04/28/typing-property-removals-in-typescript/" class="more-link">Continue reading<span class="screen-reader-text"> "Property removals in TypeScript"</span></a></p>]]></description>
				<content:encoded><![CDATA[<p>A quick note about how to easily go from a broader type to a narrower one in <a href="https://www.typescriptlang.org">TypeScript</a>.</p>
<p>Suppose you have the following two interfaces:</p>
<pre>interface ABC {
  a: number;
  b: string;
  c: boolean;
}

interface AB {
  a: number;
  b: string;
}</pre>
<p>We want to convert a var from <code>ABC</code> to <code>AB</code>. Although <code>ABC</code> meets all the constraints of <code>AB</code>, the additional excess properties sometimes break things and TypeScript will, sometimes, complain about them.</p>
<p>So we could just do this:</p>
<pre>declare var myVar: ABC;
delete myVar.c;</pre>
<p>But that&#8217;s not really desirable because, assuming TypeScript even lets you do that, you&#8217;re mutating an existing typed object. <code>myVar</code> is still typed as <code>ABC</code>, even though it no longer has a <code>c</code> property.</p>
<p>I used to frequently write code that cloned <code>myVar</code>, deleted the extra property, and then typecast the clone to a new interface. But with the introduction of destructuring and <a href="https://github.com/tc39/proposal-object-rest-spread">spread operator</a> support in TypeScript 2.1, it&#8217;s actually quite simple now:</p>
<pre>let { c, ...newVar } = myVar</pre>
<p>Tada! <code>newVar</code> is created without the <code>c</code> property, and TypeScript recognizes it</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfong.com/blog/2017/04/28/typing-property-removals-in-typescript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ram / Sheep / Goat Thing</title>
		<link>http://andrewfong.com/blog/2015/02/19/ram-sheep-goat-thing/</link>
		<comments>http://andrewfong.com/blog/2015/02/19/ram-sheep-goat-thing/#respond</comments>
		<pubDate>Thu, 19 Feb 2015 05:46:56 +0000</pubDate>
		<dc:creator><![CDATA[Andrew Fong]]></dc:creator>
				<category><![CDATA[Scribbles]]></category>
		<category><![CDATA[baa]]></category>
		<category><![CDATA[chinese new year]]></category>
		<category><![CDATA[lunar new year]]></category>
		<category><![CDATA[sheep]]></category>

		<guid isPermaLink="false">http://andrewfong.com/blog/?p=484</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<p><a href="http://andrewfong.com/blog/wp-content/uploads/2015/02/ram_sheep1.png"><img class="alignnone size-full wp-image-489" src="http://andrewfong.com/blog/wp-content/uploads/2015/02/ram_sheep1.png" alt="Happy Lunar New Year! Baa, humbug." width="781" height="554" srcset="http://andrewfong.com/blog/wp-content/uploads/2015/02/ram_sheep1.png 781w, http://andrewfong.com/blog/wp-content/uploads/2015/02/ram_sheep1-300x213.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfong.com/blog/2015/02/19/ram-sheep-goat-thing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LGBT Wedding Cakes</title>
		<link>http://andrewfong.com/blog/2015/02/12/lgbt-wedding-cakes/</link>
		<comments>http://andrewfong.com/blog/2015/02/12/lgbt-wedding-cakes/#comments</comments>
		<pubDate>Thu, 12 Feb 2015 06:48:47 +0000</pubDate>
		<dc:creator><![CDATA[Andrew Fong]]></dc:creator>
				<category><![CDATA[Fact and Law]]></category>
		<category><![CDATA[First Amendment]]></category>
		<category><![CDATA[gay marriage]]></category>
		<category><![CDATA[LGBT rights]]></category>
		<category><![CDATA[wedding cakes]]></category>

		<guid isPermaLink="false">http://andrewfong.com/blog/?p=485</guid>
		<description><![CDATA[This makes me uncomfortable. As much as I would prefer that bakeries not discriminate, I don&#8217;t like using the law to compel them to, both from a political perspective and from a legal one. Politically, I think it&#8217;s a mistake. The argment for allowing gay marriage has long been that gay marriage has almost zero &#8230; <p class="link-more"><a href="http://andrewfong.com/blog/2015/02/12/lgbt-wedding-cakes/" class="more-link">Continue reading<span class="screen-reader-text"> "LGBT Wedding Cakes"</span></a></p>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.opposingviews.com/i/religion/reactions-christian-bakery-owners-facing-discrimination-charges">This makes me uncomfortable. </a>As much as I would prefer that bakeries not discriminate, I don&#8217;t like using the law to compel them to, both from a political perspective and from a legal one.</p>
<p>Politically, I think it&#8217;s a mistake. The argment for allowing gay marriage has long been that gay marriage has almost zero impact on straight persons. If you don&#8217;t support gay marriage, then don&#8217;t marry someone of the same sex. And many, if not all, conservatives understand that &#8212; especially in more libertarian areas. Gay marriage doesn&#8217;t change the rules for straight marriage. It doesn&#8217;t compel the clergy to officiate at gay weddings or live with a gay roommate or even be polite to gay people. But &#8230; now you can be compelled to bake a gay wedding cake. And that complicates the libertarian case for LGBT rights.</p>
<p>It also comes across as spiteful. Unless you think unhappy bakery owners make your wedding cake more delicious. Salty tears and such.<span id="more-485"></span></p>
<p>Legally, there&#8217;s a First Amendment issue, but I think the ultimate outcome will turn on the facts. Now, the argment for why this is permissible generally goes: &#8220;Cake baking is commerce, not speech. It&#8217;s the same justification for why Congress can make it illegal for restuarants and shops and so forth to discriminate based on race.&#8221;</p>
<p>That distinction between commerce and speech is tricky though. While it means a book store can&#8217;t refused to sell books to a person of color (commerce), it does mean that a book store can refuse to publish, endorse, or (maybe) even offer for sale books books featuring protagonists of color (speech, association). Likewise, while the state might be able to require that a bakery serve both straight and LGBT customers, there&#8217;s a limit to how much it can compel the bakery to &#8220;edit&#8221; its cakes to fit the needs of LGBT persons (at least to the extent that cake is considered speech).</p>
<p>That is, if you sell pre-made cakes in a box, then your First Amendment case is pretty weak. But if you customize your cakes based on how you perceive the couple, then you might have a case.</p>
<p>Either way though, this case definitely rubs the spirit of the First Amendment the wrong way. My First Amendment gut check involves replacing the &#8220;good guys&#8221; in any scenario with Neo-Nazis and seeing how I feel about that. And here, that means it would be permissible for the state to compel someone to bake a birthday cake for Hitler. As I said, that makes me uncomfortable.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfong.com/blog/2015/02/12/lgbt-wedding-cakes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Life Choices</title>
		<link>http://andrewfong.com/blog/2015/02/02/life-choices/</link>
		<comments>http://andrewfong.com/blog/2015/02/02/life-choices/#respond</comments>
		<pubDate>Mon, 02 Feb 2015 06:11:34 +0000</pubDate>
		<dc:creator><![CDATA[Andrew Fong]]></dc:creator>
				<category><![CDATA[Scribbles]]></category>
		<category><![CDATA[katy perry]]></category>
		<category><![CDATA[lawyers]]></category>
		<category><![CDATA[left shark]]></category>
		<category><![CDATA[sharks]]></category>

		<guid isPermaLink="false">http://andrewfong.com/blog/?p=479</guid>
		<description><![CDATA[&#160;]]></description>
				<content:encoded><![CDATA[<figure id="attachment_480" style="width: 539px" class="wp-caption alignnone"><a href="http://andrewfong.com/blog/wp-content/uploads/2015/02/sharks1.png"><img class="wp-image-480 size-full" src="http://andrewfong.com/blog/wp-content/uploads/2015/02/sharks1-e1422857484310.png" alt="Sharks in suits" width="539" height="521" srcset="http://andrewfong.com/blog/wp-content/uploads/2015/02/sharks1-e1422857484310.png 539w, http://andrewfong.com/blog/wp-content/uploads/2015/02/sharks1-e1422857484310-300x290.png 300w" sizes="(max-width: 539px) 100vw, 539px" /></a><figcaption class="wp-caption-text">&#8220;So if this law thing doesn&#8217;t work out, I might give professional dancing a shot.&#8221;</figcaption></figure>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfong.com/blog/2015/02/02/life-choices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On Charlie Hebdo and Sacred Cows</title>
		<link>http://andrewfong.com/blog/2015/01/13/on-charlie-hebdo-and-sacred-cows/</link>
		<comments>http://andrewfong.com/blog/2015/01/13/on-charlie-hebdo-and-sacred-cows/#respond</comments>
		<pubDate>Tue, 13 Jan 2015 05:26:17 +0000</pubDate>
		<dc:creator><![CDATA[Andrew Fong]]></dc:creator>
				<category><![CDATA[Fact and Law]]></category>
		<category><![CDATA[charlie hebdo]]></category>
		<category><![CDATA[free speech]]></category>
		<category><![CDATA[politics]]></category>
		<category><![CDATA[religion]]></category>

		<guid isPermaLink="false">http://andrewfong.com/blog/?p=470</guid>
		<description><![CDATA[Cross-posted from Facebook. A few of my more liberal friends seem to be taking the stance that &#8220;yes, it&#8217;s horrible to be killed for what you say, but c&#8217;mon, Charlie Hebdo was really racist / xenophobic / Islamophobic!&#8221; I don&#8217;t speak French and have no particular insight into French media, so I can&#8217;t really say &#8230; <p class="link-more"><a href="http://andrewfong.com/blog/2015/01/13/on-charlie-hebdo-and-sacred-cows/" class="more-link">Continue reading<span class="screen-reader-text"> "On Charlie Hebdo and Sacred Cows"</span></a></p>]]></description>
				<content:encoded><![CDATA[<p><a href="https://www.facebook.com/giantsquirrel/posts/10101852568988691">Cross-posted from Facebook.</a></p>
<p>A few of my more liberal friends seem to be taking the stance that &#8220;yes, it&#8217;s horrible to be killed for what you say, but c&#8217;mon, Charlie Hebdo was really racist / xenophobic / Islamophobic!&#8221; I don&#8217;t speak French and have no particular insight into French media, so I can&#8217;t really say it isn&#8217;t (although I think <a href="http://www.theatlantic.com/international/archive/2015/01/charlie-hebdo-secularism-religion-islam/384413/">this Atlantic article</a> below does a decent job of explaining what Charlie Hebdo actually is).</p>
<p>But I would like to point out that there is a difference between racist xenophobia and a general disdain for sacred cows. An attack on an institution, its beliefs, or its leadership is not the same as an attack on a group of people. It may very well offend many within that group, but offense is not malice. It may very well be wrong, but it is not wrong because it is racist or xenophobic.</p>
<p>By way of analogy, suppose Charlie Hebdo published an image of Thomas Jefferson fucking a slave. Right-thinking patriotic Americans would almost certainly take offense, but it wouldn&#8217;t be fair to simply describe the image as anti-American or America-phobic. It is less an assault on the American people and more a mockery of American exceptionalism. The left, most of all, should understand that distinction.</p>
<p>There&#8217;s an article floating around stating that Charlie Hebdo is not satire because satire is directed at the powerful and Muslims are not powerful in France. That may be the case (see above disclaimer about my lack of Frenchiness), but there&#8217;s a difference between mocking a people and mocking the icons and ideas which hold power over them. An unemployed marginalized refugee from Syria does not hold much power, but the restrictions against the depiction of Muhammad do.</p>
<p>That distinction matters. Much of the left is built on the principles of both respect for people without regard to their origin, and on &#8220;speaking truth to power&#8221;. But if you conflate a people with the things they believe, then following this first tenet excludes an entire class of &#8220;power&#8221; from the second. In its own way, an obscene depiction of a revered religious figure speaks truth to power as much as a protest that ridicules Wall Street, a speech by the Dalai Lama that &#8220;offends the feelings of the Chinese people&#8221; or, more topically, a satirical movie about the assassination of Kim Jong Un.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfong.com/blog/2015/01/13/on-charlie-hebdo-and-sacred-cows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pagination in Meteor</title>
		<link>http://andrewfong.com/blog/2014/12/14/pagination-in-meteor/</link>
		<comments>http://andrewfong.com/blog/2014/12/14/pagination-in-meteor/#respond</comments>
		<pubDate>Sun, 14 Dec 2014 00:33:35 +0000</pubDate>
		<dc:creator><![CDATA[Andrew Fong]]></dc:creator>
				<category><![CDATA[Code and Tech]]></category>
		<category><![CDATA[Github]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Meteor]]></category>
		<category><![CDATA[Meteor.js]]></category>
		<category><![CDATA[pagination]]></category>

		<guid isPermaLink="false">http://andrewfong.com/blog/?p=466</guid>
		<description><![CDATA[Meteor&#8216;s a nifty &#8220;reactive&#8221; Javascript framework, and I&#8217;ve been plunking away on it with the help of the fantastic Discover Meteor book.  One thing I don&#8217;t quite agree with the book, however, is their Pagination Chapter (paywall, sorry) doesn&#8217;t actually implement traditional pagination so much as a variation on infinite pagination. That is, rather than show posts &#8230; <p class="link-more"><a href="http://andrewfong.com/blog/2014/12/14/pagination-in-meteor/" class="more-link">Continue reading<span class="screen-reader-text"> "Pagination in Meteor"</span></a></p>]]></description>
				<content:encoded><![CDATA[<p><a title="Meteor.js" href="https://www.meteor.com/">Meteor</a>&#8216;s a nifty &#8220;reactive&#8221; Javascript framework, and I&#8217;ve been plunking away on it with the help of the fantastic <a title="Discover Meteor" href="http://www.discovermeteor.com//">Discover Meteor book</a>.  One thing I don&#8217;t quite agree with the book, however, is their <a title="Pagination" href="https://book.discovermeteor.com/chapter/pagination">Pagination Chapter</a> (paywall, sorry) doesn&#8217;t actually implement traditional pagination so much as a variation on infinite pagination. That is, rather than show posts 1-10, then 11-20, their example shows 1-10, then 1-20, and so on.</p>
<p>This is potentially less-than-ideal for a couple of reasons. First, it forces the client to keep a growing number of posts in memory. 10-20 posts probably isn&#8217;t a big deal, depending on your app, but if you&#8217;re displaying hundreds of photographs (or animated GIFs), this could get pretty annoying. Granted, you can minimize the impact by only loading elements that are visible on screen, but it&#8217;s a headache that you don&#8217;t have to deal with traditional pagination.</p>
<p>The other potential issue is that, because Meteor is a real-time framework, the server needs to constantly monitor changes to the database and pass along those changes to the client. As the number of documents inside a database query grow, the number of updates being passed back increases as well. I haven&#8217;t been using Meteor long enough to know how much of an impact this makes in practice, but updating off-screen data is, at least, a sub-optimal use of bandwidth.</p>
<p>So, how do we work around this?</p>
<p><span id="more-466"></span></p>
<p>First, let&#8217;s look at the book&#8217;s rationale for the infinite pagination approach:</p>
<blockquote><p>Why are we using an “infinite pagination” approach instead of showing successive pages with 10 posts each, like what Google does for search results? This is actually due to the real-time paradigm embraced by Meteor.</p>
<p>Let&#8217;s imagine we are paginating our <code>Posts</code> collection using the Google results pagination pattern, and that we&#8217;re currently on page 2, which shows posts 10 to 20. What happens if another users deletes any of the previous 10 posts?</p>
<p>Since our app is real-time, our dataset would change. Post 10 would now become post 9, and drop out of our view, while post 11 would now be in range. The end result would be that the user would suddenly see their posts change for no apparent reason!</p>
<p>Even if we tolerated this UX quirk, traditional pagination is also hard to implement for technical reasons.</p>
<p>Let&#8217;s go back to our previous example. We&#8217;re publishing posts 10 to 20 from the <code>Posts</code> collection, but how would you find those posts on the client? You can&#8217;t pick posts 10 to 20, as there are only ten posts altogether in the client-side data set.</p>
<p>One solution would simply be to publish those 10 posts on the server, and then do a <code>Posts.find()</code>client-side to pick up <em>all</em> published posts.</p>
<p>This works if you only have a single subscription. But what if you start to have more than one post subscription, as we&#8217;ll do soon?</p>
<p>Let&#8217;s say one subscription asks for posts 10 to 20, and another one for posts 30 to 40. You now have 20 posts loaded client-side in total, with no way of knowing which ones belong to which subscription.</p>
<p>For all these reasons, traditional pagination just doesn&#8217;t make much sense when working with Meteor.</p></blockquote>
<p>Valid points, assuming that we want pagination that&#8217;s tied directly to the index of items returned by a particular query &#8212; i.e. we want to show items 1-10, then 11-20. However, in most cases, our paginated items are being sorted on some other value (e.g. date) &#8212; indeed, pagination doesn&#8217;t make a whole lot of sense if you can&#8217;t guarantee some sort of consistent sort. And in most cases, our end users don&#8217;t care about a particular literal page so much as being able to digest a limited amount of data at a time.</p>
<p>So instead, we can work around the pagination problem by implementing pages based on the value being sorted on. For example, if you&#8217;re sorting by most recent date, you would start by showing the 10 most recent items, followed by the 10 most recent items <em>older than </em>the oldest item in your first 10 items.</p>
<p>You can see my <a title="Meteor Pagination Demo" href="https://github.com/fongandrew/meteor-pagination-demo">sample implementation of this kind of pagination on Github</a>.</p>
<p>This avoids the issues highlighted by the book. First, because our pages are tied to a sort value, inserting an item not currently on screen doesn&#8217;t shift the items that are on the screen.  That is, if we&#8217;re displaying &#8220;the 10 most recent items older than December 1, 2014,&#8221; inserting something after December 1, 2014 doesn&#8217;t change the result of the query (nor does inserting something older than the oldest item on screen).</p>
<p>Second, items that don&#8217;t belong on a current page can be easily filtered on the client. The presence of a document on a page isn&#8217;t tied to a particular subscription but to its sort value. And since pagination lets us keep only only the current documents in memory on the client, the amount of documents we have to sort client-side (where there are currently no indices) remains small.</p>
<p>That said, there are a handful issues to be aware of with <a href="https://github.com/fongandrew/meteor-pagination-demo">my implementation</a>:</p>
<p><strong>(1)</strong> The sort value (or combination of values) has to be unique. If it isn&#8217;t unique, and the page break happens to fall between two items with the exact same sort value, then going to the next page will either skip an item (if you choose to show all items greater than that sort value) or show an item twice (if you choose to show all items greater than or equal to that sort value). In my implementation, I address this by using the <code>_id</code> of a tie-breaker when the rank (our sort value) is identical. It makes the code quite a bit messier, but isn&#8217;t necessary if you can guarantee uniqueness on the primary sort value.</p>
<p><strong>(2)</strong> My code actually requests one more post than is shown on each page. The rationale is to give some indication as to determine whether there are additional values that make it necessary to show the &#8220;next&#8221; or &#8220;back&#8221; links.</p>
<p><strong>(3)</strong> This still isn&#8217;t traditional &#8220;pagination&#8221; insofar that you can&#8217;t directly jump to &#8220;Page 5&#8221; from &#8220;Page 1&#8221;. That is, without getting Page 4, we wouldn&#8217;t know what value to start Page 5 with (and without Page 3, ditto for Page 4, and so forth). You can step one page forward or back at a time. However, note that you <em>can </em>jump by value &#8212; i.e. if our sort value is &#8220;rank&#8221;, we can jump to the &#8220;page&#8221; with a rank greater than X. In most cases, this behavior may actually be preferable to the end-user (who is thinking in terms of the sort value rather than actual pages).</p>
<p><strong>(4)</strong> A corollary to the above is that going backwards can result in some odd behavior from the user&#8217;s perspective. Suppose we have 20 items, each ranked in order from 1-20, and we show 10 items per page. The user starts on Page 1, which shows items 1-10. The user then clicks &#8220;next&#8221; and goes to Page 2, which shows items 11-20. Now suppose that a new item is added with the value 5.5.  When the user goes back from Page 2, the page will still show 10 items, but from 2-10 instead. Going back further will show a single page with Item 1. There&#8217;s technically nothing wrong with this approach, but it may be weird to have new &#8220;pages&#8221; appear before your current page or to have a &#8220;Page 1&#8221; with less than the maximum number of items on it.</p>
<p>Anyhow, hope that&#8217;s helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfong.com/blog/2014/12/14/pagination-in-meteor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hong Kong</title>
		<link>http://andrewfong.com/blog/2014/11/25/hong-kong/</link>
		<comments>http://andrewfong.com/blog/2014/11/25/hong-kong/#respond</comments>
		<pubDate>Tue, 25 Nov 2014 17:14:11 +0000</pubDate>
		<dc:creator><![CDATA[Andrew Fong]]></dc:creator>
				<category><![CDATA[Fact and Law]]></category>
		<category><![CDATA[China]]></category>
		<category><![CDATA[Hong Kong]]></category>
		<category><![CDATA[Occupy Central]]></category>
		<category><![CDATA[protests]]></category>

		<guid isPermaLink="false">http://andrewfong.com/blog/?p=452</guid>
		<description><![CDATA[It looks like the Occupy protests in Hong Kong are winding down. I had the chance to see what was actually happening on the ground last week and to talk with some people there. A few take-aways from my point of view: The majority of Hong-Kongers probably don&#8217;t support continued occupation of city streets. I think &#8230; <p class="link-more"><a href="http://andrewfong.com/blog/2014/11/25/hong-kong/" class="more-link">Continue reading<span class="screen-reader-text"> "Hong Kong"</span></a></p>]]></description>
				<content:encoded><![CDATA[<p><a href="http://andrewfong.com/blog/wp-content/uploads/2014/11/WP_20141116_16_11_55_Pro.jpg"><img class="alignnone size-large wp-image-455" src="http://andrewfong.com/blog/wp-content/uploads/2014/11/WP_20141116_16_11_55_Pro-1024x576.jpg" alt="WP_20141116_16_11_55_Pro" width="604" height="339" srcset="http://andrewfong.com/blog/wp-content/uploads/2014/11/WP_20141116_16_11_55_Pro-1024x576.jpg 1024w, http://andrewfong.com/blog/wp-content/uploads/2014/11/WP_20141116_16_11_55_Pro-300x168.jpg 300w" sizes="(max-width: 604px) 100vw, 604px" /></a></p>
<p>It looks like <a href="http://www.bbc.com/news/world-asia-china-30188665">the Occupy protests in Hong Kong are winding down</a>. I had the chance to see what was actually happening on the ground last week and to talk with some people there. A few take-aways from my point of view:</p>
<p>The majority of Hong-Kongers probably don&#8217;t support continued occupation of city streets. I think recent polls have it at somewhere around 60-80% wanting the protesters to leave. I would further guess that overall support varies drastically based on age and how often they drive.</p>
<p>The challenge for pro-democracy activists is to figure out how to turn this into a long-run movement. Opposition to Occupy isn&#8217;t based so much on opposition to universal suffrage as a belief that direct confrontation with mainland China is a losing proposition.</p>
<p><span id="more-452"></span></p>
<p>Despite some initial violence, both the police and protesters have shown a surprising amount of restraint, at least relative to the Occupy protests in America (or, more timely, Ferguson). The number of anarchists among the protesters is fairly low. The tent sites are orderly (complete with assigned addresses), there are dedicated quiet spaces for students to do homework, and, despite being engaged in an act of civil disobedience, the protesters are still fairly supportive of the general rule of law &#8212; e.g. at least one of the protest leaders believes it&#8217;s important for him to serve jail time when all is said and done.</p>
<p>The pro-Beijing camp view the protests less as pro-democracy and more as anti-China. There&#8217;s a ring of truth to that, especially if you conflate &#8220;love of country&#8221; with &#8220;support the Communist Party&#8221;. It is, any rate, not hip for a young student to go wave the Chinese flag in Hong Kong. The bigger issue though is that the concept of federalism (or state or local rights) doesn&#8217;t exist in China. In the U.S., it&#8217;s possible for you to wave the American flag all day, yet still take offense to Congress vetoing who gets elected as mayor of San Francisco (DC residents, feel free to make a snide remark). In Hong Kong, opposition to the central government, for many, is equivalent to opposing to the state altogether (which seems ironic to me given how *not* anarchistic the protesters are).</p>
<p><a href="http://andrewfong.com/blog/wp-content/uploads/2014/11/WP_20141107_17_11_50_Pro.jpg"><img class="alignnone size-large wp-image-458" src="http://andrewfong.com/blog/wp-content/uploads/2014/11/WP_20141107_17_11_50_Pro-1024x576.jpg" alt="WP_20141107_17_11_50_Pro" width="604" height="339" srcset="http://andrewfong.com/blog/wp-content/uploads/2014/11/WP_20141107_17_11_50_Pro-1024x576.jpg 1024w, http://andrewfong.com/blog/wp-content/uploads/2014/11/WP_20141107_17_11_50_Pro-300x168.jpg 300w" sizes="(max-width: 604px) 100vw, 604px" /></a></p>
<p>A related disconnect is that of outcome vs. process. My sense is that most of the protesters probably wouldn&#8217;t change all that much of the overall direction of Hong Kong (the trains do run on time). And while Beijing has a vested interest in making sure each of its localities swear fealty to the central government, it otherwise could care less about the minutiae of Hong Kong&#8217;s local politics.</p>
<p>Many Hong Kongers take this as proof that the protesters are just troublemakers &#8212; i.e. why protest the government if you wouldn&#8217;t do anything differently? For the protesters, the issue is really about process &#8212; i.e. there&#8217;s a world of difference between disallowing someone from running for office because an independent judicial process found that person guilty of treason and disallowing someone from running because a committee of unelected bureaucrats decided he or she sang the national anthem wrong. We take the importance of process as a given in the U.S. &#8212; e.g. our leaders swear allegiance not to a piece of geography or a group of people or even an ideal, but to the Constitution, which, at its core, is really a 227-year-old how-to guide. Which isn&#8217;t exactly intuitive to a lot of folks in China.</p>
<p><img class="alignnone wp-image-457 size-large" src="http://andrewfong.com/blog/wp-content/uploads/2014/11/WP_20141107_16_55_02_Pro-21-545x1024.jpg" alt="WP_20141107_16_55_02_Pro (2)" width="545" height="1024" srcset="http://andrewfong.com/blog/wp-content/uploads/2014/11/WP_20141107_16_55_02_Pro-21-545x1024.jpg 545w, http://andrewfong.com/blog/wp-content/uploads/2014/11/WP_20141107_16_55_02_Pro-21-159x300.jpg 159w, http://andrewfong.com/blog/wp-content/uploads/2014/11/WP_20141107_16_55_02_Pro-21.jpg 1478w" sizes="(max-width: 545px) 100vw, 545px" /></p>
<p><em><a href="https://www.facebook.com/giantsquirrel/posts/10101758137919311">Cross-posed on Facebook</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfong.com/blog/2014/11/25/hong-kong/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Is it Constitutional to Suspend Deportations? What About Work Permits?</title>
		<link>http://andrewfong.com/blog/2014/11/21/447/</link>
		<comments>http://andrewfong.com/blog/2014/11/21/447/#respond</comments>
		<pubDate>Fri, 21 Nov 2014 01:43:17 +0000</pubDate>
		<dc:creator><![CDATA[Andrew Fong]]></dc:creator>
				<category><![CDATA[Fact and Law]]></category>
		<category><![CDATA[constitutional law]]></category>
		<category><![CDATA[immigration]]></category>

		<guid isPermaLink="false">http://andrewfong.com/blog/?p=447</guid>
		<description><![CDATA[As much I&#8217;m OK with suspending deportations from a policy perspective, can the president constitutionally suspend deportations? If you replace &#8220;suspend deportations&#8221; with &#8220;we will deport unauthorized immigrants who have not committed a violent crime ONLY AFTER we finish deporting every unauthorized immigrant convicted of a violent crime&#8221; (read: a long, long time from now &#8230; <p class="link-more"><a href="http://andrewfong.com/blog/2014/11/21/447/" class="more-link">Continue reading<span class="screen-reader-text"> "Is it Constitutional to Suspend Deportations? What About Work Permits?"</span></a></p>]]></description>
				<content:encoded><![CDATA[<p>As much I&#8217;m OK with <a href="http://www.cnn.com/2014/11/20/politics/obama-immigration-speech/">suspending deportations</a> from a policy perspective, can the president constitutionally suspend deportations?</p>
<p>If you replace &#8220;suspend deportations&#8221; with &#8220;we will deport unauthorized immigrants who have not committed a violent crime ONLY AFTER we finish deporting every unauthorized immigrant convicted of a violent crime&#8221;<em> (read: a long, long time from now &#8212; if ever)</em>, then that just sounds like prosecutorial discretion. It&#8217;s no different that letting someone arrested for public intoxication out of jail because we don&#8217;t have the resources to try every publicly drunk person out there. That doesn&#8217;t mean we technically can&#8217;t re-arrest that person and try them later (at least until the statute of limitations runs out), it just means we&#8217;re not going to do it any time soon.</p>
<p>One catch: Obama is saying that the deportation suspension will last three years. But he&#8217;s only in office for another two. If his (possibly Republican) successor decides to re-start deportations, I&#8217;m not sure that the Obama&#8217;s three-year promise will carry much weight in court.</p>
<p>What I&#8217;m not so sure about is the granting of work permits. You could argue that this power is incident to the president suspending (or deferring) deportations, but that seems like a stretch. This would be an affirmative act by the executive branch, as opposed the president simply declining to spend a limited pool of resources in a certain way. And given that Congress has already capped the total number of work-related visas to begin with, it&#8217;s an affirmative act that conflicts with Congress&#8217;s stated intent.</p>
<p>One possibility is to simply treat the &#8220;work permits&#8221; as the president saying he will defer prosecuting any employers who hire unauthorized immigrants with such a permit. But again &#8212; seems like a stretch.</p>
<p><em>Cross-posed on <a href="https://www.facebook.com/giantsquirrel/posts/10101751659227661">Facebook</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfong.com/blog/2014/11/21/447/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>California Propositions 2014</title>
		<link>http://andrewfong.com/blog/2014/11/02/california-propositions-2014/</link>
		<comments>http://andrewfong.com/blog/2014/11/02/california-propositions-2014/#respond</comments>
		<pubDate>Sun, 02 Nov 2014 05:32:00 +0000</pubDate>
		<dc:creator><![CDATA[Andrew Fong]]></dc:creator>
				<category><![CDATA[Fact and Law]]></category>
		<category><![CDATA[California]]></category>
		<category><![CDATA[California propositions]]></category>
		<category><![CDATA[elections]]></category>
		<category><![CDATA[politics]]></category>

		<guid isPermaLink="false">http://andrewfong.com/blog/?p=442</guid>
		<description><![CDATA[Cross-posting my thoughts on this election cycle&#8217;s propositions for posterity&#8217;s sake: Prop 1 &#8211; Yes. Spend more money on much-needed water infrastructure. The con argument as far as I can tell is that isn&#8217;t a magic bullet for CA&#8217;s drought problems (which largely stem from farming water-intensive crops in dry areas) and general concerns that &#8230; <p class="link-more"><a href="http://andrewfong.com/blog/2014/11/02/california-propositions-2014/" class="more-link">Continue reading<span class="screen-reader-text"> "California Propositions 2014"</span></a></p>]]></description>
				<content:encoded><![CDATA[<p>Cross-posting <a href="https://www.facebook.com/giantsquirrel/posts/10101723670068161?pnref=story">my thoughts on this election cycle&#8217;s propositions</a> for posterity&#8217;s sake:</p>
<p><strong>Prop 1</strong> &#8211; Yes. Spend more money on much-needed water infrastructure. The con argument as far as I can tell is that isn&#8217;t a magic bullet for CA&#8217;s drought problems (which largely stem from farming water-intensive crops in dry areas) and general concerns that the state isn&#8217;t very good at handling large sums of money (which would be persuasive if there were some more responsible group that we could hand the money to).</p>
<p><strong>Prop 2</strong> &#8211; Yes. Toughen CA&#8217;s rainy day fund. Good governance generally.</p>
<p><strong>Prop 45</strong> &#8211; No. I&#8217;m a bit torn on this actually (as is the Democratic Party apparently &#8212; Senators Boxer and Feinstein endorse but <a href="http://www.sfgate.com/opinion/editorials/article/Pelosi-makes-the-case-against-Prop-45-5851347.php">Nancy Pelosi opposes</a>. Prop 45 requires that the Insurance Commissioner approves any rate hikes by insurance companies. In theory, this allows regulators to keep premiums down, but I&#8217;m not convinced that a lack of regulation is the reason for crazy health insurance premiums. Lack of pricing transparency and excess bureaucracy seem to play a bigger role, and Prop 45 doesn&#8217;t address that. However, Prop 45 would introduce additional delay and administrative uncertainty to putting new health plans on the Covered California healthcare exchange, which would reduce some of the options available to new enrollees. So, leaning no on this, but happy to hear from someone more familiar with how healthcare works.</p>
<p><strong>Prop 46</strong> &#8211; No. This proposition mixes together a bunch of medical malpractice issues that should really be addressed separately. The big one is that it increases the $250K cap on pain and suffering in medical malpractice lawsuits to $1M. This isn&#8217;t a big deal in and of itself &#8212; the $250K cap was put in place in 1975. Adjusted for inflation, that&#8217;s about $1M in today&#8217;s dollars (and really, as a lawyer, I&#8217;m not one to dispute higher jury awards).</p>
<p>What I don&#8217;t like though is that it requires mandatory drug testing of doctors whenever an &#8220;adverse event&#8221; occurs. Ugh. Being a doctor is already a pretty demoralizing job. Mistakes happen because doctors are human, and overworked sleep-deprived humans at that. Peeing in a cup won&#8217;t fix that.</p>
<p><strong>Prop 47</strong> &#8211; Yes. Prop 47 reduces penalties for drug and other minor crimes. Harsh sentencing guidelines haven&#8217;t done much to actually reduce drug use or petty theft. They have, however, cost us obscene amounts of money and wrecked havoc on civil liberties.</p>
<p><strong>Prop 48</strong> &#8211; Yes. <a href="http://www.breitbart.com/Breitbart-California/2014/11/01/Prop-48-Obscure-Indian-Gaming-Compact-Deserves-Your-Vote">The story behind Prop 48</a>, as far as I can tell, is that when the state approved casinos for Native American tribes, a couple tribes got screwed by technicalities and left out. This just puts those tribes on equal footing with the rest of the tribes. Also, casinos don&#8217;t bother me and the tribes are giving us money.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfong.com/blog/2014/11/02/california-propositions-2014/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
