18 Jul

Fabien Potencier – The PHP Ternary Operator: Fast or not?

On my laptop, snippet 1 takes more than two seconds, whereas snippet 2 takes about 0.05ms. That’s a big difference! But if the variable to test does not host many data, the speed is almost the same.

So, why does the ternary operator become so slow under some circumstances? Why does it depend on the value stored in the tested variable?

The answer is really simple: the ternary operator always copies the value whereas the if statement does not. Why? Because PHP uses a technique known as copy-on-write: When assigning a value to a variable, PHP does not actually create a copy of the content of the variable until it is modified.

via Fabien Potencier – The PHP Ternary Operator: Fast or not?. Huge speed hits using the ternary operator on larger variables. Fortunately it looks like there is already a patch to resolve the problem.

18 Jul

The Watchmaker Project – How to fix the broken iPad form label click issue

Mobile Safari, the browser found on iPhones, iPod Touches and the iPad, does not (currently) implement the same label behaviour as other browsers. Clicking on labels doesn’t do anything—possibly, as Ben Darlow suggests, it is because it would interfere with the tap-to-select-text functionality, although personally I think that usability trumps obscure text-selection use cases.

What’s even weirder is that, in over an hour of googling, I couldn’t find a single reference to this issue. Surely someone, somewhere must have noticed that clicking or tapping on labels in forms on iPad doesn’t select the input? I resolved that when I published a fix for the issue, it would include a couple of clunky sentences stuffed with as many keywords related to the tap click form label input select checkbox radio button problem as possible…

via The Watchmaker Project – How to fix the broken iPad form label click issue. Nice and simple fix, defiantly not quite as common a problem on the iPhone (rarely do I find myself wanting to hit the label vs. the input field).

18 Jul

Shawn Blanc – Reading on the iPad

And so — perhaps intentionally, or perhaps unintentionally — digital magazines that replicate their printed versions are, in some ways, feeding on the mindset that printed content has a higher value and novelty than digital content does.

They replicate their printed magazines in digital format because they are trying to convey some of that perceived quality and value that historically comes with the printed page. The reader may not be holding a piece of paper, but at least they’re looking at what would be the printed page through the window of their screen.

Unfortunately, replicating print onto a digital format doesn’t best serve the problems of great user experience, sharing through social media, and taking advantage of the rich media possibilities our iPads provide. It does, however, appease the publisher’s need to convey value with their content.

via Shawn Blanc – Reading on the iPad. Not having an iPad I can’t speak from experience but it certainly vibes with how it feels when I’ve tried digital version of magazines such as Wired.

17 Jul

Wired – How Khan Academy Is Changing the Rules of Education

For years, teachers like Thordarson have complained about the frustrations of teaching to the “middle” of the class. They stand at the whiteboard, trying to get 25 or more students to learn the same stuff at the same pace. And, of course, it never really works: Advanced kids get bored and tune out, lagging ones get lost and tune out, and pretty soon half the class isn’t paying attention. Since the rise of personal computers in the early ’80s, educators have hoped that technology could solve this problem by offering lessons tailored to each kid. Schools have blown millions, maybe billions, of dollars on sophisticated classroom technology, but the effort has been in vain.

Khan’s videos are anything but sophisticated. He recorded many of them in a closet at home, his voice sounding muffled on his $25 Logitech headset. But some of his fans believe that Khan has stumbled onto the secret to solving education’s middle-of-the-class mediocrity. Most notable among them is Bill Gates, whose foundation has invested $1.5 million in Khan’s site. “I’d been looking for something like this—it’s so important,” Gates says. Khan’s approach, he argues, shows that education can truly be customized, with each student getting individualized help when needed.

Not everyone agrees. Critics argue that Khan’s videos and software encourage uncreative, repetitive drilling—and leave kids staring at screens instead of interacting with real live teachers. Even Khan will acknowledge that he’s not an educational professional; he’s just a nerd who improvised a cool way to teach people things. And for better or worse, this means that he doesn’t have a consistent, comprehensive plan for overhauling school curricula.

Whatever Khan’s limits, his site has become extremely popular. More than 2 million users watch his videos every month, and all told they answer about 15 questions per second. Khan is clearly helping students master difficult and vital subjects. And he’s not alone: From TED talks to iTunes U to Bill Hammack the Engineer Guy, new online educational tools are bringing the ethos of Silicon Valley to education. The role these sites can (or should) play in our nation’s schools is unclear. But classes like Thordarson’s are starting to find out.

via Wired – How Khan Academy Is Changing the Rules of Education. Some really impressive work going on here.

17 Jul

Identity at Mozilla – How BrowserID differs from OpenID

We launched Mozilla Labs’ online identity experiment, BrowserID, only 24 hours ago, and the feedback has been incredibly useful already. At Mozilla, we believe in empowering individuals to shape their online experience. Our work on a decentralized identity solution for the Web matches that mission well. Also, because we believe that transparent community-based processes promote participation, accountability, and trust, we will be posting technical explanations, points of debate, and roadmaps on this blog.

One important question we immediately received from early adopters is how BrowserID compares to OpenID. Both projects have three important common goals:

(a) make it easier and safer for users to log in to web sites by reducing the number of passwords they have to remember,

(b) make it easier for web sites to add authentication features, and

(c) accomplish all of this in existing modern browsers.

Beyond these similarities, we think Mozilla Labs’ BrowserID project provides a few key advantages over OpenID. Lloyd Hilaiel has written an excellent technical primer on BrowserID, which highlights our key design goals. These have led us to three key differences.

via Identity at Mozilla – How BrowserID differs from OpenID. Some really impressive work from the team at Mozilla, defiantly simpler to get started and using than OpenID and eliminates the which OpenID provider did I use for this site.

17 Jul

guardian.co.uk – Networks are not always revolutionary

My corollary to O’Reilly’s "piracy/obscurity" quote is "fame won’t make you a success on its own, but no artist ever got rich on obscurity". That is, being widely loved isn’t sufficient for attaining fortune, but it is necessary to it.

By the same token, a global network that allows loosely coordinated groups of people to discover each other and act in concert while exposing their cause to the whole planet (especially its richest, most privileged residents) is not enough to overthrow a dictator — but I’m sure I wouldn’t want to try to stage a revolution without such a network.

via guardian.co.uk – Networks are not always revolutionary. Fair point I think, having the network or having fame isn’t enough to guarantee success but it does help.

16 Jul

Hacker News – Self Extracting PNG

I’ve been working on this for a couple weeks, attempting to get it looking perfect and get it to 1kb. It’s going to be going on stage at http://solskogen.no/ shortly, so I figured now is the perfect time to post.

As far as I know, this is the first ever case of a self-extracting PNG — the file is a PNG that first is interpreted as HTML, which then unpacks the compressed code within the PNG to start the second stage. I plan to write a blog post about how I got the size down as far as it is, but feel free to ask any questions you may have, as I’d love to see this technique spread!

Edit: Requires Chrome and Firefox — has been tested heavily on Windows and OS X, but this will eat your CPU and GPU alive.

via Hacker News – Self Extracting PNG. Wow that is some impressive work.

15 Jul

Wired – How Online Companies Get You to Share More and Spend More

You’re not stupid, but you can be fooled. For millennia, the best salespeople have known how to exploit the vulnerabilities of the human mind. In the burgeoning field of behavioral economics, we’ve begun to give precise names to the mental weaknesses that make us all susceptible to a well-crafted pitch. Drawing on the insights of psychology, behavioral economists have explained why we buy more stuff at $0.99 than at $1.00 (the “left-digit effect”), why we commit to gym memberships we’ll never use (“optimism bias”), and why we don’t return things we buy as often as we should (“post-purchase rationalization”). The giants of the web, from Amazon to Zynga, use similar tricks to keep us coming to their sites, playing their games, and buying their goods. In fact, that’s how they became giants in the first place. Here’s how they game us—and how, in some cases, we wind up gaming ourselves.

via Wired – How Online Companies Get You to Share More and Spend More. Always neat seeing psychology at play especially with companies that excel at it.

15 Jul

Mark Story – My thoughts on the built-in php server

Earlier today I saw the announcement that PHP5.4 will have a built-in web server . I mentioned on twitter that I wasn’t too happy about the server being added. In the discussion that followed, I feel like I wasn’t able to properly convey my thoughts through tweets. I figured I might be able to better explain myself in a post.

I have mixed feelings about the built-in web server to be honest. Having a low effort web server is great for lowering the barrier to entry when building things with PHP. I can also appreciate the instantaneous feedback you get from a simple command line server, and not needing to fiddle with Apache or other more complex web servers. All of these things seem really great in isolation, and when you ignore some of the problems that it creates.

I can think of a few problems that the new command line server creates. First, while its intended for quick and dirty development, it will invariably end up being used as a production server somewhere. PHP already has a spotty track record with providing features meant to be helpful, but later become painful. I’m thinking of things like magic quotes and register globals. All of these features were at some level intended to make development easier. Instead they have become huge headaches, and are only now being removed.

via Mark Story – My thoughts on the built-in php server. I think he reached into my brain and said exactly what I was thinking.