formats

Knockout.js extender for dates in ISO 8601 format

Published on May 14, 2012 by in Code

Asp.net web api is switching to json.net for data serialization, and it seems like everyone has finally decided to support the ISO 8601 date format. Since the json spec itself doesn’t specify a particular dates format, this has historically been quite a mess.

So if you are using knockout.js on the client, then you are likely to run into issues binding ISO 8601 dates to the UI. Unfortunately,  using ISO 8601 dates in knockout.js isn’t as straight-forward as it would seem. If you just shove the ISO 8601 data into your viewmodel, you’ll get the raw ISO 8601 string displayed on screen.

This is rarely what you want.

A better solution is to have knockout.js bind the date field to the UI in a human readable and writable form, but then also expose that date in ISO 8601 format when talking to the server.

This is a perfect job for a custom knockout extender.

This fiddle shows such an extender, along with an example of  it in use.

View the full fiddle here

 

 

In this case, I decided to extend the date field itself with a computed observable called formattedDate which exposes a read/write human readable value for the date. The original date field itself is left alone to track the ISO date value. Writing to either will update the other. I’ve seen other examples that show adding the computed observable to the model itself, but I felt that it was cleaner to extend the actual field rather than have two fields on the model itself representing the same data in different ways.

Note that in producing this fiddle I grabbed a good bit of helper code from around the web (why re-invent the wheel):

  • date-format.js : this is a little script by Steven Levithan that adds a format function to the date object so you can easily convert javascript dates to various human readable formats. There are dozens of similar scripts around the net, but I personally like this one for it’s simplicity, and ability to deal with ISO 8601.
  •  Date.toISOString:  is an ECMAScript 5 method. Since not all browsers support this yet, I’ve included a tiny extension that will add this to the date object on those browsers (code taken from Mozilla).
  • Date.parse:  is an extension by Colin Snover to the standard javascript parse function that just adds support for parsing ISO 8601 formats.

For any of the functionality added by these parsing and formatting extensions, you can choose other scripts or libraries to handle those jobs.

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Tumblr to WordPress, redirecting the old URLs

Published on April 26, 2012 by in Code

I’ve been blogging a long time. I’m not necessarily a popular blogger, but I do have a few posts that come up in google searches, or were linked from sites more popular than mine.

Whenever I move to a new platform I’m left with the problem of redirecting those links to the right place. Typically, this involves me wasting a day just making some sort of mapping file, and hand hacking up 301 permanent redirects.

Now, I could edit all the wordpress posts and manually change their permalink addresses to match the ones tumblr created, but I like the way wordpress generates URLs.

Fortunately, when I imported from tumblr to wordpress (indirectly, via the tumblr2wordpress converter), I ended up with a similar pattern for the post URLs on both sites.

My old Tumblr URL’s look like this:

www.reddnet.net/post/5600577691/that-place

Where the wordpress URL’s look like this:

www.reddnet.net/that-place

The URL pattern differs only in that the old one contains “post/<some number>”; which is annoying. So I went and found a nice redirect plugin that supported regular expressions. The redirection plugin by John Godley was able to handle this with grace and simplicity.

All I had to do was setup one single redirection using regular expressions:

Source URL = .*/post/\d+/(.*)
Destination URL = /$1

That’s it!

My old tumblr URLs are redirecting to the correct place. Additionally, the plugin lets me monitor the redirects, and will log any 404s for old links don’t quite match up to the new locations –which I can then fix by hand.

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Introduction to Node.js

Published on April 23, 2012 by in Code

If you haven’t had a chance yet to get your feet wet with node.js, TekPub has a very worthwhile set of introductory videos that show you around the practical basics. The topics cover node itself, as well as some of the common frameworks and data access solutions that are popular in the node community. The price ($17) is well worth it.

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Reddnet now running wordpress

As you can see, I’ve moved over to wordpress. Tumblr was pretty neat, but they have really been slow to evolve the platform. Also, I tend towards longer posts and posts with code samples where wordpress just does a better job. I’d considered going back to blogengine.net, but I’ve had so many bad experiences and frustrations with the platform in the past that I’m just not interested in going through it again.

I’m hosting with dreamhost, on a trial basis, for now. I’ll post a review of them after I have a few more days to play around with it.

I still have a lot of cleanup to do on the older posts, but I’ll get that finished up over the next few days. Then, maybe, I’ll get back to doing some real blogging.

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

The Dangers of a Windows 8 App Market

I’ve been reluctant to write about Windows 8 since the Developer Preview at the Windows Build event. I was NOT impressed by the preview, but I’m waiting to see an actual beta release before I get too invested in a well thought out opinion on Windows 8 itself.

