Coding

Ever since I advanced beyond the “hello worlds” of Java, I had never stopped coding. This section is for documenting code usages that I had employed while solving the technological problems that I had encountered.

How to ensure that your Javascript is able to write unicode characters from external Javascript files to your HTML contents

Ever tried injecting Chinese characters into your HTML DOM from an external Javascript file but got something that resembles the following?

Gibberish characters was shown when jQuery attempts to display error message in Chinese

Well that was what I got for the Chinese version of my bilingual form initially as a result of validating an input field as the user is filling up my form.

In this post, I will discuss why I got the unwanted characters and what I did to solve the problem.

Deciding which HTTP status code to use in a HTTP response

When we are in the business of creating web applications, we are always crafting HTTP responses.

A HTTP communication session is initated with a HTTP request from the client and is ended with a HTTP response from the server. In order for a HTTP communication session to take place successfully, the server must be reachable via an IP Address and a port number.

However, a successful HTTP communication session does not imply that the client always get what it wants from the server. Within the HTTP response, the server tells the client whether or not the HTTP request is plausible to fulfill via HTTP status codes.

This is a discussion of some of the status codes that I use at the HTTP server end, in an environment where most of my HTTP clients are robotic in nature.

PHP codes to tell browsers to open the download dialog box for users to download a file

Ideally, when we build web applications which generate files on demand, we will want our users to be able to use their browsers to save a copy of our files in their local harddisk. For instance, the tool for generating customized codes for countries in the world, which I had created earlier, will tell browsers to prompt a download dialog box after users had submitted the form.

Image of firefox dialog box after submitting request to generate custom codes from list of countries in the world.

However, this is not the default behavior of browsers. By default, browsers will show the contents of a HTTP response generated by our PHP script in the browser window. This behaviour can be seen when I point my browser to http://www.techcoil.com/robots.txt.

In this post, I will discuss how we can tell browsers to show a dialog box for users to save the contents generated by a PHP script as a file.

How to compress and decompress files in C#

Files are useful for applications to communicate with others. For instance, web applications can communicate with Google’s crawlers via sitemaps on the Internet. A web application write urls to its pages to its sitemap. When Google’s crawlers come to this web applications, they will download these sitemaps to index urls to the pages of .

To reduce the time needed for files to be trasmitted over the network, it is a good idea for applications to compress files before sending them out to the network, or for a web application, making them available for download via HTTP.

In this post, I document how we can compress and decompress files via the GZip implementation in C# – System.IO.Compression.GZipStream.

How to ensure that your user only runs one instance of your C# program

There are times when we want to limit our users to run an instance of our C# program at any one time. Such situations can be applicable for network monitoring tools, messaging applications, web server monitoring application and etc. In this post, I discuss how we can achieve that via the mutual exclusive (Mutex) mechanism available in C#.

Handy Javascript code segments

The augmentation of Javascript to CSS and HTML is beautiful. While trying out jQuery to create my own tic tac toe game, I realised that there are Javascript/jQuery code segments that could be helpful to me when building web applications.

In this post, I collate Javascript and jQuery code segments that I had utilized in my web projects for ease of future references.

How to execute codes periodically in C#

While some applications passively wait for files to be available for processing, there are many others that need to periodically execute codes to fulfill business requirements. For instance, some may constantly trigger other applications via the command line to monitor the network while some others may constantly access databases to generate graphical reports for business analysts.

C#.Net is one programming language that you can use to create applications that need to do work periodically, especially in a windows environment. In this post, I document the usage of the System.Timers.Timer class to execute codes periodically.

How to send HTTP post requests and HTTP get requests using jQuery

This was a proof of concept to try out jQuery’s ajax features. Asynchronus Javascript And XML is a way for avoiding unnecessary refresh of the entire web page. When used properly, it can enhance user experience for your website, especially when you have lots of images on your page which does not change often across different pages.

This proof of concept was based on jQuery version 1.7.1.

Code segments for rendering html 4.0 pages

Very often, I find myself creating HTMl pages from scratch. Those could have been situations when I want to try out some javascripts or write some php proof of concepts.

Although there are many frameworks around, I still prefer the pristine way of rendering HTML pages as I can be certain that there will not be conflicting javascripts or php scripts when I need to try something out.

In this post, I put together pieces of HTML codes that I find myself using often. This will make HTML development more convenient as I do not have to wade through the many search results from google to look for them.