Python – Normalize User Input

After remaining in drafting for over a year (initial draft was on 7 August, 2013), I have finished this new Python tutorial. There is a lot to be written about case normalization, both for the upsides and downsides, but it is generally agreed upon that user input should be normalized, or converted into such a form that any checks run on the input can be case-insensitive. This tutorial shows how you can do that and provides a through example of case normalization in action. No, just because I use the term “in action” does not mean it is your favorite or the newest theatrical action movie. 😛

Enjoy. 🙂


Continue reading “Python – Normalize User Input”


LR2 Track Selector and LR Track Selector v2.0

A long time ago in a place not far from here, a certain triangle wrote a program to randomly select tracks from the game LEGO® Racers for the player to race. Soon thereafter, a friend asked for an equivalent version for LEGO® Racers 2. The request was acknowledged, and work so began. However, due to confusing logic and a lack of programming skills needed to carry out such a task, development was halted, and the request was never fulfilled.

One year later, the unfinished program was referenced, and after reviewing the state of the code, it was decided that the know-how required to complete it was now available. A mere two hours later, the program had been finished, and the promise made had been kept.

Continue reading “LR2 Track Selector and LR Track Selector v2.0″

Count the number of lines in a file – Python

This is a super simple tutorial. So simple, in fact, it is the shortest one I have ever written.

If you ever need to count the number of lines a file has in it and not even process the file, only count the lines, simply open the file and use a for loop to iterate over the number of lines and update an incrementer already in place. No need to even read the contents.

(View on GitHub Gist)

I told you this was a super simple and short tutorial. 🙂


Internet Explorer and Inkscape SVGs

Vector graphics are slowly supplementing bitmap images and have become a cornerstone in modern web design for an amazingly simple reason: because they are composed of mathematically defined coordinated rather that a fixed number of pixels, they scale up and down with no loss in quality. This fact makes them great for responsive web design (a single site whose layout scales and reflows according to screen size, mostly removing the need for a separate site for mobile devices). Slowly but surely, vector graphics are being used in place of bitmapped buttons, small simple images, and layout elements (such as a navigation bar) in websites. Already it makes more sense in the corporate world to design a logo in vector instead of bitmap so as to scale it for any advertisement size and layout, the same with many mobile applications too, so website designers are now adopting this trend fueled by the explosion of smart phones, touchscreens, and tablets of varying sizes.

Thankfully, web browsers and website frameworks have noticed this trend and have done their best to support vector graphics, mainly in the form of SVG files, which are either saved as an external file and loading using an <img> tag or through inlining the file (much like using a Base64 encoded bitmap image) using the <svg> tag. Today, any web designer can create a SVG vector image using any vector graphic creator, such as Adobe Illustrator or Inkscape, add it to a website, and have it rendered and ready for scaling in every modern web browser.

That is, except for Internet Explorer.

For as long as website design has been seriously considered, Internet Explorer has been a major force to be reckoned with, either for good or bad. As the browser with the most market share, developers are often placed in an all-or-nothing support situation, with some degree of support being performed most of the time. Further complicating the matter is the various versions of IE in use, mainly ranging from IE 8 to the newest IE 11. While IE 10 and 11 are drastically improved compared to the last few versions, there are still plenty of standards compliance issues designers and developers alike must workaround without crippling more compliant browsers. One such IE issue that must be dealt with even in the newest version is (surprise!) SVG support. However, the issue is not as simple as it sounds. Although Internet Explorer supports SVG graphics, it has a beef with SVGs exported from Inkscape (but not from other Vector graphic editors), even when using the “Plain SVG” Save As option.

In this post, we are going to be exploring this strange scenario, why it happens, and how we can avoid having Internet Explorer choke on our beloved vector graphics. A live demo of the issue at hand is available at You will need to use Internet Explorer to view this. However, I have provided screenshots of the issue, though, as it makes everything much easier to comprehend when you can see what is happening (and making up for the Impossible, unless you know how cross-browser support). ;).

Continue reading “Internet Explorer and Inkscape SVGs”

Web Coding Style Guides

There is nothing like well written code. I am not talking about the efficient type either. I mean the clean, well-formatted, neat looking code. Code that looks the same no matter what environment it is displayed in. Clean code, both efficient and neat, makes the world go ’round.

However, how do you know what is considered clean code? What is the baseline you are to compare your code to? The answer lie in style guides. Every programming language has them, both for the code you write and the code that powers the language. By reading and following your chosen language’s style guide, you can be sure your code is a piece of code beauty (that does not mean ASCII art either 😛 ). In the world of HTML, CSS, and JavaScript, there is no single style guide to follow but rather many to choose from. Although there are a few predominant ones and they usually contain some of the same suggestions, it is up to you to choose which one to follow. Furthermore, there may be a few rules from one you like from guide X but overall prefer guide Y. You may also have personal preferences not listed. All the decisions can become confusing.

This is where this post comes in. I am going to show off a few of the most well-known style guides and provide some tips on handling it all.

Are you in the reading mode? I hope so, because this quest for cleaner code is going to be long. Forward, march!

Note: this post is not directly about discussing code styles you, I, or the programmer next to you uses. While I will briefly mention some of my coding style, the primary objective of this installment is to explore some of the HTML, CSS, and JavaScript style guides out there and help you develop your own personal guidelines. Discussing personal style guides is beyond the scope of this post. 😉 In addition, the words “rules” and “guidelines” and their variations are used synonymously to mean “suggested practice”, per the aforementioned purpose of this document.

Continue reading “Web Coding Style Guides”