Archive for March 2009

Will Code For Food

A few months ago I quit my day job in favor of dedicating more of my time to school. Seeing as how after three months my cash reserves are all but depleted I’ve decided to offer my services to anyone in need (PHP, Java, SQL etc).

Check out the For Hire page for more info.

3D CAPTCHA

Slashdot posted an interested article yesterday about a new form of CAPTCHA. Rather than solving math problems or trying to read obscured text, this method requires users to compare objects in 3D space. In the example I saw (http://www.yuniti.com/register.php) three objects were displayed and the user had to match each of them to a corresponding object, selected from a list. The corresponding image depicted the same object, however it was oriented differently.

Though this is a unique approach and I’m sure it will deter the spam bots for a while, given how it appears now, it is not to difficult to image some algorithm being able to match these images. For instance, if you took the original image and overlaid it on each of the images from the list and, using the amount of non-overlapping area as a performance measure, begin applying some transformation (even simple 2D rotation) you would soon find that the corresponding image has the highest performance among all of the images in the list.

Some possible improvements to prevent this kind of attack:

  1. Rather than having the objects appear independently, overlap them slightly.
  2. Choose images that are irregular, meaning that they appear differently on one side than on another, but to a person, are still recognizable on either side. A light bulb for instance is a bad choice because it is regular.
  3. Set traps; put images in the list that are similar in shape and size, but clearly different to a person.

Slashdot Article: http://it.slashdot.org/article.pl?sid=09/03/27/2332253&art_pos=1

Semicolons

You know you’ve spent too much time programming when you start ending your sentences with a semicolon;

Consolidating Error Pages with .htaccess

Before I get into the topic of how to consolidate all of your error pages, let me first explain how to use .htaccess to create custom error pages. If you already know how to do this feel free to skip to the next section.

Creating Custom Error Pages

.htaccess, among other things, allows you to specify custom error pages for your site. Say a user requests a file that does not exist, typically that person will get an error page that looks somewhat like this:

—————————————————-
Not Found

The requested URL /somepage.html was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
—————————————————-

Not only is this message not helpful, but it is unappealing. Most likely you worked tirelessly making your site look presentable, so it would be a shame for a user attempting to access a page on your site to be given an ugly error message.

.htaccess allows you to specify the page you would like to use as an error page for a particular error (404, 301, 500 etc.). To do this, if it does not already exist, create a file called .htaccess in the root ( / ) directory of your site, or whatever directory you want to use custom error pages for. Note that these custom error pages will be used not only for the directory that the .htaccess file is located in, but all of the ones below it, unless you specifically override it.

Once you have created your .htaccess file, for each error you would like a custom page for add the following line:
ErrorDocument
So for example, if you would like to use a custom error page for a 404 (file not found) do the following:
ErrorDocument 404 /404.html
Where 404.html is your custom error page. Note that not every code is an error code. If you tried to set up an error page for code 200 you would end up creating an infinite loop.

Consolidating Your Error Pages

So you’ve setup your custom error pages. Mostly likely you haven’t taken the time to create a custom page for every error, and its most likely the case you don’t need to. I can honestly say I’ve never gone to a site and have it come up with a 414 Request URI Too Long error. Still, you might have taken the time to create several pages for the more common errors. You may even have a whole directory dedicated to error pages. Instead, you may want to consider using a single error page for all errors. If you’re experienced with .htaccess, you may already know how to accomplish this, if not I’ll show you.

In your .htaccess file you’ll still need to add a line for each error code you want to use a custom page for. Make sure to use the same scheme when naming all of your error pages, for example fourohfour.html, and 5hundred.php would be a bad choice. For this example I’ll use error.php (ie error404.php). These pages don’t actually need to (and should not) exist. Now we just need to create a RewriteRule for our error pages:
RewriteEngine On
ErrorDocument 404 /error404.php
ErrorDocument 500 /error500.php
RewriteRule ^error([0-9]+) error.php?code=$1 [NC]


You could eleminate the need for the rewrite rule by redirecting all of your errors to the same page like so:
RewriteEngine On
ErrorDocument 404 /error.php?code=404
ErrorDocument 500 /error.php?code=500


This, however, reveals the underlying system. This might not be a problem for most people, but some people prefer the look of urls that don’t contain parameters (?code=xxx). Also, if you decide you want to track what errors your users are getting (like what pages they are linking to that don’t exist) you can store this information in a database, in which case you wouldn’t want users to be aware of the underlying system.

Now whenever a user gets a 404 or a 500 error they will be redirected to error.php and the error code will be passed to that script. In error.php you can now set up custom messages for each error code. Here is a simple script as an example:

$code = $_GET['code']; //the error code
$code .= ''; //avoid integer indexing of the array

$errors = array( '300' => 'Multiple Choices',
                 '301' => 'Moved Permanently',
                 '302' => 'Moved Temporarily',
                 '303' => 'See Other',
                 '304' => 'Not Modified',
                 '305' => 'Use Proxy',
                 '400' => 'Bad Request',
                 '401' => 'Authorization Required',
                 '402' => 'Payment Required',
                 '403' => 'Forbidden',
                 '404' => 'Not Found',
                 '405' => 'Method Not Allowed',
                 '406' => 'Not Acceptable',
                 '407' => 'Proxy Authentication Required',
                 '408' => 'Request Timed Out',
                 '409' => 'Conflicting Request',
                 '410' => 'Gone',
                 '411' => 'Content Length Required',
                 '412' => 'Precondition Failed',
                 '413' => 'Request Entity Too Long',
                 '414' => 'Request URI Too Long',
                 '415' => 'Unsupported Media Type',
                 '500' => 'Internal Server Error',
                 '501' => 'Not Implemented',
                 '502' => 'Bad Gateway',
                 '503' => 'Service Unavailable',
                 '504' => 'Gateway Timeout',
                 '505' => 'HTTP Version Not Supported'
                      );

echo $code . ' ' . $errors[$code];

Clearly the error page generated by the script above would be no better than the default ones, but it is just an example. You could easily embed it into your site in order to maintain consistency for your users.

Finals Week

If coffee were cocaine… I’d be Rick James.

In Over My Head

Every now and then I sit down for a test that I am completely unprepared for. In that moment of desperation I think to myself “Maybe I can infer the required knowledge before time runs out”.

——————————–

1. \int_{0}^{e} {1/x}dx

TODO:
Invent Calculus

——————————–

Expanding My Horizons

The more I learn the more I realize there is so much more out there that I have yet to experience. With regard to programming, I’ve gotten to a point where I am no longer limited to any one language. I do feel, however, that I have yet to experience the huge variety of languages out there. When it comes to software engineering, object oriented programming is pervasive. This approach, has so far, dominated my experiences as a programmer.

Yet there are many more approaches. Here is a fairly comprehensive list of the various paradigms out there:

Each one of these paradigms has its own list of languages associated with it. Some of them you’ve heard of, some of them are more obscure. Some languages transcend multiple paradigms (C++, PHP, Oz) while others are pure forms of its associated paradigm (Java).

My Goal

I’m primarily a Java and PHP programmer. This means that I’ve really only experienced two paradigms: Object-Oriented and Imperative (I’ve dabbled in functional using LISP, but not enough). My goal is to either learn a language, or a new approach with a language that I already know, that falls under every one of the categories above.

To get started, I think I’m going to take a shot a parallel programming, either in join java or Oz. This is most likely going to be an ongoing project for quite a while as school is devouring all of my time (honestly I shouldn’t even be writing this right now).

WordPress Scheduling

Should I ever become terminally ill, I plan to make excessive use of the WordPress post scheduling feature so I appear to be blogging from beyond the grave.

By the way…
I wrote this on the 8th, but it wasn’t published until the 13th. I might be dead already. :o

People on the Internet

Anyone who has ever used the Internet is probably familiar with the notion that people on the Internet act in ways that they would not act in person. You don’t have to think too hard about why this is to come to the conclusion that the cause of this is anonymity and a lack of consequences.

We don’t have to go online to see this kind of behavior, however. How many drivers are willing to cut people off, tail-gate, honk, or just generally be a jerk behind the wheel? When you’re in a car, you’ve distanced yourself from the people around you. You are in your own bubble and save for the small chance of getting pulled over, nothing you do is going to have any negative impact on your life.

So far everything I’ve written is fairly obvious: When some people are placed in a situation where there are no consequences for their actions, they act differently than they would when there are consequences. You may be inclined to infer from this that some people on the Internet act different from how they really are. I think that in person people act differently from how they really are.

During our day to day lives, whenever we make decisions we weigh their consequences. If I decide to call my co-worker a douche bag it probably won’t have a positive impact on my life at work, so I don’t do that (even if he is one). Our desires are temerped by the consequences of our actions. These desires and impulses are all revealed when we enter a situation where we do not have to face the consequences of carrying out those desires.

If someone writes that bubble sort is the best algorithm for sort any type of data in any circumstance I might be inclined to write back “OMG You freakin’ idiot. Don’t you understand the time complexity of that algorithm with reference to the amount of data you’re sorting?! I hope you die in a fire!!!”. In person, however, I might say “Actually I think there are many different better algorithms. Also your decision should ultimately be based on the circumstances, as no algorithm is best in all cases.” Now consider what is the same and what is different in these two instances. In both cases I point out that the person is wrong, but in one I humiliate and insult that person. There is one more similarity: In both cases my desire is to humiliate and insult the person. (at this point you should note that when I say “I” or “me” I’m talking in the abstract, I don’t actually desire to humiliate people who make poor algorithm choices… OK that’s a lie, but not all the time).

The lack consequences reveals my desires, and from that you may be able to infer more about me than you would, had my desires been filtered by consequences.

Adjusting the Curve

Every time I have an exam, I show up to class and place my scan tron and number 2 pencil on my desk, in plain sight. This is perfectly normal for exams that require a scan tron, but in those that don’t it may cause people to run to the bookstore and then arrive once again ten minutes late, clearly exhausted.

Variations on this method:

  • Show up with a blue book
  • Show up with a clearly different scan tron
  • Show up with an abacus

That last one may not cause anyone to run to the store, but it may cause them to have second thoughts about how they invested their studying time.