<?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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Aetus Designs</title>
	
	<link>http://aetus.net</link>
	<description>Vikhyat Korrapati's Random Thoughts</description>
	<lastBuildDate>Thu, 29 Oct 2009 10:21:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<creativeCommons:license>http://creativecommons.org/licenses/by-sa/3.0/</creativeCommons:license><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/AetusDesigns" type="application/rss+xml" /><feedburner:emailServiceId>AetusDesigns</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Project Euler Problem 40</title>
		<link>http://feedproxy.google.com/~r/AetusDesigns/~3/s1I4VsOmMWk/</link>
		<comments>http://aetus.net/319/programming/project-euler-problem-40/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 10:21:42 +0000</pubDate>
		<dc:creator>Vikhyat Korrapati</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://aetus.net/?p=319</guid>
		<description><![CDATA[Project Euler Problem 40
In my opinion, this was the easiest problem so far. The brute-force method is easy to implement and runs very fast.
This is the code:

$fraction = ''
&#160;
1.upto&#40;1000000&#41; do &#124;i&#124;
  $fraction &#60;&#60; i.to_s
end
&#160;
def d_&#40;n&#41;
  $fraction&#91;n-1&#93;.to_i
end
&#160;
puts d_&#40;1&#41; * d_&#40;10&#41; * d_&#40;100&#41; * d_&#40;1000&#41; * d_&#40;10000&#41; * d_&#40;100000&#41; * d_&#40;1000000&#41;

It runs in slightly lesser [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://projecteuler.net/index.php?section=problems&#038;id=40">Project Euler Problem 40</a></p>
<p>In my opinion, this was the easiest problem so far. The brute-force method is easy to implement and runs very fast.</p>
<p>This is the code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;"><span style="color:#ff6633; font-weight:bold;">$fraction</span> = <span style="color:#996600;">''</span>
&nbsp;
1.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1000000</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#ff6633; font-weight:bold;">$fraction</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> i.<span style="color:#9900CC;">to_s</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> d_<span style="color:#006600; font-weight:bold;">&#40;</span>n<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#ff6633; font-weight:bold;">$fraction</span><span style="color:#006600; font-weight:bold;">&#91;</span>n<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> d_<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">*</span> d_<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">*</span> d_<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">100</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">*</span> d_<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1000</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">*</span> d_<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">10000</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">*</span> d_<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">100000</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">*</span> d_<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1000000</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>It runs in slightly lesser than one second.</p>
<p>The last line isn&#8217;t very Ruby-ish because I copied it from the problem description page, because I&#8217;m too lazy to write it myself. That&#8217;s also why I have a <code>d_(n)</code> function.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/D2b9m3uwVhtoSnXSv8yNTEeNBbQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/D2b9m3uwVhtoSnXSv8yNTEeNBbQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/D2b9m3uwVhtoSnXSv8yNTEeNBbQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/D2b9m3uwVhtoSnXSv8yNTEeNBbQ/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=s1I4VsOmMWk:0gLEJb6T5gc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=s1I4VsOmMWk:0gLEJb6T5gc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=s1I4VsOmMWk:0gLEJb6T5gc:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=s1I4VsOmMWk:0gLEJb6T5gc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=s1I4VsOmMWk:0gLEJb6T5gc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=s1I4VsOmMWk:0gLEJb6T5gc:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=s1I4VsOmMWk:0gLEJb6T5gc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=s1I4VsOmMWk:0gLEJb6T5gc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=s1I4VsOmMWk:0gLEJb6T5gc:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=YwkR-u9nhCs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AetusDesigns/~4/s1I4VsOmMWk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aetus.net/319/programming/project-euler-problem-40/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aetus.net/319/programming/project-euler-problem-40/</feedburner:origLink></item>
		<item>
		<title>Project Euler Problem 21 (Ruby)</title>
		<link>http://feedproxy.google.com/~r/AetusDesigns/~3/9veVwUkObes/</link>
		<comments>http://aetus.net/302/programming/ruby-programming/project-euler-problem-21-ruby/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 16:57:21 +0000</pubDate>
		<dc:creator>Vikhyat Korrapati</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://aetus.net/?p=302</guid>
		<description><![CDATA[If you intend to solve the problem on your own, I wouldn&#8217;t recommend reading any further.
Let  be defined as the sum of proper divisors of  (numbers less than  which divide evenly into ).
If  and , where , then a and b are an amicable pair and each of a and b [...]]]></description>
			<content:encoded><![CDATA[<p><em>If you intend to solve the problem on your own, I wouldn&#8217;t recommend reading any further.</em></p>
<blockquote><p>Let <img src='http://s.wordpress.com/latex.php?latex=d%28n%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d(n)' title='d(n)' class='latex' /> be defined as the sum of proper divisors of <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> (numbers less than <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> which divide evenly into <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' />).<br />
If <img src='http://s.wordpress.com/latex.php?latex=d%28a%29%20%3D%20b&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d(a) = b' title='d(a) = b' class='latex' /> and <img src='http://s.wordpress.com/latex.php?latex=d%28b%29%20%3D%20a&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d(b) = a' title='d(b) = a' class='latex' />, where <img src='http://s.wordpress.com/latex.php?latex=a%20%5Cneq%20b&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='a \neq b' title='a \neq b' class='latex' />, then a and b are an amicable pair and each of a and b are called amicable numbers.</p>
<p>For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore <img src='http://s.wordpress.com/latex.php?latex=d%28220%29%20%3D%20284&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d(220) = 284' title='d(220) = 284' class='latex' />. The proper divisors of 284 are 1, 2, 4, 71 and 142; so <img src='http://s.wordpress.com/latex.php?latex=d%28284%29%20%3D%20220&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d(284) = 220' title='d(284) = 220' class='latex' />.</p>
<p>Evaluate the sum of all the amicable numbers under 10000.</p>
<p>(<a href="http://projecteuler.net/index.php?section=problems&#038;id=21">Problem 21 &#8211; Project Euler</a>)
</p></blockquote>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;"><span style="color:#9966CC; font-weight:bold;">def</span> d<span style="color:#006600; font-weight:bold;">&#40;</span>n<span style="color:#006600; font-weight:bold;">&#41;</span>
  total = <span style="color:#006666;">0</span>
  1.<span style="color:#9900CC;">upto</span> n<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">2</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>n <span style="color:#006600; font-weight:bold;">%</span> i<span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#006666;">0</span>
      total <span style="color:#006600; font-weight:bold;">+</span>= i
    <span style="color:#9966CC; font-weight:bold;">end</span>  
  <span style="color:#9966CC; font-weight:bold;">end</span>
  total
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
amicable_sum = <span style="color:#006666;">0</span>
&nbsp;
10000.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>a<span style="color:#006600; font-weight:bold;">|</span>
  b = d<span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> d<span style="color:#006600; font-weight:bold;">&#40;</span>b<span style="color:#006600; font-weight:bold;">&#41;</span> == a <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> b <span style="color:#006600; font-weight:bold;">&gt;</span> a
    amicable_sum <span style="color:#006600; font-weight:bold;">+</span>= a <span style="color:#006600; font-weight:bold;">+</span> b
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> amicable_sum</pre></div></div>

<p>My version of <img src='http://s.wordpress.com/latex.php?latex=d%28n%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d(n)' title='d(n)' class='latex' /> isn&#8217;t as efficient as the one in the PDF you get after solving the problem, but it gets the job done.</p>
<p>Running it takes around 8.5 seconds on my machine. That&#8217;s not too bad for ~20 lines of code.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/qlLddShKwd1dY_cYXev_qY1bAiQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/qlLddShKwd1dY_cYXev_qY1bAiQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qlLddShKwd1dY_cYXev_qY1bAiQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/qlLddShKwd1dY_cYXev_qY1bAiQ/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=9veVwUkObes:x53Xr3ixM94:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=9veVwUkObes:x53Xr3ixM94:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=9veVwUkObes:x53Xr3ixM94:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=9veVwUkObes:x53Xr3ixM94:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=9veVwUkObes:x53Xr3ixM94:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=9veVwUkObes:x53Xr3ixM94:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=9veVwUkObes:x53Xr3ixM94:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=9veVwUkObes:x53Xr3ixM94:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=9veVwUkObes:x53Xr3ixM94:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=YwkR-u9nhCs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AetusDesigns/~4/9veVwUkObes" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aetus.net/302/programming/ruby-programming/project-euler-problem-21-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aetus.net/302/programming/ruby-programming/project-euler-problem-21-ruby/</feedburner:origLink></item>
		<item>
		<title>Fajan’s Rules</title>
		<link>http://feedproxy.google.com/~r/AetusDesigns/~3/feexT8pU8wE/</link>
		<comments>http://aetus.net/266/science/fajans-rules/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 09:56:24 +0000</pubDate>
		<dc:creator>Vikhyat Korrapati</dc:creator>
				<category><![CDATA[Chemistry]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[fajan]]></category>
		<category><![CDATA[inorganic chemistry]]></category>

		<guid isPermaLink="false">http://aetus.net/?p=266</guid>
		<description><![CDATA[Fajan&#8217;s Rules are a set of empirical rules that are used to predict whether an inorganic compound will be ionic or covalent.
I find it easier to remember stuff when it look&#8217;s like math, so I organized these rules in the form of proportions. Hopefully, it will help others as well.










]]></description>
			<content:encoded><![CDATA[<p>Fajan&#8217;s Rules are a set of empirical rules that are used to predict whether an inorganic compound will be ionic or covalent.<span id="more-266"></span></p>
<p>I find it easier to remember stuff when it look&#8217;s like math, so I organized these rules in the form of proportions. Hopefully, it will help others as well.</p>
<ul>
<li>
		<img src='http://s.wordpress.com/latex.php?latex=%5Ctext%7BCation%20Size%7D%20%5Cvarpropto%20%5Ctext%7B%20Ionic%20nature%20%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\text{Cation Size} \varpropto \text{ Ionic nature }' title='\text{Cation Size} \varpropto \text{ Ionic nature }' class='latex' />
	</li>
<li>
		<img src='http://s.wordpress.com/latex.php?latex=%5Ctext%7BAnion%20Size%7D%20%5Cvarpropto%20%5Cfrac%7B1%7D%7B%5Ctext%7B%20Ionic%20nature%20%7D%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\text{Anion Size} \varpropto \frac{1}{\text{ Ionic nature }}' title='\text{Anion Size} \varpropto \frac{1}{\text{ Ionic nature }}' class='latex' />
	</li>
<li>
		<img src='http://s.wordpress.com/latex.php?latex=%5Ctext%7BCharge%20on%20the%20cation%20or%20anion%20%28or%20both%29%7D%20%5Cvarpropto%20%5Cfrac%7B1%7D%7B%5Ctext%7B%20Ionic%20nature%20%7D%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\text{Charge on the cation or anion (or both)} \varpropto \frac{1}{\text{ Ionic nature }}' title='\text{Charge on the cation or anion (or both)} \varpropto \frac{1}{\text{ Ionic nature }}' class='latex' />
	</li>
<li>
		<img src='http://s.wordpress.com/latex.php?latex=%5Ctext%7BCation%20with%20inert%20gas%20configuration%7D%20%5Cqquad%20%5Cquad%20%5C%20%20%5Crightarrow%20%5C%20%20%5Ctext%7BIonic%20Compound%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\text{Cation with inert gas configuration} \qquad \quad \  \rightarrow \  \text{Ionic Compound}' title='\text{Cation with inert gas configuration} \qquad \quad \  \rightarrow \  \text{Ionic Compound}' class='latex' /><br />
		<img src='http://s.wordpress.com/latex.php?latex=%5Ctext%7BCation%20with%20pseudo-inert%20gas%20configuration%7D%20%5Crightarrow%20%5C%20%20%5Ctext%7BCovalent%20Compound%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\text{Cation with pseudo-inert gas configuration} \rightarrow \  \text{Covalent Compound}' title='\text{Cation with pseudo-inert gas configuration} \rightarrow \  \text{Covalent Compound}' class='latex' />
	</li>
</ul>

<p><a href="http://feedads.g.doubleclick.net/~a/rwfQIyvtB3RL_p5eYu_Mbq_J-AA/0/da"><img src="http://feedads.g.doubleclick.net/~a/rwfQIyvtB3RL_p5eYu_Mbq_J-AA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/rwfQIyvtB3RL_p5eYu_Mbq_J-AA/1/da"><img src="http://feedads.g.doubleclick.net/~a/rwfQIyvtB3RL_p5eYu_Mbq_J-AA/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=feexT8pU8wE:Dk23NrcEHcE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=feexT8pU8wE:Dk23NrcEHcE:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=feexT8pU8wE:Dk23NrcEHcE:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=feexT8pU8wE:Dk23NrcEHcE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=feexT8pU8wE:Dk23NrcEHcE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=feexT8pU8wE:Dk23NrcEHcE:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=feexT8pU8wE:Dk23NrcEHcE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=feexT8pU8wE:Dk23NrcEHcE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=feexT8pU8wE:Dk23NrcEHcE:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=YwkR-u9nhCs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AetusDesigns/~4/feexT8pU8wE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aetus.net/266/science/fajans-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aetus.net/266/science/fajans-rules/</feedburner:origLink></item>
		<item>
		<title>Velox – Random Latin Words</title>
		<link>http://feedproxy.google.com/~r/AetusDesigns/~3/PEPVNjKBHYI/</link>
		<comments>http://aetus.net/249/misc/velox-random-latin-words/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 10:49:04 +0000</pubDate>
		<dc:creator>Vikhyat Korrapati</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://aetus.net/?p=249</guid>
		<description><![CDATA[I&#8217;ve always had a hard time naming the photographs I post on dA. Eventually, I started using a random Latin word. But going through a huge list of words looking for something that sounds cool was still tedious. So I did what anyone else in my situation would &#8211; write a web app to make [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always had a hard time naming the photographs I post on <a href="http://celebrus.deviantart.com/">dA</a>. Eventually, I started using a random Latin word. But going through a huge list of words looking for something that sounds cool was still tedious. So I did what anyone else in my situation would &#8211; write a web app to make my life easy. It&#8217;s called Velox (which was one of the words it came up with while testing it). As usual, it&#8217;s hosted at <a href="http://heroku.com/">Heroku</a>. Here&#8217;s a link to it- <a href="http://velox.heroku.com/">Velox &#8211; Random Latin Words</a>.<span id="more-249"></span></p>
<p>Here&#8217;s the complete source code.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;">%w[ sinatra datamapper erb ].each do {|lib| require lib }
&nbsp;
# Database stuff
DataMapper.setup(:default, ENV['DATABASE_URL'] || &quot;sqlite3://#{Dir.pwd}/db.sqlite3&quot;)
&nbsp;
class Word
  include DataMapper::Resource
  property :id, Serial
  property :wd, String, :length =&gt; 16
end
&nbsp;
DataMapper.auto_upgrade!
# End of database stuff
&nbsp;
# Build a database containing all of those words the first time the app is
# run. 'database.rb' basically contains a huge array of latin words and some
# code that iterates through it and adds each word to a database. It's quite
# slow on sqlite because (I think) every database query has to be written to the
# hard disk.
configure :production do
  require 'database'
end
&nbsp;
get '/' do
  # Get a random word, make it small characters and get rid of any 
  # non-alphanumeric characters.
  @word = Word.get(1+rand(3402)).wd.downcase.gsub(/\W/, '')
  erb :index
end
&nbsp;
use_in_file_templates!
&nbsp;
__END__
&nbsp;
@@ layout
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Velox - Random Latin Words&lt;/title&gt;
    &lt;style type=&quot;text/css&quot;&gt;
      body {
        background-color: #fafafa;
        font-family: Century Gothic, Apple Gothic, sans-serif;
        margin: auto;
        width: 70%;
        padding-top: 25px;
      }
      h1 {
        color: #888;
        font-size: 3em;
        margin-bottom: 0;
      }
      div.word {
        font-family: Palatino, Palatino Linotype, Hoefler Text, Times, Times New Roman, serif;
        font-size: 2.5em;
        padding-left: 20px;
      }
      p.more {
        padding-top: 5px;
      }
      p.more a {
        text-decoration: none;
        color: #33f;
      }
      p.more strong {
        padding: 5px;
      }
    &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;Velox - Random Latin Words&lt;/h1&gt;
    &lt;div class=&quot;word&quot;&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>=yield<span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/div&gt;
    &lt;p class=&quot;more&quot;&gt;&lt;a href=&quot;/&quot;&gt;Get Another!&lt;/a&gt;&lt;/p&gt;
    &lt;p class=&quot;more&quot; style=&quot;text-align:right;padding-top:50px&quot;&gt;
      &lt;a href=&quot;http://aetus.net/&quot;&gt;Aetus Designs&lt;/a&gt;
      &lt;strong&gt;|&lt;/strong&gt;
      &lt;a href=&quot;http://revolutionx.smfforfree3.com/&quot;&gt;Revolution X&lt;/a&gt;
    &lt;/p&gt;
  &lt;/body&gt;
&lt;/html&gt;
&nbsp;
@@ index
<span style="color:#006600; font-weight:bold;">&lt;%</span>=@word<span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>


<p><a href="http://feedads.g.doubleclick.net/~a/3YaNiWzAKHARWE0UOwbET-LI7AY/0/da"><img src="http://feedads.g.doubleclick.net/~a/3YaNiWzAKHARWE0UOwbET-LI7AY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/3YaNiWzAKHARWE0UOwbET-LI7AY/1/da"><img src="http://feedads.g.doubleclick.net/~a/3YaNiWzAKHARWE0UOwbET-LI7AY/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=PEPVNjKBHYI:T0dYI4hcqLM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=PEPVNjKBHYI:T0dYI4hcqLM:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=PEPVNjKBHYI:T0dYI4hcqLM:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=PEPVNjKBHYI:T0dYI4hcqLM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=PEPVNjKBHYI:T0dYI4hcqLM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=PEPVNjKBHYI:T0dYI4hcqLM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=PEPVNjKBHYI:T0dYI4hcqLM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=PEPVNjKBHYI:T0dYI4hcqLM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=PEPVNjKBHYI:T0dYI4hcqLM:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=YwkR-u9nhCs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AetusDesigns/~4/PEPVNjKBHYI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aetus.net/249/misc/velox-random-latin-words/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aetus.net/249/misc/velox-random-latin-words/</feedburner:origLink></item>
		<item>
		<title>Automatically Resize Large Images with Javascript</title>
		<link>http://feedproxy.google.com/~r/AetusDesigns/~3/SP4zANCCaqo/</link>
		<comments>http://aetus.net/217/programming/automatically-resize-large-images-with-javascript/#comments</comments>
		<pubDate>Sun, 24 May 2009 06:49:59 +0000</pubDate>
		<dc:creator>Vikhyat Korrapati</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://aetus.net/?p=217</guid>
		<description><![CDATA[When you allow users to submit content, and allow that content to include images, there&#8217;s always a chance that some user will submit a really large image that will break your layout. One way to solve that is to check the content for large images and resize them using a server-side program. However, sometimes, that [...]]]></description>
			<content:encoded><![CDATA[<p>When you allow users to submit content, and allow that content to include images, there&#8217;s always a chance that some user will submit a really large image that will break your layout. One way to solve that is to check the content for large images and resize them using a server-side program. However, sometimes, that is simply not possible. In those cases, we use what&#8217;s left- Javascript.<span id="more-217"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#40;</span>
    <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>maxht<span style="color: #339933;">,</span> maxwt<span style="color: #339933;">,</span> minht<span style="color: #339933;">,</span> minwt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> imgs <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// Image resizing function</span>
      <span style="color: #003366; font-weight: bold;">var</span> resize_image <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>img<span style="color: #339933;">,</span> newht<span style="color: #339933;">,</span> newwt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        img.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> newht<span style="color: #339933;">;</span>
        img.<span style="color: #660066;">width</span>  <span style="color: #339933;">=</span> newwt<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> imgs.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Set a variable for the current image to make the code</span>
        <span style="color: #006600; font-style: italic;">// make more sense.</span>
        <span style="color: #003366; font-weight: bold;">var</span> img <span style="color: #339933;">=</span> imgs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>img.<span style="color: #660066;">height</span> <span style="color: #339933;">&gt;</span> maxht <span style="color: #339933;">||</span> img.<span style="color: #660066;">width</span> <span style="color: #339933;">&gt;</span> maxwt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #006600; font-style: italic;">// Use Ratios to constraint proportions.</span>
          <span style="color: #003366; font-weight: bold;">var</span> old_ratio <span style="color: #339933;">=</span> img.<span style="color: #660066;">height</span> <span style="color: #339933;">/</span> img.<span style="color: #660066;">width</span><span style="color: #339933;">;</span>
          <span style="color: #003366; font-weight: bold;">var</span> min_ratio <span style="color: #339933;">=</span> minht <span style="color: #339933;">/</span> minwt<span style="color: #339933;">;</span>
          <span style="color: #006600; font-style: italic;">// If it can scale perfectly.</span>
          <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>old_ratio <span style="color: #339933;">===</span> min_ratio<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            resize_image<span style="color: #009900;">&#40;</span>img<span style="color: #339933;">,</span> minht<span style="color: #339933;">,</span> minwt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span> 
          <span style="color: #006600; font-style: italic;">// We need to do some magic now.</span>
          <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> newdim <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>img.<span style="color: #660066;">height</span><span style="color: #339933;">,</span> img.<span style="color: #660066;">width</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #006600; font-style: italic;">// Sort out the height first.</span>
            newdim<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> minht<span style="color: #339933;">;</span>
            <span style="color: #006600; font-style: italic;">// The logic behind this is that if ratio = ht / wt,</span>
            <span style="color: #006600; font-style: italic;">// then wt = ht / ratio.</span>
            newdim<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> newdim<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">/</span> old_ratio<span style="color: #339933;">;</span>
            <span style="color: #006600; font-style: italic;">// Do we still have to sort out the width?</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>newdim<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> maxwt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
              <span style="color: #006600; font-style: italic;">// Just do what we did with the height</span>
              newdim<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> minwt<span style="color: #339933;">;</span>
              newdim<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> newdim<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> old_ratio<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #006600; font-style: italic;">// So yeah, resize the image</span>
            resize_image<span style="color: #009900;">&#40;</span>img<span style="color: #339933;">,</span> newdim<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> newdim<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>To change the dimensions above which images should be resized, and the dimensions to which it should be resized, you&#8217;d want to edit line 43.</p>
<p>This script depends up on jQuery <em>only</em> to make it run after the page has loaded. If you want to get it to work without jQuery, you&#8217;d only need to swap out that part. You could also use jQuery&#8217;s wrap function to put the resized image in a frame with a notice and stuff. You can see that in action <a href="http://9861.smfforfree.com/index.php/topic,8.html">here</a>.</p>
<p>Feel free to use this (as long as you give credit), and let me know if you do.</p>
<p style="font-size:0.5em"><a rel="license" href="http://creativecommons.org/licenses/by/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by/3.0/88x31.png" class="noframe" /></a><br />This work by <a xmlns:cc="http://creativecommons.org/ns#" href="http://aetus.net/217/programming/automatically-resize-large-images-with-javascript/" property="cc:attributionName" rel="cc:attributionURL">Aetus Designs</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/B9Corw3q6751rUqYirwhHbPfkaU/0/da"><img src="http://feedads.g.doubleclick.net/~a/B9Corw3q6751rUqYirwhHbPfkaU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/B9Corw3q6751rUqYirwhHbPfkaU/1/da"><img src="http://feedads.g.doubleclick.net/~a/B9Corw3q6751rUqYirwhHbPfkaU/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=SP4zANCCaqo:HX2BweHYEj8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=SP4zANCCaqo:HX2BweHYEj8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=SP4zANCCaqo:HX2BweHYEj8:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=SP4zANCCaqo:HX2BweHYEj8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=SP4zANCCaqo:HX2BweHYEj8:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=SP4zANCCaqo:HX2BweHYEj8:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=SP4zANCCaqo:HX2BweHYEj8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=SP4zANCCaqo:HX2BweHYEj8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=SP4zANCCaqo:HX2BweHYEj8:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=YwkR-u9nhCs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AetusDesigns/~4/SP4zANCCaqo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aetus.net/217/programming/automatically-resize-large-images-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aetus.net/217/programming/automatically-resize-large-images-with-javascript/</feedburner:origLink></item>
		<item>
		<title>Zenity.rb</title>
		<link>http://feedproxy.google.com/~r/AetusDesigns/~3/YyMazNdIEUs/</link>
		<comments>http://aetus.net/195/programming/zenityrb/#comments</comments>
		<pubDate>Tue, 12 May 2009 06:55:18 +0000</pubDate>
		<dc:creator>Vikhyat Korrapati</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://aetus.net/?p=195</guid>
		<description><![CDATA[Zenity is a command line based tool that helps shell scripts display GTK dialog boxes as a more interactive way to display error messages, get user input and other stuff like that. From it&#8217;s Freshmeat page, 
Zenity is a tool that allows you to display Gtk+ dialog boxes from the command line and through shell [...]]]></description>
			<content:encoded><![CDATA[<p>Zenity is a command line based tool that helps shell scripts display GTK dialog boxes as a more interactive way to display error messages, get user input and other stuff like that.<span id="more-195"></span> From it&#8217;s <a href="http://freshmeat.net/projects/zenity">Freshmeat page</a>, </p>
<blockquote><p>Zenity is a tool that allows you to display Gtk+ dialog boxes from the command line and through shell scripts. It is similar to gdialog, but is intended to be saner. It comes from the same family as dialog, Xdialog, and cdialog, but it surpasses those projects by having a cooler name.</p></blockquote>
<p>Zenity.rb is a gem (or optionally a single file that you can download and include in your script) that provides a easy way to display zenity dialogs. You can look at the <a href="http://github.com/vikhyat/zenity.rb/tree">Github</a> and <a href="http://rubyforge.org/projects/zenityrb/">RubyForge</a> project pages.</p>
<p>To install it, run this command in a shell (you may need to run it as su)</p>

<div class="wp_syntax"><div class="code"><pre class="plain-text" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;">gem install Zenity.rb</pre></div></div>

<p>Then try this out in irb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'zenity'</span>
Zenity::entry<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Enter some text'</span>, <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'This is a password dialog.'</span>, <span style="color:#ff3333; font-weight:bold;">:arg</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'hide-text'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>The last line there gets translated to this: &#8220;<strong><code>zenity --entry --title='Enter some text' --text='This is a password dialog.' --hide-text</code></strong>&#8221; which is then passed to the operating system. So it basically depends upon the presence of zenity.</p>
<p>The code itself is very minimal. The only important file is listed below. If it doesn&#8217;t fit completely on your screen, you can also view it <a href="http://github.com/vikhyat/zenity.rb/blob/master/lib/zenity.rb">here</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;"><span style="color:#9966CC; font-weight:bold;">module</span> Zenity
  <span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#0000FF; font-weight:bold;">self</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># Let's just use method_missing instead of defining all of those.</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>m, options=<span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#008000; font-style:italic;"># Check if the dialog box we have to show is allowed</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#ff3333; font-weight:bold;">:calendar</span>, <span style="color:#ff3333; font-weight:bold;">:entry</span>, <span style="color:#ff3333; font-weight:bold;">:error</span>, :<span style="color:#996600;">'file-selection'</span>, <span style="color:#ff3333; font-weight:bold;">:info</span>, <span style="color:#ff3333; font-weight:bold;">:list</span>,
           <span style="color:#ff3333; font-weight:bold;">:notification</span>, <span style="color:#ff3333; font-weight:bold;">:progress</span>, <span style="color:#ff3333; font-weight:bold;">:question</span>, :<span style="color:#996600;">'text-info'</span>, <span style="color:#ff3333; font-weight:bold;">:warning</span>, <span style="color:#ff3333; font-weight:bold;">:scale</span> 
      <span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>? m
        <span style="color:#008000; font-style:italic;"># It's in the array and everything seems to be fine</span>
        ret = <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#008000; font-style:italic;">#{parseopts('zenity --' + m.to_s, options)} ]</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#008000; font-style:italic;"># We don't know about this dialog, raise an error</span>
        <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;Unknown dialog #{m}&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#008000; font-style:italic;"># Check if any of the options passed were invalid.</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> ret.<span style="color:#9900CC;">rstrip</span> == <span style="color:#996600;">'This option is not available. Please see --help for all possible usages.'</span>
        <span style="color:#008000; font-style:italic;"># Write a message to STDERR if there were invalid options, but don't</span>
        <span style="color:#008000; font-style:italic;"># raise an error.</span>
        STDERR <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;Invalid option&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#008000; font-style:italic;"># Everything looks fine. Return what we got.</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> ret
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
&nbsp;
    private
    <span style="color:#008000; font-style:italic;"># Very confusing code that generates the shell command.</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> parseopts<span style="color:#006600; font-weight:bold;">&#40;</span>cmd, options<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> options != <span style="color:#0000FF; font-weight:bold;">false</span>
        options.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>k, v<span style="color:#006600; font-weight:bold;">|</span>
          cmd <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot; --#{k}='#{v}'&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> k != <span style="color:#ff3333; font-weight:bold;">:arg</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
        options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:arg</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>opt<span style="color:#006600; font-weight:bold;">|</span> cmd <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot; --#{opt}&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options.<span style="color:#9900CC;">has_key</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:arg</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      cmd
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>As you can see, I chose to use <code>method_missing</code> to reduce the amount of code I&#8217;d need to write. As a possible side-effect of this, you may not be able to mix the module into your own classes or into the global namespace.</p>
<p>Overall, the purpose of packaging this in a gem was more for convenience of usage than anything else.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/k0pAEn0irLnQJYE0Ro4F-KxIymE/0/da"><img src="http://feedads.g.doubleclick.net/~a/k0pAEn0irLnQJYE0Ro4F-KxIymE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/k0pAEn0irLnQJYE0Ro4F-KxIymE/1/da"><img src="http://feedads.g.doubleclick.net/~a/k0pAEn0irLnQJYE0Ro4F-KxIymE/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=YyMazNdIEUs:YEWkVMXey5Y:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=YyMazNdIEUs:YEWkVMXey5Y:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=YyMazNdIEUs:YEWkVMXey5Y:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=YyMazNdIEUs:YEWkVMXey5Y:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=YyMazNdIEUs:YEWkVMXey5Y:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=YyMazNdIEUs:YEWkVMXey5Y:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=YyMazNdIEUs:YEWkVMXey5Y:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=YyMazNdIEUs:YEWkVMXey5Y:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=YyMazNdIEUs:YEWkVMXey5Y:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=YwkR-u9nhCs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AetusDesigns/~4/YyMazNdIEUs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aetus.net/195/programming/zenityrb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aetus.net/195/programming/zenityrb/</feedburner:origLink></item>
		<item>
		<title>Getting a Method to Accept an Arbitary Number of Arguments in Ruby</title>
		<link>http://feedproxy.google.com/~r/AetusDesigns/~3/MQ4GsxxuRRg/</link>
		<comments>http://aetus.net/167/programming/function-accept-any-number-of-arguments-in-ruby-splat/#comments</comments>
		<pubDate>Sat, 09 May 2009 10:42:35 +0000</pubDate>
		<dc:creator>Vikhyat Korrapati</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://aetus.net/?p=167</guid>
		<description><![CDATA[In LISP-like languages such as Scheme, you can do arithmetic with code like this:

&#40;+ 5 5&#41;           ; =&#62; 10
&#40;- 3 2&#41;           ; =&#62; 1

The + operator there behaves like a function. The striking thing is [...]]]></description>
			<content:encoded><![CDATA[<p>In LISP-like languages such as Scheme, you can do arithmetic with code like this:</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;"><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">5</span> <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>           <span style="color: #808080; font-style: italic;">; =&gt; 10</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">3</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>           <span style="color: #808080; font-style: italic;">; =&gt; 1</span></pre></div></div>

<p>The + operator there behaves like a function. The striking thing is that it can accept any number of arguments. So you can also do stuff like this:</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;"><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #cc66cc;">3</span> <span style="color: #cc66cc;">4</span> <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>     <span style="color: #808080; font-style: italic;">; =&gt; 15</span></pre></div></div>

<p>You can also do that in Ruby, using the <code>splat</code>(*) operator. The splat operator can do a lot of fancy stuff, but I&#8217;m not going to cover all of that here.<span id="more-167"></span></p>
<p>This is how you would use the splat operator in a method definition to achieve that.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;"><span style="color:#9966CC; font-weight:bold;">def</span> func<span style="color:#006600; font-weight:bold;">&#40;</span>param1, <span style="color:#006600; font-weight:bold;">*</span>rest<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;"># Code goes here</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Due to the way we defined that method, it needs to have at least one argument passed to it when we call it. We can, however, pass it more arguments if we wish to.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;">func<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'test'</span><span style="color:#006600; font-weight:bold;">&#41;</span>              <span style="color:#008000; font-style:italic;"># param1 = 'test', rest = []</span>
func<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'test'</span>, <span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>     <span style="color:#008000; font-style:italic;"># param1 = 'test', rest = [1, 2, 3]</span></pre></div></div>

<p>We can implement a LISP-style add function like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;"><span style="color:#9966CC; font-weight:bold;">def</span> add<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
  args.<span style="color:#9900CC;">inject</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>m, n<span style="color:#006600; font-weight:bold;">|</span> m <span style="color:#006600; font-weight:bold;">+</span>= n <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006666;">0</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Let's try out the add method</span>
add               <span style="color:#008000; font-style:italic;"># =&gt; 0</span>
add <span style="color:#006666;">5</span>, <span style="color:#006666;">5</span>          <span style="color:#008000; font-style:italic;"># =&gt; 10</span>
add <span style="color:#006666;">5</span>, <span style="color:#006666;">5</span>, <span style="color:#006666;">5</span>       <span style="color:#008000; font-style:italic;"># =&gt; 15</span></pre></div></div>


<p><a href="http://feedads.g.doubleclick.net/~a/Sa8SUNDh8TGzu6Ej9zPQ4xbdtK8/0/da"><img src="http://feedads.g.doubleclick.net/~a/Sa8SUNDh8TGzu6Ej9zPQ4xbdtK8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Sa8SUNDh8TGzu6Ej9zPQ4xbdtK8/1/da"><img src="http://feedads.g.doubleclick.net/~a/Sa8SUNDh8TGzu6Ej9zPQ4xbdtK8/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=MQ4GsxxuRRg:0xdbrRR1DpY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=MQ4GsxxuRRg:0xdbrRR1DpY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=MQ4GsxxuRRg:0xdbrRR1DpY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=MQ4GsxxuRRg:0xdbrRR1DpY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=MQ4GsxxuRRg:0xdbrRR1DpY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=MQ4GsxxuRRg:0xdbrRR1DpY:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=MQ4GsxxuRRg:0xdbrRR1DpY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=MQ4GsxxuRRg:0xdbrRR1DpY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=MQ4GsxxuRRg:0xdbrRR1DpY:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=YwkR-u9nhCs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AetusDesigns/~4/MQ4GsxxuRRg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aetus.net/167/programming/function-accept-any-number-of-arguments-in-ruby-splat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aetus.net/167/programming/function-accept-any-number-of-arguments-in-ruby-splat/</feedburner:origLink></item>
		<item>
		<title>Very Simple Metronome in Ruby</title>
		<link>http://feedproxy.google.com/~r/AetusDesigns/~3/SooQjug8eNk/</link>
		<comments>http://aetus.net/154/programming/very-simple-metronome-in-ruby/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 10:52:27 +0000</pubDate>
		<dc:creator>Vikhyat Korrapati</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[guitar]]></category>
		<category><![CDATA[metronome]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://aetus.net/?p=154</guid>
		<description><![CDATA[A metronome is basically something that beeps periodically, indicating the exact tempo of some music. I wanted one for my guitar practice, but the only one in Ubuntu&#8217;s repos (GTick) wouldn&#8217;t work, so I wrote this up.

# Emit a tick
def beep
  Thread.new &#123; print &#34;\a&#34; &#125;
end
&#160;
def every&#40;delay&#41;
  loop do
    sleep&#40;delay&#41;
 [...]]]></description>
			<content:encoded><![CDATA[<p>A metronome is basically something that beeps periodically, indicating the exact tempo of some music. I wanted one for my guitar practice, but the only one in Ubuntu&#8217;s repos (GTick) wouldn&#8217;t work, so I wrote this up.<span id="more-154"></span></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;"><span style="color:#008000; font-style:italic;"># Emit a tick</span>
<span style="color:#9966CC; font-weight:bold;">def</span> beep
  <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\a</span>&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> every<span style="color:#006600; font-weight:bold;">&#40;</span>delay<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#CC0066; font-weight:bold;">loop</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#CC0066; font-weight:bold;">sleep</span><span style="color:#006600; font-weight:bold;">&#40;</span>delay<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">yield</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Get the BPM</span>
<span style="color:#9966CC; font-weight:bold;">if</span> ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#0000FF; font-weight:bold;">nil</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Enter the BPM&quot;</span>
  bpm = <span style="color:#CC0066; font-weight:bold;">gets</span>.<span style="color:#9900CC;">to_f</span>
<span style="color:#9966CC; font-weight:bold;">else</span>
  bpm = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_f</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Convert beats per minute to the number of seconds to wait. For </span>
<span style="color:#008000; font-style:italic;"># example, a bpm of 60 would equal a one second wait.</span>
delay_seconds = <span style="color:#006666;">60.0</span> <span style="color:#006600; font-weight:bold;">/</span> bpm
&nbsp;
every delay_seconds <span style="color:#006600; font-weight:bold;">&#123;</span> beep <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>If you want to change how the beeping happens, you only have to edit the beep method right at the top. To do that on Windows, have a look at this post on the <a href="http://rubyonwindows.blogspot.com/2007/05/adding-sound-to-your-ruby-apps.html">win32-sound library</a>. On Linux you could <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/204223">write to /dev/dsp</a> but it might be better to use <a href="http://www.alsa-project.org/">ALSA</a>. The <a href="http://github.com/fugalh/ruby-audio/tree/master">ruby/audio</a> library is also worth having a look over.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/5KsgbSY6QpW-zfwkvblsCsBz0hY/0/da"><img src="http://feedads.g.doubleclick.net/~a/5KsgbSY6QpW-zfwkvblsCsBz0hY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/5KsgbSY6QpW-zfwkvblsCsBz0hY/1/da"><img src="http://feedads.g.doubleclick.net/~a/5KsgbSY6QpW-zfwkvblsCsBz0hY/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=SooQjug8eNk:tSL8o6ZaNaY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=SooQjug8eNk:tSL8o6ZaNaY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=SooQjug8eNk:tSL8o6ZaNaY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=SooQjug8eNk:tSL8o6ZaNaY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=SooQjug8eNk:tSL8o6ZaNaY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=SooQjug8eNk:tSL8o6ZaNaY:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=SooQjug8eNk:tSL8o6ZaNaY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=SooQjug8eNk:tSL8o6ZaNaY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=SooQjug8eNk:tSL8o6ZaNaY:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=YwkR-u9nhCs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AetusDesigns/~4/SooQjug8eNk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aetus.net/154/programming/very-simple-metronome-in-ruby/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://aetus.net/154/programming/very-simple-metronome-in-ruby/</feedburner:origLink></item>
		<item>
		<title>How to Learn a New Programming Language</title>
		<link>http://feedproxy.google.com/~r/AetusDesigns/~3/mu0ipa9XZFY/</link>
		<comments>http://aetus.net/121/programming/how-to-learn-a-new-programming-language/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 17:40:44 +0000</pubDate>
		<dc:creator>Vikhyat Korrapati</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://aetus.net/?p=121</guid>
		<description><![CDATA[Learning a new language isn&#8217;t the easiest thing to do. It can, however, be a very rewarding experience if you are persistent enough. Luckily, if you know how to code in one language, it is much, much easier to learn another language. Here are some tips that can help you.
Practice
Really, practicing is the only way [...]]]></description>
			<content:encoded><![CDATA[<p>Learning a new language isn&#8217;t the easiest thing to do. It can, however, be a very rewarding experience if you are persistent enough. Luckily, if you know how to code in one language, it is much, much easier to learn another language. Here are some tips that can help you.<span id="more-121"></span></p>
<h3>Practice</h3>
<p>Really, practicing is the only way you can learn a programming language. It is useful to have some standard programs that are the first programs you try out. Since you would already have the logic worked out, the focus would be more on grasping the language&#8217;s syntax. Here are some program ideas you can start off with:</p>
<ul>
<li>Ask the user for his/her favorite number, and then send back a message saying that <tt>(favorite_number+1)</tt> would have been a bigger and better favorite number.</li>
<li>Implement some form of <a href="http://www.gameprogrammer.com/fractal.html">fractal terrain generation</a>.</li>
<li><a href="http://aetus.net/131/programming/implemeting-hq9-in-10-lines-of-ruby/">An implementation of the HQ9+ programming language.</a> It is very simple to do and will give you a good idea of flow control.</li>
</ul>
<p>There is a more exhaustive list <a href="http://www.jobsnake.com/seek/articles/index.cgi?openarticle&#038;8533">here</a>.</p>
<h3>Use It</h3>
<p>You aren&#8217;t going to get anywhere if you keep going back to your favorite language to solve everyday problems. You need to pro-actively <em>force</em> yourself to use the language you are trying to master. If, for instance, you know Ruby and want to learn C, stop writing those small, everyday code snippets in Ruby and do them in C instead.</p>
<h3>Do it Often</h3>
<p>Learn a new language every once in a while. If you keep doing it, you never get out of the flow or settle down with what you know so much that learning something new becomes a struggle. Some people say that you should learn a new language every year, but I think that&#8217;s too often. Do what seems right to you.</p>
<h3>Don&#8217;t Blatantly Reject New Ideas</h3>
<p>Seriously, don&#8217;t. You need to change your perspective, and even if you can&#8217;t move on. Every language has it&#8217;s pros and cons. There is no &#8216;One True Way&#8217;, and something need not be right just because you believe it to, or because it&#8217;s how your current favorite language implements it. I think I&#8217;ll mention an example here. Python forces indentation, so what? It may not be so bad after all, maybe you&#8217;ll prefer it&#8217;s way later on, and even if you don&#8217;t, so what? There are loads of other cool features in it.</p>
<h3>Read Code</h3>
<p>I can&#8217;t possibly stress this enough. Read as much code written by people proficient in the language you are learning. You need to read loads of code. Reading code helps you learn a lot about the language itself, common idioms, quirks and lots of other stuff. Ideally, you should be reading at least as much code as you write.</p>
<h3>Summary</h3>
<p>This isn&#8217;t the first or the final article about this. It&#8217;s just what I have to say. Having said that, I&#8217;m open to criticism. I&#8217;d like to know what you liked and what you didn&#8217;t like about this article. I&#8217;d appreciate it if you left a comment here.</p>
<p>Be open and be sure to enjoy learning. It shouldn&#8217;t be mechanical or forced.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/NDj-_bVRKUw_E5GCicqbUcZQWZc/0/da"><img src="http://feedads.g.doubleclick.net/~a/NDj-_bVRKUw_E5GCicqbUcZQWZc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/NDj-_bVRKUw_E5GCicqbUcZQWZc/1/da"><img src="http://feedads.g.doubleclick.net/~a/NDj-_bVRKUw_E5GCicqbUcZQWZc/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=mu0ipa9XZFY:dw7nOVBukOQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=mu0ipa9XZFY:dw7nOVBukOQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=mu0ipa9XZFY:dw7nOVBukOQ:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=mu0ipa9XZFY:dw7nOVBukOQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=mu0ipa9XZFY:dw7nOVBukOQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=mu0ipa9XZFY:dw7nOVBukOQ:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=mu0ipa9XZFY:dw7nOVBukOQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=mu0ipa9XZFY:dw7nOVBukOQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=mu0ipa9XZFY:dw7nOVBukOQ:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=YwkR-u9nhCs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AetusDesigns/~4/mu0ipa9XZFY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aetus.net/121/programming/how-to-learn-a-new-programming-language/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://aetus.net/121/programming/how-to-learn-a-new-programming-language/</feedburner:origLink></item>
		<item>
		<title>Implemeting HQ9+ in 10 lines of Ruby</title>
		<link>http://feedproxy.google.com/~r/AetusDesigns/~3/24x6FVEMYS4/</link>
		<comments>http://aetus.net/131/programming/implemeting-hq9-in-10-lines-of-ruby/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 05:43:32 +0000</pubDate>
		<dc:creator>Vikhyat Korrapati</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[hq9+]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://aetus.net/?p=131</guid>
		<description><![CDATA[HQ9+ is a excessively simple esoteric programming language. It has only four commands:
H: Print &#8220;Hello, World!&#8221;
Q: Prints the contents of the program onto the screen
9: Print the canonical lyrics of the song, &#8220;99 bottles of beer&#8221;.
+: Increment the accumulator
Here&#8217;s the entire implementation:

1
2
3
4
5
6
7
8
9
10
def hq9&#40;src&#41;
  src.downcase.split&#40;''&#41;.each do &#124;i&#124;
    case i
    [...]]]></description>
			<content:encoded><![CDATA[<p>HQ9+ is a excessively simple esoteric programming language. It has only four commands:<br />
<strong>H</strong>: Print &#8220;Hello, World!&#8221;<br />
<strong>Q</strong>: Prints the contents of the program onto the screen<br />
<strong>9</strong>: Print the canonical lyrics of the song, &#8220;99 bottles of beer&#8221;.<br />
<strong>+</strong>: Increment the accumulator</p>
<p>Here&#8217;s the entire implementation:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;font-family:Consolas,Bitstream Vera Sans Mono,mono;"><span style="color:#9966CC; font-weight:bold;">def</span> hq9<span style="color:#006600; font-weight:bold;">&#40;</span>src<span style="color:#006600; font-weight:bold;">&#41;</span>
  src.<span style="color:#9900CC;">downcase</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#9966CC; font-weight:bold;">case</span> i
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'h'</span>; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Hello, World!&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'q'</span>; <span style="color:#CC0066; font-weight:bold;">puts</span> src
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'9'</span>; 99.<span style="color:#9900CC;">downto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>b<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{b==0?'No more b':&quot;</span><span style="color:#008000; font-style:italic;">#{b} B&quot;}ottle#{'s'if b!=1} of beer on the wall, #{b==0?'No more':b} bottle#{'s'if b!=1} of beer.#{b==0?&quot;nGo to the store and buy some more, 99 bottles of beer on the wall.&quot;:&quot;nTake one down and pass it around, #{b-1} bottle#{'s'if b!=2} of beer on the wall.nn&quot;}&quot; }</span>
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'+'</span>; <span style="color:#ff6633; font-weight:bold;">$i</span> = <span style="color:#ff6633; font-weight:bold;">$i</span> ? <span style="color:#ff6633; font-weight:bold;">$i</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1</span> : <span style="color:#006666;">0</span>;
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p><em>Note: I got the lyric printing code from <a href="http://99-bottles-of-beer.net/language-ruby-673.html">here</a>.</em></p>

<p><a href="http://feedads.g.doubleclick.net/~a/SUKx1QuBLdBKoM_blMoMpDjA9V4/0/da"><img src="http://feedads.g.doubleclick.net/~a/SUKx1QuBLdBKoM_blMoMpDjA9V4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/SUKx1QuBLdBKoM_blMoMpDjA9V4/1/da"><img src="http://feedads.g.doubleclick.net/~a/SUKx1QuBLdBKoM_blMoMpDjA9V4/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=24x6FVEMYS4:rcpwbPMDXOI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=24x6FVEMYS4:rcpwbPMDXOI:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=24x6FVEMYS4:rcpwbPMDXOI:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=24x6FVEMYS4:rcpwbPMDXOI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=24x6FVEMYS4:rcpwbPMDXOI:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=24x6FVEMYS4:rcpwbPMDXOI:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=24x6FVEMYS4:rcpwbPMDXOI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?i=24x6FVEMYS4:rcpwbPMDXOI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AetusDesigns?a=24x6FVEMYS4:rcpwbPMDXOI:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/AetusDesigns?d=YwkR-u9nhCs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AetusDesigns/~4/24x6FVEMYS4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aetus.net/131/programming/implemeting-hq9-in-10-lines-of-ruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://aetus.net/131/programming/implemeting-hq9-in-10-lines-of-ruby/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 1.275 seconds. --><!-- Cached page generated by WP-Super-Cache on 2009-11-11 23:18:46 -->
