Coding Range

Thoughts on iOS 7

June 12th, 2013

New Macbooks Air. Sneak peek of the next generation of Mac Pro. iOS 7. OS X ran-out-of-cat-names Mavericks. All typical announcements for a WWDC keynote, but these seem to indicate another transition for Apple.

If there’s one thing Apple loves, it’s big changes. Transitions. Carbon to Cocoa. PowerPC to Intel. OS X to iOS (sort of, at least OS X-only to OS X+iOS). Whilst I was too young and out of the loop to know almost anything about Carbon to Cocoa at the time, the last few have not been a cutover. Apple have never gone “Sorry folks, that’s it. New stuff from here on, leave your old crap at the door.”

Consider PowerPC to Intel. OS X stayed the same. iLife stayed the same. Applications needed to be recompiled and tweaked, but they stayed the same. The only big change was the processor architecture all the way down at the very deepest level of software.

OS X to iOS was the exact opposite. Apple kept Mach, Darwin, Core Foundation, Foundation and the other system libraries, but entirely revamped the user interface for a mobile touchscreen device. Gone was the mouse and physical keyboard, you now had a device with extremely limited screen real-estate that could only be operated through fingers. Same core OS, completely different interface.

iOS 7 seems like another such change, but is much less drastic because the interaction style remains the same. iOS 7 keeps the same core as OS X and iOS 6 - Mach, Darwin, GCD, OpenCL, OpenGL, Foundation, etc. - but it’s a new userland. The principles are the same, but things have now moved, gestures changed, glyphs and icons redesigned. The familiar has once again become the unfamiliar, something Apple have no qualms about doing. Many of the design patterns from iOS 6 have stayed, but many more have been replaced.

iOS 7 is what happens when you look at the userland in iOS 6. At features that have been crammed in on top of their predecessors because there wasn’t much room. At visual styles that try too hard to replicate the familiar that they become repulsive. At concepts like skeuomorphism where the word itself just looks repulsive. When you take a look at that, and you go “nope, let’s try that again,” you land up with such a drastic redesign.

People are kneejerk-complaining, but if you consider that what we’ve seen so far is around 7 months of work, it’s extremely impressive. The time limitation does show - the homescreen icons feel like a rush job and there’s no iPad seed yet - but given some more time (such as the few months remaining before Gold Master and public release) it looks to be wonderful.

Apple Double Standard? 

May 19th, 2013

When I signed up for the iOS Developer Program, Apple required a credit card to verify my identity. I didn’t have one at the time, so I had to email Apple a copy of my Drivers Licence signed by a JP.

So apparently a credit card is enough to verify your identity for the iOS and Mac Developer Programs, but not to purchase an iPhone. WTF Apple?

From four to eight

May 16th, 2013

Back when I wrote Hello World 2.0, I was enthused about blogging with Squarespace. True to their marketing, they took the need to battle with layout and custom HTML out of making my Wordpress post manageable with a great WYSIWYG web interface, and kept everything nice and simple. Experiencing a product is the best way to try it, and I had been playing around with a trial for a couple of weeks at the time. However, their editor gets buggier the more you try and do with it to the point where I was spending more time fighting the WYSIWYG editor instead of writing. Again.

Unfortunately, my writing habits have changed over time. I’ve gone from just sitting down at a computer and writing to pre-preparing snippets or entire posts and then publishing them at once. And for that I’ve been using Markdown. For most of my recent posts, I’ve been using a combination of MarkdownPad and iA Writer to write markdown, and then just throwing it into a Markdown block in Squarespace and hitting publish.

So if I’m effectively only using Squarespace as a server-side Markdown translator, what do I really need it for at that price?

Effective immediately, this blog is now powered by Octopress. Octopress sits on top of Jekyll to let me write Markdown on my home machine, then from that generate HTML and upload a static site to my server, as opposed to the more traditional method of placing all the load on the server with a quasi-static (dynamically generated but for all intents and purposes static) web page. This allows the site to load faster, run with less overhead, and gives me much more options for hosting, too.

As a developer, I’m also paying attention to performance metrics. Self-hosting lets me tweak with the web server in ways that a hosted solution such as Squarespace doesn’t expose. Content is appropriately GZipped with expiry times set for caching, scripts minified, etc.

I’ve had to manually port over the old content, and I think I got most of it, and all the important content. I’ve had to use a redirect for the RSS feed (now Atom), so I’m hoping most RSS clients will see the change and continue trucking.

Hopefully now, with a framework more conducive to my writing workflow I can again write more. I noticed I seem to have posted less and less frequently in the passing months, so here’s to getting back up to scratch.

Masking headers in Varnish

April 15th, 2013

It’s always a good idea not to let your HTTP headers tell the world your exact setup. Unfortunately, Nginx won’t let you turn off the Server header, it requires you to edit the source code and recompile.

If you have Varnish in front (or any other reverse proxy), however, you have a point in the pipeline where you can alter the response before it gets transmitted.

All the guides I found were old versions of Varnish, so here are some rules for 3.0:

sub vcl_fetch {
    unset beresp.http.Server;
    if (beresp.ttl <= 0s ||
        beresp.http.Set-Cookie ||
        beresp.http.Vary == "*") {
                /*
                 * Mark as "Hit-For-Pass" for the next 2 minutes
                 */
                set beresp.ttl = 120 s;
                return (hit_for_pass);
    }
    return (deliver);
}