But one aspect of the strategy around Windows 8 really does bother me -the Windows App Market.

With the phone and X-Box, Microsoft has followed Apple’s app store model far too closely for my tastes, and from what we’ve heard from official sources so far, it seems that the Windows 8 App Market will continue that pattern. The current intent is that all metro style apps will be distributed ONLY though the official Microsoft app market. It will be policed, not just for technical issues, but for content and functionality. Basically, if Microsoft doesn’t like what the app does, how it does it, or the content they will refuse to distribute it.  

Think about that for a moment.

They’ve already established an “objectionable content” (no-porn) policy. So imagine it is 1998, and apps are coming from an app store like what microsoft is proposing. Would Duke Nukem have been approved? What about Grand Theft Auto a few years later? What about a Hustler subscription app? What about an app that displays the naked human body for use by human anatomy students. What about apps dealing with human reproductive biology? And that’s just the censorship arguments.

What about apps that compete with Microsoft’s own?

How long before my ISP, or the MPAA, starts paying Microsoft to reject or pull BitTorrent clients?

Even the pro-security arguments in favor of policed app markets are problematic. What about apps that have new capabilities no one’s seen yet? Imagine an app market back in 1993. Now consider the Trumpet Winsock TCP/IP suite, which allowed windows 3.1 to talk to that brand new internet thing. Would that kind of insecure network stack have been an approved app for distribution in a Microsoft policed app store?  

And how long before governments start passing laws policing those same centralized app stores too? 

I understand the arguments for better quality control, policing against malicious apps, easier app discovery, etc. I don’t have a problem with the default setup preventing most consumers from installing apps from 3rd party sources. But there needs to be a way for people to unlock their devices and use 3rd party markets if they choose (without paying Microsoft, without being a developer, and without having to register with Microsoft to unlock the device).    

Currently Microsoft is playing these concerns off by pointing out that these restrictions only apply to the new metro-style apps. You can still load and distribute traditional desktop apps without going through the store. That’s a bullshit argument though. It limits the free-exchanges for apps to “legacy” technologies, which Microsoft’s incentive will be to eliminate one-by-one over the next several years. If they are successful with a Microsoft exclusive, locked-down market for Metro-Apps, it’s almost inevitable that future versions of windows will do the same to traditional apps too.      

I’m all for there being a nice safe, secure, and policed Microsoft app market. But having that as the ONLY option is probably the scariest proposal Microsoft has ever made.    

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Review: Kindle Fire

I picked up a kindle fire as a christmas gift for my daughter. After setting it up and playing around with it (you know, to make sure it works), I thought I’d drop a mini-review. 

The Verdict: 

If you want to read books, then just get the Kindle touch instead. It has the E Ink display, a good-enough touch interface, way better battery life, is thinner and lighter, and is only 1/2 the price —but most importantly, it wont piss you off with all the things it should be able to do but doesn’t.  

If you want a multi-function entertainment device, then buy a real tablet. It’ll cost a lot more than a Kindle Fire, but you’ll be much happier.

The biggest problem with the Fire is that it actually does “feel” like a tablet… but since it isn’t, you’ll find yourself frustrated by the things it can’t do, rather than enjoying the few things it does do well. 

A Bit of Detail: 

  • Storage: the limit of 8GB is a problem on a device doing music and movies. It doesn’t have any way to attach external storage either. You’d think that “the cloud” would solve this problem, but it only does so if you don’t stray outside of WiFi coverage areas often.

  • Performance: it doesn’t perform bad at all compared to other Kindles, but it isn’t quite smooth like a real tablet, or even most smartphones. It is sluggish all around. Opening a text file can take 3 to 5 seconds, browsing the web feels more like 3G than WiFi, and it often takes longer than expected to bring up menus and such. I suspect that having only 512MB of memory is a huge part of the problem, and the rest I blame on the OS being a custom fork of an older version of Android. With luck, future OS updates might smooth out some of these issues a little.
  • Apps: The amazon store isn’t too bad, but keep in mind that this thing doesn’t have GPS, compass, camera, microphone, or external storage. A lot of apps and games rely on one or more of those things, so they aren’t viable on the Fire at all. Also, there is no traditional “homescreen”, so you don’t get widgets, gadgets, or smart-tile like features.
  • Bugs & Oversights: This is likely to improve over the next few months, but the initial software does have a LOT of annoyances and bugs. The UI occasionally locks up for a long period of time (minutes even). It frequently doesn’t respond to taps or gestures, or takes a long time to respond. Documents and pictures don’t sync with the Amazon Cloud Drive (which is inexplicably stupid). The Carousel on the home screen is super-annoying; it just shows EVERYTHING you’ve interacted with recently… which will be really embarrassing when you go to show off your new toy, and the top item on the carousel happens to be pumpkinfuckers.com.

