<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>tail -f findings.out</title>
	
	<link>http://dancingpenguinsoflight.com</link>
	<description />
	<lastBuildDate>Sat, 13 Mar 2010 23:22:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/dancingpenguinsoflight" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="dancingpenguinsoflight" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Tune MySQL like a pro with MySQLTuner</title>
		<link>http://dancingpenguinsoflight.com/2010/03/tune-mysql-like-a-pro-with-mysqltuner/</link>
		<comments>http://dancingpenguinsoflight.com/2010/03/tune-mysql-like-a-pro-with-mysqltuner/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 23:22:10 +0000</pubDate>
		<dc:creator>Samuel Huckins</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=1447</guid>
		<description><![CDATA[I don&#8217;t know why I didn&#8217;t know about this before (or why I forgot about it, more likely), but I came across MySQLTuner recently and was most pleasantly surprised. It&#8217;s a Perl script that only requires your MySQL user and password to provide detailed and useful checks of a running MySQL instance. First though, check [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know why I didn&#8217;t know about this before (or why I forgot about it, more likely), but I came across <a title="MySQLTuner blog" target="_blank" href="http://blog.mysqltuner.com/">MySQLTuner</a> recently and was most pleasantly surprised. It&#8217;s a Perl script that only requires your MySQL user and password to provide detailed and useful checks of a running MySQL instance. First though, check out the awesome URL you <a title="MySQLTuner download" target="_blank" href="http://blog.mysqltuner.com/download/">download it</a> at:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">wget</span> mysqltuner.pl</div></td></tr></tbody></table></div>
<p>Yeah, that&#8217;s the actual URL that works. Pretty sweet.</p>
<p>Anyway, next you make it executable, run it, enter creds:</p>
<p><img src="http://dancingpenguinsoflight.com/wp-content/uploads/2010/03/Screenshot1.png" alt="Get MySQLTuner running" title="MySQLTuner_first-steps" width="613" height="414" class="size-full wp-image-1452" /></p>
<p>Then the goodies appear:</p>
<p><img src="http://dancingpenguinsoflight.com/wp-content/uploads/2010/03/results.png" alt="MySQLTuner Results" title="MySQLTuner_results" width="640" height="630" class="size-full wp-image-1449" /></p>
<p>Oh, that query_cache_limit is tiny! At this point, no changes have been made to your setup. But at a glance you get helpful stats, validate that changes you&#8217;ve decided to make are in place, and get alerted to potential improvements.</p>
<p>If I knew Perl now and refreshed my MySQL tuning knowledge, I&#8217;d love to help as a <a href="http://blog.mysqltuner.com/2010/01/searching-for-a-new-mysqltuner-maintainer/">maintainer</a> of this lovely script. Maybe sometime soon&#8230;</p>
   ]]></content:encoded>
			<wfw:commentRss>http://dancingpenguinsoflight.com/2010/03/tune-mysql-like-a-pro-with-mysqltuner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting multiple images to one PDF on Linux</title>
		<link>http://dancingpenguinsoflight.com/2010/02/converting-multiple-images-to-one-pdf-on-linux/</link>
		<comments>http://dancingpenguinsoflight.com/2010/02/converting-multiple-images-to-one-pdf-on-linux/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 18:12:26 +0000</pubDate>
		<dc:creator>Samuel Huckins</dc:creator>
				<category><![CDATA[CLI]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PDF]]></category>

		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=1440</guid>
		<description><![CDATA[There are a number of ways you can go about the process of converting image files into PDFs, most simply by opening a given image and printing it. You can select &#8220;Print to file&#8221; instead of a printer device, PDF format is the default for this type of output. But say you have a folder [...]]]></description>
			<content:encoded><![CDATA[<p>There are a number of ways you can go about the process of converting image files into PDFs, most simply by opening a given image and printing it. You can select &#8220;Print to file&#8221; instead of a printer device, PDF format is the default for this type of output. But say you have a folder full of images and you want to make one big PDF of them. Here&#8217;s how you can do that:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> FOLDER_WITH_IMAGES<br />
<span style="color: #007800;">FILES</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">*</span>jpg<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> temp <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">cd</span> temp<br />
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$FILES</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #007800;">BASE</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$file</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/.jpg//g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; convert ..<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$BASE</span>.jpg <span style="color: #007800;">$BASE</span>.pdf; <span style="color: #000000; font-weight: bold;">done</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span><br />
pdftk <span style="color: #000000; font-weight: bold;">*</span>pdf <span style="color: #c20cb9; font-weight: bold;">cat</span> output ..<span style="color: #000000; font-weight: bold;">/</span>FINAL_NAME.pdf <span style="color: #000000; font-weight: bold;">&amp;&amp;</span><br />
<span style="color: #7a0874; font-weight: bold;">cd</span> ..<br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> temp</div></td></tr></tbody></table></div>
<p>This loops through all the .jpg images in the directory and converts them to a PDF file of the same name. Once that is done they are all combined into FINAL_NAME.pdf by <a title="pdftk home" href="http://www.accesspdf.com/pdftk/" target="_blank">pdftk</a>, a handy PDF utility. The temp dir business is there to make the temp PDF file removal easier.</p>
   ]]></content:encoded>
			<wfw:commentRss>http://dancingpenguinsoflight.com/2010/02/converting-multiple-images-to-one-pdf-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>git tip: Ignoring modifications to tracked files</title>
		<link>http://dancingpenguinsoflight.com/2010/02/git-tip-ignoring-modifications-to-tracked-files/</link>
		<comments>http://dancingpenguinsoflight.com/2010/02/git-tip-ignoring-modifications-to-tracked-files/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 04:13:29 +0000</pubDate>
		<dc:creator>Samuel Huckins</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[RubyOnRails]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[VCS]]></category>

		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=1427</guid>
		<description><![CDATA[Problem
You have a file already tracked in your git repository, but you don&#8217;t want future modifications to it to be tracked.
A perfect example of this is the DB config file for Rails projects (config/database.yml). You&#8217;ll probably want to track this to keep the production and staging configuration stored and consistent. But it&#8217;s quite likely that [...]]]></description>
			<content:encoded><![CDATA[<h2>Problem</h2>
<p><em>You have a file already tracked in your git repository, but you don&#8217;t want future modifications to it to be tracked.</em></p>
<p>A perfect example of this is the DB config file for Rails projects (config/database.yml). You&#8217;ll probably want to track this to keep the production and staging configuration stored and consistent. But it&#8217;s quite likely that individual development configurations will be different. Having a commit for each developer adding their own local configuration and thereby polluting it for others when they push is just silly.</p>
<h2>Solution</h2>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">git update-index <span style="color: #660033;">--assume-unchanged</span> FILENAME</div></td></tr></tbody></table></div>
<h2>The fun details</h2>
<p>I had initially thought that <a title="git-ignore docs" href="http://ftp.cc.uoc.gr/pub/software/scm/git/docs/gitignore.html" target="_blank">git-ignore</a> was the thing to use for this. That was wrong: git-ignore&#8217;s purpose is to allow ignoring of <em>untracked</em> files. In the case of the Rails DB conf example above, the file is already tracked. It has the instance information that needs to be shared and now we want to add local development details. Since it&#8217;s tracked, any modifications are going to be picked up by <a title="git-status docs" href="http://www.kernel.org/pub/software/scm/git/docs/git-status.html" target="_blank">git-status</a>. When you do a commit including changes to tracked files listed in .gitignore, the changes do indeed get pushed, which isn&#8217;t what we want.</p>
<p>When looking around for solutions to this, I saw &#8220;git rm &#8211;cached FILENAME&#8221; suggested as a way to stop tracking currently tracked files. And it does this, but it also deletes the file in the commit, which isn&#8217;t what we want either.</p>
<p><a title="git update-index man page" href="http://kernel.org/pub/software/scm/git/docs/v1.0.13/git-update-index.html">git update-index</a> allows you to alter your <a title="Post on git's staging area" href="http://www.gitready.com/beginner/2009/01/18/the-staging-area.html" target="_blank">staging area</a> more manually than usual. With it you can perform a wide range of operations not otherwise possible through standard commands. Continuing with the Rails DB conf example, here&#8217;s what the workflow would look like:</p>
<ol>
<li>config/database.yml with permanent instance info is added, committed, and pushed</li>
<li>Application code is pulled down by new developer</li>
<li>Local modifications made to database.yml for new developer&#8217;s local DB setup</li>
<li>git update-index &#8211;assume-unchanged config/database.yml</li>
</ol>
<p>Thereafter, the changes to conf/database.yml won&#8217;t appear in status or get committed. You can continue making and committing other changes, going about business as usual. But any changes to config/database.yml won&#8217;t ever appear.</p>
<p>In case you decide you <em>do</em> want to start tracking changes on a file previously ignored, just run:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">git update-index <span style="color: #660033;">--no-assume-unchanged</span> FILENAME</div></td></tr></tbody></table></div>
<p>Thereafter changes to FILENAME will appear in git-status.</p>
<h2>Gotcha</h2>
<p>The annoying part about this solution is that it has to be run against every new checkout of the repo with the files whose modifications should not be tracked. The command sets a particular bit per checkout, and it&#8217;s not passed on to new checkouts.</p>
<p>Just as I was finishing up some fact checking for this write-up, I came across <a href="http://justaddwater.dk/2009/12/07/how-to-make-git-ignore-files-that-already-exist-in-your-project/" target="_blank">Jesper Rønn-Jensen&#8217;s post</a> on this exact topic. If only it had come up in my initial searches! Here&#8217;s hoping the next searcher has better luck.</p>
   ]]></content:encoded>
			<wfw:commentRss>http://dancingpenguinsoflight.com/2010/02/git-tip-ignoring-modifications-to-tracked-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with ASCII art</title>
		<link>http://dancingpenguinsoflight.com/2009/12/fun-with-ascii-art/</link>
		<comments>http://dancingpenguinsoflight.com/2009/12/fun-with-ascii-art/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 06:06:02 +0000</pubDate>
		<dc:creator>Samuel Huckins</dc:creator>
				<category><![CDATA[CLI]]></category>
		<category><![CDATA[Bash]]></category>

		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=1381</guid>
		<description><![CDATA[No, in fact ASCII art isn&#8217;t dead, it&#8217;s all the rage. Now that that&#8217;s established, check out these handy programs for generating your own ASCII art messages:
1figlet -f smslant Boxes rules. &#124; boxes -d parchment -a hcvc

Figure 1. boxes provides boundless entertainment.
1figlet -f standard Also figlet. &#124; boxes -d mouse -a hcvc

Figure 2. figlet and [...]]]></description>
			<content:encoded><![CDATA[<p>No, in fact <a title="ASCII art on Wikipedia" href="http://en.wikipedia.org/wiki/Ascii_art" target="_blank">ASCII art</a> isn&#8217;t dead, it&#8217;s all the rage. Now that that&#8217;s established, check out these handy programs for generating your own ASCII art messages:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">figlet <span style="color: #660033;">-f</span> smslant Boxes rules. <span style="color: #000000; font-weight: bold;">|</span> boxes <span style="color: #660033;">-d</span> parchment <span style="color: #660033;">-a</span> hcvc</div></td></tr></tbody></table></div>
<p><img class="aligncenter size-full wp-image-1390" title="boxes" src="http://dancingpenguinsoflight.com/wp-content/uploads/2009/12/boxes.png" alt="boxes" width="435" height="144" /></p>
<p style="text-align: center;">Figure 1. <em>boxes</em> provides boundless entertainment.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">figlet <span style="color: #660033;">-f</span> standard Also figlet. <span style="color: #000000; font-weight: bold;">|</span> boxes <span style="color: #660033;">-d</span> mouse <span style="color: #660033;">-a</span> hcvc</div></td></tr></tbody></table></div>
<p><img class="aligncenter size-full wp-image-1391" title="figlet" src="http://dancingpenguinsoflight.com/wp-content/uploads/2009/12/figlet.png" alt="figlet" width="417" height="266" /></p>
<p style="text-align: center;">Figure 2. <em>figlet</em> and its inherent awesomeness.</p>
<p>Spice up those bland Bash scripts with entertaining comment formats!</p>
<p>But seriously, these utilities can make for more interesting banners, alert messages, and so on:</p>
<ul>
<li><a title="boxes homepage" href="http://boxes.thomasjensen.com/" target="_blank">boxes</a>: Creates ASCII art boxes around entered text</li>
<li><a title="figlet homepage" href="http://www.figlet.org/" target="_blank">figlet</a>: Creates large ASCII art versions of entered characters</li>
</ul>
<p>Just because it&#8217;s the command line doesn&#8217;t mean it has to be boring!</p>
   ]]></content:encoded>
			<wfw:commentRss>http://dancingpenguinsoflight.com/2009/12/fun-with-ascii-art/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Hiding anchor tooltips on hover</title>
		<link>http://dancingpenguinsoflight.com/2009/11/hiding-anchor-tooltips-on-hover/</link>
		<comments>http://dancingpenguinsoflight.com/2009/11/hiding-anchor-tooltips-on-hover/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 18:25:48 +0000</pubDate>
		<dc:creator>Samuel Huckins</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=1362</guid>
		<description><![CDATA[Navigation menus on websites most often consist of a list of links. When looking through a menu, it&#8217;s not unreasonable for a visitor to have their mouse cursor over some of the menu item links for a few moments as they read through the options. Using an unadorned anchor tag in this situation has a [...]]]></description>
			<content:encoded><![CDATA[<p>Navigation menus on websites most often consist of a list of links. When looking through a menu, it&#8217;s not unreasonable for a visitor to have their mouse cursor over some of the menu item links for a few moments as they read through the options. Using an unadorned <a href="http://www.w3schools.com/TAGS/tag_a.asp">anchor tag</a> in this situation has a troublesome side effect:</p>
<p><img src="http://dancingpenguinsoflight.com/wp-content/uploads/2009/11/title-hover-example.png" alt="title-hover-example" title="title-hover-example" width="634" height="111" class="aligncenter size-full wp-image-1363" style="border: 1px dotted black;" /></p>
<p>The title attribute of the anchor tag will appear as a tooltip, potentially obscuring menu items and minimally being a useless distraction. But removing titles from navigation links isn&#8217;t a good option, since this attribute is helpful for SEO and accessibility purposes.</p>
<p>When discussing this problem with friend Google, I ran across many examples of how to change the display of anchor tooltips, as well as how to hide them altogether. But what I wanted was removal of the title attribute on navigation links only when the mouse cursor hovered over them, adding it back when the cursor left. The solution I settled on consisted of jQuery&#8217;s handy <a title="jQuery hover" target="_blank" href="http://docs.jquery.com/Events/hover">hover function</a> and some basic JavaScript. <em>hover()</em> allows you to specify a function to call when the cursor hovers onto an object and another to call when the cursor hovers off. Perfect! Here&#8217;s a simple example:</p>
<div class="codecolorer-container html4strict blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>A test<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
<br />
&nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- Load in jQuery for handy hover function --&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;</span><br />
&nbsp; &nbsp; $(document).ready(function() { &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; // All links in main menu div<br />
&nbsp; &nbsp; &nbsp; &nbsp; var menu_links = $('div[id=main-menu] a');<br />
&nbsp; &nbsp; &nbsp; &nbsp; // On mouse hover<br />
&nbsp; &nbsp; &nbsp; &nbsp; menu_links.hover(<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // In: Store and remove title<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function() { &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; old_title = $(this).attr('title'); &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(this).attr('title',''); <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Out: Replace title<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function() { &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(this).attr('title', old_title); &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp;<br />
&nbsp; &nbsp; }); &nbsp;<br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;main-menu&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Titles are great for SEO and accessibility but don&amp;#8217;t need to be seen by users normally!&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;zenoss.com&quot;</span>&gt;</span>MenuItem1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Titles are great for SEO and accessibility but don&amp;#8217;t need to be seen by users normally!&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;zenoss.com&quot;</span>&gt;</span>MenuItem2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Titles are great for SEO and accessibility but don&amp;#8217;t need to be seen by users normally!&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;zenoss.com&quot;</span>&gt;</span>MenuItem3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span>I am text! Hurray! <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bodylink1&quot;</span> <span style="color: #000066;">target</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;_blank&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;zenoss.com&quot;</span>&gt;</span>I am a normal link.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>You can verify the functionality by inspecting one of the MenuItem links with <a title="Get Firebug" target="_blank" href="http://getfirebug.com/">Firebug</a> and watching the title attribute as you move the cursor on and off the same link.</p>
<p>After the page is finished loading, when a cursor hovers onto any links within the div of id &#8220;main-menu&#8221; the title attribute is stored and set to an empty string (so no tooltip). When the cursor leaves, the title attribute is set back to its original value. Simple but effective!</p>
   ]]></content:encoded>
			<wfw:commentRss>http://dancingpenguinsoflight.com/2009/11/hiding-anchor-tooltips-on-hover/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Better access to MySQL create view statements</title>
		<link>http://dancingpenguinsoflight.com/2009/11/better-access-to-mysql-create-view-statements/</link>
		<comments>http://dancingpenguinsoflight.com/2009/11/better-access-to-mysql-create-view-statements/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 04:23:29 +0000</pubDate>
		<dc:creator>Samuel Huckins</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=1066</guid>
		<description><![CDATA[I&#8217;ve found that I often create several views that are variations on an initial one, providing a slightly different convenient slice of the data as the need arises. But when a view is created the syntax actually stored can be quite different than what you put in. The parser reorganizes and rewrites to make everything [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve found that I often create several views that are variations on an initial one, providing a slightly different convenient slice of the data as the need arises. But when a view is created the syntax actually stored can be quite different than what you put in. The parser reorganizes and rewrites to make everything explicit. While better for performance in running the view, this has the unfortunate side effect of transmuting a once readable statement into a forest of parentheses and backticks that can and does induce tears.</p>
<p>First an example view that I created using the <a title="Post on quickly setting up the test world database" target="_blank" href="http://dancingpenguinsoflight.com/2009/09/rapidly-set-up-a-mysql-database-for-testing/">handy world database</a>:</p>
<div class="codecolorer-container sql blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">VIEW</span> world<span style="color: #66cc66;">.</span>low_central_luzon <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> a<span style="color: #66cc66;">.</span>Name <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;City&quot;</span><span style="color: #66cc66;">,</span> b<span style="color: #66cc66;">.</span>Name <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Country&quot;</span><span style="color: #66cc66;">,</span> a<span style="color: #66cc66;">.</span>Population<span style="color: #66cc66;">,</span> a<span style="color: #66cc66;">.</span>District <br />
<span style="color: #993333; font-weight: bold;">FROM</span> world<span style="color: #66cc66;">.</span>City a<br />
<span style="color: #993333; font-weight: bold;">JOIN</span> world<span style="color: #66cc66;">.</span>Country b <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">.</span>CountryCode <span style="color: #66cc66;">=</span> b<span style="color: #66cc66;">.</span>Code<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">WHERE</span> b<span style="color: #66cc66;">.</span>Continent <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;Asia&quot;</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AND</span> a<span style="color: #66cc66;">.</span>District <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;Central Luzon&quot;</span><br />
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> a<span style="color: #66cc66;">.</span>Population<br />
<span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">10</span>;</div></td></tr></tbody></table></div>
<p>This is a view of the 10 cites with the lowest population in the Central Luzon region of Asia. Now let&#8217;s see what actually got stored. To get a view&#8217;s create statement you can use the MySQL Query Browser and right click the view name shown in the right under Schemata, selecting &#8220;Copy SQL to Clipboard&#8221;. Or you can run a query like:</p>
<div class="codecolorer-container sql blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> VIEW_DEFINITION <span style="color: #993333; font-weight: bold;">FROM</span> information_schema<span style="color: #66cc66;">.</span>VIEWS<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> TABLE_NAME <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;low_central_luzon&quot;</span><br />
<span style="color: #993333; font-weight: bold;">AND</span> TABLE_SCHEMA <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;world&quot;</span>;</div></td></tr></tbody></table></div>
<p>Here&#8217;s the result for the view above:</p>
<div class="codecolorer-container sql blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">`a`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`Name`</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">`City`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`b`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`Name`</span> <br />
<span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">`Country`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`a`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`Population`</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">`Population`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`a`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`District`</span> <br />
<span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">`District`</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`world`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`City`</span> <span style="color: #ff0000;">`a`</span> <span style="color: #993333; font-weight: bold;">JOIN</span> <span style="color: #ff0000;">`world`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`Country`</span> <span style="color: #ff0000;">`b`</span> <br />
<span style="color: #993333; font-weight: bold;">ON</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`a`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`CountryCode`</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">`b`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`Code`</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`b`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`Continent`</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Asia'</span><span style="color: #66cc66;">&#41;</span> <br />
<span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`a`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`District`</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Central Luzon'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">`a`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`Population`</span> <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">10</span></div></td></tr></tbody></table></div>
<p>I added the line breaks for a modicum of readablilty, the statement is stored without them. I sure don&#8217;t want to edit that version in making a variant! This example isn&#8217;t actually too bad, but for real world complicated views, it really is quite difficult to read views exported in this way. I often try to store the original create view query just to avoid this pain. But sometimes I only have the stored syntax.</p>
<p>I&#8217;ve created a Bash function to make this whole process less painful:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> mysqldump_view <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Grabs the create statement for the view passed in the db passed.</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Performs some text cleanup to make it more human readable, outputs</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># to file.</span><br />
&nbsp; &nbsp; <span style="color: #007800;">USAGE</span>=<span style="color: #ff0000;">&quot;USAGE: mysqldump_view DATABASE_NAME VIEW_NAME&quot;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">opt_err</span>=<span style="color: #ff0000;">&quot;Must pass db and view.&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-ne</span> 2 <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$opt_err</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$USAGE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> 1<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #007800;">DB</span>=$1<br />
&nbsp; &nbsp; <span style="color: #007800;">VIEW</span>=$2<br />
&nbsp; &nbsp; <span style="color: #007800;">DEFAULT_USER</span>=<span style="color: #ff0000;">&quot;root&quot;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">OUTPUT_FILE</span>=<span style="color: #ff0000;">&quot;view-<span style="color: #007800;">$VIEW</span>.sql&quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Attempting to connect with mysql defaults, user <span style="color: #007800;">$DEFAULT_USER</span>...&quot;</span><br />
mysql <span style="color: #660033;">-u</span> <span style="color: #007800;">$DEFAULT_USER</span> <span style="color: #660033;">-p</span> <span style="color: #660033;">--skip-column-names</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;SELECT VIEW_DEFINITION FROM <span style="color: #000099; font-weight: bold;">\<br />
</span>information_schema.VIEWS where TABLE_NAME = <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">$VIEW</span><span style="color: #000099; font-weight: bold;">\&quot;</span> and TABLE_SCHEMA = <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">$DB</span><span style="color: #000099; font-weight: bold;">\&quot;</span>;&quot;</span> \<br />
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;1s/^\(.*\)$/CREATE VIEW <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">$VIEW</span><span style="color: #000099; font-weight: bold;">\&quot;</span> as<span style="color: #000099; font-weight: bold;">\n</span>\1/&quot;</span> \<br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/`,`/`,\n`/g'</span> \<br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/ from /\nfrom /g'</span> \<br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/ join /\n\tjoin /g'</span> \<br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/ where /\nwhere /g'</span> \<br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/ and /\n\tand /g'</span> \<br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/ limit /\nlimit /g'</span> \<br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/ order /\norder /g'</span> \<br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'$s/$/;/'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$OUTPUT_FILE</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Done. View syntax written to <span style="color: #007800;">$OUTPUT_FILE</span>.&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now to get a cleaned up view you can call this function followed by the database and view names:<br />
<img src="http://dancingpenguinsoflight.com/wp-content/uploads/2009/11/example.png" alt="example" title="example" width="580" height="271" class="aligncenter size-full wp-image-1348" /></p>
<p>To get the create statements for multiple views you can <a target="_blank" title="Post on Bash loops" href="http://dancingpenguinsoflight.com/2007/10/loops-in-cli-warm-and-fuzzy/">use a loop</a>. For example:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">for</span> VIEW <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;high_central_luzon&quot;</span> <span style="color: #ff0000;">&quot;low_central_luzon&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span> mysqldump_view world <span style="color: #007800;">$VIEW</span>; <span style="color: #000000; font-weight: bold;">done</span></div></td></tr></tbody></table></div>
<p>If you need some more flexibility than this I implemented it in Python after an initial fit of rage caused by trying to get various levels of nested strings properly escaped in Bash. That ended up being overly long and unnecessary, and a cooler head prevailed. But <a target="_blank" title="mysqldump_view.py on shuckins' github" href="http://github.com/shuckins/sph_code/blob/master/sysadmin/mysql/mysqldump_view.py">the script</a> is here on GitHub if you want it. It creates the same file although without using sed and with some error handling.</p>
   ]]></content:encoded>
			<wfw:commentRss>http://dancingpenguinsoflight.com/2009/11/better-access-to-mysql-create-view-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A better way to search for methods of Python objects</title>
		<link>http://dancingpenguinsoflight.com/2009/11/a-better-way-to-search-for-methods-of-python-objects/</link>
		<comments>http://dancingpenguinsoflight.com/2009/11/a-better-way-to-search-for-methods-of-python-objects/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 22:08:10 +0000</pubDate>
		<dc:creator>Samuel Huckins</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[efficiency]]></category>

		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=1316</guid>
		<description><![CDATA[Python&#8217;s introspection abilities are quite extensive and useful. They are also well-documented, so I won&#8217;t go into the basics here. Check out this article if you need a good overview. N.B.: discussion and code below applies to both methods and attributes. I will simply refer to &#8220;methods&#8221; for simplicity.
Beyond simply listing the methods of an [...]]]></description>
			<content:encoded><![CDATA[<p>Python&#8217;s introspection abilities are quite extensive and useful. They are also well-documented, so I won&#8217;t go into the basics here. <a title="Guide to Python Introspection" target="_blank" href="http://www.ibm.com/developerworks/library/l-pyint.html">Check out this article</a> if you need a good overview. N.B.: discussion and code below applies to both methods and attributes. I will simply refer to &#8220;methods&#8221; for simplicity.</p>
<p>Beyond simply listing the methods of an object, however, I often find that I want to search through them for something in particular. And eyeballing the output of dir(obj) is only efficient in the simplest of cases. hasattr(obj, &#8220;method&#8221;) won&#8217;t get you far either, as you need to match the &#8220;method&#8221; name exactly. What if you just have a good guess about the name of a method based on what you need to do? What if you want to know everything you can do with directories in the os module or ISO related methods in datetime.date? I haven&#8217;t found anything to help with this sort of problem yet. Approaches like writing a loop to do the search every time or perusing the pertinent API docs are too circuitous for such quick questions. So let&#8217;s make a tool to do this more easily!</p>
<p>We start with knowing some object and some string containing all or part of the method(s) we&#8217;re interested in:</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> mf<span style="color: black;">&#40;</span>obj, term<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #483d8b;">&quot;&quot;&quot;<br />
&nbsp; &nbsp; Searches through the methods and attributes defined for obj, <br />
&nbsp; &nbsp; looks for those containing the term passed.<br />
&nbsp; &nbsp; Returns all matches or a warning if none found.<br />
&nbsp; &nbsp; &quot;&quot;&quot;</span><br />
&nbsp; &nbsp; meths = <span style="color: #008000;">dir</span><span style="color: black;">&#40;</span>obj<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; match_meths = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> meth <span style="color: #ff7700;font-weight:bold;">in</span> meths:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> meth.<span style="color: black;">rfind</span><span style="color: black;">&#40;</span>term<span style="color: black;">&#41;</span> <span style="color: #66cc66;">!</span>= -1:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; match_meths.<span style="color: black;">append</span><span style="color: black;">&#40;</span>meth<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> match_meths:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> match_meths<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">else</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;No matches!&quot;</span></div></td></tr></tbody></table></div>
<p>This simply iterates over the methods and attributes defined for the object passed and looks for the term passed within the name of each. rfind returns the highest index of the substring passed in the string it&#8217;s called on and returns -1 if no match is found. Once the matches are collected they are printed out. An example:</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&gt;&gt;&gt;</span>from method_finder <span style="color: #ff7700;font-weight:bold;">import</span> mf<br />
<span style="color: #66cc66;">&gt;&gt;&gt;</span>import <span style="color: #dc143c;">os</span><br />
<span style="color: #66cc66;">&gt;&gt;&gt;</span>mf<span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>, <span style="color: #483d8b;">&quot;dir&quot;</span><span style="color: black;">&#41;</span><br />
<span style="color: black;">&#91;</span><span style="color: #483d8b;">'chdir'</span>, <span style="color: #483d8b;">'curdir'</span>, <span style="color: #483d8b;">'fchdir'</span>, <span style="color: #483d8b;">'listdir'</span>, <span style="color: #483d8b;">'makedirs'</span>, <span style="color: #483d8b;">'mkdir'</span>, <span style="color: #483d8b;">'pardir'</span>, <span style="color: #483d8b;">'removedirs'</span>, <span style="color: #483d8b;">'rmdir'</span><span style="color: black;">&#93;</span></div></td></tr></tbody></table></div>
<p>For convenience let&#8217;s make it available on the Python interactive prompt at every load without any extra effort. This is easy enough using a .pythonstartup file. This file can be used to load various useful items like tab completion for interactive Python sessions. If you haven&#8217;t used it before, you&#8217;ll need to add the following to your .bashrc:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PYTHONSTARTUP</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/.pythonstartup&quot;</span></div></td></tr></tbody></table></div>
<p>Then in your home directory create a .pythonstartup file containing something like the following:</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span><br />
<span style="color: #808080; font-style: italic;"># Adds mf(obj, &quot;str&quot;) allowing search for methods matching 'str' on obj</span><br />
<span style="color: #808080; font-style: italic;"># as well as obinfo(obj) returning lots of info on obj</span><br />
util_loc = <span style="color: #483d8b;">&quot;/home/shuckins/code/code_homerepo/python-programming/utilities&quot;</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">isdir</span><span style="color: black;">&#40;</span>util_loc<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span><br />
&nbsp; &nbsp; <span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>util_loc<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">from</span> utils <span style="color: #ff7700;font-weight:bold;">import</span> mf, obinfo<br />
&nbsp; &nbsp; <span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span>.<span style="color: black;">remove</span><span style="color: black;">&#40;</span>util_loc<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">del</span> <span style="color: #dc143c;">sys</span><br />
<span style="color: #ff7700;font-weight:bold;">del</span> <span style="color: #dc143c;">os</span></div></td></tr></tbody></table></div>
<p>You&#8217;ll need to change the path specified to wherever you placed utils.py containing the mf() function of course. You can <a target="_blank" title="utils.py on github" href="http://github.com/shuckins/sph_code/blob/master/python-programming/utilities/utils.py">download mine here</a> if you&#8217;d like. The del statements are to clean up any trace of this operation once you get to the interactive interpreter. This way you get the added functions without mucking up your namespace. </p>
<p>This also loads in an obinfo(obj) function that I included in the same utils.py file. This is based on the interrogate() function written by Patrick O&#8217;Brien in the <a title="Guide to Python Introspection" target="_blank" href="http://www.ibm.com/developerworks/library/l-pyint.html">introspection article mentioned above</a>. My version just adds a check for objects without docstrings and prints more of the docstring:</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> obinfo<span style="color: black;">&#40;</span>obj<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #483d8b;">&quot;&quot;&quot;<br />
&nbsp; &nbsp; Print useful information about object.<br />
<br />
&nbsp; &nbsp; From http://www.ibm.com/developerworks/library/l-pyint.html<br />
&nbsp; &nbsp; &quot;&quot;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">hasattr</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">'__name__'</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;NAME: &nbsp; &nbsp;&quot;</span>, obj.__name__<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">hasattr</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">'__class__'</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;CLASS: &nbsp; &quot;</span>, obj.__class__.__name__<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;ID: &nbsp; &nbsp; &nbsp;&quot;</span>, <span style="color: #008000;">id</span><span style="color: black;">&#40;</span>obj<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;TYPE: &nbsp; &nbsp;&quot;</span>, <span style="color: #008000;">type</span><span style="color: black;">&#40;</span>obj<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;VALUE: &nbsp; &quot;</span>, <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>obj<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;CALLABLE:&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">callable</span><span style="color: black;">&#40;</span>obj<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Yes&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">else</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;No&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">hasattr</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">'__doc__'</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; doc = <span style="color: #008000;">getattr</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">'__doc__'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; doc = doc.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; topfive = doc.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>0:4<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;DOC: &nbsp; &nbsp; &quot;</span>, <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>topfive<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">else</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;No docstring. Yell at the author.&quot;</span></div></td></tr></tbody></table></div>
<p>It&#8217;s fairly useful:</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&gt;&gt;&gt;</span> obinfo<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;some&quot;</span>, <span style="color: #483d8b;">&quot;list&quot;</span><span style="color: black;">&#93;</span>.<span style="color: black;">count</span><span style="color: black;">&#41;</span><br />
NAME: &nbsp; &nbsp; count<br />
CLASS: &nbsp; &nbsp;builtin_function_or_method<br />
ID: &nbsp; &nbsp; &nbsp; <span style="color: #ff4500;">139922087930696</span><br />
TYPE: &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>type <span style="color: #483d8b;">'builtin_function_or_method'</span><span style="color: #66cc66;">&gt;</span><br />
VALUE: &nbsp; &nbsp;<span style="color: #66cc66;">&lt;</span>built-<span style="color: #ff7700;font-weight:bold;">in</span> method count of <span style="color: #008000;">list</span> <span style="color: #008000;">object</span> at 0x7f422658ef80<span style="color: #66cc66;">&gt;</span><br />
CALLABLE: Yes<br />
DOC: &nbsp; &nbsp; &nbsp;L.<span style="color: black;">count</span><span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span> -<span style="color: #66cc66;">&gt;</span> integer -- <span style="color: #ff7700;font-weight:bold;">return</span> number of occurrences of value</div></td></tr></tbody></table></div>
   ]]></content:encoded>
			<wfw:commentRss>http://dancingpenguinsoflight.com/2009/11/a-better-way-to-search-for-methods-of-python-objects/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Quick tips for NVIDIA and ATI graphics configuration repairs on Ubuntu</title>
		<link>http://dancingpenguinsoflight.com/2009/11/quick-tips-for-nvidia-and-ati-graphics-configuration-repairs-on-ubuntu/</link>
		<comments>http://dancingpenguinsoflight.com/2009/11/quick-tips-for-nvidia-and-ati-graphics-configuration-repairs-on-ubuntu/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 02:15:10 +0000</pubDate>
		<dc:creator>Samuel Huckins</dc:creator>
				<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=1306</guid>
		<description><![CDATA[While graphics card and display configuration on Ubuntu has come a long way from the days of always having to edit xorg.conf by hand, I still run into issues now and again. I almost never have problems any more when setting up a new system. But changing cards in an existing system is another story, [...]]]></description>
			<content:encoded><![CDATA[<p>While graphics card and display configuration on Ubuntu has come a long way from the days of always having to edit xorg.conf by hand, I still run into issues now and again. I almost never have problems any more when setting up a new system. But changing cards in an existing system is another story, especially if switching between NVIDIA and ATI. </p>
<p>Today I did indeed switch from an NVIDIA to an ATI graphics card on an Ubuntu 9.10 machine. I had the nvidia-glx kernel mod in place, and xorg.conf specified the NVIDIA related modules to load, so just switching out the card and rebooting resulted in a flickering text login, no more desktop. This post covers the commands needed to install the appropriate kernel module and reconfigure Xorg in such situations. </p>
<p>After putting in your new card if you aren&#8217;t able to get to your desktop/get sent to a text login when you boot/get an Xorg error, reboot and hit Escape when GRUB prompts you. Boot into the recovery mode for the latest kernel shown in the list. Drop into root prompt with networking when prompted.</p>
<h2>NVIDIA to ATI</h2>
<p>This assumes you have an ATI card in place. Once at the root prompt run:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> xorg-driver-fglrx</div></td></tr></tbody></table></div>
<p>This will remove nvidia-glx if you have it installed and install the driver for ATI Radeon and FireGL graphics cards. After this is complete you need to reconfigure xorg.conf to use the new module. Fear not, no manual editing should be required to get a basic configuration working. Just run:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">aticonfig <span style="color: #660033;">--initial</span></div></td></tr></tbody></table></div>
<p>This script comes with the xorg-driver-fglrx. Running this will add screen and device sections in /etc/X11/xorg.conf appropriate for an ATI card, backing up /etc/X11/xorg.conf beforehand. If you added any special configurations for your screen section before you might want to edit the file manually and copy the customizations into the appropriate new sections. The sections already in xorg.conf will still be there, just commented out or not actually called when loading X. Next run:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">startx</div></td></tr></tbody></table></div>
<p>If all goes well you will be back to a working desktop. You can also check from the command line by running &#8220;fglrxinfo&#8221;.</p>
<p>For more information on using the ATI drivers on Ubuntu see <a target="_blank" title="ATI binary driver guide" href="https://help.ubuntu.com/community/BinaryDriverHowto/ATI">this wiki article</a>.</p>
<h2>ATI to NVIDIA</h2>
<p>And in the reverse situation:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">apt-cache</span> search nvidia-glx<br />
<span style="color: #666666; font-style: italic;"># Install the latest stable one. Currently:</span><br />
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> nvidia-glx-<span style="color: #000000;">185</span></div></td></tr></tbody></table></div>
<p>And the equivalent for aticonfig:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">nvidia-xconfig</div></td></tr></tbody></table></div>
<p>As above:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">startx</div></td></tr></tbody></table></div>
<p>For more information on using the NVIDIA drivers on Ubuntu see <a target="_blank" title="NVIDIA binary driver guide" href="https://help.ubuntu.com/community/BinaryDriverHowto/Nvidia">this wiki article</a>.</p>
<p>No guarantees here, but these have worked for me.</p>
   ]]></content:encoded>
			<wfw:commentRss>http://dancingpenguinsoflight.com/2009/11/quick-tips-for-nvidia-and-ati-graphics-configuration-repairs-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Catching warnings from the MySQLdb module</title>
		<link>http://dancingpenguinsoflight.com/2009/10/catching-warnings-from-the-mysqldb-module/</link>
		<comments>http://dancingpenguinsoflight.com/2009/10/catching-warnings-from-the-mysqldb-module/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 03:53:50 +0000</pubDate>
		<dc:creator>Samuel Huckins</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=1300</guid>
		<description><![CDATA[The MySQLdb Python module implements the Python DB API for MySQL. I&#8217;ve written about its use before. MySQL issues warning messages in a number of circumstances and PEP 249 (which specifies the Python DB API) describes a Warning error message to be included.
One issue I ran into recently was how to catch warnings thrown by [...]]]></description>
			<content:encoded><![CDATA[<p>The <a target="_blank" title="MySQLdb home" href="http://sourceforge.net/projects/mysql-python/">MySQLdb Python module</a> implements the Python DB API for MySQL. I&#8217;ve written about its use <a target="_blank" title="MySQL queries in Python" href="http://dancingpenguinsoflight.com/2009/03/running-mysql-queries-in-python/">before</a>. MySQL issues <a target="_blank" title="MySQL show warnings" href="http://dev.mysql.com/doc/refman/5.0/en/show-warnings.html">warning messages</a> in a number of circumstances and <a target="_blank" title="PEP 249" href="http://www.python.org/dev/peps/pep-0249/">PEP 249</a> (which specifies the Python DB API) describes a Warning error message to be included.</p>
<p>One issue I ran into recently was how to catch warnings thrown by this module when running queries. Oftentimes tutorials or forum discussions that cover warnings in the context of MySQLdb describe how to filter them (they can clog up script output). But in a recent case I wanted to grab and check the warning, logging a dependent result. I had hoped this clean implementation would work in a method used for all calls to the MySQL DB:</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">try</span>:<br />
&nbsp; &nbsp; cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span>query<span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">except</span> MySQLdb.<span style="color: black;">Error</span>, e:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">raise</span> e<br />
<span style="color: #ff7700;font-weight:bold;">except</span> MySQLdb.<span style="color: #008000;">Warning</span>, e:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">raise</span> e<br />
<span style="color: #ff7700;font-weight:bold;">finally</span>:<br />
&nbsp; &nbsp; data = cursor.<span style="color: black;">fetchall</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; rows_returned = cursor.<span style="color: black;">rowcount</span><br />
&nbsp; &nbsp; cursor.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; db.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>
<p>But the warnings just went right through. Instead I needed the warnings module&#8217;s assistance:</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">warnings</span><br />
<span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #dc143c;">warnings</span>.<span style="color: black;">catch_warnings</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #dc143c;">warnings</span>.<span style="color: black;">simplefilter</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'error'</span>, MySQLdb.<span style="color: #008000;">Warning</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">try</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span>query<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">except</span> MySQLdb.<span style="color: black;">Error</span>, e:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">raise</span> e<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">finally</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; data = cursor.<span style="color: black;">fetchall</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rows_returned = cursor.<span style="color: black;">rowcount</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cursor.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; db.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>
<p>This catches the warnings and raises them as errors, although their class is still correct, allowing a clean implementation to call the above code (wrapped into a method called do_query):</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">try</span>:<br />
&nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">do_query</span><span style="color: black;">&#40;</span>make_cool_table<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; logger.<span style="color: black;">info</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Created cool_table table.&quot;</span><span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">except</span> MySQLdb.<span style="color: #008000;">Warning</span>:<br />
&nbsp; &nbsp; logger.<span style="color: black;">info</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;cool_table already exists.&quot;</span><span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>
   ]]></content:encoded>
			<wfw:commentRss>http://dancingpenguinsoflight.com/2009/10/catching-warnings-from-the-mysqldb-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Viewing all users on a Linux system</title>
		<link>http://dancingpenguinsoflight.com/2009/10/viewing-all-users-on-a-linux-system/</link>
		<comments>http://dancingpenguinsoflight.com/2009/10/viewing-all-users-on-a-linux-system/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 20:35:59 +0000</pubDate>
		<dc:creator>Samuel Huckins</dc:creator>
				<category><![CDATA[CLI]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=1274</guid>
		<description><![CDATA[There are a number of widely-used and stable utilities on Linux systems that allow you to view information related to users. You can see who&#8217;s logged in with who, get info on a particular user with finger, see who you are with whoami and see who logged in last with last and lastlog. And there [...]]]></description>
			<content:encoded><![CDATA[<p>There are a number of widely-used and stable utilities on Linux systems that allow you to view information related to users. You can see who&#8217;s logged in with <a href="http://linux.die.net/man/1/who">who</a>, get info on a particular user with <a href="http://linux.die.net/man/1/finger">finger</a>, see who you are with <a href="http://linux.die.net/man/1/whoami">whoami</a> and see who logged in last with <a href="http://linux.die.net/man/1/last">last</a> and <a href="http://linux.die.net/man/8/lastlog">lastlog</a>. And there are commands to create, remove, and change users and their groups. </p>
<p>But what if you just want to see all the users defined on the entire system? Looking in /home won&#8217;t show you users that don&#8217;t have a home dir or one not located there. All users are indeed listed in <a target="_blank" title="Article on /etc/passwd format" href="http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/">/etc/passwd</a>, but having to look through this file every time you just want a list of users is tedious. I haven&#8217;t found a utility that performs this role. </p>
<p>This was somewhat surprising, as it&#8217;s not an uncommon need. Perhaps I&#8217;ve missed some essential program along my Linux journey. If so, feel free to enlighten me in a comment <img src='http://dancingpenguinsoflight.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  In the meantime, let&#8217;s fill this gap:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># Prints all users, divided by login ability and homedir:</span><br />
<span style="color: #000000; font-weight: bold;">function</span> userinfo <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;----- Users that can login -----&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">&quot;:&quot;</span> <span style="color: #ff0000;">'!/bin\/false/ { print &quot;username: &quot; $1 &quot;, uid: &quot; $3 &quot;, homedir: &quot; $6 }'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span><br />
<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>----- And have /home dir -----&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">&quot;:&quot;</span> <span style="color: #ff0000;">'!/bin\/false/ &amp;&amp; /\/home/ { print &quot;username: &quot; $1 &quot;, uid: &quot; $3 &quot;, homedir: &quot; $6 }'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span><br />
<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>----- Users that can't login -----&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">&quot;:&quot;</span> <span style="color: #ff0000;">'/\/bin\/false/ { print &quot;username: &quot; $1 &quot;, uid: &quot; $3 &quot;, homedir: &quot; $6 }'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>This function should work on any *nix system. Place it inside your ~/.bashrc, reload that (. ~/.bashrc), and try out &#8220;userinfo&#8221;:</p>
<p><img src="http://dancingpenguinsoflight.com/wp-content/uploads/2009/10/userinfo.png" alt="userinfo" title="userinfo" width="534" height="645" class="aligncenter size-full wp-image-1280" /></p>
<p>Three sections are displayed showing usernames, user IDs, and homedirs for users in /etc/passwd who:</p>
<ul>
<li>Don&#8217;t have /bin/false for a shell (i.e. users that can login)</li>
<li>Also have a homedir under /home (i.e. the users that aren&#8217;t for system processes)</li>
<li>Do have /bin/false for a shell (i.e. users that can&#8217;t login)</li>
</ul>
<p>Note that the users that can login category only shows users to which one could switch with &#8220;sudo su &#8211; USERNAME&#8221; from a shell. This doesn&#8217;t mean anything about whether they can login via SSH or other access methods.</p>
   ]]></content:encoded>
			<wfw:commentRss>http://dancingpenguinsoflight.com/2009/10/viewing-all-users-on-a-linux-system/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
