Archive for the ‘Featured’ Category

Project Euler, #1-10

Posted by Avrithor On July - 1 - 2009

Since I discovered it yesterday, I’ve been hooked on Project Euler, working furiously on solving as many problems as possible. It’s a site that poses hundreds of math problems designed to be solved by writing computer programs, and tracks which ones you’ve solved. Naturally, I’m using JavaScript, and I’ve solved the first ten problems so far. Now, given my inexperience, the solutions I arrived at are going to be flawed—mostly in terms of efficiency—but obviously they work.

I made a file for the project, euler.html, where I’ll write my solutions for each problem. Of course there will be some functions shared among different problems, which is part of the reason for doing it in a single script. I’ll put a button on the page for each problem that’ll run its solution and spit out the answer. Although it doesn’t really matter here, I’ll also stick to best-practices and avoid polluting the global namespace by encapsulating my script’s functionality in a self-executing function. Common, private variables and functions will be defined, and then a hash will be returned with a member for each problem. This exposes them to the rest of the page (so the aforementioned buttons can call them), but they’ll have access to the private stuff thanks to closure.

var Euler = (function() {
  // private stuff here

  return {
    P1: function() {
      // algorithm for problem 1
    },
    // etc...
  };
})();

On to the first 10 problems. Note: If you want to solve them yourself, “spoilers” follow after the jump! Please don’t cheat.
Read the rest of this entry »

Guide: How To Securely Manage Strong Passwords

Posted by Avrithor On June - 11 - 2009

Think fast: How many passwords do you have?

A lot? Surely you have many systems that you log in to, but perhaps you’ve taken to using a particular password on multiple sites, to avoid confusion and the hassles that go with forgetting a password.

Maybe you even use the same password to log into your computer, to log into YouTube, and to log into your online banking site. It’s just easier that way—I hear that sentiment loud and clear.

How strong is that password? Realize that if an attacker somewhere on the internet cracks your YouTube password, even though you may not care about YouTube they have now also gained access to your finances if you use the same password for your bank!

Unfortunately, we’re stuck with an online world in which a variety of destinations, tools, and services use only username/password authentication. As we rely more and more on these services and the risk as well as the potential damage of identity theft rise, it becomes ever more critical to have strong, unique passwords and protect them carefully. What I’d like to do here is explain my approach to password management and how you can have a set of exceptionally strong and unique passwords for everything you log into, without ever worrying about forgetting them.

Step-by-step guide after the jump!

Read the rest of this entry »

JavaScript Custom Event Handling

Posted by Avrithor On June - 4 - 2009

Update, 7/1/2009: Switched code sections from manual coloring to an automatic syntax formatting plugin.

NOTE (6/20/2009): I didn’t intend to close comments on this post. The setting is on “enabled” and I’ve tried disabling and re-enabling them to no avail. Some glitch either with the WordPress 2.8 update or installing the new theme has screwed it up. If you have something to say about this post, drop me a line. My Gmail username is the same as everywhere else.

I haven’t been posting much lately; I have, however, been thinking about my future in some area of computer science, software development, and/or web development. And I’ve been tinkering more with JavaScript since my last post. One thing I’ve discovered how to do is baking event handling into your custom objects. This isn’t really innovative—all the major frameworks out there include it—but I had fun figuring it out on my own. Here’s the solution I arrived at.

I decided that the best way to store and fire event listeners was in an associative array, where the keys are the event names and the values are associative arrays linking IDs to functions. So, for example, a set of registered event listeners for an object representing a door might look like this:

Door.Event
   "Open"   => "a"  => function
   "Close"  => "b1" => function
               "c"  => function
   "Lock"   => (empty)
   "Unlock" => "b2" => function
               "d"  => function

The IDs here are just quick meaningless samples; the idea is that they come from and uniquely identify the object that registered their respective event listeners. They will be used by their originating object to unregister its own event listeners and not any other object’s event listeners if need be, since you may have multiple objects registering listeners for the same event, possibly even the same function registered as a listener by multiple objects. As an example of this, consider a card game. If there are two cards on the board that say, “Whenever a player discards a card, that player takes 5 damage,” you will have two instances of the triggered function (dealing 5 damage to the player) registered on an array of global events for “Discard”, and when that event is fired, both will go off and the function will be executed twice. Yet, if one of those cards is destroyed, it should remove its own specific instance of event listener registration—perhaps the other has had a spell cast on it modifying its effect, so it could matter which one gets deregistered.

Using this system, implementing event listener registration is simple.

Read the rest of this entry »

About Me

I'm a computer science student at the University of Minnesota and enthusiast for the arts, gaming, and technology.

Quotable

"Madame, my kingdom is a small one,
but I am king there."


—Frederic Chopin, asked why he wrote many nocturnes, but never a symphony or opera