Overall, the Kindle is very good at being an Amazon Digital Content delivery device, but it falls WAY short of being a full tablet. Unless you just have a burning need for portable video in addition to books, I’d recommend you get the Kindle Touch and invest what you saved into a new smartphone; or put it towards a real tablet next year. 

 

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

CSS 3 Grid – just like layout tables, but more annoying

While I do respect the idea behind separating content markup (HTML) from visual styling rules (CSS), it sucks in actual practice.

Consider the CSS 3 Grid.

This would be much easier if we just had gone with an HTML <layout> or <grid> tag back in 1995, then developed media/device specific sub-dialects of HTML instead of going down the CSS route. Back then, supporting a grid or layout element would have been as simple as copying/pasting table rendering code; and there were a lot of proposals to add exactly that kind of element back then.

Instead though, committees were formed and CSS was inflicted. The CSS proponents, and those that came to the web afterwards and don’t know any different, all have a lot of praise for CSS and the neat things it lets us do.

But to me, real result of going with CSS instead of sanity is that, 15 years later, we’re still only in the proposal stage for an officially sanctioned grid-style layout mechanism.   

 
Tags: , , , ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Dart: Because Google is Tired of Getting Sued

Google has announced Dart; a structured programming language for the web.  If you don’t understand why Google is making Dart, or wonder “do we really need a new language” then you need to understand two things.

  1. JavaScript sucks. Sorry, it just does. It has come a long way over the years, but the best that can be said is that it sucks less than it used to. No matter how far it evolves, it will always carry the baggage it picked up during its chaotic youth.  

  2. Google has always relied heavily on tools to convert real programming languages (Java mostly) into JavaScript. But they, like Microsoft in the late 90’s, have gotten sued by Java’s overlords. So they, like Microsoft, have decided to write their own platform. Not only can they solve the problem better, they also are less likely to get sued for it. 

Dart has a decent shot at gaining real popularity from what I see. There certainly is a lot of demand for something like this, and Google’s name should help sell it.    

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Amazing Little Things

One thing I love about programming is that, even after 15 years, I still come across little things that amaze me.

This JavaScript (derived from an answer on stack overflow) toggles the value used by an HTML checkbox.

isChecked ^= 1;

This trivial logic combined with JavaScript’s peculiar type conversion mechanics results in one of the most elegant expressions of intent I’ve ever seen in a single line of code.

 
Tags: ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Regular Expression for Validating a Social Security Number (SSN) issued after June 25ᵗʰ, 2011

As of June 25ᵗʰ, 2011 the Social Security Administration has changed how SSNs are assigned, and now the regular expressions I’ve traditionally used to validate them are no longer useful. The super-simplistic “is it 9 digits” kind of validation will still work fine, but I’ve always preferred expressions that enforce more of the old SSN structure rules (which were somewhat complex).   

Unfortunately, I couldn’t easily locate a good expression online for the new format. The ones I kept finding were either too-simplistic, or just plain flawed (which is often the case with RegEx patterns you find online). 

The official article on SSN Randomization from the Social Security Administration describes a structure that will be much simpler than the old one. It seems that the only remaining restrictions are that the areas 666, 000, and 900-999 remain off-limits.

If you dig deeper into the official FAQ there is also the rule that no part (area, group, or serial) will contain all zeros. I couldn’t find any other rules though, so a lot of previously restricted numbers will now be available for assignment.  

I also wanted my expression to allow, optionally, for the use of a single dash or space separator character between each group (allowing for mix-n-match separators, which you do see in some systems). 

With that set of rules, I come up with the following regular expression for validation.

^(?!000)(?!666)(?!9)d{3}[- ]?(?!00)d{2}[- ]?(?!0000)d{4}$

I ran it against 200k real SSNs, and it validated them all correctly. This pattern should also remain viable for a while, at least until the SSA decides to start giving out the 900-999 area.

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

node.js: Revolution or Just a Repeat of 15 Years of Failure?

Published on August 29, 2011 by in Code

Server-side JavaScript (SSJS), we are being told, again, will deliver the web’s new and brighter future; a future that, apparently, looks just like the parts of Microsoft’s 1996 that no one cared about.

In 1996 Microsoft had comprehensive support for JavaScript on the server. You had Active Server Pages for the web, and Windows Scripting Host for systems automation. Both technologies had  built-in support for JavaScript as a first-class language. 

No one gave a shit.

In 2001 Microsoft released JScript.NET, a version of JavaScript on steroids. It was highly optimized for server-side development, and was promoted as a first class language along-side C# and VB.NET; it was especially promoted for ASP.NET web applications. 

