<?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>Benjamin McCann - Development Blog &#187; Tips and Tricks</title>
	<atom:link href="http://www.benmccann.com/dev-blog/category/tips-and-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.benmccann.com/dev-blog</link>
	<description>The software development weblog of Benjamin McCann.</description>
	<lastBuildDate>Fri, 27 Jan 2012 01:34:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Running Ubuntu on VirtualBox</title>
		<link>http://www.benmccann.com/dev-blog/running-ubuntu-on-virtualbox/</link>
		<comments>http://www.benmccann.com/dev-blog/running-ubuntu-on-virtualbox/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 22:53:03 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.benmccann.com/dev-blog/?p=541</guid>
		<description><![CDATA[I had to figure out a few things to get Ubuntu installed and working well on VirtualBox. I had to enable virtualization technologies in my BIOS. I have a Lenovo T520 and did this by pressing F1 during startup and then going to Security > Virtualization. If I did not do this then I would [...]]]></description>
			<content:encoded><![CDATA[<p>I had to figure out a few things to get Ubuntu installed and working well on VirtualBox.</p>
<p>I had to enable virtualization technologies in my BIOS.  I have a Lenovo T520 and did this by pressing F1 during startup and then going to Security > Virtualization.  If I did not do this then I would receive the error &#8220;VT-x features locked or unavailable in MSR&#8221; when trying to run with more than 1 CPU or 3584 MB of RAM.</p>
<p>Also, I had to run &#8220;sudo apt-get install dkms&#8221; to get the VirtualBox Guest Additions to work well.</p>
<p>Finally, I remapped the host key.  By default all kinds of weird things happen when you use the right Ctrl button.  This can be fixed by going to File > Preferences&#8230; > Input and then setting Host Key to something you never use like Pause.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmccann.com/dev-blog/running-ubuntu-on-virtualbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sed Cookbook</title>
		<link>http://www.benmccann.com/dev-blog/sed-cookbook/</link>
		<comments>http://www.benmccann.com/dev-blog/sed-cookbook/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 05:50:49 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.benmccann.com/dev-blog/?p=460</guid>
		<description><![CDATA[The Linux sed command is a stream editor.  What that means is basically that you can do a regex operation on each line of a file or a piped stream.  I always have a bit of trouble remembering how to use it since its regex implementation is a bit different than the ones I&#8217;m used [...]]]></description>
			<content:encoded><![CDATA[<p>The Linux sed command is a stream editor.  What that means is basically that you can do a regex operation on each line of a file or a piped stream.  I always have a bit of trouble remembering how to use it since its regex implementation is a bit different than the ones I&#8217;m used to.  I&#8217;ll post more examples as I encounter them in my work.</p>
<p>Sed regex reminders:</p>
<ul>
<li>You need a backslash before parens in a regex grouping</li>
<li>You refer to matched regex groups using \1, \2, etc.</li>
<li>The + regex operator does not work</li>
<li>Non-greedy quantifiers don&#8217;t work.  For example, .*? will not work</li>
<li>The output is printed to standard out by default.  You need the -i option if you want to edit a file with sed.</li>
</ul>
<p><strong>Remove all but the first column in a .tsv stream</strong><br />
sed &#8216;s/\([^\t]*\).*/\1/&#8217;</p>
<p><strong>Edit a .tsv file by removing all but the first column</strong><br />
sed -i &#8216;s/\([^\t]*\).*/\1/&#8217;</p>
<p><strong>Remove the first line of a stream</strong><br />
sed &#8217;1d&#8217;</p>
<p><strong>Strip trailing whitespace from a file</strong><br />
sed -i -e &#8216;s/ *$//&#8217;</p>
<p><strong>Replace @inheritDoc with @override after marking for edit</strong><br />
grep @inheritDoc -l -r java/com/benmccann | xargs p4 edit<br />
grep @inheritDoc -l -r java/com/benmccann | xargs sed -i &#8216;s/\(.*\)@inheritDoc/\1@override/&#8217;</p>
<p><strong>Replace @inheritDoc with @override in JS files after marking for edit</strong><br />
find java/com/benmccann -name &#8216;*.js&#8217; -print0 | xargs -0 grep -l @inheritDoc | xargs p4 edit<br />
find java/com/benmccann -name &#8216;*.js&#8217; -print0 | xargs -0 grep -l @inheritDoc | xargs sed -i &#8216;s/\(.*\)@inheritDoc/\1@override/&#8217;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmccann.com/dev-blog/sed-cookbook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote Java debugging in Eclipse</title>
		<link>http://www.benmccann.com/dev-blog/remote-java-debugging-in-eclipse/</link>
		<comments>http://www.benmccann.com/dev-blog/remote-java-debugging-in-eclipse/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 06:20:30 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.benmccann.com/dev-blog/?p=434</guid>
		<description><![CDATA[To debug a Java program being run on the command line from Eclipse you can start the Java program in remote debugging mode: java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y -jar myProgram.jar The program will wait for you to attach the Eclipse debugger to it. Open Eclipse and choose: Run > Debug Configurations... > Remote Java Application > New [...]]]></description>
			<content:encoded><![CDATA[<p>To debug a Java program being run on the command line from Eclipse you can start the Java program in remote debugging mode:</p>
<pre><code>java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y -jar myProgram.jar</code></pre>
<p>The program will wait for you to attach the Eclipse debugger to it.  Open Eclipse and choose:</p>
<pre><code>Run > Debug Configurations... > Remote Java Application > New</code></pre>
<p>Make sure to enter the same port that you chose on the command line.  The default is port 8000.  Now hit &#8220;Debug&#8221; and you&#8217;re off!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmccann.com/dev-blog/remote-java-debugging-in-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Commands Cheatsheet</title>
		<link>http://www.benmccann.com/dev-blog/mysql-commands-cheatsheet/</link>
		<comments>http://www.benmccann.com/dev-blog/mysql-commands-cheatsheet/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 22:40:03 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Datastores]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.benmccann.com/dev-blog/?p=370</guid>
		<description><![CDATA[Install SQL Buddy sudo apt-get install apache2 libapache2-mod-php5 php5-mysql sudo /etc/init.d/apache2 restart Download SQL Buddy, unzip, and move to /var/www Allow connections from a remote server: Set the bind address in /etc/mysql/my.cnf to your ip address Open the port in the firewall by running &#8220;/sbin/iptables -A INPUT -i eth0 -p tcp &#8211;destination-port 3306 -j ACCEPT&#8221; [...]]]></description>
			<content:encoded><![CDATA[<div><strong>Install SQL Buddy</strong></div>
<pre><code>sudo apt-get install apache2 libapache2-mod-php5 php5-mysql
sudo /etc/init.d/apache2 restart</code></pre>
<p>Download <a href="http://www.sqlbuddy.com/">SQL Buddy</a>, unzip, and move to /var/www</p>
<div><strong><a href="http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html">Allow connections from a remote server</a>:</strong></div>
<div>
<ul>
<li>Set the bind address in /etc/mysql/my.cnf to your ip address</li>
<li>Open the port in the firewall by running &#8220;/sbin/iptables -A INPUT -i eth0 -p tcp &#8211;destination-port 3306 -j ACCEPT&#8221; followed by &#8220;iptables-save&#8221;</li>
<li>Grant privileges on remote host as shown below</li>
</ul>
</div>
<div><strong>Login via MySql client:</strong></div>
<pre><code>$ <a href="http://dev.mysql.com/doc/refman/5.0/en/mysql.html">mysql</a> -u XXXXX -pXXXXX <em>db_name</em></code></pre>
<div><strong>Create a new user:</strong></div>
<pre><code>CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';
GRANT ALL ON *.* TO 'user1'@'localhost';
CREATE USER 'user1'@'%' IDENTIFIED BY 'pass1';
GRANT ALL ON *.* TO 'user1'@'%';</code></pre>
<div><strong>List users:</strong></div>
<pre><code>select host, user, password, Create_priv from mysql.user;</code></pre>
<div><strong>List databases and tables:</strong></div>
<pre><code>show databases;
show tables;</code></pre>
<div><strong>Rename column:</strong></div>
<pre><code>ALTER TABLE Article change article_id id bigint(20);</code></pre>
<div><strong>Make column non-null:</strong></div>
<pre><code>ALTER TABLE Person MODIFY firstName varchar(255) NOT NULL;</code></pre>
<div><strong>Make column unique:</strong></div>
<pre><code>ALTER TABLE Person ADD UNIQUE INDEX(memberId);</code></pre>
<div><strong>Calculate the database size:</strong></div>
<pre><code>SELECT table_schema "DB Name", sum(data_length + index_length) / 1024 / 1024  "DB size in MB" FROM information_schema.TABLES GROUP BY table_schema;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.benmccann.com/dev-blog/mysql-commands-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating .asc signature files with GPG</title>
		<link>http://www.benmccann.com/dev-blog/creating-asc-signature-files-with-gpg/</link>
		<comments>http://www.benmccann.com/dev-blog/creating-asc-signature-files-with-gpg/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 03:35:34 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.benmccann.com/dev-blog/?p=329</guid>
		<description><![CDATA[First make sure you don&#8217;t have a key already: gpg --list-keys If you didn&#8217;t and need to create a key then run: gpg --gen-key It might hang for awhile while generating enough random entropy. Run &#8220;ls -R /&#8221; to speed things up. And upload it to a public key server: gpg --keyserver hkp://pgp.mit.edu --send-keys &#60;keyid&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>First make sure you don&#8217;t have a key already:</p>
<pre><code>gpg --list-keys</code></pre>
<p>If you didn&#8217;t and need to create a key then run:</p>
<pre><code>gpg --gen-key</code></pre>
<p>It might hang for awhile while generating enough random entropy.  Run &#8220;ls -R /&#8221; to speed things up.</p>
<p>And upload it to a public key server:</p>
<pre><code>gpg --keyserver hkp://pgp.mit.edu --send-keys &lt;keyid&gt;</code></pre>
<p>Now list the keys again to get the keyid:</p>
<pre><code>gpg --list-keys</code></pre>
<p>The keyid is the half after the / in:</p>
<pre><code>pub   XXXX/XXXXXXXX 2011-12-05</code></pre>
<p>Then generate your key:</p>
<pre><code>gpg -ab &lt;filename&gt;</code></pre>
<p>If you&#8217;re doing this for an upload to the Maven repositories, you&#8217;ll need to do this for each of the four file (.jar, -sources.jar, -javadoc.jar, and .pom) and then jar all eight files together in a bundle.jar file.  More details available on <a href="https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven">Maven&#8217;s how to generate PGP signatures page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmccann.com/dev-blog/creating-asc-signature-files-with-gpg/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Trouble Resuming NX Session</title>
		<link>http://www.benmccann.com/dev-blog/trouble-resuming-nx-session/</link>
		<comments>http://www.benmccann.com/dev-blog/trouble-resuming-nx-session/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 04:25:51 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[NX]]></category>

		<guid isPermaLink="false">http://www.benmccann.com/dev-blog/?p=251</guid>
		<description><![CDATA[Resume button disabled I was unable to resume my NX session.  While trying to connect, the resume button was greyed out (or grayed out)  This apparently can happen if the two machines are running at a different color depth. The machine I was trying to connect to was running Ubuntu, so I checked the color [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Resume button disabled</strong></p>
<p>I was unable to resume my NX session.  While trying to connect, the resume button was greyed out (or grayed out)  This apparently can happen if the two machines are running at a different color depth.</p>
<p>The machine I was trying to connect to was running Ubuntu, so I checked the color depth (sudo cat /etc/X11/xorg.conf) and saw that it was running at 24 bit.  Then I checked the color depth on my Windows machine (Control Panel &gt; Display &gt; Settings &gt; Color Quality) and saw it was running at 16 bit.  There was no option to set it to 24-bit, so I chose the option &#8220;Highest (32 bit)&#8221;.  No more disabled resume button!</p>
<p>I think the cause of the problem was plugging my laptop into the projector at work yesterday.  It apparently changed my color depth and Windows didn&#8217;t reset it when I exited presentation mode.</p>
<p><strong>Execution of last command failed</strong></p>
<p>Trying to reconnect to my NX session kept failing.  I hit the Details button and saw the following:</p>
<pre><code>NX&gt; 596 NX&gt; 596 ERROR: NXNODE Ver. 3.4.0-6  (Error id e76DC5C)
NX&gt; 596 NX&gt; 596 ERROR: resume session: run commands
NX&gt; 596 NX&gt; 596 ERROR: execution of last command failed
NX&gt; 596 NX&gt; 596 last command: '/bin/kill -USR2 16905'
NX&gt; 596 NX&gt; 596 exit value: 1
NX&gt; 596 NX&gt; 596 stdout:
NX&gt; 596 NX&gt; 596 stderr: /bin/kill: 16905: No such process</code></pre>
<p>The only thing I found that would let me connect to my box via NX at all was to &#8220;rm /usr/NX/var/db/running/*&#8221; in order to kill my current session.  Killing the session is a sucky option, but at least now I can use NX again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmccann.com/dev-blog/trouble-resuming-nx-session/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Printing a Stack Trace anywhere in Java</title>
		<link>http://www.benmccann.com/dev-blog/printing-a-stack-trace-anywhere-in-java/</link>
		<comments>http://www.benmccann.com/dev-blog/printing-a-stack-trace-anywhere-in-java/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 21:40:59 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.benmccann.com/dev-blog/?p=202</guid>
		<description><![CDATA[You don&#8217;t need to catch an Exception in order to print a stack trace in Java.  Sometimes they can be helpful for debugging and logging purposes.  Here&#8217;s an example of how to print a stack trace at any moment: new Exception().printStackTrace(); If you want more control over the output, you can build some code off [...]]]></description>
			<content:encoded><![CDATA[<p>You don&#8217;t need to catch an Exception in order to print a stack trace in Java.  Sometimes they can be helpful for debugging and logging purposes.  Here&#8217;s an example of how to print a stack trace at any moment:<br />
<code>
<pre>new Exception().printStackTrace();</pre>
<p></code></p>
<p>If you want more control over the output, you can build some code off the following:<br />
<code>
<pre>  System.out.println("Printing stack trace:");
  StackTraceElement[] elements = Thread.currentThread().getStackTrace();
  for (int i = 1; i < elements.length; i++) {
    StackTraceElement s = elements[i];
    System.out.println("\tat " + s.getClassName() + "." + s.getMethodName()
        + "(" + s.getFileName() + ":" + s.getLineNumber() + ")");
  }</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmccann.com/dev-blog/printing-a-stack-trace-anywhere-in-java/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Determining Port Usage</title>
		<link>http://www.benmccann.com/dev-blog/determining-port-usage/</link>
		<comments>http://www.benmccann.com/dev-blog/determining-port-usage/#comments</comments>
		<pubDate>Mon, 18 May 2009 22:11:13 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.benmccann.com/dev-blog/?p=192</guid>
		<description><![CDATA[Want to know how to figure out what&#8217;s running on a given port on your machine?  The following example will show you what&#8217;s running on port 80 on your Linux machine: lsof -i -n -P &#124; grep :80]]></description>
			<content:encoded><![CDATA[<p>Want to know how to figure out what&#8217;s running on a given port on your machine?  The following example will show you what&#8217;s running on port 80 on your Linux machine:</p>
<p><code> </code></p>
<pre>lsof -i -n -P | grep :80</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.benmccann.com/dev-blog/determining-port-usage/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Helpful Bash Aliases</title>
		<link>http://www.benmccann.com/dev-blog/helpful-bash-aliases/</link>
		<comments>http://www.benmccann.com/dev-blog/helpful-bash-aliases/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 02:55:01 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.benmccann.com/dev-blog/?p=152</guid>
		<description><![CDATA[Just a few to post for right now, but this entry may grow later. alias ll='ls -la'           # list all directory contents in listing format alias untargz="tar zxvf" # unpacks a .tar.gz file alias rd='cd `pwd -P`'   # change to the real directory if in a linked directory]]></description>
			<content:encoded><![CDATA[<p>Just a few to post for right now, but this entry may grow later.</p>
<pre><code>alias ll='ls -la'           # list all directory contents in listing format
alias untargz="tar zxvf"    # unpacks a .tar.gz file
alias rd='cd `pwd -P`'      # change to the real directory if in a linked directory</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.benmccann.com/dev-blog/helpful-bash-aliases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Essential Linux Commands</title>
		<link>http://www.benmccann.com/dev-blog/essential-linux-commands/</link>
		<comments>http://www.benmccann.com/dev-blog/essential-linux-commands/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 21:08:07 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.lumidant.com/blog/?p=41</guid>
		<description><![CDATA[Getting started on Linux can be challenging.  Largely because the first time user won&#8217;t have any idea how to track down potential problems.  The following Linux commands are essential to get additional information about your system when something goes wrong. Machine info sudo lshw -html &#62; hardware.html &#8211; Creates an HTML page showing what hardware [...]]]></description>
			<content:encoded><![CDATA[<p>Getting started on Linux can be challenging.  Largely because the first time user won&#8217;t have any idea how to track down potential problems.  The following Linux commands are essential to get additional information about your system when something goes wrong.</p>
<div><strong>Machine info</strong></div>
<ul>
<li><strong>sudo lshw -html &gt; hardware.html</strong> &#8211; Creates an HTML page showing what hardware is on your system<strong><br />
</strong></li>
<li><strong>uname -mr</strong> &#8211; Shows what kernel version and processor you are running on</li>
<li><strong>df </strong>and<strong> fdisk -l</strong> &#8211; Gives you file system info.  Can help you figure out how things are mounted</li>
</ul>
<div><strong>Logs</strong></div>
<ul>
<li><strong>dmesg</strong> &#8211; Useful for tracking down problems during boot</li>
<li><strong>tail -f /var/log/messages</strong> &#8211; Now run the process giving you problems and you might see helpful error messages</li>
</ul>
<div><strong>Processes</strong></div>
<ul>
<li><strong>top</strong> &#8211; Shows the programs which are the top memory and CPU users</li>
<li><strong>free -m</strong> &#8211; Shows how much memory is free.  Linux uses 100% memory by default so as to not waste memory by letting it sit empty.  Look at the buffers/cache line to see how much is really used.</li>
<li><strong>pgrep </strong>- Returns the process ids of a given program, allowing you to kill frozen programs</li>
</ul>
<div><strong>File transfer</strong></div>
<ul>
<li><strong>scp -i key.pem local_file user@remote_machine:remote_path</strong> &#8211; Securely transfers a file</li>
</ul>
<div><strong>In depth</strong></div>
<ul>
<li><strong><a href="http://www.benmccann.com/dev-blog/using-find/">find</a></strong> &#8211; Find a file on the file sytem</li>
<li><strong><a href="http://www.benmccann.com/dev-blog/sed-cookbook/">sed</a></strong> &#8211; Programmatically edit a file or stream</li>
</ul>
<p>If you&#8217;ve got other suggestions, please feel free to comment below.  Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmccann.com/dev-blog/essential-linux-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

