Skip to main content

24 posts tagged with "programming"

View All Tags

Back to Basics

· 3 min read

When I started my formal education in computer science, I had to take a module on programming with the C language. I remember this was a module that caused many of my peers to re-think their decision to study computer engineering; the concept of pointers was so foreign to many of them that even the smart ones scored poorly.

Download JSON as a Text File

· 3 min read

As a Web developer, I sometimes find a need to download some huge JSON object into a text file.

Modern browsers now come with some form of developer tool/console to help debug the monstrous amount of JavaScript in the Web page. For Chrome and Firefox, I simply press F12 to bring up the console. From the console, you can naturally copy the JSON object in its string form by first converting the object into a string like so:

JSON.stringify(obj);

Then highlight the output from the developer console and press Ctrl-C to copy. The trouble comes in when the object is huge - to the tune of thousands of properties.

When an object gets to that size, you will need to scroll to be able to select the complete output. Scrolling the console is itself a tiresome task with text that small. Moreover you run the risk of "over scrolling" such that you select two objects rather than one because you can't tell the difference when they are simply chunks of text.

The best solution is to download the JSON as a text file and then use/manipulate the JSON from the file.

The way to do this is to create a function like this:

Stripping Carriage Returns From Text Files

· One min read

One of the problems with working on Linux and Windows OSes has to do with manipulating text files. Lines are separated by a carriage return and a line break character in text files on Windows, whereas on Linux, the separation is done through a single line break character.

When text files from Windows are opened in Linux, you often see ^M appearing at the end of lines like this:

Line 1^M Line 2^M

The easiest way to remove the carriage return characters (represented by ^M) is to use the dos2unix command. This lightweight program can be easily obtained on Debian-based systems with the command:

sudo apt-get install dos2unix

Other than using the dos2unix command, the fastest way to remove the carriage return characters is the following command:

cat file1.txt | tr -d '\r' > file2.txt

Solving the Mystery Behind Alternating Failed Tests in QUnit

· 3 min read

I’ve recently started using QUnit for my JavaScript testing. It’s a unit testing framework for JavaScript. It’s quite an easy framework to learn and I strongly encourage everyone who is doing any decent JavaScript coding to use it or any one of the myriad frameworks out there.

One of the strange problems I faced with QUnit is a strange phenomenon where a custom written plugin fails the test on every alternate invocations of the test.

CSS Best Practices

· 7 min read

As mentioned before in earlier posts, I’m involved in a Web application development project. Recently I had to do some testing on the Web application (although it’s barely beta ready, but that’s a different story). During the testing process, I’ve got to see for myself the implications of not incorporating scalability designs early on into the code.

This post will take a simplistic approach to look at why load times can be improved by consolidating CSS files. At the same time, I will also take a look at naming CSS selectors as the approach to consolidating CSS. By taking a consistent approach to naming CSS selectors and organising the selectors in a structured manner in CSS files, we can minimise the number of CSS files.

Google Apps Provisioning API Version 2

· 4 min read

Google Apps Provisioning API is a set of API that allows other programs to access stored on Google’s servers. This is done via the Atom Publishing Protocol and HTTP requests (what the industry terms general as a RESTful interface).

The set of data that Google exposes via the Provisioning API include the user accounts and groups and other related data.

Google has improved its groups mechanism not too long ago. With this came improvements to other Google properties such as Google Docs where sharing documents with groups is possible. Previously, this was not available because the original concept of a group in Google Apps is nothing more than an email list where emailing to the “group” allowed users in the “group” to receive the email as well. But this was all that version 1 of “groups” (technically known as an email list) could do.