<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description></description><title>I Like Programming</title><generator>Tumblr (3.0; @nickretallack)</generator><link>http://blog.nickretallack.com/</link><item><title>4Fourths</title><description>&lt;p&gt;What a beautiful game!  I got to play with this at &lt;a href="http://www.kokoromi.org/gamma4/"&gt;Gamma 4&lt;/a&gt; as part of their One Button showcase.  It’s a co-operative game where four players control two ships using one button each: players 1 and 3 can charge and shoot their lasers, while players 2 and 4 control the upward thrust of each ship.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://4fourths.com/"&gt;4Fourths&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unlike a lot of co-operative games, this one does nothing to stop players from killing each other.  In fact, it’s pretty fun to spar between challenges, and most players who pick the game up got right into shooting and dodging each other.  Before long, the first enemy is lowered between the players like a giant wall, forcing them to break it up and learn how to work together without a word of dialog.  But as the game goes on, bosses place less walls between the players until they must be very careful not to blow each other up.&lt;/p&gt;

&lt;p&gt;Despite the fun of shooting each other, there are no competitive scoring elements.  Also, it’s rather difficult to defeat a boss without both players’ combined firepower, and failing to do so in time means everyone loses.  That makes this one of the most purely co-operative games I’ve played.&lt;/p&gt;

&lt;p&gt;Also, I love the bright colors and boxy graphics.  It’s so Nu-Lo-Fi.  And it’s made in &lt;a href="http://unity3d.com/"&gt;unity&lt;/a&gt;.&lt;/p&gt;</description><link>http://blog.nickretallack.com/post/443112921</link><guid>http://blog.nickretallack.com/post/443112921</guid><pubDate>Fri, 12 Mar 2010 05:37:11 -0500</pubDate></item><item><title>N-Key Rollover, or Why Modern Keyboards Suck</title><description>&lt;p&gt;Have you ever tried to play a two-player game on one keyboard?  Chances are it wasn’t a fun experience.  You press down a few keys, and the rest don’t register at all!  What gives?&lt;/p&gt;

&lt;p&gt;What we want is called &lt;a href="http://en.wikipedia.org/wiki/Rollover_(key)"&gt;n-key rollover&lt;/a&gt; aka NKRO, a feature that older keyboards like the IBM Model M used to have.  But these days, manufacturers have been cutting costs.  According to &lt;a href="http://www.renoise.com/indepth/equipment/crippled-chords-without-full-n-key-rollover"&gt;this blog&lt;/a&gt;, keyboard manufacturers save seven cents per key by using &lt;a href="http://www.dribin.org/dave/keyboard/one_html/"&gt;matrix circuits&lt;/a&gt;.  That’s $7.28 for 104 keys, which makes me wonder how vendors can justify charging over $50 for “gaming keyboards” that don’t have it.&lt;/p&gt;

&lt;p&gt;It’s hard to find any keyboards these days with NKRO.  Fortunately, the &lt;a href="http://www.elitekeyboards.com/products.php?sub=filco_keyboards"&gt;Filco keyboards&lt;/a&gt; on EliteKeyboards.com advertise the feature prominently.  I’ll have to get one of these.&lt;/p&gt;</description><link>http://blog.nickretallack.com/post/192229436</link><guid>http://blog.nickretallack.com/post/192229436</guid><pubDate>Sat, 19 Sep 2009 23:16:00 -0400</pubDate></item><item><title>JavaScript Scoping Oddity</title><description>&lt;p&gt;Guess the output.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var outer = "test1"

function test1(){
  var inner = outer
  return inner
}

function test2(){
  var inner = outer
  var outer = "test2"
  return inner
}

test1()
test2()
&lt;/code&gt;&lt;/pre&gt;</description><link>http://blog.nickretallack.com/post/185172109</link><guid>http://blog.nickretallack.com/post/185172109</guid><pubDate>Fri, 11 Sep 2009 04:07:00 -0400</pubDate></item><item><title>Shrinky-Fit TextArea</title><description>&lt;p&gt;While working on my &lt;a href="http://nickretallack.com/outliner/"&gt;latest hobby project&lt;/a&gt;, I wanted the text entry boxes to always be just large enough for the text you’re typing into them, similar to the text boxes in desktop apps like OmniFocus.&lt;/p&gt;

