Pages

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: