David Golding



Cursed Leap Years!

By David Golding | Print This Post Print This Post

I used to think that leap years only happened every four years. In fact, every centennial year that is not evenly divisible by 400 is not a leap year.

I don’t expect to live to 2100, so it shouldn’t matter. But, unfortunately, in programming world, remembering this caveat on the leap year could result in a bug, or worse, world cataclysm like we saw didn’t see with Y2K.

I recently landed this bug and had to write a way out of it. Here’s my solution in PHP, JavaScript, and Cappuccino.

1
2
3
4
5
6
7
8
9
10
11
function isLeapYear($aYear) {
    if (($aYear % 4) == 0) {
        if (($aYear % 100) == 0 && (($aYear % 400) != 0) {
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
}
1
2
3
4
5
6
7
8
9
10
11
function isLeapYear(aYear) {
    if ((aYear % 4) == 0) {
        if ((aYear % 100) == 0 && ((aYear % 400) != 0) {
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
}
1
2
3
4
5
6
7
8
9
10
11
+ (BOOL)isLeapYear:(int)aYear {
    if ((aYear % 4) == 0) {
        if ((aYear % 100) == 0 && ((aYear % 400) != 0) {
            return NO;
        } else {
            return YES;
        }
    } else {
        return NO;
    }
}


Phase In, Phase Out

By David Golding | Print This Post Print This Post

So 2009 has been a whirlwind for all of us. The global economy has gone to pot and many of us are struggling mightily to make ends meet. As for me, I have the benefit of laying low, kinda. I’ve been hard at work pursuing a graduate degree, and since this is a necessary step in my professional aspirations, now is perhaps the best time to be chugging away at schoolwork rather than taking the job market head-on. What this has meant, though, is more or less a hiatus from the full-steam-ahead web development work of 2008. And this blog has been quiet as well.

But students are not immune from ailing economies. Funding has dried up all over the place. My particular university noticed a drop of around a third in their endowment fund. So just as I was phasing out of web work to embark in more academic pursuits, I have found myself falling back and relying heavily on web development to get me through. I have more to blog about, more CakePHP to discuss, and hopefully more screencasts to film.

As a blog-warming gift to those readers who have stuck around, here’s a handy PHP script I wrote for managing 2-way encryption for credit card numbers. Like anything in data security, it’s not completely bulletproof, but I think I’ve managed a moderately to highly secure algorithm here that allows one to hold onto credit card numbers in an encrypted form, and still decipher those numbers for later processing. Of course, there’s no replacement for overall site security, so be sure to install this file outside the server root, and take care of those database calls so that you forestall any intrusion hacks.

A test credit card number from American Express:

1
371449635398431

encrypts as:

1
snRLL^AN+HtsBi3$J)sHpLsRG

Of course, by altering some settings, that same number can come out even longer:

1
a<:8aaaUTE)TR(/%dL7[?kLe0_Gry@ZR{bTaB!~E3arALaRL

Installation is pretty easy. Just include the script, instantiate the

1
DGCrypt

class, and run either

1
encode()

or

1
decode()

. Be sure to edit the class properties with your own values, or your salt values will be compromised.

Encrypting a number

1
2
3
4
5
include_once(PATH_TO_FILE.DIRECTORY_SEPARATOR.'dgcrypt.php');
$cc = new DGCrypt();

$encryptedNumber = $cc->encode($_POST['credit_card']);
//save $encryptedNumber

Decrypting a saved string

1
echo $cc->decode($encryptedString);

Download

So here it is. One file, nice and easy. Enjoy, and best of luck to everyone in your pursuits.

Download DGCrypt


Future of Web Dev and the Perfect Skill Set

By David Golding | Print This Post Print This Post

As Microsoft tries to patch up its mutt of a web browser, some questions remain about the Internet Explorer behemoth and what may come of other technologies raising the ante on what’s possible with the web. I’m fairly convinced that with time, IE will be dethroned, thanks to open source projects like Firefox and WebKit. With Google Chrome entering the foray with WebKit as its rendering engine, it’s only a matter of time before IE will get pushed aside by the developers out there. And the rise of the iPhone… like Cameron Moll has been saying, the future of web dev is in mobile devices. How might a shift in the internet market further push IE to the side?

I only focus on IE because it’s really the only thing I see as holding back the progress of web technology. Across the board, it’s inferior in terms of the technical aspects of making things possible. Its JavaScript processing is terrible, it’s XHTML isn’t up to speed (it’s best to stick with XHTML 1.0 Transitional… wha? “Transitional” means not permanent, yet IE seems content to encourage holding to outdated methods), and I don’t even want to start in on how it handles CSS. To me, IE is the bottleneck.

However, this fact doesn’t seem to be slowing down real innovators out there. We’ve seen a rise in frameworks-based solutions in the last couple of years, until at this moment, some incredibly useful options exist for almost every major programming platform. In many ways, the days of writing individual scripts and classes are over.

Where I’m most impressed with what folks have been creating for web developers is with Cappuccino and SproutCore. These two projects work to abstract the JavaScript/AJAX aspect of web applications. Cappuccino appears to do a better job of abstracting entirely any JavaScript, HTML, and CSS, so all you have to do is immerse yourself in Objective-J and you’ve got yourself a stylish web app. If you want to be wowed, just go and see 280 Slides: a fully web-based Keynote-esque application. The whole thing was done in Cappuccino and (I’m fairly sure) Rails.

With the advent of such robust JavaScript frameworks, the web browser has all of a sudden become a bridge rather than a browser. The early “web-based OS” projects, I initially thought, seemed redundant and a little excessive (why build a web-based OS if, to access it, another OS must necessarily be running?). And I still hold to that opinion, though I do believe Cappuccino and SproutCore are moving in the right direction. They serve more like web application and UI frameworks, much like Cocoa on MacOS. You still need to know your programming language (Objective-C, C++, Java, or Python), but how the language interacts with the UI gets abstracted wonderfully, saving time and improving the user experience at the same time.

So, I suppose my rant here is simply to encourage developers to learn these new technologies and to use them well. I, for one, am excited about open source taking over web development. It at least helps to move us beyond waiting for the big companies to get it right. And the limits of our skills get pushed out as well.

My idea of the perfect skill set for web devs? (Just for fun :)

  • PHP 5 / Ruby 1.8
  • MySQL 5
  • CakePHP 1.2 / Rails 2.2
  • Cappuccino / Objective-J
  • jQuery 1.2.6
  • XHTML 1.0 Strict
  • CSS 3.0
  • Unix
  • Git
  • An eye for good UI

Notice how much of these are open source?


« Older Entries

Beginning CakePHP: From Novice to Professional by David Golding

David Golding

A blog about CakePHP, web design, and grad studies in religion. © 2008, D. Golding