&lt;p&gt;The first solution I found, &lt;a href="http://plugins.jquery.com/project/autogrow"&gt;jquery.autogrow&lt;/a&gt;, was not satisfactory.  It simply did not respond to input quick enough to avoid having text slip out of the top of my input for a moment if I hit enter too fast, and it assumed you’d leave some space to write and not truly shrink to fit.&lt;/p&gt;

&lt;p&gt;Wishing to replace it, I chatted with a friend and we came up with a scheme quite similar to &lt;a href="http://peter.michaux.ca/articles/automatically-expanding-textarea-elements-with-yahoo-ui"&gt;another solution by Peter Michaux&lt;/a&gt; which I didn’t discover until after I threw together mine.&lt;/p&gt;

&lt;p&gt;The gists of all of them are similar: take the text of your current textarea, place it in a similarly-styled div, let the browser flow it the way you want it, then apply its height back to the textarea.&lt;/p&gt;

&lt;p&gt;My solution made a few little changes.  Here’s &lt;a href="http://gist.github.com/178299"&gt;the gist of it&lt;/a&gt;.  I attached this as a keydown handler on the affected textareas.  Each keydown, it copies the text into a similarly styled div, then sets the height like usual.  Also, I used a zero-millisecond setTimeout so it would fire just after the textarea’s text was changed.  I suppose I could have used bubbling up events instead.  Not to be wasteful, my version only uses one doppelganger div for each different style of textarea I needed.  Both are positioned absolutely at left:-9999999px.&lt;/p&gt;</description><link>http://blog.nickretallack.com/post/176106759</link><guid>http://blog.nickretallack.com/post/176106759</guid><pubDate>Mon, 31 Aug 2009 02:46:46 -0400</pubDate></item><item><title>Who says Python doesn't have function static variables?</title><description>&lt;p&gt;If you want to store internal state in a python function, most people would say you need to create a class and use class or instance attributes.  Of course you don’t.  Python 3 introduces “nonlocal” as a keyword for creating static variables, but you can already make them without this help.&lt;/p&gt;

&lt;p&gt;In fact, you might even create them accidentally, due to this &lt;a href="http://stackoverflow.com/questions/146329/what-is-the-worst-gotcha-youve-experienced#147877"&gt;weird behavior with default arguments&lt;/a&gt;.  Python only evaluates default arguments once, so if your default argument is mutable complex type, you have yourself some internal state.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&gt;&gt;&gt; def counter(count=[0]):
...   count[0] += 1
...   return count[0]
... 
&gt;&gt;&gt; counter()
1
&gt;&gt;&gt; counter()
2
&gt;&gt;&gt; counter()
3
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Well, that’s kind of a hack.  A better way to do this is to use function attributes.  Yes, functions can have attributes, just like classes.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def counter():
  counter.count += 1
  return counter.count
counter.count = 0
&lt;/code&gt;&lt;/pre&gt;</description><link>http://blog.nickretallack.com/post/117150710</link><guid>http://blog.nickretallack.com/post/117150710</guid><pubDate>Tue, 02 Jun 2009 23:38:00 -0400</pubDate></item><item><title>Building a Good New User Experience for Elemental Chess</title><description>&lt;p&gt;People don’t like to log in to things until they’re convinced it’s worth it.  That’s a given.  My first thought was to just make a sandbox mode for my game, where you can play it purely on the client side, with a friend or against the computer.  If you wanted to play against other players online, you’d need to log in with an openid provider.&lt;/p&gt;
&lt;p&gt;I showed off my new sandbox mode at Google IO.  It didn’t have AI or checkmate detection yet, since I couldn’t decide whether to implement that on the client side or the server side.  &lt;a href="http://code.google.com/webtoolkit/"&gt;Google Web Toolkit&lt;/a&gt; seems like a nice solution for client/server code sharing that I will definitely pursue.  But then I thought, I can solve this code sharing problem &lt;i&gt;and&lt;/i&gt; provide a better user experience, if I get a little more ambitious with my user account handling.  I’ll let users do anything they want except hang onto their history if they’re not logged in.&lt;/p&gt;
&lt;p&gt;When a user hits the site without a user in their session cookie, I’ll create a brand new user for them with a randomized name (and plenty of invitation to change it).  This is a full-featured user, with one caveat: it can expire, at about the time their cookie-based session should.  To keep it from expiring, all the user has to do is associate it with an OpenID.  This is exactly the same thing as logging in.&lt;/p&gt;
&lt;p&gt;Okay, but what if a lazy user who already has a saved account comes along and plays a few games without logging in?  Easy.  When they eventually do log in, we can delete their temporary account and replace every instance of it with the real one!  Talk about awesome.&lt;/p&gt;
&lt;p&gt;Since I’m totally overloading my Login button to function as “Login”, “Register”, “Save”, and “Merge Accounts”, I think it’s appropriate to call it something else.  “Recognize Me” sounds pretty good!&lt;/p&gt;</description><link>http://blog.nickretallack.com/post/116140624</link><guid>http://blog.nickretallack.com/post/116140624</guid><pubDate>Mon, 01 Jun 2009 03:15:59 -0400</pubDate></item><item><title>Rebuilding</title><description>&lt;p&gt;I’ve lost tons of work in the past in almost every way imaginable, from melted or crushed hard disks to raid failures and unreliable hosts.  I thought redundancy would save me, but these failures always seem to happen in pairs.  I could fill a &lt;a href="http://wiki.nickretallack.com/graveyard"&gt;graveyard&lt;/a&gt; with all the work I’ve lost.&lt;/p&gt;
&lt;p&gt;But I’m not gonig to let this get me down.  I can still remember how I made most of those old things, and some of them were pretty good simple ideas, so it might be fun to re-make them better stronger faster than before!&lt;/p&gt;
&lt;p&gt;In the future, I’ll use reliable backup sites like github, amazon s3, and I’ll look into Mozy.  &lt;a href="http://www.youtube.com/watch?v=w_F_6xOlke0&amp;videos=3izu1LXoPZE"&gt;Their commercial&lt;/a&gt; is spot on, after all.  Fortunately, not all of my data is gone.  A good hunk of it survived on my 120GB WD Passport, which includes things as far back as 2005. I better back this up before I lose it!&lt;/p&gt;</description><link>http://blog.nickretallack.com/post/109442571</link><guid>http://blog.nickretallack.com/post/109442571</guid><pubDate>Mon, 18 May 2009 07:15:11 -0400</pubDate></item><item><title>Reduce by Any Other Name</title><description>&lt;p&gt;One of my favorite functions is `reduce`.  It’s the perfect way to represent anything like sum, product, factorial, reverse, that walks along a list accumulating the values it finds.  Unfortunately, it’s hard to share my love of reduce when every language calls it something different.  Observe:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;# Python - reduce&lt;br/&gt;# reduce(function, iterable[, initializer])&lt;br/&gt;def factorial(n):&lt;br/&gt; return reduce(lambda acc,x: acc*x, range(1,n), 1)&lt;br/&gt;&lt;br/&gt;# Ruby - inject&lt;br/&gt;# Enumerable#inject(init) {|result, item| ...}&lt;br/&gt;def factorial(n)&lt;br/&gt; (1..n).inject(1) {|acc,x| acc*x}&lt;br/&gt;end&lt;br/&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;-- Haskell - fold&lt;br/&gt;-- foldl :: (a -&gt; b -&gt; a) -&gt; a -&gt; [b] -&gt; a&lt;br/&gt;factorial n = foldl (*) 1 [1..n]&lt;br/&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;// C# - Aggregate&lt;br/&gt;// Enumerable.Aggregate&lt;(Of &lt;(TSource, TAccumulate&gt;)&gt;)&lt;br/&gt;//   Method (IEnumerable&lt;(Of &lt;(TSource&gt;)&gt;), &lt;br/&gt;//     TAccumulate, Func&lt;(Of &lt;(TAccumulate, TSource, TAccumulate&gt;)&gt;))&lt;br/&gt;// (This type signature is pretty ridiculous)&lt;br/&gt;int factorial(int n){&lt;br/&gt; return Enumerable.Range(1, n).Aggegate(1, (acc,x) =&gt; acc*x);&lt;br/&gt;}&lt;/code&gt;&lt;/p&gt;</description><link>http://blog.nickretallack.com/post/103936635</link><guid>http://blog.nickretallack.com/post/103936635</guid><pubDate>Tue, 05 May 2009 19:51:00 -0400</pubDate></item><item><title>Board Game Abstraction</title><description>&lt;p&gt;How would you model a board game in a sql database?  I’ve been overthinking this.  I’d probably have a Game model to keep track of whose turn it is, with a lot of Pieces associated with it.  But that’s obvious.&lt;/p&gt;
&lt;p&gt;To be totally generic, a Piece could consist of string:kind, string:space, and string:color.  But what if you were playing a game like chess with a 2D board?  You could name the space something like 2-2.  What if the piece has meta information like rank and class?  You could encode it in the kind, like fire-2.  Why bother using data types other than string if you’re just going to fetch all pieces and assemble the board whenever you compute a move?&lt;/p&gt;
&lt;p&gt;Or is there a reason to query on meta information and board positions?  Would you optimize your game logic by not constructing the whole board each time?  Should you create a new model for the kind of piece that exists in each game, like a monopoly piece which moves around the board linearly versus a checkers piece which traverses in two dimensions and can be kinged?  Do you want many small tables or few large ones?&lt;/p&gt;</description><link>http://blog.nickretallack.com/post/103297823</link><guid>http://blog.nickretallack.com/post/103297823</guid><pubDate>Mon, 04 May 2009 08:11:23 -0400</pubDate></item><item><title>Ruby Doesn't Have Inner Functions</title><description>&lt;p&gt;Ruby syntax allows you to write something that looks a lot like an inner function in other languages.  However, it really isn’t.  Lets explore this odd behavior.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Foo
  def bar
    x = "scoped variable"
    def baz
      puts x
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This looks like a pretty standard test of closures.  One might expect the &lt;code&gt;bar&lt;/code&gt; method to define a function &lt;code&gt;baz&lt;/code&gt; with access to bar’s scope, namely the variable &lt;code&gt;x&lt;/code&gt;.  Lets see what really happens.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;puts Foo.instance_methods.include?("bar") # true
puts Foo.instance_methods.include?("baz") # false
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Still consistent with our expectations, we see we have created an instance method &lt;code&gt;bar&lt;/code&gt;, but not baz.  Lets test out &lt;code&gt;bar&lt;/code&gt; on an instance.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;instance = Foo.new
instance.bar
puts Foo.instance_methods.include?("baz") # true
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Oho, where did this &lt;code&gt;baz&lt;/code&gt; method come from that wasn’t there before?  Running &lt;code&gt;bar&lt;/code&gt; created it!  In fact, calling `bar’ in our instance even changed the global class definition to include it!  Lets try it out!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;instance.baz # NameError: undefined local variable or method ‘x’ for #&lt;Foo:0x1cee4&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So much for closures.  It seems baz doesn’t have access to bar’s scope.  It’s just a plain old instance method that we’ve defined.&lt;/p&gt;

&lt;p&gt;Well, it doesn’t behave much like other languages, but this behavior could still be useful.  You could use it to evaluate method definitions conditionally, or just wait and create some of your methods after others have run.  It’s not all that useful, but it’s still good to know so you don’t accidentally use this syntax wrong.&lt;/p&gt;</description><link>http://blog.nickretallack.com/post/71039207</link><guid>http://blog.nickretallack.com/post/71039207</guid><pubDate>Fri, 16 Jan 2009 21:16:00 -0500</pubDate></item></channel></rss>