No one gave a shit then either. 

Microsoft still ships classic ASP and the WSH, and both still support JavaScript. They also have continued to release new versions of JScript.NET, though these days they just call it JScript 10.0.

It isn’t as if Microsoft was the only one to do viable SSJS implementations over the years either, and universally they have all failed to generate prolonged interest. JavaScript has come a long way over the years, but there hasn’t been a significant change in the language to makes it suddenly more appropriate for server-side scenarios. The best that can be said is that JavaScript doesn’t suck as bad as it used to.

But now, after 15 years of apathy towards server-side javascript, suddenly people can’t seem to stop talking about it! Projects like node.js, Helma, and Jaxer (just to name three) are getting a lot of press. I’ve even heard 2011 called “the year of server-side JavaScript” by some. Node.js seems to be getting the lion’s share of the attention, and there is even a .NET clone of it called node.net (WTF!?!?! Really?) 

The irony is almost maddening! 

Also, don’t buy this nonsense about re-using the same skills on both the client and the server. That was exactly the same marketing used for JavaScript on old ASP back in 1996.

JavaScript was my first language, and I was one of those few who wrote classic ASP in it. My excuse was that I’d be reusing my existing investment in JavaScript. Take it from me… the skill-reuse argument is pure bullshit.

The actual “skill” in JavaScript is in learning the (horrible) HTML object model and client libraries. None of that translates to the server, so all you keep is the C style language syntax. So, why not just use actual C, or one of the dozens of popular, and more server-appropriate, languages with a C derived syntax?  

Despite all the history though, it’s clear that node.js in particular has gained some impressive traction. There are a ton of rapidly evolving modules for it along with a growing and enthusiastic developer community.  

So, maybe Server-Side JavaScript’s time has finally arrived this time. I personally hope it’s just a fad though. I’d much rather see all this effort get put into bringing real programming languages to the browser (like Google’s Native Client does). 

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Prometheus

Prometheus, thief of light, giver of light, bound by the gods, must have been a book.

– Mark Z. Danielewski (House of Leaves)

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Data Liberation, the Killer Feature of Google+

Published on July 9, 2011 by in General

Google+ could kick facebook in the teeth, but one of the key reasons it has a chance is the presence of a feature set that very few people are likely to ever use —Data Liberation.  

Google has an entire team of engineers, called the Data Liberation Front, whose job is to protect users by making sure that Google’s products all provide export functionality. Their web site provides information on which of Google products have been liberated so far, as well as information on how to use those export features. 

In the Google+ settings menu, under the heading ‘Data Liberation’, you will find a unified export tool. This appears to be a variation on a new tool from the Data Liberation Team called Google Takeout (this link is for the non-Google+ specific version). The tool allows you to export all of your data from a variety of Google’s services all at once. Currently, only the major social products related to Google+ are included, but they plan to add other services to the takeout utility over time.    

Even though few people will export their Google+ data, the fact that an export feature exists at all has significant appeal. Google isn’t free of privacy, security and customer abuse concerns, but high-visibility features like this go a long way towards reassuring people.

In Google+, data liberation features pair well with an excellent set of privacy and security features. While the UI and functionality of Google+ are critically important, it’s the less visible details like data liberation that will decide if users are comfortable enough to even consider a switch from other social services.   

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

The Impact of Windows 8

The Impact of Windows 8

This is a really good early developer analysis of Windows 8. The most interesting point made though is one I’d not considered before; the fact that windows is no longer restricted by the terms of the anti-trust settlement.

Still though, Windows 8 had better be more than just be incrementally better if they plan to hold on to their user base, especially considering the insanely long development cycle.

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Droid X – The Moto-Bungled Gingerbread Update

I’ve had the official Droid X Gingerbread 2.3 update for a couple of weeks now… and I can say with full confidence that it sucks complete ass!

The new software should be faster, slicker, have more features, and be more stable. For every other Android device by any other manufacturer this is true, but not for the Motorola Droid X.

The UI lags, sometimes locking up for as long as an entire minute. Pretty much all animations are jiggy to the point of being more disorienting than fun. The stock keyboard lags even worse than it did in the last software versions (which seriously, is a problem that will drive you insane after a few days); and 3rd party keyboard apps suffer the same fate on the X too. And to top it off, about twice a day it will randomly hard-crash and reboot itself for no apparent reason, sometimes when I’m doing something, sometimes not.

I’d just replaced my Droid X (the old one had a faulty speaker) before the update too, so I don’t have a lot of my apps installed yet, and certainly nothing major like alternate launchers or anything.

Motorola makes good hardware, but their software is so bad it ruins the whole experience; and their competence clearly does NOT improve over time. I miss my HTC Incredible.

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments