<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>twistedgenes.com - Blogs by Rakesh Gupta &#187; code</title>
	<atom:link href="http://www.twistedgenes.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.twistedgenes.com</link>
	<description>Blogs on truth, technology, food, linux, leisure, experiences, adventure, romance, friends etc !</description>
	<lastBuildDate>Sat, 12 Jun 2010 14:24:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A strikingly odd web application exposure</title>
		<link>http://www.twistedgenes.com/2008/12/a-strikingly-odd-web-application-exposure/</link>
		<comments>http://www.twistedgenes.com/2008/12/a-strikingly-odd-web-application-exposure/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 19:06:39 +0000</pubDate>
		<dc:creator>Rakesh</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Crazy]]></category>
		<category><![CDATA[Experiences]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[all]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Curl]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://www.twistedgenes.com/?p=124</guid>
		<description><![CDATA[Without having to expose your backend stuff to the internet, how do you service a WAP/WEB request. The blog below discusses a typical method of achieving the same. Assuming that whole web system is being developed in a intranet and not hosted outside. Let us call the internal unexposed server as A. We need a [...]]]></description>
			<content:encoded><![CDATA[<p>Without having to expose your backend stuff to the internet, how do you service a WAP/WEB request. The blog below discusses a typical method of achieving the same. Assuming that whole web system is being developed in a intranet and not hosted outside. Let us call the internal unexposed server as A. We need a server hosted on internet to fetch the WAP/WEB requests from the mobile or computer. This server is called as B. The request is being fired on the server B, the request is written to a flat file called request file. Server A runs a shell program viz fetchrequest.sh which reads the request file every second for any new requests coming  using the curl unix utility. Meanwhile, the server B sleeps off and waits for a response from server A. Server A will read the request and if its new (newness of a request is determined by saving the previous  request number in a global shell environment variable) server A processes it and shoots back the response to server B in the form of a file via FTP. Server B, in its sleeping state waits for the this FTP response file. Once recieved, it pushes back the response to the user. The whole wait process is scheduled for a fixed period of time, after which a dummy response is send like server is down, request failed, bla bla etc . Let us see how the same is achieved in fetchreques.sh running on server A.</p>
<p>File fetchrequest.sh</p>
<pre>
#!/bin/bash
while [ 10 -eq 10 ]

#Runs in a infinite loop checking request file at server B every second
do
if [ `env | grep -c lastCounter` = 1 ];then
newCounter=`curl -s http://serverB/requestFile.txt | tail -1 | cut -d: -f1`

#Reading request file at server B
param=`curl -s serverB/requestFile.txt | tail -1 | cut -d: -f2` #Extracting the request parameters
echo newCounter : $newCounter lastCounter : $lastCounter

#If there is a new request, sending a response back to the server B
if [ "$newCounter" != "$lastCounter" ]; then
echo "Need to send a response"
echo "Response URL : http://serverA/something.pl?action=something&amp;param1&amp;param2"

#Trimming of the response that needs to be send to serverB and storing it in a variable
output=`curl -s "http://serverA/something.pl?action=something&amp;param1&amp;param2" | grep 'cap\\|img' |
sed \ 's/&lt;src&gt;.*&lt;\/src&gt;//g;s/&lt;cap&gt;/\:/g;s/&lt;\/cap&gt;//g;s/&lt;img&gt;/\:/g;s/&lt;\/img&gt;//g'`
echo "Response received : $output"

#writing the response to a flat file to be FTPed to server B
`echo $output&gt;"rp_$newCounter.txt"`
`export filename==rp_$newCounter.txt`
`echo ls -l "rp_$newCounter.txt"`
typeset -i responseSize=`wc -c rp_$newCounter.txt | cut -d" " -f1`
echo "Response size $responseSize"

#If the process response is garbled, small or null, sending a dummy error in FTP file
if [ $responseSize = 1 ];then
`echo "We are working , try later" &gt; "rp_$newCounter.txt"`
fi

#making an FTP connection to serverB and launching the response file
`curl -s -T "rp_$newCounter.txt" -u username:password"ftp://serverB/rp_$newCounter.txt"`
echo "Uploaded the FTP file for $newCounter request"
`rm -f rp_$newCounter.txt`
echo "Deleting rp_$newCounter.txt after upload"

#Updating the request environment variable
lastCounter=$newCounter
export lastCounter
fi
else
lastCounter=`curl -s http://serverB/mobRequests.txt | tail -1 | cut -d: -f1`
export lastCounter
fi
done
</pre>
<p>The whole system works very well, and the requests are processed and response send to user. There are however limitations to this model.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twistedgenes.com/2008/12/a-strikingly-odd-web-application-exposure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrade Fedora without burning the DVD/CDs</title>
		<link>http://www.twistedgenes.com/2008/11/upgrade-fedora-without-burning-the-dvdcds/</link>
		<comments>http://www.twistedgenes.com/2008/11/upgrade-fedora-without-burning-the-dvdcds/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 17:27:27 +0000</pubDate>
		<dc:creator>Rakesh</dc:creator>
				<category><![CDATA[Cool]]></category>
		<category><![CDATA[Experiences]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Rocking]]></category>
		<category><![CDATA[Truth]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Fedora]]></category>

		<guid isPermaLink="false">http://www.twistedgenes.com/?p=130</guid>
		<description><![CDATA[An upgrade of Fedora Core version normally requires burning the new version&#8217;s image in a DVD or CDs.  An alternate approach to the same is upgrading by copying the same to a hard drive or a pen drive. The approach mentioned below worked very well from me for an upgrade of FC9 to FC10.
Download the [...]]]></description>
			<content:encoded><![CDATA[<p>An upgrade of <a href="http://fedoraproject.org" target="_blank">Fedora Core</a> version normally requires burning the new version&#8217;s image in a DVD or CDs.  An alternate approach to the same is upgrading by copying the same to a hard drive or a pen drive. The approach mentioned below worked very well from me for an upgrade of FC9 to FC10.</p>
<p>Download the new version&#8217;s (say FC 10)  iso(DVD) image and save it to a disk drive partition. I used a pen drive for the same. It works very well for filesystems viz. FAT32,ext2 and not NTFS. Copy the image file to any directory say for example /mnt/FedoraCoreDVD.iso( Assuming, that pen drive is mounted at /mnt) . Mount the iso image in a directory(any) to extract the isolinux folder.</p>
<p><span style="#ff0000;"><span style="#ff0000;">#mount -o loop /mnt/FedoraCoreDVD.iso /home/user/Fedora/</span></span></p>
<p>Copy the isolinux folder and paste it inside the boot folder.</p>
<p><span style="#ff0000;">#cp -r /home/user/Fedora/isolinux /boot</span></p>
<p>Now we need to make an entry in the <a href="http://www.gnu.org/software/grub" target="_blank">grub file</a> to boot the copied isolinux folder&#8217;s install.img</p>
<p><span style="#ff0000;"># cat /etc/grub.conf</span></p>
<p>______________________________</p>
<p><span style="#ff0000;">title Fedora Upgrade<br />
root (hd0,8) </span>&#8212;&#8212;&#8212;&#8211;&gt; should be your  partition containing the current linux installation (0-&gt;First Hard Drive,8-&gt; Partition number on this drive )<br />
<span style="#ff0000;">kernel /isolinux/vmlinuz<br />
initrd /isolinux/initrd.img</span><br />
______________________________</p>
<p>Copy the isolinux folder also to the pen drive(/dev/sdb, mounted at /mnt in this case) and reboot the system. Select the &#8221; Fedora Upgrade&#8221; option in grub and the normal installation/upgrade demon anaconda will start. It will ask for the option of disk partition and folder containing the iso image and iso linux folder, which is /dev/sdb1 in this case. Select the same and the upgradation works like a charm.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twistedgenes.com/2008/11/upgrade-fedora-without-burning-the-dvdcds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Virtual Machine on Fedora</title>
		<link>http://www.twistedgenes.com/2008/10/virtual-machine-on-fedora/</link>
		<comments>http://www.twistedgenes.com/2008/10/virtual-machine-on-fedora/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 18:26:00 +0000</pubDate>
		<dc:creator>Rakesh</dc:creator>
				<category><![CDATA[Cool]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://rak19.wordpress.com/2008/10/09/virtual-machine-on-fedora/</guid>
		<description><![CDATA[Fedora comes with a virtual machine manager( similar to vmware products) which enables you to create a virtual machine and run various other operating system. I tried installing Windows XP on a virtual machine created using virt-manager in my Fedora. Key steps to begin ..
- Make sure libvirtd demon is running- Allocate the space as [...]]]></description>
			<content:encoded><![CDATA[<p>Fedora comes with a virtual machine manager( similar to vmware products) which enables you to create a virtual machine and run various other operating system. I tried installing Windows XP on a virtual machine created using virt-manager in my Fedora. Key steps to begin ..</p>
<p>- Make sure libvirtd demon is running<br />- Allocate the space as per your needs viz hard disk, RAM etc<br />- This one is the key step, do not forget to add a cdrom (/dev/hdc) pointning to iso image of Windows XP Disc, as after the first boot, XP installation searches for the Windows XP disk and it cannot read the host&#8217;s CDROM.</p>
<p>Everything goes on smooth with all these parameters.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twistedgenes.com/2008/10/virtual-machine-on-fedora/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SELinux, Apache and Postgres SQL Connectivity</title>
		<link>http://www.twistedgenes.com/2008/09/selinux-apache-and-postgres-sql-connectivity/</link>
		<comments>http://www.twistedgenes.com/2008/09/selinux-apache-and-postgres-sql-connectivity/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 23:31:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Experiences]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Rocking]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://rak19.wordpress.com/2008/09/25/selinux-apache-and-postgres-sql-connectivity/</guid>
		<description><![CDATA[Recently, I decided to migrate the work from Apache windows to the Apache running on my Vmware fedora machine. Everything was supposed to work like a charm. Unfortunately, it did not. The perl  in the cgi-bin directory was throwing internal server error 500. The apache error log indicated &#8216;permission denied to create a socket&#8217;, [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align:justify;font-family:verdana;">Recently, I decided to migrate the work from Apache windows to the Apache running on my Vmware fedora machine. Everything was supposed to work like a charm. Unfortunately, it did not. The perl  in the cgi-bin directory was throwing internal server error 500. The apache error log indicated &#8216;permission denied to create a socket&#8217;, &#8216;premature end of the script headers&#8217;. The stuff was supposed to be retrieved from postgres sql database by the perl thingy. It appeared to me that database server is not allowing my IP address to establish a connection, as recomended by pgadmin as well. After a successful entry of my IP in the conf file of postgres database server, problem still persisted. I tried almost everything, changing the file owner to apache, suexec in apache and hell lots of other possibilities. Then in the trial process I noticed a small pop up in the corner of the window, SELinux denial. SELinux is an enhanced feature in Linux, that can put restrictions on your applications in apache making database connection, nmap, access to network filesystem and lots and lots more. After giving apache persmission to make database connections, the error was resolved and application ran smoothly.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.twistedgenes.com/2008/09/selinux-apache-and-postgres-sql-connectivity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQUID Proxy Server Authenticated Mode</title>
		<link>http://www.twistedgenes.com/2008/09/squid-proxy-server-authenticated-mode/</link>
		<comments>http://www.twistedgenes.com/2008/09/squid-proxy-server-authenticated-mode/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 00:45:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cool]]></category>
		<category><![CDATA[Crazy]]></category>
		<category><![CDATA[Experiences]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Rocking]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://rak19.wordpress.com/2008/09/21/squid-proxy-server-authenticated-mode/</guid>
		<description><![CDATA[We run a squid proxy server at our two system network at home   in unauthenticated mode. I was just going through the squid logs at /var/logs/squid/access.log, and I saw few miscreant IPs eating up my network bandwith by using our proxy server. Then, I decided to tune up the authentication mode for squid proxy [...]]]></description>
			<content:encoded><![CDATA[<div align="justify"><span>We run a squid proxy server at our two system network at home <img src='http://www.twistedgenes.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  in unauthenticated mode. I was just going through the squid logs at /var/logs/squid/access.log, and I saw few miscreant IPs eating up my network bandwith by using our proxy server. Then, I decided to tune up the authentication mode for squid proxy server. Squid doesn&#8217;t have its authentication module and we need to us LDAP,PAM or NCSA. I came accross NCSA based authentication at http://www.cyberciti.biz/tips/linux-unix-squid-proxy-server-authentication.html. Given below. It worked very well in our case. </p>
<p><strong>Configure an NCSA-style username and password authenticatio</strong>n</p>
<p>I am going to assume that squid is installed and working fine.</p>
<p>Tip: Before going further, test basic Squid functionality. Make sure squid is functioning without requiring authorization <img src='http://www.twistedgenes.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <br />Step # 1: Create a username/password</p>
<p>First create a NCSA password file using htpasswd command. htpasswd is used to create and update the flat-files used to store usernames and password for basic authentication of squid users.<br /># htpasswd /etc/squid/passwd user1<br />Output:</p>
<p>New password:<br />Re-type new password:<br />Adding password for user user1</p>
<p>Make sure squid can read passwd file:<br /># chmod o+r /etc/squid/passwd<br />Step # 2: Locate nsca_auth authentication helper</p>
<p>Usually nsca_auth is located at /usr/lib/squid/ncsa_auth. You can find out location using rpm (Redhat,CentOS,Fedora) or dpkg (Debian and Ubuntu) command:<br /># dpkg -L squid | grep ncsa_auth<br />Output:</p>
<p>/usr/lib/squid/ncsa_auth</p>
<p>If you are using RHEL/CentOS/Fedora Core or RPM based distro try:<br /># rpm -ql squid | grep ncsa_auth<br />Output:</p>
<p>/usr/lib/squid/ncsa_auth</p>
<p>Step # 3: Configure nsca_auth for squid proxy authentication</p>
<p>Now open /etc/squid/squid.conf file<br /># vi /etc/squid/squid.conf<br />Append (or modify) following configration directive:<br />auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd<br />auth_param basic children 5<br />auth_param basic realm Squid proxy-caching web server<br />auth_param basic credentialsttl 2 hours<br />auth_param basic casesensitive off</p>
<p>Also find out your ACL section and append/modify<br />acl ncsa_users proxy_auth REQUIRED<br />http_access allow ncsa_users<br />Make sure that you do not have any other http_access statement.  <br />Save and close the file.</p>
<p>Where,</p>
<p>  * auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd : Specify squid password file and helper program location<br />  * auth_param basic children 5 : The number of authenticator processes to spawn.<br />  * auth_param basic realm Squid proxy-caching web server : Part of the text the user will see when prompted their username and password<br />  * auth_param basic credentialsttl 2 hours : Specifies how long squid assumes an externally validated username:password pair is valid for &#8211; in other words how often the helper program is called for that user with password prompt. It is set to 2 hours.<br />  * auth_param basic casesensitive off : Specifies if usernames are case sensitive. It can be on or off only<br />  * acl ncsa_users proxy_auth REQUIRED : The REQURIED term means that any authenticated user will match the ACL named ncsa_users<br />  * http_access allow ncsa_users : Allow proxy access only if user is successfully authenticated.</p>
<p>Restart squid:<br /># /etc/init.d/squid restart</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.twistedgenes.com/2008/09/squid-proxy-server-authenticated-mode/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Vaccum kills us, space kills javascript</title>
		<link>http://www.twistedgenes.com/2008/09/vaccum-kills-us-space-kills-javascript/</link>
		<comments>http://www.twistedgenes.com/2008/09/vaccum-kills-us-space-kills-javascript/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 09:40:00 +0000</pubDate>
		<dc:creator>Rakesh</dc:creator>
				<category><![CDATA[Cool]]></category>
		<category><![CDATA[Experiences]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Rocking]]></category>
		<category><![CDATA[Truth]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://rak19.wordpress.com/2008/09/16/vaccum-kills-us-space-kills-javascript/</guid>
		<description><![CDATA[I was exporting certain attributes viz roadname, ids, ways etc which were of alphanumeric type by appending them with a &#8216;+&#8217; charachter from my server side perl program to the javascript program at the client. The firebug popped up, unterminated string literal, lets see whats that &#8230;. Googling did not turned out to be of [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align:justify;"><span class="Apple-style-span" style="font-family:'trebuchet ms';">I was exporting certain attributes viz roadname, ids, ways etc which were of alphanumeric type by appending them with a &#8216;+&#8217; charachter from my server side perl program to the javascript program at the client. The firebug popped up, </span><span class="Apple-style-span" style="color:rgb(255,0,0);"><span class="Apple-style-span" style="font-family:'trebuchet ms';">unterminated string literal</span></span><span class="Apple-style-span" style="font-family:'trebuchet ms';">, lets see whats that &#8230;. Googling did not turned out to be of much help. I tried making the string short, taking into an array etc. Sometimes it worked, sometimes it did not. Amazed, I came to a stupid conclusion on the size of the arguments that need to be passed. Perhaps, that was not the cause.On of my appended field was having a space, and string thereafter was considered as a different argument by javascript. Due to mismatch in the number of arguments for that js function, it was breaking. Such a silly mistake !!! <img src='http://www.twistedgenes.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</span></div>
<div style="text-align:justify;"><span class="Apple-style-span" style="font-size:medium;"><span class="Apple-style-span" style="font-family:'trebuchet ms';">Hence,</span></span><span class="Apple-style-span" style="font-size:medium;"><span class="Apple-style-span" style="font-family:'trebuchet ms';"> </span></span><span class="Apple-style-span" style="white-space:pre;"><span class="Apple-style-span" style="font-size:medium;"><span class="Apple-style-span" style="font-family:'trebuchet ms';">Vaccum kills us, space kills javascript or rather any function in any damn<br />language.</span></span><span class="Apple-style-span" style="font-size:medium;"><span class="Apple-style-span" style="font-family:'trebuchet ms';"> </span></span></span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.twistedgenes.com/2008/09/vaccum-kills-us-space-kills-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Draw a Circle in Java, the fundamental &#8220;pixels&#8221; way !</title>
		<link>http://www.twistedgenes.com/2008/06/draw-a-circle-in-java-the-fundamental-pixels-way/</link>
		<comments>http://www.twistedgenes.com/2008/06/draw-a-circle-in-java-the-fundamental-pixels-way/#comments</comments>
		<pubDate>Sun, 22 Jun 2008 00:16:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cool]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Rocking]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://rak19.wordpress.com/2008/06/21/draw-a-circle-in-java-the-fundamental-pixels-way/</guid>
		<description><![CDATA[The following code draws a circle of particular diameter by setting the PIXELS falling inside the circle to a different RGB value. It involves simple co-ordinate geometry fundas. There are some approximations being taken.


import java.awt.image.*;import javax.swing.*;import javax.swing.JComponent.*;
public class circles extends JFrame {public static void main(String args[])     {double d=Double.parseDouble(args[0]);   int [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bp2.blogger.com/_1pCudCDCfOY/SF1U-D7XTjI/AAAAAAAABBk/Lv_jtx_3Z8U/s1600-h/Screenshot-1.png"><img style="float:left;cursor:pointer;margin:0 10px 10px 0;" src="http://bp2.blogger.com/_1pCudCDCfOY/SF1U-D7XTjI/AAAAAAAABBk/Lv_jtx_3Z8U/s320/Screenshot-1.png" alt="" border="0" /></a><span style="font-family:courier new;">The following code draws a circle of particular diameter by setting the PIXELS falling inside the circle to a different RGB value. It involves simple co-ordinate geometry fundas. There are some approximations being taken.</span></p>
<p><span style="font-family:verdana;"><br />
</span></p>
<p><span style="color:rgb(0,0,0);font-family:trebuchet ms;"><span style="font-family:courier new;">import java.awt.image.*;</span><br /><span style="font-family:courier new;">import javax.swing.*;</span><br /><span style="font-family:courier new;">import javax.swing.JComponent.*;</span></p>
<p></span><span style="color:rgb(0,0,0);font-family:trebuchet ms;"><span style="font-family:courier new;">public class circles extends JFrame {</span><br /><span style="font-family:courier new;">public static void main(String args[])     {</span><br /><span style="font-family:courier new;">double d=Double.parseDouble(args[0]);   <br />int diameter= (int)d;</span><br /><span style="font-family:courier new;">circles ca= new circles();      </span><br /><span style="font-family:courier new;">ca.drawCircle(diameter);</span><br /><span style="font-family:courier new;">}</span><br /><span style="font-family:courier new;">public void drawCircle(int diameter) {</span><br /><span style="font-family:courier new;">    int x=0,y=0,radius;  </span><br /><span style="font-family:courier new;">    JFrame frame=new JFrame();</span><br /><span style="font-family:courier new;">JLabel lab;</span><br /><span style="font-family:courier new;">    BufferedImage bi=new BufferedImage (diameter,diameter,BufferedImage.TYPE_BYTE_GRAY );</span><br /><span style="font-family:courier new;">    WritableRaster raster=bi.getRaster();</span><br /><span style="font-family:courier new;">    double [] iPix=new double [diameter*diameter]; <br />if(diameter%2 == 1) {<br />        diameter-=1;<br />        }   <br /></span><span style="font-family:courier new;">    radius=diameter/2;</span><br /><span style="font-family:courier new;">    for(int i=0;i</span></span><span style="color:rgb(0,0,0);font-family:courier new;">(radius)){<br /></span><span style="color:rgb(0,0,0);font-family:courier new;">                y=y%(radius);<br /></span><span style="color:rgb(0,0,0);font-family:courier new;">            }<br /></span><span style="color:rgb(0,0,0);font-family:courier new;">else<br />{<br /></span><span style="color:rgb(0,0,0);font-family:courier new;">y-=radius;</span><br /><span style="color:rgb(0,0,0);font-family:courier new;">                y=-y;</span><br /><span style="color:rgb(0,0,0);font-family:courier new;">                     } </span><br /><span style="color:rgb(0,0,0);font-family:courier new;">            if((x*x+y*y)&lt;=((radius)*(radius)))    {                 iPix[i]=255;             }             else  {             iPix[i]=0;             }  }</span><span style="color:rgb(0,0,0);font-family:courier new;"><br />raster.setPixels(0,0,diameter,diameter,iPix);     lab=new JLabel(new ImageIcon(bi));                frame.add(lab);</span><br /><span style="color:rgb(0,0,0);font-family:courier new;"> frame.setVisible(true);        frame.setSize(600,600);<br /></span><span style="color:rgb(0,0,0);font-family:courier new;">}         </span><br /><span style="color:rgb(0,0,0);font-family:courier new;">}</span><br /><span style="font-family:courier new;"></p>
<p></span><span style="color:rgb(51,0,153);font-family:courier new;">compile the program as javac circles.java</p>
<p></span><span style="color:rgb(51,0,153);font-family:courier new;">run as java circles diameter_value</p>
<p></span><span style="color:rgb(51,0,153);font-family:courier new;">e.g. java circles 500</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.twistedgenes.com/2008/06/draw-a-circle-in-java-the-fundamental-pixels-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Swap two numbers without a &#8216;=&#8217; operator</title>
		<link>http://www.twistedgenes.com/2008/06/swap-two-numbers-without-a-operator/</link>
		<comments>http://www.twistedgenes.com/2008/06/swap-two-numbers-without-a-operator/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 17:36:00 +0000</pubDate>
		<dc:creator>Rakesh</dc:creator>
				<category><![CDATA[Cool]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Rocking]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://rak19.wordpress.com/2008/06/11/swap-two-numbers-without-a-operator/</guid>
		<description><![CDATA[Came across an interesting problem of swapping two numbers without using &#8216;=&#8217; operator. I thought of this approach. It&#8217;s little lengthy and can be modified I guess.________________________________________________________________________________________________________________________________________________________
#includestatic int counter;int main(){int a,b;printf(&#8221;Enter two numbers&#8221;);scanf(&#8221;%d%d&#8221;,&#38;a,&#38;b);
if(a&#62;b){switch ((a-b)%2){case 0 :while((a-b))       {       counter++;      [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-family:courier new;">Came across an interesting problem of swapping two numbers without using &#8216;=&#8217; operator. I thought of this approach. It&#8217;s little lengthy and can be modified I guess.<br />____________________________________________________________________________<br /></span><span style="font-family:courier new;">____________________________________________________________________________</p>
<p></span><span style="font-family:courier new;">#include<br />static int counter;<br />int main()<br />{<br />int a,b;<br />printf(&#8221;Enter two numbers&#8221;);<br />scanf(&#8221;%d%d&#8221;,&amp;a,&amp;b);</p>
<p>if(a&gt;b)<br />{<br />switch ((a-b)%2)<br />{<br />case 0 :while((a-b))<br />       {<br />       counter++;<br />       a&#8211;;<br />       b++;<br />   }<br />   while (counter &gt;0)<br />       {<br />       counter&#8211;;<br />       a&#8211;;<br />       b++;<br />       }<br />   printf(&#8221;\nThe swapped set : %d\t%d&#8221;,a,b);<br />   break;<br />case 1 :while((a-b-1))<br />       {<br />       counter++;<br />       a&#8211;;<br />       b++;<br />   }<br />   counter++;<br />   while (counter &gt;0)<br />       {<br />       counter&#8211;;<br />       a&#8211;;<br />       b++;<br />       }<br />   printf(&#8221;\nThe swapped set : %d\t%d&#8221;,a,b);<br />   break;<br />}<br />}</p>
<p>else<br />{<br />switch ((b-a)%2)<br />{<br />case 0 :while((b-a))<br />       {<br />       counter++;<br />       a++;<br />       b&#8211;;<br />   }<br />   while (counter &gt;0)<br />       {<br />       counter&#8211;;<br />       a++;<br />       b&#8211;;<br />       }<br />   printf(&#8221;\nThe swapped set : %d\t%d&#8221;,a,b);<br />   break;<br />case 1 :while((b-a-1))<br />       {<br />       counter++;<br />       a++;<br />       b&#8211;;<br />   }<br />   counter++;<br />   while (counter &gt;0)<br />       {<br />       counter&#8211;;<br />       a++;<br />       b&#8211;;<br />       }<br />   printf(&#8221;\nThe swapped set : %d\t%d&#8221;,a,b);<br />   break;<br />}<br />}<br />return 0;<br />}</p>
<p></span><span style="font-family:courier new;">____________________________________________________________________________<br /></span><span style="font-family:courier new;">____________________________________________________________________________</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.twistedgenes.com/2008/06/swap-two-numbers-without-a-operator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Determining IP address for eth0 failed</title>
		<link>http://www.twistedgenes.com/2008/04/determining-ip-address-for-eth0-failed/</link>
		<comments>http://www.twistedgenes.com/2008/04/determining-ip-address-for-eth0-failed/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 18:19:00 +0000</pubDate>
		<dc:creator>Rakesh</dc:creator>
				<category><![CDATA[Cool]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Rocking]]></category>
		<category><![CDATA[Truth]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://rak19.wordpress.com/2008/04/22/determining-ip-address-for-eth0-failed/</guid>
		<description><![CDATA[
I had a tough time configuring wired internet connection on UBUNTU (7.10 Gusty Gibbon) and FEDORA Core 8 boxes. However after few amendments, I was able to fix and start internet in both. The Network Adapter (eth0) was not able to take IP address from the DHCP servers of my ISP ( Reliance, the case [...]]]></description>
			<content:encoded><![CDATA[<p><!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  -->
<p align="justify"><span style="font-family:DejaVu Sans, sans-serif;">I had a tough time configuring wired internet connection on UBUNTU (7.10 Gusty Gibbon) and FEDORA Core 8 boxes. However after few amendments, I was able to fix and start internet in both. <b>The Network Adapter (eth0) was not able to take IP address from the DHCP servers </b>of my ISP ( Reliance, the case here) because the Linux distros support the future i.e. IPv6. Hence, the task at hand was to disable IPv6 and enable IPv4.</span></p>
<p align="justify"><span style="font-family:DejaVu Sans, sans-serif;">Let us discuss both of them in detail.</span></p>
<p align="justify"><span style="font-family:DejaVu Sans, sans-serif;"><u>Ubuntu </u></span> </p>
<p align="justify"><span style="font-family:DejaVu Sans, sans-serif;">There is process avahi-demon running which is responsible for IPv6 assignment. It can be disabled by removing from the following location<br /><span style="color:#330099;"><i>/etc/init.d/avahi-demon</i></span>. Please not that all these should be done as sudo.<br />This should be able to fix the problem. You can restart the network and network interfaces by</span></p>
<p align="justify"><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><i>/etc/init.d/networking restart<br />ifdown eth0<br />ifup eth0</i></span></span></p>
<p><span style="font-family:DejaVu Sans, sans-serif;">Also, the interfaces file specifies starting of Network adapter and assigning address.<br />cd /etc/Network/interface</p>
<p>It should have following entry to take IP from dhcp server for eth0.</span></p>
<pre style="border:1px solid rgb(0,0,0);text-align:left;padding:.07in;"><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><i># The loopback network interface</i></span></span><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><i>auto lo</i></span></span><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><i>iface lo inet loopback</i></span></span>

<span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><i># The primary network interface</i></span></span><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><i>auto eth0</i></span></span><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><i>iface eth0 inet dhcp</i></span></span></pre>
<p> <span style="font-family:DejaVu Sans, sans-serif;"><br />Forcibly , IP address can be assigned by <span style="color:#330099;"><i>dhclient eth0.</i></span><i></p>
<p></i><u>Fedora Core</u></p>
<p>Disabling IPv6 in Fedora core 8 can also be done in similar fashion.</span></p>
<p><span style="font-family:DejaVu Sans, sans-serif;">Now here is how you can do this with FC8 to disable IPv6:</span></p>
<ol>
<li>
<p style="margin-bottom:0;"><span style="font-family:DejaVu Sans, sans-serif;"><span style="font-size:100%;">Append  the following line to </span></span><span style="font-size:100%;"><code><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><i>/etc/modprobe.conf</i></span></span></code></span><span style="font-size:100%;color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><i>:</i></span></span><span style="font-family:DejaVu Sans, sans-serif;font-size:100%;"><br /></span><span style="font-size:100%;"><code><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><i>install  ipv6 /bin/true<br /></i></span></span></code></span><span style="font-size:85%;color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><i>alias  net-pf-10 off<br />alias ipv6 off </i></span></span>  </p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:DejaVu Sans, sans-serif;">Append  the following line to </span><code style="color:rgb(51,0,153);"><span style="font-family:DejaVu Sans, sans-serif;"><span style="font-size:130%;"><i>/etc/sysconfig/network</i></span></span></code><span style="color:rgb(51,0,153);font-family:DejaVu Sans, sans-serif;"><span style="font-size:130%;"><i>:</i></span></span><span style="font-family:DejaVu Sans, sans-serif;"><br /></span><code style="color:rgb(51,0,153);"><span style="font-family:DejaVu Sans, sans-serif;"><span style="font-size:100%;"><i>NETWORKING_IPV6=no</i></span></span></code><span style="font-family:DejaVu Sans, sans-serif;"><i>  </i></span>  </p>
</li>
<li>
<p><span style="font-family:DejaVu Sans, sans-serif;">Ensure your network  adapter is configured not to use IPv6. This is an easy edit in the  </span><code><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><span style="font-size:130%;"><i>system-config-network</i></span></span></span></code><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;">  <span style="color:rgb(0,0,0);">gui, or do it manually in</span> </span></span><code><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><span style="font-size:130%;">/etc/sysconfig/network-scripts/ifcfg-eth0</span></span></span></code><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;">  <span style="color:rgb(0,0,0);">(ammend for name of your adapter) by appending </span></span></span><code><span style="color:#330099;"><span style="font-family:DejaVu Sans, sans-serif;"><span style="font-size:130%;"><i>IPV6INIT=no</i></span></span></span></code><span style="font-family:DejaVu Sans, sans-serif;">  </span>  </p>
</li>
</ol>
<p><span style="font-family:DejaVu Sans, sans-serif;">To restart the Network Adapter and assign address using DHCP.<br />  <span style="color:#330099;">  </span><span style="color:#330099;"><i>ifconfig eth0 down</i></span><i><br /></i><span style="color:#330099;"><i>    ifconfig eth0 up</i></span><i><br /></i><span style="color:#330099;"><i>    dhclient eth0</i></span><i></p>
<p></i>After all these changes are made the network adapter takes an IPv4 IP address and works fine.<i><br /></i></span></p>
<p align="justify">
<p style="margin-bottom:0;"></p>
]]></content:encoded>
			<wfw:commentRss>http://www.twistedgenes.com/2008/04/determining-ip-address-for-eth0-failed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hey dude, shutdown the machine, enough of surfing. Oops ! but the dude is sleeping!</title>
		<link>http://www.twistedgenes.com/2007/06/hey-dude-shutdown-the-machine-enough-of-surfing-oops-but-the-dude-is-sleeping/</link>
		<comments>http://www.twistedgenes.com/2007/06/hey-dude-shutdown-the-machine-enough-of-surfing-oops-but-the-dude-is-sleeping/#comments</comments>
		<pubDate>Fri, 01 Jun 2007 10:46:00 +0000</pubDate>
		<dc:creator>Rakesh</dc:creator>
				<category><![CDATA[Cool]]></category>
		<category><![CDATA[Crazy]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://rak19.wordpress.com/2007/06/01/hey-dude-shutdown-the-machine-enough-of-surfing-oops-but-the-dude-is-sleeping/</guid>
		<description><![CDATA[Last night, i had a situation. A download was running on my Windows Server 2003 machine. But i had to retire for the bed and shutdown the machine after two hours. The command line interface permits to shutdown machine till a maximum of ten minutes* delay only. Hence, i started surfing the web for some [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align:justify;"><span style="font-family:trebuchet ms;font-size:100%;">Last night, i had a situation. A download was running on my <span style="font-weight:bold;">Windows Server 2003</span> machine. But i had to retire for the bed and shutdown the machine after two hours. The <span style="color:#990000;">command line interface</span> permits to shutdown machine till a maximum of <span style="color:#999900;font-weight:bold;">ten minutes*</span> delay only. Hence, i started surfing the web for some auto shutdown timer softwares. But apart from giving fancy multicolored buttons for reboot and standby, i got nothing useful. Then i came up with the following.<br />
</span><span style="font-size:100%;"><br />
</span><span style="font-weight:bold;font-family:trebuchet ms;font-size:100%;"><span style="font-style:italic;">File &#8211; shutdown.pl<br />
</span></span><span style="font-family:trebuchet ms;font-size:100%;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
</span><span style="font-family:trebuchet ms;font-size:100%;"><span style="color:#660000;">#! /usr/bin/perl<br />
</span></span><span style="font-family:trebuchet ms;font-size:100%;"><span style="color:#660000;">sleep(5400);<span style="font-size:85%;"> # time in seconds after which you want to shutdown.Its 5400 seconds here or 90 minutes.</span><br />
</span></span><span style="font-family:trebuchet ms;font-size:100%;"><span style="color:#660000;">system(&#8221;shutdown /s /t 00&#8243;);<br />
<span style="font-weight:bold;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span><br />
</span></span><span style="font-family:trebuchet ms;font-size:100%;">Run the program as <span style="font-weight:bold;">perl shutdown.pl<br />
</span></span><span style="font-family:trebuchet ms;font-size:100%;">And my job was done. <span style="color:#000099;">However there might be more smarter ways to handle the situation.</span></span><span style="font-size:100%;"><br />
</span></div>
<p><span style="font-size:85%;"><span style="font-family:verdana;"><span style="color:#000099;"><span style="font-size:100%;"><br />
</span><span style="font-weight:bold;font-size:100%;">__________________________________________________________________________________</span></span></span></span></p>
<p><span style="font-size:78%;">*type shutdown on windows server 2003 command prompt and read carefully<br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.twistedgenes.com/2007/06/hey-dude-shutdown-the-machine-enough-of-surfing-oops-but-the-dude-is-sleeping/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-4811008-2");
pageTracker._setDomainName(".twistedgenes.com");
pageTracker._trackPageview();
} catch(err) {}</script>