Categories
Nerd Fun

Upcoming Important Holidays (Now that Nerds Rule)

Mark your calendars so that you can send an eCard to your favorite hacker, startup co-founder, or sys admin!

  • March 14 – Pi Day – Celebration of everyone’s fav irrational number!
  • March 25 – Tolkien Reading Day – Commemoration of the fall of Sauron (where did I put that ring?)
  • April 25 – DNA day – The day the paper on the structure of DNA was published in the journal Nature and later the day when the Human Genome Project was declared “mostly done.”
  • April 27 – Morse Code Day – The day Samuel Morse was born …. .- .– .– -.– / -… .. .-. – …. -.. .- -.– / … .- —
  • May 1 – No Pants Day – Thanks Knighthood of Buh!
  • May 4 – Star Wars Day – May the fourth be with you!
  • May 25 – Towel Day – According to the Hitchhiker’s Guide to the Galaxy you should alway have your towel with you (it’s in my backpack)
  • May 26 – National Paper Airplane Day – The only way to fly!
Categories
Nerd Fun Programming Self Improvement

H@PPY N3W Y3@2 2015!

My Resolutions for 2015

  • Contribute to an open source project
  • Write a mobile app every month
  • Master VIM, GIT, and Make
  • Read all of Focus’ suggested computer science papers at least once 🙂
  • Write ALL the tests first! Roar!
  • Buy and read books printed on paper!

I’ll post weekly updates!

Categories
Nerd Fun

Surface Pro 3: Quick Status Update

I’ve been using the Surface Pro 3 all week and I continue to find ways to integrate it into my daily routine and overcome minor obstacles.

Apple Magic Mouse and Wireless Keyboard.

I have some unused Apple bluetooth peripherals lying around the house and I wanted to see how they paired with the Surface Pro 3. The Apple Wireless Keyboard works flawlessly. I love the firm feel and responsiveness of Apple’s keyboard. Most wireless keyboards, including Microsoft’s, feel chintzy to me. I’m happily typing away with the Apple Wireless Keyboard and the Surface Pro 3 as I write this blog post. Just remember: The Apple command key maps to the Microsoft windows key.

The Apple Magic Mouse was more problematical. It paired immediately with the Surface Pro 3 and works find as far as left and right clicking go. But the touch-based scrolling feature of the Magic Mouse is disabled. There is a utility that claims to enable the full functionality of the Magic Mouse. You can find it here: Trackpad Magic. It didn’t work for me. I installed both the drivers and the utilities. But they must be out of date or just incompatible with the Surface Pro 3. It doesn’t matter! I’m really used to interacting with the screen to pan and scroll and scrolling with a mouse is starting to feel unnatural. I only need a mouse for precision clicking when the pen or my finger would be too awkward or imprecise.

 

Categories
Nerd Fun

This Page Intentionally Left Blank

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(Yeah, I’ve been meaning to post an intentionally left blank page for some time now. Whenever I see one my mind spins in a little mental loop: The page is blank. But the page is not blank because it has writing on it. But the page is blank because it was the author’s intention to leave it blank and she wrote a note about that intention. But the page is not blank because the authors intention was to write the words “This Page Intentionally Left Blank” on it. So the author is lying. No, actually, the author is in self-denial. No, the author was didn’t want to be ambiguous. But what is more ambiguous than a blank page with a message on it that claims it is a page without a message. Is there a message within the message? Is it all a joke? Is it a metaphor for something? A pointer to void? The page is blank…)

Categories
Nerd Fun Product Design

Surface Pro 3: Patience is Rewarded

I recently acquired a Surface Pro 3 during a Black Friday sale from a local Microsoft Store. I knew I was in for a challenge but I was up for it. I’m from the generation that witnessed the rise of personal computing in the late 20th century from clunky calculator-like boxes with tiny displays and obscure software commands to modern sleek slates of glass and metal that are all display and responsive to touch and voice. It’s been a fun ride and part of the thrill was trying to figure out how to get anything useful out of the ever evolving personal computer. Quite frankly I’ve been a bit bored with modern iOS and Android devices. Well designed and rapidly becoming indistinguishable, my iPad, iPhone, and Android phone pretty much work as expected and do no more and no less then their makers intend.

I’m also a little worried about the future of the general purpose personal computer. The biggest game changer in my life has not been the ability to play games, write blog posts, or edit movies on an affordable computer. It’s the ability to write computer programs that create games, blogging systems, and multimedia editors that has given me a community, confidence, and a livelihood.

PC sales have been and continue to be in decline. To fight this decline Apple and Microsoft are making their PCs more like tablets with keyboard: sealed boxes with safety belts and airbags that keep users from getting into trouble–like installing botnets or mining bitcoin.

In another five or ten years the general personal computer that can compile and link C code into a tool or application might be a thing of the past. Computer engineering might require expensive development systems and a University education. That’s were we started in the 1960s. The web, the apps, and the games that we use everyday have only been possible because kids, with little money or training, have been able to purchase a general purpose personal computer and start hacking around. For me, and millions like me, exploring the capabilities of a personal computer is like going on a hike. It’s fun and there is no other purpose then to do it. Software like Facebook, Flappy Bird, and FileMaker are just side effects.

So I bought a Surface Pro 3, which is a real PC that looks like a tablet, and put my MacBook Air aside. I’ve spent the last few weeks figuring it out. I’m not quite there but I’m having a blast as I try to relearn basic computer skills, discover its limits, and find workarounds for it’s bugs and so-called features!

Below are some of my field notes:

  • The Surface Pro 3 is a real computer and a tablet combined. It’s light enough to use as an ereader but powerful enough to code with. It’s also powerful enough to play serious games, edit images, and do anything a modern laptop can do. It’s not a desktop replacement but it’s close enough for me.
  • The Surface Pro 3 is still a work in progress. There are many good ideas but either they aren’t implemented well or they should be reworked. Let’s look at a few examples:
    • The Type Cover, which is a full keyboard and cover combined, is an awesome idea but feels flimsy on my lap, makes too much noise while typing, has to be physically connected, and is awkward when you don’t need it but want to keep it handy. The little track pad on the Type Cover is terrible, not needed, and makes the text cursor bounce all over the screen. Luckily you can turn it off! You won’t miss it!
    • The Windows 8.1 user interface works pretty well with a finger or a pen, but there are a few major problems when editing text with Google Chrome as the web browser. With the Type Cover connected a finger tap brings up the touch keyboard and obscures the lower third of the screen. The touch keyboard goes away on its own when you type on the Type Cover but it breaks your concentration.
    • Your finger is all you need if you are not drawing except when it comes to small icons and so-called left mouse clicks. I’ve got enough motor control that only the smallest of icons and buttons are inaccessible to my index finger but I can’t execute some left mouse clicks without a pen (or mouse) on the Surface Pro 3 with Google Chrome. Windows 8.1 maps a long-press to the left click but it doesn’t work for spell checking. As a terrible speller I need that popup menu of spelling corrections!
  • Windows 8.1 is a work in progress as well! It poorly combines the the user experience of Windows 7 with a touch interface. The results are confusing and inconsistent:
    • There are two system control panels and it’s not always clear where a setting will show up.
    • If you are not connected to a wireless network the Windows 7 part of the interface tells you that “no networking hard is detected”. But all you have to do is touch the little signal bars icon on the task bar and a list of wireless networks appear.
    • The Windows 8.1 start screen wants to replace the Windows 7 start menu. But the start screen feels like a disordered Mondrian painting. My advice to Microsoft: go back to the usability lab. Nobody uses Apple’s app launcher either. We use the task bar and the Finder.
  • The best feature of the Surface Pro 3 for the practicing coder is that you can install and run real development software like Node.js, Ruby, Git, Sublime, Vim, Emacs, C, and other UNIX-based tools. Many of these tools have Windows equivalents and others run well via Cygwin and Msys. Cloud 9, the web-based IDE for web apps also works fine with the Surface Pro 3 via Google Chrome. The HipChat client really needs a UI update but does it’s job so you can chat with your fellow engineers.
  • I’ve download the open source version of Microsoft’s Visual Studio and runs very well on the Surface Pro 3. I’m not a Windows developer (any more–the last time I developed with Windows was Windows 95!) but I’m impressed with Microsoft’s adoption of JavaScript as a primary programming language. I formally forgive Microsoft for JScript.
  • In my spare time I like to draw and paint with my computer and I’ve found that the Surface Pro 3 runs Abode Photoshop and Clip Studio Paint (Manga Studio) very well. It has a few minor problems distinguishing a resting palm from a touch but the pressure sensitive pen is as good as a Wacom tablet.
  • If you need to use the Microsoft Office, the Surface Pro 3 and Windows 8.1 is excellent at it. I know this isn’t cool but my favorite word processor is Microsoft Word. The Office apps simply don’t run well on a Mac and are missing important features. The one aspect of my MacBook Air that I don’t miss is struggling with Microsoft Word 2011!

So there you have it. If you enjoy a challenge and being different and have the patience to put up with some annoying bugs then the Surface Pro 3 might be for you. It’s more realistically usable than a ChromeBook but far from the antiseptic polish of a Macbook.

Categories
Nerd Fun

I Wrote a Customer Review on Amazon

I purchased an Asus monitor for my Mac Mini as a cheap alternative to the 27″ Apple Thunderbolt Display. I had a couple of tips and shared them on Amazon.

A couple of things to note:

  • Amazon make writing the review insanely easy. When I logged into Amazon it prompted me to rate and review all of my recent purchases.
  • The review was published within an hour. Perhaps sooner.
  • Amazon is protecting my privacy. I’m not sure why but perhaps that is there default setting. Much appreciated!
  • I immediately got a comment on my review with a better, cheaper alternative to the tip I presented.
  • Nobody, as of this writing, has found my review helpful.

I’m proud of my little review and I’ll check in on it from time to time to see how it’s faring in the wooly world of Amazon customer reviews!

Categories
Nerd Fun

This belongs on Tumblr

Categories
Cocos2d-iPhone Programming

Cocos2D-Swift 3.0: A great way to get started developing iOS games!

If you’re new to iOS game development now is a great time to get started. In 2008 a brilliant engineer named Ricardo Quesada rewrote his 2D game engine for Apple’s iOS and released it as open source. It’s no exaggeration to say that hundreds of games, like my own, were developed using Cocos2D—including dozens of hits. Now it’s 2014 and the newbie game developer has several versions of Quesada’s Cocos2D framework to choose from. But for me the branch of Cocos2D devoted to the iPhone and iPad will always have a special place in my heart. Clearly Cocos2D-iPhone (now called Cocos2D-Swift) was the inspiration for Apple’s SpriteKit framework. And once you learn the fundamentals of Cocos2D on iOS you can easily transfer these skills to Android, Windows, and HTML5 versions of the Cocos2d family. Working with Cocos2d-Swift is like “reading Shakespeare in the original Klingon.”

Learning iPhone Game Development with Cocos2d 3.0 by Kirill Muzykov is a book I wish I had when I was learning to develop my first iPhone game. Muzykov patiently covers all the basics (nodes, sprites, actions, text, sound, buttons, menus) and jumps into advanced topics (particles, physics, tile maps, iTunesConnect, Game Center, and in-app purchases) while guiding the reader though creating a game called CocosHunt and using important tools (Particle Designer, Texture Packer, Tiled) and websites (freesound.org, media.io).

Along the way the reader also learns about Objective-C, Xcode, and iOS APIs. You’re still a beginner by the time you finish Muzykov’s book but you’re a well informed beginner and ready to tackle larger and more complex projects—like the next Candy Crush.

One of the best things I like about Muzykov’s book is it’s structure. A typical chapter starts with setting up a project and cycles through segments entitled “time for action” and “what just happened?”. This alternating rhythm becomes a reliable way to digest the material and ensure the author doesn’t wave his hands over new concepts. Almost every chapter includes a pop-quiz. I’m not a big fan of quizzes but if that’s what you need to re-enforce the material Muzykov provides them.

The source code is clean and clearly written with good comments. Muzykov keeps the syntax simple, using “typedef enum” instead of “typedef NS_ENUM” and “#define” instead of “FOUNDATION_EXPORT NSString *const” which is probably for portability. Much of a game is managing state and game developer who follow Muzykov examples in his classes won’t get into trouble.

If you’re new to mobile game development and you want to focus on iOS then Learning iPhone Game Development with Cocos2d 3.0 is a good book for you.

Categories
Programming

Apple’s Snakes and Ladders Swift Example

All the cool kids are learning Swift this week! Not wanting to be left out I downloaded Xcode beta 6 and the iBook introduction and started following long with the code sample in Xcode’s new playground.

Swift is impressive as it fixes a number of issues with Objective-C by replacing it wholesale with a modern language that feels like a well thought-out JavaScript. I love the idea of optional values, implicit types, simple generics, and how let and var are used to create immutable and mutable objects. I’m still digesting the class vs struct vs enum idea. I’m not sure why they are just not all classes but give me time, I’m sure I’ll see the light.

The Snakes and Ladders example is a fine bit of sample code and shows off Swift’s power as a teaching language. But I had a couple of issues with it and tweaked it. See below and check out the comments for why I did what I did. You should be able to copy and paste this code into a playground and watch it run!

// Playground - noun: a place where people can play

import Cocoa

// Snakes and Ladders Game

let finalSquare = 25 // 25 squares in the game (0 to 24)

// init all squares to 0 and included a 26th square (to simplify the code)
// Note: you can use var or let to define the array board (Apple uses var, I'm using let)
// - let makes board a constant but values of a const array are still mutable
// - its the number of elements in the array that are immutable
// - using let allows the compiler to optimize looking up values in the array
let board = Int[] (count: finalSquare + 1, repeatedValue: 0)

// in 4 squares as ladders (+ values) and 4 squares as snakes (- values)
// ladders move the player forward by value in square
// snakes move the player backward by value in square
board[03] = +08; board[06] = +11; board[09] = +09; board[10] = +02
board[14] = -10; board[19] = -11; board[22] = -02; board[24] = -08

var square = 0   // player position
var diceRoll = 0 // moves are determined by an 8-sided die

println("Game Starting at square \(square)")
// start the game
while square 

Update!

I could not get the sweet while loop with the label "gameLoop" to work in the playground. It's no surprise that Swift has a couple of bugs. So with a bit of fiddling I got it to work with a gameOver flag. And while I was at it I created a swifty function to hide the ugly arc4Rand_uniform() call and refactored the print statements so you can follow along with the game in the console.

func randNum(limit: Int) -> Int {
  return Int(arc4random_uniform(UInt32(limit)))
}

// start the game
println("Game Starting at square \(square)")

var gameOver = false

gameLoop: while square != finalSquare {
  diceRoll = randNum(7)
  switch square + diceRoll {
  case finalSquare:
    // diceRolled moved player to finalSquare
    // game over
    print("starting \(square), ")
    print("diceRoll \(diceRoll), ")
    print("destination \(square + diceRoll), Game Over")
    println()
    
    // Swift didn't recognise the loop's label so I commented it out
    // This teams the break only breaks out of the switch
    // The gameOver flag is used to break out of the while loop
    gameOver = true
    break //gameloop
  case let newSquare where newSquare > finalSquare:
    // diceRoll moved player beyound finalSquare
    // roll again
    print("starting \(square), ")
    print("diceRoll \(diceRoll), ")
    print("destination \(square + diceRoll), Re-roll")
    println()
    
    // Swift didn't recognise the loop's label but in this case
    // it doesn't matter...
    continue //gameloop
  default:
    // valid move
    // update board
    print("starting \(square), ")
    print("diceRoll \(diceRoll), ")
    square += diceRoll
    print("destination \(square), ")
    print("instruction \(board[square]), ")
    square += board[square]
    print("result \(square)")
    println()
  }
  // if flag is set break out of the while loop
  if gameOver {
    break
  }
}
Categories
Programming Sprite Kit

Sprite Kit, Retina, iOS7 and Getting It Right

I spent more time that I care to admit figuring out how to reconcile my old Dungeonators code with Apple’s Sprite Kit, Retina displays, and iOS 7. Along the way I searched the web for help and ran into tons of tutorials and advice for indy game developers (I highly recommend  www.raywenderlich.com for a great set of systematic and well written tutorials). But I learned to be wary of advice on some sites that is confused or actually wrong. For example I came across this macro in one of Ray’s tutorials that originated from a Stack Overflow conversation:

#define IS_WIDESCREEN ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

This macro was written by a floating point math C macro professional. It’s used to determine if the resolution of an iPhone screen is 4 inches. iOS 7 only runs on iPhone’s with Retina displays but there are still  millions of iPhone 4 and 4s models in use with 3.5 inch screens. The iPhone 5, 5c, and 5s has a widescreen of 4 inches.

But why do I need a fancy macro for that? It’s code that I’m only going to run once. And it’s not a particularly CPU intensive calculation. And really, I want to understand what every line of code in my game does. Copy and paste code is always a bad idea.

It’s not hard to figure out what this macro does: It gets the height of the screen, subtracts the resolution of the 4 inch iPhone from it and makes sure the result is less than a number that is as close to zero as the phone’s floating point system can represent. However, there is no reason that we have to go to this level of complexity!

My feeling about macros is that you almost never need to use them. And if you do, call in a pro C programmer. Macros can optimize your code but if you don’t use the right number of parens you could end up with subtle side effects and bugs that are hard to track down.

As an added bonus this macro is only useful if you have determined that the iOS device your game is running on is an iPhone. Taken out of context this speedy line of code could give your game the wrong idea.

To do it right, as in doing it with code that is safe, maintainable, and as efficient as it needs to be, you have to understand how Apple internally represents the resolution of an iOS device. (I’m assuming you want your game to be universal across the Apple universe.)

So let’s say you want to write a universal iOS game in Objective-C using Sprite Kit. Here are the consequences of your decision:

  • Your game can only run on iOS devices running iOS7. This fact eliminates the original non-Retina iPhones but not non-Retina iPads
  • Your game must support both 3.5 and 4 inch iPhones.
  • Your game must support iPad and iPad Retina devices.
  • Don’t worry about model names! The name of the device (iPad, iPad Air, iPhone 5, iPhone 4s, iPadophone 7xyz) doesn’t tell you anything reliable about the number of pixels you have to play with.

Here’s the non-obvious part: You’re going to create your game with pixels in mind but Apple is going to give coordinates in points. I wish Apple had not done it this way. I guess they were trying to be helpful. At lest let developers turn of the points paradigm if like me, they find it unhelpful. But we can’t turn it off so we have to live with it!

Apple says there are 2 pixels in a point. This table should help:

Device Type    Pixels        Points      Models
iPhone 3.5"    960 x 640     480 x 320   iPhone 4, 4s
iPhone 4"      1136 x 640    568 x 320   iPhone 5, 5c, 5s
iPad           1024 x 768    1024 x 768  iPad, iPad Mini
iPad Retina    2048 x 1536   1024 x 768  iPad with Retina

Apple gives us a macro of it’s own to figure out if we’re running on an iPhone or iPad, UI_USER_INTERFACE_IDIOM() and a way to discover the screen’s dimensions in points,
[UIScreen mainScreen].bounds.size.height

Thus, here is a simple method that you can add to your game projects to figure out what sort of iOS device you’re running on based on it’s screen real estate.

- (NSString *)figureOutScreen {
    // Call once during initialization!
    NSString *result;
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        
        // iPhone
        
        if ([UIScreen mainScreen].bounds.size.height==568.0f) {
            
            // iPhone Retina 4-inch
            result = @"iPhone Retina 4-inch";
        } else {
            
            // iPhone filename 3.5-inch            
            result = @"iPhone Retina 3.5-inch";
        }
    } else {
        
        // iPad (Can't tell if it is mini, standard, or Retina 'cause all the dimensions in points are the same
        result = @"iPad";
    }
    return result;
}