<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Random Noise</title>
	<atom:link href="http://serialize.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://serialize.wordpress.com</link>
	<description>cat /dev/random &#62;&#62; /dev/dsp</description>
	<lastBuildDate>Tue, 01 Jan 2013 16:53:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='serialize.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Random Noise</title>
		<link>http://serialize.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://serialize.wordpress.com/osd.xml" title="Random Noise" />
	<atom:link rel='hub' href='http://serialize.wordpress.com/?pushpress=hub'/>
		<item>
		<title>BDA Graph using GraphEdit for Genpix</title>
		<link>http://serialize.wordpress.com/2013/01/01/bda-graph-using-graphedit-for-genpix/</link>
		<comments>http://serialize.wordpress.com/2013/01/01/bda-graph-using-graphedit-for-genpix/#comments</comments>
		<pubDate>Tue, 01 Jan 2013 16:53:46 +0000</pubDate>
		<dc:creator>Vivek Unune</dc:creator>
				<category><![CDATA[VC++]]></category>
		<category><![CDATA[bda]]></category>
		<category><![CDATA[genpix]]></category>

		<guid isPermaLink="false">http://serialize.wordpress.com/?p=183</guid>
		<description><![CDATA[Pictures speak thousand words.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=183&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://serialize.wordpress.com/2013/01/01/bda-graph-using-graphedit-for-genpix/genpix-graph/" rel="attachment wp-att-184"><img class="alignnone size-medium wp-image-184" alt="genpix-graph" src="http://serialize.files.wordpress.com/2013/01/genpix-graph.png?w=300&#038;h=163" width="300" height="163" /></a> <img class="alignnone size-medium wp-image-185" alt="genpix-graph-2" src="http://serialize.files.wordpress.com/2013/01/genpix-graph-2.png?w=300&#038;h=168" width="300" height="168" /></p>
<p>Pictures speak thousand words.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/serialize.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/serialize.wordpress.com/183/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=183&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://serialize.wordpress.com/2013/01/01/bda-graph-using-graphedit-for-genpix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/54fbdf814723425c6ce3e94aefaad4c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Vivek</media:title>
		</media:content>

		<media:content url="http://serialize.files.wordpress.com/2013/01/genpix-graph.png?w=300" medium="image">
			<media:title type="html">genpix-graph</media:title>
		</media:content>

		<media:content url="http://serialize.files.wordpress.com/2013/01/genpix-graph-2.png?w=300" medium="image">
			<media:title type="html">genpix-graph-2</media:title>
		</media:content>
	</item>
		<item>
		<title>ssh: Server refused our key</title>
		<link>http://serialize.wordpress.com/2012/12/17/server-refused-our-key/</link>
		<comments>http://serialize.wordpress.com/2012/12/17/server-refused-our-key/#comments</comments>
		<pubDate>Mon, 17 Dec 2012 16:47:44 +0000</pubDate>
		<dc:creator>Vivek Unune</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[puttygen]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://serialize.wordpress.com/?p=180</guid>
		<description><![CDATA[I know you must be banging your head against the wall over this. I did. Make sure use are logged in as the user you want to give ssh permission to: su sshuser cd ~/ All you need to do is fix the permissions and owner on .ssh and authorized_keys: chmod 700 ~/.ssh chmod 600 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=180&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I know you must be banging your head against the wall over this. I did.</p>
<p>Make sure use are logged in as the user you want to give ssh permission to:</p>
<pre>su sshuser
cd ~/</pre>
<p>All you need to do is fix the permissions and owner on .ssh and authorized_keys:</p>
<pre>chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown sshuser:sshuser ~/.ssh
chown sshuser:sshuser ~/.ssh/authorized_keys

</pre>
<p>This should do the work.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/serialize.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/serialize.wordpress.com/180/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=180&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://serialize.wordpress.com/2012/12/17/server-refused-our-key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/54fbdf814723425c6ce3e94aefaad4c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Vivek</media:title>
		</media:content>
	</item>
		<item>
		<title>Windows 8 or not to Windows 8</title>
		<link>http://serialize.wordpress.com/2012/10/25/windows-8-or-not-to-windows-8/</link>
		<comments>http://serialize.wordpress.com/2012/10/25/windows-8-or-not-to-windows-8/#comments</comments>
		<pubDate>Thu, 25 Oct 2012 21:08:52 +0000</pubDate>
		<dc:creator>Vivek Unune</dc:creator>
		
		<guid isPermaLink="false">http://serialize.wordpress.com/?p=177</guid>
		<description><![CDATA[I clearly remember how exited I was when I got the Windows XP Beta CD with one of the magazines my friend use to subscribe (BYTE?). I used Windows 98 then. And I knew in and out of the OS like nothing else. After observing the UI overhaul in XP I was truly impressed. I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=177&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I clearly remember how exited I was when I got the Windows XP Beta CD with one of the magazines my friend use to subscribe (BYTE?). I used Windows 98 then. And I knew in and out of the OS like nothing else. After observing the UI overhaul in XP I was truly impressed. I actually use to peek inside the system dlls for cool icons shipped with XP.</p>
<p>Fast Forward 10 years and I&#8217;m in same situation. After using Windows 7 for over 2 years &#8211; I have my brain wired to it. And I love it. I have a win7 on laptop and HTPC which run 24/7. With dedicated linux NAS to store media. Windows 8  RTM was out on MSDN over two months ago, immediately I wanted to take it for a spin. So, I installed it on my HTPC. After two months all I can say is that the pain is unbelievable!</p>
<p>1. Start button &#8211; I must be the millionth person to say this. Listen MS &#8211; ability to view installed applications and quickly access it is necessary. Now you would argue you can do the same from Metro screen. No &#8211; it takes up lot of scrolling and searching for the &#8220;tile&#8221; and trying to recognize the icon for that application! I end up creating shortcuts of all the frequent programs on desktop -which is ugly. Even my wife misses the start button utterly. Utter pain without it.</p>
<p>2. Take me directly to desktop if I&#8217;m using a desktop! - Why do we have the metro welcome/lock screen? Then again I have to go through the metro apps screen to get to desktop!</p>
<p>3. Dropping out the HD codecs and filters! &#8211; the whole idea of skipping the hd codecs was pretty lame on MS part. I have a sizable bluray and hd library stored on NAS. With AV receiver and a flat screen hooked to the HTPC &#8211; it needs hd codecs out of the box to play these files. After the first day of installation &#8211; my wife got frustrated as to why those files aren&#8217;t working anymore. She resorted to the win7 laptop instead. When I was back from work I had to install FFDshow filters to get the files to work. Seriously MS &#8211; if people have to end up using opensource directshow filters why bother paying for windows at all. I will be more than happy to install Ubuntu or Openelec (XBMC).</p>
<p>4. I&#8217;m a power user and let me control my machine &#8211; The biggest gripe that I have is getting things done. It has become difficult on Windows 8 to perform day-today activities. Like accessing Control Panel, Searching for files, Shutting down PC, Restarting it, accessing Device manager etc. It is a desktop not a tablet. I was so use to accessing the search. running any app was just few keys away! Why take out the search? Why is Shut Down under Settings?</p>
<p>5. Mouse vs. touch gestures &#8211; When I park my mouse at right edge of the desktop it shows me unnecessary options. Also while trying to close a window using the &#8216;x&#8217;,  the options shows up. Again while trying to open the first app (windows explorer) on the task bar. It is not only confusing but frustrating. If I&#8217;m using a desktop and when I have no devices that support touch guestures - why does windows enable touch gestures?</p>
<p>After two months of using Win8, yesterday I went back to Windows 7.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/serialize.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/serialize.wordpress.com/177/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=177&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://serialize.wordpress.com/2012/10/25/windows-8-or-not-to-windows-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/54fbdf814723425c6ce3e94aefaad4c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Vivek</media:title>
		</media:content>
	</item>
		<item>
		<title>Managing personal media and Custom NAS</title>
		<link>http://serialize.wordpress.com/2012/09/04/managing-personal-media-and-custom-nas/</link>
		<comments>http://serialize.wordpress.com/2012/09/04/managing-personal-media-and-custom-nas/#comments</comments>
		<pubDate>Tue, 04 Sep 2012 18:12:41 +0000</pubDate>
		<dc:creator>Vivek Unune</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[NAS]]></category>

		<guid isPermaLink="false">http://serialize.wordpress.com/?p=161</guid>
		<description><![CDATA[For over a year I used Buffalo Linkstation Duo Pro with 2x1TB mirrored drives. It served me well, but it was starting to gradually fill up &#8211; pictures, videos, taxes/documents, more pictures. And there were other things I wanted to move from my local drives, but still needed them to be accessible on-demand &#8211; ISOs [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=161&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>For over a year I used Buffalo Linkstation Duo Pro with 2x1TB mirrored drives. It served me well, but it was starting to gradually fill up &#8211; pictures, videos, taxes/documents, more pictures. And there were other things I wanted to move from my local drives, but still needed them to be accessible on-demand &#8211; ISOs &#8211; Linux, Windows, IDE installers, Old code etc. And then was wife&#8217;s music collection, docs etc.</p>
<p>Judging from above I came up with following requirements:<strong><br />
</strong></p>
<p>1. At least 4-6TB space. Future proof for 3-4 years<br />
2. Gigabit Network Capable. I&#8217;m done with slooow speed NAS<br />
3. Expandable. Add more space as needed.</p>
<p>There were three options available:<br />
Plan A &#8211; Buy new NAS drive(s) &#8211; solves the problem for now. Average cost $300<br />
Plan B &#8211; Build a new low power PC, install FreeNAS or something similar. Move the old NAS drives to this and add more drives. Around $300-$500<br />
Plan C &#8211; Purchase Cloud Storage subscription &#8211; varies, from monthly to year plans.</p>
<p>Considering the requirements, clearly my options were limited to Plan B. Plan A and Plan C were pre-baked solutions that did not offer me what I really needed. Plan B meant I needed to spend some time for this project.</p>
<p><strong>Components:</strong></p>
<p>I&#8217;m a big fan of <a href="http://www.microcenter.com/" target="_blank">Micro Center</a> because I can pickup components as and when I need them. Also, they offer pretty good deals and match NewEgg&#8217;s prices &#8211; minus the shipping costs. Returning stuff is hastle free as well.</p>
<p>So I started looking for best motherboard to get the job done. Essentially, I was looking for a mordern (but not latest and greatest) mobo that had 6 SATA ports, on board graphics chip and a gigabit ethernet. So, I picked up the cheapest one &#8211; Gigabyte GA-78LMT-S2P for $43 after MIR, Sempron 145 &#8211; 45W, Diablotek EVO Mid Tower ATX case, a 500W power supply and 2x1TB drives.</p>
<p>After spending sometime with the board, I realized that there is a known issue with the GA-78LMT-S2P &#8211; it fails to recognize the drives when switched to AHCI mode!! So back I returned it and got the next in line Asrock 880GM-LE FX. This one cost me $10 more, but has a better graphics chip (HD 4250). Not that I would need it. I installed the CPU and spare 4GB ram that I had. Sempron&#8217;s can be unlocked to a dual core CPUs, this one didn&#8217;t. But that was OK since I needed less power hungry machine. Then I plugged in four drives (500GB, 750GB, 2x1TB new drives)</p>
<p><strong>Software:</strong></p>
<p>I Initially installed FreeNAS on a 8GB flash drive. Now, all my drives were ntfs and soon enough I ran into issues. Drives were failing to mount since they had errors &#8211; threre is no way to fix them on linux. These needed to be fixed by connecting them to a windows machine and running <code>CHDISK /force</code>. <strong>I took a step back</strong>(read below), and thought that if all my drives are ntfs why not run windows instead? More over Windows 8 has this new feature so that you can run it off a usb drive!</p>
<p><strong>New requirement:</strong></p>
<p>At least 32GB is needed for Windows-To-Go. Which meant I need to buy a 32GB flash drive. So I did &#8211; Sandisk Glide 32 GB. Installing windows 8 on the flash drive is real pain. With help of GImageX you can copy the install.wim image on to the flash drive. The copy took around 90 minutes!! Argh! Booting from the flash drive and initial setup took around 30 minutes more! Also, using windows-to-go is really really really slow. I cannot stress it enough. Partly the issue was the Sandisk Glide drive but I think more due to how windows worked. It kept hammering the flash drive. I read that USB 3.0 will improve the speed a little and in any case my 880GM-LE FX board didn&#8217;t have it. Finally I gave in.</p>
<p>So where was I? I have to convert all my drives to etx3/4 and move around few TB of data. Before I returned the 32GB flash drive, I CHDISK&#8217;d all my drives so at least they would mount on <del>FreeNAS</del> <a href="http://partedmagic.com/doku.php" target="_blank">PartedMagic</a>. Then I connected the new drives, formatted them to ext4 and copied over the data to new drives, formatted the nas drives to ext4 and copy back the data from new drives. Same for the old 500GB and 750GB &#8211; rinse repeat.</p>
<p><strong>FreeNAS vs OpenMediaVault:</strong></p>
<p>In short, OpenMediaVault is what you want. Stable, functional and actively developed.<br />
Returned the dreadfully slow Sandisk Glide and installed OpenMediaValut on 8GB Kingston G3 drive.<br />
Configured the shares and ftp. For detailed setup please read this <a href="http://thekentishman.wordpress.com/guides-2/open-media-vault-set-up/" target="_blank">blog</a></p>
<p><strong>Performance:</strong></p>
<p>The last but not the least goal was to have gigabit copy speeds. I set the 9K MTU on the interface using the web interface and I was all set. I get around 80Mb/s copy speeds which I&#8217;m pretty satisfied.</p>
<p><strong>Expandability:</strong></p>
<p>I ended up removing the 500GB drive and moving all the important documents to it. I will pair that with another 500GB in a Raid 0 configuration. With 5 drives, I now have almost 4.75 TB of space. With 5 more drive slots to go  - it can continue to expand as needed.</p>
<p>As an engineers we are always on a quest to solve problems and in the process we sometimes over-engineer things. I think this to be true in this case. However, the new NAS would be good for another 3-4 years.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/serialize.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/serialize.wordpress.com/161/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=161&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://serialize.wordpress.com/2012/09/04/managing-personal-media-and-custom-nas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/54fbdf814723425c6ce3e94aefaad4c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Vivek</media:title>
		</media:content>
	</item>
		<item>
		<title>Blackberry: ContentHandler and ApplicationMenuItem</title>
		<link>http://serialize.wordpress.com/2010/06/30/contenthandler/</link>
		<comments>http://serialize.wordpress.com/2010/06/30/contenthandler/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 02:40:26 +0000</pubDate>
		<dc:creator>Vivek Unune</dc:creator>
				<category><![CDATA[blackberry]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JSR211]]></category>

		<guid isPermaLink="false">http://serialize.wordpress.com/?p=110</guid>
		<description><![CDATA[ContentHandler gives us the ability to register our application, so that our app is invoked automatically when user clicks to open particular type of a file. ContentHandler uses &#8216;Server &#8211; Client&#8217; model. Client requests for processing a file type and Server processes it. All the application-filetype bindings are stored in a Registry, the client must [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=110&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>ContentHandler gives us the ability to register our application, so that our app is invoked automatically<br />
when user clicks to open particular type of a file. ContentHandler uses &#8216;Server &#8211; Client&#8217; model.<br />
Client requests for processing a file type and Server processes it. All the application-filetype bindings are<br />
stored in a Registry, the client must query this registry to find out if there are any handlers available for that<br />
file type. Then invoke it.</p>
<p>To make our app a &#8216;Server&#8217;, we need to implement RequestListener. See below for sample implementation of a mp3 file handler.</p>
<p>It is important to register our app. It is recommended to perform/verify registration once during device startup.<br />
You shoud pass an argument say &#8220;startup&#8221; during startup to differentiate from other entry points.<br />
In eclipse this can be configured by editing the App_Descriptor.xml.</p>
<p>Also note that APP_IDs used for registration must be unique and failure to do so will render your app unusable.</p>
<p><pre class="brush: csharp;">
package com.serialize.apps;

public class Mp3Player extends UiApplication implements RequestListener {
	public static final long MY_APP_KEY = 0x4a23b634ab2baf78L;
	public static final String MY_APP_CLASS = Mp3Player.class.getName();
	public static final String MY_APP_ID = &quot;com.serialize.Mp3Player&quot;
	private Invocation pending;
	private ContentHandlerServer server;
	
	public Mp3Player() {
		try {
			this.server = Registry.getServer(MY_APP_CLASS);
			//start listening formp3 invocation requests
			this.server.setListener(this);	
		} catch (ContentHandlerException e) {
		}					
	}

	public static void main(String[] args) {
		// On device startup register our app
		if (args != null &amp;&amp; args.length &gt; 0 &amp;&amp; args[0].equals(&quot;startup&quot;)) {
			ensureRegistration();
		} else {			
			Mp3Player app = new Mp3Player();
			app.enterEventDispatcher();
		}
	}

	private static void ensureRegistration() {
		Object o = RuntimeStore.getRuntimeStore().get(MY_APP_KEY);
		// register only if not done already.
		if (o == null) {
			String[] types = {&quot;audio/mp3&quot;};
			String[] suffixes = {&quot;.mp3&quot;};            
			String[] actions = {ContentHandler.ACTION_OPEN};
			String[] actionNames = {&quot;Open with Mp3Player&quot;}; 
			ActionNameMap[] actionNameMaps = {new ActionNameMap(actions,actionNames,&quot;en&quot;)};


			Registry registry = Registry.getRegistry(MY_APP_CLASS);
		
			try {
				// Register our app as mp3 content handler
				registry.register(MY_APP_CLASS, types ,	suffixes , actions , actionNameMaps, MY_APP_ID, null);

				/* Register Menu Item here */
				new Mp3MenuItem().registerInstance();			
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	/* Utility method to perform invocation from other classes */
	public synchronized static void invoke(String className, String fileName, byte[] contents) {

		Invocation request = new Invocation();
		request.setID(MY_APP_ID); // request Mp3Player
		request.setURL(fileName);
		request.setData(contents); // set byte array if we have it
		request.setType(&quot;audio/mp3&quot;);

		// we don't care about the response
		request.setResponseRequired(false);

		try {
			Registry registry = Registry.getRegistry(className);
			registry.invoke(request);
		} catch (Exception ex) {
			System.out.println(className + &quot;: Error occured while opening file&quot;);
		}
	}	
	
	public synchronized void invocationRequestNotify(ContentHandlerServer handler) {

		pending = handler.getRequest(false);
		
		if (pending != null) {
			byte[] contents = getContents();
			if (contents != null &amp;&amp; contents.length != 0) {
				// TODO: Implement your Main screen and push it on the stack
				// remember that pushScreen is non blocking
				pushScreen(new Mp3PlayerScreen(contents));
				
				// notify the server that we are handling the invocation
				this.server.finish(pending, Invocation.OK);
			}
			else{
				// Close this instance or else you'll get &quot;previous instance still active&quot;
				// So we stop listening to invocation requests
				System.exit(0);
			}			
		} else {
			// Stop listening to invocation requests
			System.exit(0);
		}			
	}

	// Reads data from the invocation request
	// The invocation may contain associated byte array or URL to a file
	// or it could have associated stream (say network stream).
	private byte[] getContents() {
		InputStream is = null;
		StreamConnection sc = null;
		FileConnection fc = null;
		try {
			String filename = null;
			byte[] data = null;
			synchronized (this) {
			
				filename = pending.getURL();
				
				/* try to get associated byte array */
				if(filename.toLowerCase().indexOf(&quot;mp3&quot;) != -1) {
					data = pending.getData();
				}
				else {
				    // if file name did not end with mp3, don't handle it
					filename = null;
				}
			}
			
			// if we retrieved a byte array
			if (data != null &amp;&amp; data.length &gt; 0) {
				return data;
			} else if (filename != null) {
				
				// this is blocking call. use thread instead [e.g for network connection.]
				Connection conn = pending.open(false);
				
				// if this is a file connection the file is already on our phone
				// remember that a FileConnection is also a StreamConnection, 
				// so check FileConnection first				
				if (conn instanceof FileConnection) {
					fc = (FileConnection) conn;
					is = fc.openInputStream();
					
					return IOUtilities.streamToBytes(is);
				} else {
					sc = (StreamConnection) conn;
					is = sc.openInputStream();
					return IOUtilities.streamToBytes(is);
					// TODO: Save the array to SD Card?
				}

			}
		} catch (Exception ex) {
			System.out.println(&quot;Error occured while reading file.&quot;);
		} finally {
			try {
				if (is != null) {
					is.close();
				}
				if (fc != null) {
					fc.close();
				}
				if (sc != null) {
					sc.close();
				}
			} catch (Exception ex) {

			}
		}
		return new byte[0];
	}
}
</pre></p>
<p><strong>Implementing the ApplicationMenuItem:</strong></p>
<p>Although you may not need to implement a custom context menu item, it is particularly useful when there are<br />
other third party applications already handling the same file type.</p>
<p>ApplicationMenuItem provides an alternate entry point, i.e a way to add a custom menu item when a specific application is running.<br />
For example File Browser or Email app. To do this you have to register your implementation with ApplicationMenuItemRepository,<br />
once registered that instance will be cached in memory until the device is on. But this repository gets wiped out every time the device is rebooted.</p>
<p>So it is a good practice to register once per startup(see above). Now, if you have a UIApplication and it has an icon, user will<br />
start it by selecting it. In this case we have to make sure that we do not register our menu item twice. For this we will have to<br />
use RuntimeStore to save state of our registration.</p>
<p>ApplicationMenuItem construct takes a context, if you are registering this menu item for specific files, mime type of the file type<br />
must be passed as context. This especially important when you are registering your menu item with File Browser.</p>
<p>Important gotcha here is that when you request for an invocation, and the server is not running,<br />
the server will be initialized <em>before</em> the invocation request is made.</p>
<p><pre class="brush: csharp;">
package com.serialize.apps;

public class Mp3MenuItem extends ApplicationMenuItem {
	public static final long MP3_MENU_ITEM_KEY = 0x1a23b6c6ab2b1075L;

	public Mp3MenuItem() {
		/* will only be shown if the file mime type matches the context */ 
		super(&quot;audio/mp3&quot;, 500000); // order is found by trial and error method
	}

	/* This will be menu item text */
	public String toString() {
		return &quot;Open MP3 File&quot;;
	}

	public void registerInstance() {
		/* verify Registration */
		Object o = RuntimeStore.getRuntimeStore().remove(MP3_MENU_ITEM_KEY);
		 if(o == null) {
			ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
			// Gets Mp3Player descriptor, since this method is called from ensureRegistration()
			ApplicationDescriptor ad_startup = ApplicationDescriptor.currentApplicationDescriptor();
			ApplicationDescriptor ad_gui = new ApplicationDescriptor(ad_startup, new String[] {&quot;menuitem_entry&quot;});
			
			/* Register for File Browser */
			amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_FILE_EXPLORER, this, ad_gui);	 	
			RuntimeStore.getRuntimeStore().put(MP3_MENU_ITEM_KEY, this);
		 }
	}

	/* Mp3Player main() will be called before call to this function */
	public Object run(Object context) {
		if (context != null &amp;&amp; context instanceof String) {
			String inputFile = (String) context;

			// excecution control is automatically passed to Mp3Player.invocationRequestNotify() after this
			Mp3Player.invoke(getClass().getName(), inputFile, null);
		}
		return context;
	}
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/serialize.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/serialize.wordpress.com/110/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=110&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://serialize.wordpress.com/2010/06/30/contenthandler/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/54fbdf814723425c6ce3e94aefaad4c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Vivek</media:title>
		</media:content>
	</item>
		<item>
		<title>MSBuild Task: Solution and Project dependencies</title>
		<link>http://serialize.wordpress.com/2009/12/16/msbuild-task/</link>
		<comments>http://serialize.wordpress.com/2009/12/16/msbuild-task/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 20:50:49 +0000</pubDate>
		<dc:creator>Vivek Unune</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[msbuild]]></category>

		<guid isPermaLink="false">http://serialize.wordpress.com/?p=88</guid>
		<description><![CDATA[Few months ago I needed to use MSbuild to build solution. Sounds simple right? Yeah, but not quite. Somehow, my msbuild failed with project dependency issues. It turns out that MSBuild doesn&#8217;t respect project dependencies in a solution. Google &#8220;msbuild solution dependencies&#8221; and you&#8217;ll find various post complaining about the problem with MSBuild. I modified [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=88&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Few months ago I needed to use MSbuild to build solution. Sounds simple right? Yeah, but not quite.<br />
Somehow, my msbuild failed with project dependency issues. It turns out that MSBuild doesn&#8217;t respect project dependencies in a solution. Google &#8220;msbuild solution dependencies&#8221; and you&#8217;ll find various post complaining about the problem with MSBuild.</p>
<p>I modified the MSBuild task found <a href="http://msbuildtasks.tigris.org/source/browse/msbuildtasks/trunk/Source/MSBuild.Community.Tasks/Solution/GetSolutionProjects.cs?revision=321&amp;view=markup">here</a> to get projects in a solution file in dependency order.</p>
<p>You can then call the task to get the projects and compile them in order:<br />
<pre class="brush: xml;">
&lt;Target Name=&quot;BuildProjects&quot;&gt;
		&lt;GetProjecsInOrder Solution=&quot;$(MSBuildProjectDirectory)\MySolution.sln&quot;&gt;
		  &lt;Output ItemName=&quot;ProjectFiles&quot; TaskParameter=&quot;Output&quot;/&gt;
		&lt;/GetProjecsInOrder&gt;

		&lt;MSBuild Projects=&quot;%(ProjectFiles.FullPath)&quot;
				 Targets=&quot;Build&quot;
				 Properties=&quot;Configuration=Release&quot;/&gt;
&lt;/Target&gt;
</pre>		</p>
<p>You can download the modified source from <a href="http://www.esnips.com/doc/8e232db4-21ac-4d93-90dc-2a8bc4db34a8/MSBuildTasks">http://www.esnips.com/doc/8e232db4-21ac-4d93-90dc-2a8bc4db34a8/MSBuildTasks</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/serialize.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/serialize.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=88&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://serialize.wordpress.com/2009/12/16/msbuild-task/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/54fbdf814723425c6ce3e94aefaad4c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Vivek</media:title>
		</media:content>
	</item>
		<item>
		<title>IDataReader GetValue Extension method</title>
		<link>http://serialize.wordpress.com/2009/07/15/idatareader-getvalue-extension-method/</link>
		<comments>http://serialize.wordpress.com/2009/07/15/idatareader-getvalue-extension-method/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 21:27:41 +0000</pubDate>
		<dc:creator>Vivek Unune</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://serialize.wordpress.com/?p=79</guid>
		<description><![CDATA[It is offten desired to get a value from DataReader using column name with known Type. For example you want to get a string value of column &#8216;first_name&#8217; and int value of column &#8216;account_number&#8217;. The following extension method makes it easy to fetch values from a DataReader using Type and column name: public static class [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=79&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>It is offten desired to get a value from DataReader using column name with known Type. For example you want to get a string value of column &#8216;first_name&#8217; and int value of column &#8216;account_number&#8217;. The following extension method makes it easy to fetch values from a DataReader using Type and column name:</p>
<pre><span style="font-size:small;"><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> ReaderHelper
{
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> IsNullableType(Type valueType)
    {
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> (valueType.IsGenericType &amp;&amp;
            valueType.GetGenericTypeDefinition().Equals(</span><span style="color:#0000FF;">typeof</span><span style="color:#000000;">(Nullable&lt;&gt;)));
    }

    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> T GetValue&lt;T&gt;(</span><span style="color:#0000FF;">this</span><span style="color:#000000;"> IDataReader reader, </span><span style="color:#0000FF;">string</span><span style="color:#000000;"> columnName)
    {
        </span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value = reader[columnName];
        Type valueType = </span><span style="color:#0000FF;">typeof</span><span style="color:#000000;">(T);
        </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (value != DBNull.Value)
        {
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (!IsNullableType(valueType))
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> (T)Convert.ChangeType(value, valueType);
            }
            </span><span style="color:#0000FF;">else</span><span style="color:#000000;">
            {
                NullableConverter nc = </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> NullableConverter(valueType);
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> (T)Convert.ChangeType(value, nc.UnderlyingType);
            }
        }
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">default</span><span style="color:#000000;">(T);
    }
}</span></pre>
<p>It can be used as:</p>
<pre><span style="font-size:small;"><span style="color:#000000;">User GetUser(IDataReader reader)
{
    User user = </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> User();
    user.FirstName = reader.GetValue&lt;</span><span style="color:#0000FF;">string</span><span style="color:#000000;">&gt;(</span><span style="color:#800000;">"first_name"</span><span style="color:#000000;">);
    user.LastName = reader.GetValue&lt;</span><span style="color:#0000FF;">string</span><span style="color:#000000;">&gt;(</span><span style="color:#800000;">"last_name"</span><span style="color:#000000;">);
    user.Email = reader.GetValue&lt;</span><span style="color:#0000FF;">string</span><span style="color:#000000;">&gt;(</span><span style="color:#800000;">"email"</span><span style="color:#000000;">);
    user.AccountNumber = reader.GetValue&lt;</span><span style="color:#0000FF;">int</span><span style="color:#000000;">&gt;(</span><span style="color:#800000;">"account_number"</span><span style="color:#000000;">);
    user.NumberOfVehiclesOwned = reader.GetValue&lt;</span><span style="color:#0000FF;">int?</span><span style="color:#000000;">&gt;(</span><span style="color:#800000;">"vehicle_count"</span><span style="color:#000000;">); </span><span style="color:#008000;">// nullable data field</span><span style="color:#000000;">
    </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> user;
}
</span></span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/serialize.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/serialize.wordpress.com/79/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=79&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://serialize.wordpress.com/2009/07/15/idatareader-getvalue-extension-method/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/54fbdf814723425c6ce3e94aefaad4c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Vivek</media:title>
		</media:content>
	</item>
		<item>
		<title>Experiments with OpenWRT and USR5465</title>
		<link>http://serialize.wordpress.com/2008/12/10/experiments-with-openwrt-and-usr5465/</link>
		<comments>http://serialize.wordpress.com/2008/12/10/experiments-with-openwrt-and-usr5465/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 03:28:48 +0000</pubDate>
		<dc:creator>Vivek Unune</dc:creator>
				<category><![CDATA[openwrt]]></category>
		<category><![CDATA[usrobotics]]></category>
		<category><![CDATA[vpnc]]></category>

		<guid isPermaLink="false">http://serialize.wordpress.com/?p=68</guid>
		<description><![CDATA[I recently purchased U.S Robotics USR5465 router. I chose it because it had 4MB flash and 16MB ram; enough to run  linux based distribution for router such as OpenWRT. Out of the box, this router runs linux kernel 2.4 along with busy box. But I was very much interested to run latest kernel (2.6.x) on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=68&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I recently purchased U.S Robotics USR5465 router. I chose it because it had 4MB flash and 16MB ram; enough to run  linux based distribution for router such as OpenWRT. Out of the box, this router runs linux kernel 2.4 along with busy box. But I was very much interested to run latest kernel (2.6.x) on it. With OpenWRT it is easy to create the development environment. Just login to your favorite linux as a non-root and follow few steps mention here. Once you configure your router kernel and run make command. OpenWRT automatically downloads required toochain source and compiles it for your PC.</p>
<p>USR5465 has one serial port and possibly a 12 pin JTAG. So, I brought myself a Nokia DKU-5 cable (SN: WT048000317).  This cable has a usb to serial converter; and it&#8217;s cheap! I cut/removed the phone connector end of the cable. After a little research, I found out that:</p>
<pre>Phone connector Pin#        Wire Color        Signal
            8                 RED              GND
            7                 GREEN            TX
            6                 WHITE            RX
            4                 ORANGE           3.3 OUT  (Not used, do not connect!!)</pre>
<p>After connecting wires to jumper J301, compiling ark3116 kernel module  and using 115200 baud rate with 8-N-1, I was able to connect my laptop to the router. When I restarted the router I saw the boot messages from router. Here is how I connected the wires:</p>
<pre>j301
|o|  ---&gt;   GREEN   (TX)
|o|  ---&gt;   WHITE   (RX)
|o|
|o|  ---&gt;   RED     (GND)

______
o -&gt; Power led

#################################     &lt;--- Motherboard edge</pre>
<p>Another advantage of this router is that it has a USB 2.0 port. To use usb, I had to use revision 13088 and patched it using <a href="http://dongsupark.de/openwrt/kamikaze-r13088-b43ssb-2.6.27.diff" target="_blank">this patch</a></p>
<p>svn checkout -r13088 <a href="https://svn.openwrt.org/openwrt/trunk" rel="nofollow">https://svn.openwrt.org/openwrt/trunk</a> kamikaze<br />
patch -p1 &lt; kamikaze-r13088-b43ssb-2.6.27.diff</p>
<p>I had to change &#8220;BUSWIDTH 2&#8243; to &#8220;BUSWIDTH 1&#8243; in drivers/mtd/maps/bcm47xx-flash.c file in order to get a working image. Otherwise I saw few &#8220;error -5&#8243; lines after booting.</p>
<p>I wasn&#8217;t able to connect to the internet, even after I got the image to boot successfully. I found that the problem was due to incorrect labeling of the WAN and the LAN ports by OpenWRT.  Since I was able to connect to the router using the serial port I changed the VLAN config in /etc/config/network to:</p>
<pre>#### VLAN configuration
config switch eth0
        option vlan0    "0 1 2 3 5*"
        option vlan1    "4 5"</pre>
<p>Only then I was able to get a valid IP address and connect to the internet.</p>
<p>Other than wireless (which didn&#8217;t bother me, as I always use wired connection) everything is now working perfectly. Since this model is not supported by OpenWRT, it doesn&#8217;t know the led configurations and does not recognize the model. So I had to add that info. in diag.c file. gpioctl utility was useful to find out the led and  reset button gpios.</p>
<p>You can download modified diag.c from <a href="http://serialize.files.wordpress.com/2008/12/diagc.doc" target="_blank">here</a>. Once you compile you should see WAN led and USB led litup (need to do some configuration for USB led).</p>
<p>Further I was also able to install VPNC on the router and connect to CISCO VPN without any problem <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  This makes it easier for me when using Vista x64, as cisco doesn&#8217;t provide vpn client for 64bit windows.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/serialize.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/serialize.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=68&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://serialize.wordpress.com/2008/12/10/experiments-with-openwrt-and-usr5465/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/54fbdf814723425c6ce3e94aefaad4c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Vivek</media:title>
		</media:content>
	</item>
		<item>
		<title>Visual Studio 2008 color settings</title>
		<link>http://serialize.wordpress.com/2008/09/27/visual-studio-2008-color-settings/</link>
		<comments>http://serialize.wordpress.com/2008/09/27/visual-studio-2008-color-settings/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 21:14:22 +0000</pubDate>
		<dc:creator>Vivek Unune</dc:creator>
				<category><![CDATA[Misc.]]></category>
		<category><![CDATA[color settings]]></category>
		<category><![CDATA[vs2008]]></category>

		<guid isPermaLink="false">http://serialize.wordpress.com/?p=54</guid>
		<description><![CDATA[I recently switched to &#8220;dark&#8221; vs2008 color scheme since it is easy on eyes. I started with RagnaRok color scheme created by Tomas Restrepo and modified it to my convenience. You can download the modified version from here: RagnaRok-modified.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=54&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I recently switched to &#8220;dark&#8221; vs2008 color scheme since it is easy on eyes.</p>
<p>I started with RagnaRok color scheme created by Tomas Restrepo and modified it to my convenience.</p>
<p>You can download the modified version from here: <a href="http://www.hotlinkfiles.com/files/1891615_pazaw/RagnaRok-Modified.zip" target="_blank">RagnaRok-modified</a>.</p>
<p><a href="http://serialize.files.wordpress.com/2008/09/vs20081.png"><img class="aligncenter size-full wp-image-61" title="vs20081" src="http://serialize.files.wordpress.com/2008/09/vs20081.png?w=700" alt=""   /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/serialize.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/serialize.wordpress.com/54/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=54&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://serialize.wordpress.com/2008/09/27/visual-studio-2008-color-settings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/54fbdf814723425c6ce3e94aefaad4c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Vivek</media:title>
		</media:content>

		<media:content url="http://serialize.files.wordpress.com/2008/09/vs20081.png" medium="image">
			<media:title type="html">vs20081</media:title>
		</media:content>
	</item>
		<item>
		<title>RotateString v2.0</title>
		<link>http://serialize.wordpress.com/2008/09/27/rotatestring-v20/</link>
		<comments>http://serialize.wordpress.com/2008/09/27/rotatestring-v20/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 16:46:57 +0000</pubDate>
		<dc:creator>Vivek Unune</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[stackoverflow]]></category>

		<guid isPermaLink="false">http://serialize.wordpress.com/?p=47</guid>
		<description><![CDATA[I added the ability to rotate string right or left. Here is the code: public enum Direction { Right, Left } string rotateString(string source, int rotationCount, Direction direction) { if (String.IsNullOrEmpty(source) &#124;&#124; rotationCount &#60;= 0) return source; int pivot = 0; List&#60;int&#62; delimiterLocations = new List&#60;int&#62;(); char[] sourceChars = new char; char temp; // Reverse [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=47&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I added the ability to rotate string right or left. Here is the code:</p>
<pre><span style="font-size:small;">
<span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">enum</span><span style="color:#000000;"> Direction { Right, Left }

</span><span style="color:#0000ff;">string</span><span style="color:#000000;"> rotateString(</span><span style="color:#0000ff;">string</span><span style="color:#000000;"> source, </span><span style="color:#0000ff;">int</span><span style="color:#000000;"> rotationCount, Direction direction)
{
    </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (String.IsNullOrEmpty(source) </span><span style="color:#000000;">||</span><span style="color:#000000;"> rotationCount </span><span style="color:#000000;">&lt;=</span><span style="color:#000000;"> </span><span style="color:#800080;">0</span><span style="color:#000000;">)
        </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> source;

    </span><span style="color:#0000ff;">int</span><span style="color:#000000;"> pivot </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">0</span><span style="color:#000000;">;
    List</span><span style="color:#000000;">&lt;</span><span style="color:#0000ff;">int</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> delimiterLocations </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> List</span><span style="color:#000000;">&lt;</span><span style="color:#0000ff;">int</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">();
    </span><span style="color:#0000ff;">char</span><span style="color:#000000;">[] sourceChars </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#0000ff;">char</span><span style="color:#000000;">;

    </span><span style="color:#0000ff;">char</span><span style="color:#000000;"> temp;
    </span><span style="color:#008000;">//</span><span style="color:#008000;"> Reverse the whole string and
    </span><span style="color:#008000;">//</span><span style="color:#008000;"> save the dilimiter locations</span><span style="color:#008000;">
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">for</span><span style="color:#000000;"> (</span><span style="color:#0000ff;">int</span><span style="color:#000000;"> i </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">0</span><span style="color:#000000;">; i </span><span style="color:#000000;">&lt;</span><span style="color:#000000;"> source.Length; i</span><span style="color:#000000;">++</span><span style="color:#000000;">)
    {
        sourceChars </span><span style="color:#000000;">=</span><span style="color:#000000;"> source[i];

        </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (source[i] </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#800000;">'</span><span style="color:#800000;"> </span><span style="color:#800000;">'</span><span style="color:#000000;">)
            delimiterLocations.Add(source.Length </span><span style="color:#000000;">-</span><span style="color:#000000;"> i </span><span style="color:#000000;">-</span><span style="color:#000000;"> </span><span style="color:#800080;">1</span><span style="color:#000000;">);
    }

    </span><span style="color:#008000;">//</span><span style="color:#008000;"> calculate neededDelimiters mod wordCount
    </span><span style="color:#008000;">//</span><span style="color:#008000;"> (assume words = delimiterCount + 1)</span><span style="color:#008000;">
</span><span style="color:#000000;">    pivot </span><span style="color:#000000;">=</span><span style="color:#000000;"> rotationCount </span><span style="color:#000000;">%</span><span style="color:#000000;"> delimiterLocations.Count;

    </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (pivot </span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> </span><span style="color:#800080;">0</span><span style="color:#000000;">)
    {
        </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (direction </span><span style="color:#000000;">==</span><span style="color:#000000;"> Direction.Left)
            pivot </span><span style="color:#000000;">=</span><span style="color:#000000;"> delimiterLocations.Count </span><span style="color:#000000;">-</span><span style="color:#000000;"> pivot;

        pivot </span><span style="color:#000000;">=</span><span style="color:#000000;"> delimiterLocations[delimiterLocations.Count </span><span style="color:#000000;">-</span><span style="color:#000000;"> pivot];
    }
    </span><span style="color:#0000ff;">else</span><span style="color:#000000;">
    { </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> source; }

    </span><span style="color:#008000;">//</span><span style="color:#008000;"> reverse the first part</span><span style="color:#008000;">
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">for</span><span style="color:#000000;"> (</span><span style="color:#0000ff;">int</span><span style="color:#000000;"> i </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">0</span><span style="color:#000000;">, j </span><span style="color:#000000;">=</span><span style="color:#000000;"> pivot </span><span style="color:#000000;">-</span><span style="color:#000000;"> </span><span style="color:#800080;">1</span><span style="color:#000000;">; i </span><span style="color:#000000;">&lt;=</span><span style="color:#000000;"> j; i</span><span style="color:#000000;">++</span><span style="color:#000000;">, j</span><span style="color:#000000;">--</span><span style="color:#000000;">)
    {
        temp </span><span style="color:#000000;">=</span><span style="color:#000000;"> sourceChars[i];
        sourceChars[i] </span><span style="color:#000000;">=</span><span style="color:#000000;"> sourceChars[j];
        sourceChars[j] </span><span style="color:#000000;">=</span><span style="color:#000000;"> temp;
    }

    </span><span style="color:#008000;">//</span><span style="color:#008000;"> reverse the second part</span><span style="color:#008000;">
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">for</span><span style="color:#000000;"> (</span><span style="color:#0000ff;">int</span><span style="color:#000000;"> i </span><span style="color:#000000;">=</span><span style="color:#000000;"> pivot </span><span style="color:#000000;">+</span><span style="color:#000000;"> </span><span style="color:#800080;">1</span><span style="color:#000000;">, j </span><span style="color:#000000;">=</span><span style="color:#000000;"> sourceChars.Length </span><span style="color:#000000;">-</span><span style="color:#000000;"> </span><span style="color:#800080;">1</span><span style="color:#000000;">;
         i </span><span style="color:#000000;">&lt;=</span><span style="color:#000000;"> j; i</span><span style="color:#000000;">++</span><span style="color:#000000;">, j</span><span style="color:#000000;">--</span><span style="color:#000000;">)
    {
        temp </span><span style="color:#000000;">=</span><span style="color:#000000;"> sourceChars[i];
        sourceChars[i] </span><span style="color:#000000;">=</span><span style="color:#000000;"> sourceChars[j];
        sourceChars[j] </span><span style="color:#000000;">=</span><span style="color:#000000;"> temp;
    }

    </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#0000ff;">string</span><span style="color:#000000;">(sourceChars);
}</span>
</span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/serialize.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/serialize.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=serialize.wordpress.com&#038;blog=4194111&#038;post=47&#038;subd=serialize&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://serialize.wordpress.com/2008/09/27/rotatestring-v20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/54fbdf814723425c6ce3e94aefaad4c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Vivek</media:title>
		</media:content>
	</item>
	</channel>
</rss>