sub vcl_deliver {
    remove resp.http.Via;
    remove resp.http.X-Varnish;

    return (deliver);
}

sub vcl_error {
    set obj.http.Content-Type = "text/html; charset=utf-8";
    set obj.http.Retry-After = "5";
    remove obj.http.Server;

    synthetic {"
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>"} + obj.status + " " + obj.response + {"</title>
  </head>
  <body>
    <h1>Error "} + obj.status + " " + obj.response + {"</h1>
    <p>"} + obj.response + {"</p>
    <h3>Guru Meditation:</h3>
    <p>XID: "} + req.xid + {"</p>
  </body>
</html>
"};
    return (deliver);
}

Everything in vcl_fetch below unset is the default rule. I’ve also told Varnish to remove it’s own headers in vcl_deliver and vcl_error (as well as <p>Varnish cache server</p>) to stop it speaking too loudly too.

So I installed Office:Mac 2011...

April 4th, 2013

… and it was an “interesting” out-of-the-box (download?) experience:

Almost as horrible a setup experience as Eclipse and the Android SDK.

Nagios alerts via App.Net

March 28th, 2013

After hearing someone at work mention Nagios, I figured I’d give it a try, considering the only way I could currently tell if my personal services were up was by checking them manually.

Why did nobody tell me about this sooner?

Anyway, I followed a basic tutorial on installing Nagios along with Nconf (because manually screwing around with text-based config files sucks).

For alerting though, I wanted to plug it into the App.Net Messaging system, simply because I prefer keeping email for personal communications, and I don’t have a free way to send alert SMS messages to my phone.

It’s surprisingly simple.

The first step of the puzzle was finding a command-line App.Net client. Fortunately, @doctorlinguist was crazy enough to make one - Texapp.

Next, I had to set up Texapp to be authenticated. To do this I simply ran Texapp under a normal user, then copied the .texappkey key file to /var/lib/nagios/ (the home directory of the Nagios user).

In the same folder, I put two scripts: notify-host-by-adn-pager, and notify-service-by-adn-pager. I use Netbot on my mobile devices for App.Net, and it doesn’t support push notifications for Messages, so I did a two-stage solution. The alert account replies to me with a basic alert (e.g. there was a problem with some service), then sends the full (private) details as a message. The two scripts are as follows:

notify-host-by-adn-pager.sh:

#!/bin/bash

TEXKEYF=/var/lib/nagios/.texappkey
TEXAPP=/var/lib/nagios/texapp
STATUS="@$1 Nagios: $2 notification for host (state: $5)"
PRIVMSG="Nagios: $2 - $4 ($3) is $5"

${TEXAPP} -keyf=${TEXKEYF} -runcommand="/pm $1 ${PRIVMSG}"
${TEXAPP} -keyf=${TEXKEYF} -status="${STATUS}"

notify-host-by-adn-pager.sh:

#!/bin/bash

TEXKEYF=/var/lib/nagios/.texappkey
TEXAPP=/var/lib/nagios/texapp
STATUS="@$1 Nagios: $2 notification for $5 (state: $6)"
PRIVMSG="Nagios: $2 - $5 on $4 ($3) is $6"

${TEXAPP} -keyf=${TEXKEYF} -runcommand="/pm $1 ${PRIVMSG}" >> /tmp/adn.log
${TEXAPP} -keyf=${TEXKEYF} -status="${STATUS}" >> /tmp/adn.log

To tie this in with Nagios, I set up two misccommands in NConf, as follows:

notify-service-by-adn-pager

/var/lib/nagios/notify-service-by-adn-pager.sh $CONTACTPAGER$ $NOTIFICATIONTYPE$ $HOSTADDRESS$ $HOSTALIAS$ "$SERVICEDESC$" $SERVICESTATE$

notify-host-by-adn-pager

/var/lib/nagios/notify-host-by-adn-pager.sh $CONTACTPAGER$ $NOTIFICATIONTYPE$ $HOSTADDRESS$ $HOSTALIAS$ $HOSTSTATE$

Once that’s done, create a new contact or modify an existing one. Add notify-host-by-adn-pager to ‘host notification commands’ and notify-service-by-adn-pager to ‘service notification commands’. Enter the App.Net username in the contact’s pager field, and there you go!

Computer Science in Vietnam 

March 21st, 2013

I asked what a teacher’s salary was. $100 per month. So I went to an ATM and bought them a second teacher for the next year.

In which @NewtonMark makes a very good point

March 11th, 2013

How are they even driving, @MattWadeSMH?

March 10th, 2013

State government figures show that at the end of the 2000s, just 3 per cent of teenagers in the greater Sydney region were fully licensed to drive, down from nearly a quarter in the early 1990s

Under the current NSW licencing scheme, you cannot be “fully licensed” until you turn 20. The earliest you can get your Learner’s licence is 16.

You have to have your Learner’s for a minimum of a year, your P1 (Provisional 1) for another year, and P2 (Provisional 2) for two more years. So by the time you have your full licence, you have to be over 20 years old.

So how is this 3% fully licenced while still being teenagers?