Featured Posts

Web Presense Solution I've officially started up my independent web development side-business. I am hoping to bring quite a few small businesses into the present with a simple, cost-effective package that provides them with...

Readmore

MS SQL date / time conversion I often find myself turning to MSDN to get the possible conversion options on MS SQL's date data type, so I finally became un-lazy and created a little script to use in the future to quickly list all possibilities...

Readmore

jQuery Delay Happy Note: I was contacted by the jQuery team and my code is being added to the core functionality; that really made my day!  You will want to remove the current code from your site if you plan on upgrading...

Readmore

ASP Search Stemmer Class The original stemmer class was developed by Martin Porter to bring words back to their word stems. For example "abilities" would stem to "able", "smelling" to "smell", "I'm awesome" to "damn straight",...

Readmore

  • Prev
  • Next

How to check for legit credit card numbers

Posted on : 30-07-2009 | By : chelfers | In : ASP, Web

0

I think the title says it all; I've seen many implementations for checking credit card numbers and in my opinion there is really only one that you need and actually works.

Sadly, still in use today by many code examples that I've run across is the good old

if ( first_digit = 4 ) then "visa" elseif ( first_digit = 5 ) then "mastercard" elseif ( first_digit = 3 ) then "amex" elseif ( first_digit = 6 ) then "discover" else "invalid card" end if

/facepalm

This isn't entirely bad ( yes it is, I'm just trying to be nice ), most likely those first digits will always be associated with the cards mentioned above, the problem is the numbers that follow.

"But I found one that checks and second and third numbers!"

Awesome, one tiny step closer to almost not really getting anywhere!

Obviously I'm leading up to the one and only Luhn algorithm which is basically a simple checksum formula used to validate a few different sequences of numbers, for example credit card account numbers.

Straight from Wikipedia here is what is going on with the algorithm

The formula verifies a number against its included check digit, which is usually appended to a partial account number to generate the full account number. This account number must pass the following test:

1. Counting from the check digit, which is the rightmost, and moving left, double the value of every second digit.
2. Sum the digits of the products together with the undoubled digits from the original number.
3. If the total ends in 0 (put another way, if the total modulo 10 is congruent to 0), then the number is valid according to the Luhn formula; else it is not valid.

As an illustration, if the account number is 49927398716, it will be validated as follows:

1. Double every second digit, from the rightmost: (1×2) = 2, (8×2) = 16, (3×2) = 6, (2×2) = 4, (9×2) = 18
2. Sum all the individual digits (digits in parentheses are the products from Step 1): 6 + (2) + 7 + (1+6) + 9 + (6) + 7 + (4) + 9 + (1+8) + 4 = 70
3. Take the sum modulo 10: 70 mod 10 = 0; the account number is valid.

Below is an ASP version I've ported, enjoy.

ACCOUNT = "4500000000000001" alt = false sum = 0     for i = len( ACCOUNT ) to 1 step - 1             digit = mid( ACCOUNT, i, 1 )                     if ( alt = true ) then                 digit = digit * 2                     if ( digit > 9 ) then digit = digit - 9 end if             end if         sum = ( sum + digit ) mod 10                                                 if ( alt = true ) then alt = false else alt = true     next if ( sum = 0 ) then   'legit else   'did not pass the test end if

CSS Sprites or How to make your pages load faster

Posted on : 28-07-2009 | By : chelfers | In : CSS, HTML, Web

0

Regurgitating old web techniques seems to be somewhat of a trend I've fallen into recently, but as I see questions and non-existent usage of these important and basic techniques I feel obligated to help spread the word once again.

Here are a couple of great articles explaining what CSS sprites are, their purpose, makeup, and why no site has a reason to NOT be using this technique aside from laziness ( which is why my blog doesn't use them, <3 Wordpress ).

- http://www.alistapart.com/articles/sprites
- http://css-tricks.com/css-sprites/

Save the Pandas, take the bus, stick to w3 standards! Ah, who am I kidding.

Evony.com or why I’m quitting

Posted on : 24-07-2009 | By : chelfers | In : Games, Web

12

I was passed this article and have finally made my decision to quit playing, wee.

The game is Evony, I've been playing for a couple weeks and feel I've come to the end; the game is decent, but starting to get boring now that accomplishing anything really takes an entire day or more of waiting ( and it just gets longer, way longer ), and lots of time searching for various objects that seem to be non-existent aside from the online shop that only accepts cash. The player vs player, or player vs computer is also very redundant; you 'spy' on the target, decide how many of your troops are needed and click attack; nothing more to it, repeat perpetually.

I've been doing my best to ignore the extreme push to spend real US dollars to purchase objects that enhance game play. The objects generally speed the game up for the player, but the part that really irks me is the objects called 'medals' that are required to advance in rank. At the start of the game these medals are given out like candy, and as you advance further they can only be obtained by winning computer generated battles at a rate of what seems to be less than 1%. If you don't wish to spend weeks of countless battles looking for these non-existent objects you could spend a few seconds buying them in the online shop for real US dollars, giving you a clear advantage in a game that is advertised as 'Free Forever'.

The real reason that pushed me to quit playing is the game's affiliation with a famous World of Warcraft gold farming company. For those who are unfamiliar with this, the companies basically hire Chinese workers for almost no pay to collect in-game currency and resell it for real world cash. The business model alone isn't what gets people in a tizzy, it's the conditions that the workers are put in and how they are treated. I know my word isn't worth much, but trust me anyone associated with these types of companies are complete scum and I will not be associated with them in any way.

Let's sum up what I don't like and why I'm quitting before I start on a real rant.

  1. Affiliation with a disgustingly inhuman company.
  2. Pushed to spend USD
  3. Boob advertising or overall 'sex sells' mentality that appears in the majority of all Evony ads; here are a few of the many ads that appear on family friendly sites:

Good luck to everyone, and Go Vikings ( server 24 :P )!

Edit: And awesome, now I get to play tag with Google's Adsense to try and block Evony and WoW gold farming ads.

Evony 100,000 Prestige Noob

Posted on : 17-07-2009 | By : chelfers | In : Games, Web

92

Let's set things straight right off; I do not think prestige is important for judging someone's abilities in game, it has its uses but for the most part it means nothing.  This guide is to explain how prestige works and how easily it can be gained.

Replacing HTML character codes / escaped strings

Posted on : 17-07-2009 | By : chelfers | In : HTML, Javascript, Web

0

I've been coding web pages and applications for quite a few years using quite a few different languages. When I learn something so basic and fundamental I often wonder how much of a noob I really am, and then how many other developers are in my same shoes.

The problem I had was converting HTML character codes such as & # 35 ( apostrophe ) to its ascii equivalent. I've done this many times before, but have always been too lazy to find a different method. After searching through various blogs for a solution I finally came across a beauty.

.replace(/\&\#(\d+);?/g, function (m,n) { return String.fromCharCode(n); } )

A basic explanation of the code goes a little something like this; now this is a story all about how my life got flipped-turned upside down, and I liked to take a minute just sit right there, I'll tell ya how I became the prince of a town called Bel Air *record scratch*, err no wait.

Back on track, this function call does a couple of different things; first we are will search the entire string for every instance of our matches, and secondly we try to make our two matches ( yes two! ). The first match for our regular expression is looking for "&#"; this is our entry point into the search and should nab us every instance of those dang character codes. The second part of our match is the (\d+) sub expression, this is really what we are after and will give us the correct end result.

Once our expression has found a good match we will pass it to our callback function.

function (m,n) { return String.fromCharCode(n); }

The first thing you should notice are the m and n parameters that are being passed, these are tied directly to the matches and follow the order they were matched in, or in other words m = "&#", and n = [ our numerical match ]. These could really be variable name you wish, I stuck with the original example because that's how I rock out.

On the inside of our function we simply ignore the m parameter as we are only interested in the digits baby. We pass the n parameter to our Javascript function and BAM, straight up ascii conversion, what, WHAT.

As always, hope this helps someone :]