Pages

Tuesday, March 11, 2014

Preprocessor to control printf debugging

A fundamental way of debugging an application, especially developed using  C / C++ programming languages is "printf debugging". i.e. To dump a message on to console output with some variables.

However, including too many "printf debugging" statements can hinder the performance of an application. Therefore, it is important to include a mechanism to automatically remove all such debugging statements. The easiest way to achieve this is through conditional compilations.

One straight forward way is to wrap the printf statements within a preprocessor directive as follows.


#ifdef _DEBUG
    printf("Debug message\n");
#endif


This approach adds too much clutter into the source code. Therefore, I was looking for a elegant solution to this fundamental problem and came across the following code block.

Saturday, February 22, 2014

Download YouTube videos with VLC Media Player

Saving  YouTube media files on the computer for offline viewing is easier once we have made all the configurations in the VLC media player as given here.
  1. Under Tools menu, select Codec Information (Ctrl + J).
  2. Copy the URL given as Location (As highlighted below), in the Current Media Information popup window.  

Friday, February 14, 2014

Play YouTube videos with VLC Media Player

I was searching the internet for a way to play YouTube videos with special audio and video effects like color correction, hue & contrast adjustment and other special effects. It was quite a surprise to learn that the solution was within my fingertips all the time. 

Countless times, videos have been viewed using VLC media player, simply by double clicking the file on Windows Explorer. Therefore, the Media menu rarely attracted attention and the solution was silently waiting there to be explored.

Here are the simple steps.

Friday, February 7, 2014

FTP made easy with LFTP

I was looking for a decent FTP client program to perform a relatively complex series of file transfers using a Linux shell script and came across LFTP.

LFTP is a freely available file transfer program which allows FTP, HTTP and a number of other connections to a remote host.

A few of the evaluation commands I tried with LFTP are listed here as a future reference to my self as well as anyone looking for quick examples.

Monday, February 3, 2014

Virtual WiFi hotspot with Windows 7

I had a problem with connecting multiple mobile devices to the wireless router as it had reached the maximum number of nodes. I was looking for a way to convert my laptop to a virtual WiFi hot spot and connect the mobile devices to the internet by sharing the LAN internet connection with the virtual WiFi adapter. 

A bit of Googling reviled a number of third party apps which can create a virtual WiFi. But with further reading, I learnt that this is a built in feature of Windows 7 operating system. A few configurations in the Windows "Network and Sharing Center" or a few commands on the Command Prompt do the trick.

Friday, January 24, 2014

Play WAV files with Java


The following simple application demonstrates how to play back a WAV audio file with Java APIs.
The key step is to specify the correct parameters and create an AudioFormat object.


Wednesday, January 15, 2014

Playing with Big Integers using Java BigInteger

The BigInteger class in java.math package allows to perform arithmetic operations on large numbers which do not fit into the Java primitive data types. The BigInteger class is particularly useful in cryptography operations where large prime numbers play a pivotal role.

The following snippet, which calculates the smallest factor of an integer (not in the most efficient way) gives a simple demonstration of fundamentals of using BitInteger instances in a program.

A key point to remember is the immutable nature of BitInteger instances.

Monday, January 13, 2014

Inter Process Communication: Windows NamedPipes & Java Applications

A Named Pipe is a mechanism for communication between processes. One process has to create the Named Pipe (termed as pipe server) and one or more processes can connect to this Named Pipe (pipe clients) using the unique name given to it, when it was created. 

Saturday, January 11, 2014

HTML iframe without src attribute



The HTML <iframe> tag denotes an inline frame within the HTML document. The primary usage of the inline frame is to embed another document within the current HTML document. In order to embed the intended document within the <iframe>, the address of the target document should be specified as src attribute value.

The following simple code snippet shows how to embed this page within another HTML document.

<!DOCTYPE html> <html> <body> <iframe src="http://www.duleekag.blogspot.com" width="200" height="200"> <p>iframes are not supported.</p> </iframe> </body> </html>

The paragraph tag (<p>) is used to indicate the browsers that do not support this tag. 

The intended purpose of <iframe> is to embed another document within the current HTML document. But sometimes, we all get the urge to tryout unorthodox stuff within our code. This is one such scenario where hard coded HTML content is embedded within an <iframe>. The obvious question is "why bother to add it within an <iframe>, if the content can be hard coded". Well.. this is just out of curiosity. 


<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>iframe without src attribute</title>

<script type="text/javascript">
    function onTryItClick() {
        var content = document.getElementById("iframecontent").innerHTML;
        var iframe = document.getElementById("myiframeid");

        var frameDoc = iframe.document;
        if (iframe.contentWindow)
            frameDoc = iframe.contentWindow.document;

        frameDoc.open();
        frameDoc.writeln(content);
        frameDoc.close();
    }
</script>
</head>
<body>
    <div id="iframecontent" style="display: none;">
        <b>Hello World!</b> <br /> <i>Hello Again !</i>
    </div>

    <div style="margin: auto; width: 80%;">
        <iframe height="100" width="100%" src="about:blank" name="myiframe"
         id="myiframeid"> </iframe>
        <br />
        <button id="tryIt" onclick="onTryItClick()">Try It</button>
    </div>
</body>
</html>



Thursday, January 2, 2014

Watch Star Wars through Telnet

Stumbled upon this while trying to troubleshoot a problem with Microsoft Windows Telnet client.

Telnet is a text-based program which can be used to connect to another computer using the Internet. On Microsoft Window, the Telnet client is not enabled by default. The Telnet client can be enabled by following the step by step instructions available here.

Once the Telnet client is enabled, open up a Command Prompt,

Wednesday, January 1, 2014

See if you can figure out this Benjamin Banneker mathematical puzzle..?

I got the following mathematical challenge from a friend. A bit of Googling revealed that the original challenge was presented by Benjamin Banneker.

You must spend $100 and buy 100 animals from the following list.
You must buy at least one of each category.
Cows $5.oo each
Goats $1.00 each
Chickens .05 cents each

How many Cows, Goats and Chickens you have to buy to meet the above two conditions ?

Playing with the parameters of the puzzle showed that solutions exists for different combinations of prices of animals, total spent and total number of animals purchased. 

Feel free the try out different combinations and see which ones meet the two criteria.
Example: How many Cows ($5), Goats(1$) and Chickens ($0.05) do you have to select to purchase 99 animals using $100 ?


Cow:
Goat:
Chicken:
Total Animals:
Total Amount: