<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>oddsblogs</title>
	<link>http://www.oddsblogs.com</link>
	<description>programming. math. gambling.</description>
	<pubDate>Fri, 19 Oct 2007 08:28:57 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1</generator>
	<language>en</language>
			<item>
		<title>Equality Checking Symbol (Question Mark over Equals) in LaTeX</title>
		<link>http://www.oddsblogs.com/2007/02/14/equality-checking-symbol-question-mark-over-equals-in-latex/</link>
		<comments>http://www.oddsblogs.com/2007/02/14/equality-checking-symbol-question-mark-over-equals-in-latex/#comments</comments>
		<pubDate>Tue, 13 Feb 2007 22:00:15 +0000</pubDate>
		<dc:creator>Billy</dc:creator>
		
		<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://www.oddsblogs.com/2007/02/14/equality-checking-symbol-question-mark-over-equals-in-latex/</guid>
		<description><![CDATA[Took me forever to figure this one out today&#8230;a simple question mark over an equals sign, for checking equality in a paper writt3n in LaTeX. There are a billion &#8220;special&#8221; commands for something over an equals sign, why not a question mark? Well, that would be too easy&#8230;
This is the best I could come up [...]]]></description>
			<content:encoded><![CDATA[<p>Took me forever to figure this one out today&#8230;a simple question mark over an equals sign, for checking equality in a paper writt3n in LaTeX. There are a billion &#8220;special&#8221; commands for something over an equals sign, why not a question mark? Well, that would be too easy&#8230;</p>
<p>This is the best I could come up with.</p>
<p><code>\alpha \stackrel{?}{=} \beta</code> gave me <img src="http://www.oddsblogs.com/wp-content/cache/tex_e0c9880dddca8efd15314743183b5bca.gif" class="tex" alt="\alpha \stackrel{?}{=} \beta" />.</p>
<p>Close enough, although the question mark is a little high. Wordpress LaTeX stuff provided by <a href="http://studium.fstyle.de/weblog/2006/12/22/mimetex_112/">this</a> plugin modified from <a href="http://en.dahnielson.com/2006/09/mimetex-plugin.html">this</a> one.</p>
<p><strong>Update:</strong> Lisa recommended this:</p>
<p><code>\alpha \stackrel{_?}{=} \beta</code> renders as <img src="http://www.oddsblogs.com/wp-content/cache/tex_6ebe2a6b31a90e6902fd47be81000756.gif" class="tex" alt="\alpha \stackrel{_?}{=} \beta" />. Much better, thanks!<hr/>Copyright &copy; 2008 <strong><a href="http://www.oddsblogs.com">oddsblogs</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact www.oddsblogs.com so we can take legal action immediately.
<p class="akst_link"><a href="http://www.oddsblogs.com/?p=20&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_20" class="akst_share_link" rel="nofollow">Share This</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oddsblogs.com/2007/02/14/equality-checking-symbol-question-mark-over-equals-in-latex/feed/</wfw:commentRss>
		</item>
		<item>
		<title>IP Address to Integer Conversion in C# (and other languages)</title>
		<link>http://www.oddsblogs.com/2007/02/11/ip-address-to-integer-conversion-in-c-and-other-languages/</link>
		<comments>http://www.oddsblogs.com/2007/02/11/ip-address-to-integer-conversion-in-c-and-other-languages/#comments</comments>
		<pubDate>Sun, 11 Feb 2007 21:22:28 +0000</pubDate>
		<dc:creator>Billy</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.oddsblogs.com/2007/02/11/ip-address-to-integer-conversion-in-c-and-other-languages/</guid>
		<description><![CDATA[A couple of times, I&#8217;ve needed a function to convert a string representation of an IP address to a 32-bit unsigned integer, to save in a database for example. It&#8217;s kind of a waste to save the string representation of an IP address in a database, as IPv4 addresses are only 32 bits and fit [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of times, I&#8217;ve needed a function to convert a string representation of an IP address to a 32-bit unsigned integer, to save in a database for example. It&#8217;s kind of a waste to save the string representation of an IP address in a database, as IPv4 addresses are only 32 bits and fit nicely in a 32-bit unsigned integer field of, for example, a MySQL table. Each character in the string would be a byte!</p>
<p>I&#8217;ve had to do this in lots of languages, but the source here is in C#. The approach is similar for other languages. Each octet of the IP address is 8 bits, so we start an accumulator at 0, XOR with the first bit, shift the accumulator left 8 bits, rinse, repeat.</p>
<textarea name="code" class="c#:showcolumns" cols="60" rows="10">
public uint IPStringToInt(string IPAddress) {
    uint r = 0;
    foreach (string s in IPAddress.Split('.'))
	r = (r << 8 ) ^ (uint)UInt32.Parse(s);
    return r;
}
</textarea>
<p>Pretty compact. I&#8217;ve mostly used this for getting the 32-bit unsigned integer representation of the running machine, so I pull the string IPAddress off the network card in a normal fashion (maybe like <a href="http://www.codeproject.com/csharp/network.asp">so</a> or <a href="http://www.garyshort.org/?p=381">so</a> or resolve anything like <a href="http://www.howtogeek.com/howto/programming/get-ip-address-from-dns-hostname-in-c/">so</a>).<hr/>Copyright &copy; 2008 <strong><a href="http://www.oddsblogs.com">oddsblogs</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact www.oddsblogs.com so we can take legal action immediately.
<p class="akst_link"><a href="http://www.oddsblogs.com/?p=19&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_19" class="akst_share_link" rel="nofollow">Share This</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oddsblogs.com/2007/02/11/ip-address-to-integer-conversion-in-c-and-other-languages/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Playing Card Hands - A Wordpress Plugin for Displaying Cards</title>
		<link>http://www.oddsblogs.com/2007/02/10/playing-card-hand-a-wordpress-plugin-for-displaying-cards/</link>
		<comments>http://www.oddsblogs.com/2007/02/10/playing-card-hand-a-wordpress-plugin-for-displaying-cards/#comments</comments>
		<pubDate>Sat, 10 Feb 2007 12:18:14 +0000</pubDate>
		<dc:creator>Billy</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.oddsblogs.com/2007/02/10/playing-card-hand-a-wordpress-plugin-for-displaying-cards/</guid>
		<description><![CDATA[Playing Card Hands is a wordpress plugin that allows playing cards to be easily inserted and displayed using simple tags in posts and comments. This is useful for bloggers writing about any card game: poker, spades, bridge, etc. The plugin is simple to install and use.
About a year ago, I was looking for a wordpress [...]]]></description>
			<content:encoded><![CDATA[<p>Playing Card Hands is a <a href="http://wordpress.org/">wordpress</a> plugin that allows playing cards to be easily inserted and displayed using simple tags in posts and comments. This is useful for bloggers writing about any card game: poker, spades, bridge, etc. The plugin is simple to install and use.<!--adsensestart--></p>
<p>About a year ago, I was looking for a wordpress plugin that would allow me to display entire hands of cards (for example, a poker hand). I ran into <a href="http://mtdewvirus.com/archives/2004/09/28/wordpress-plugin-card-converter/">this plugin</a>, but each card had to be surrounded by a tag; this wasn&#8217;t what I wanted. So, I decided to roll my own <img src='http://www.oddsblogs.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<ul>
<li><strong>Download Link:</strong> <a href="http://www.oddsblogs.com/wp-content/uploads/playing-card-hands-v1_0.zip">playing-card-hands-v1_0.zip</a></li>
<li><strong>Installation:</strong>
<ol>
<li>Download and unzip the plugin to your wordpress plugin directory. On Linux, this might look like &#8230;<br />
<code>cd wp-content/plugins<br />
wget http://www.oddsblogs.com/wp-content/uploads/playing-card-hands-v1_0.zip<br />
unzip playing-card-hands-v1_0.zip</code></li>
<li>In your wordpress administration page, go to the &#8220;Plugins&#8221; tab and click &#8220;Activate&#8221; to activate the plugin.</li>
</ol>
</li>
<li><strong>Usage:</strong> Surround the hand you want by the <code>&#91;cards&#93;...&#91;/cards&#93;</code> tag. Separate individual cards by spaces. The first character indicates the card rank (2-A), the last the card suit (c, d, h, s for clubs, diamonds, hearts, spades, respectively). For example, <code>&#91;cards&#93;th jh qh kh ah&#91;/cards&#93;</code> produces <span class="redcard">T&hearts;</span><span class="redcard">J&hearts;</span><span class="redcard">Q&hearts;</span><span class="redcard">K&hearts;</span><span class="redcard">A&hearts;</span>, a royal flush. Sometimes you want to show say ace ace, or any diamond, or maybe any king or something; <code>&#91;cards&#93;a a d k&#91;/cards&#93;</code> gives you <span class="blackcard">A&nbsp;</span><span class="blackcard">A&nbsp;</span><span class="redcard">&nbsp;&diams;</span><span class="blackcard">K&nbsp;</span>.</li>
<li><strong>License:</strong> <a href="http://www.gnu.org/licenses/gpl.txt">GPL</a>.</li>
<li><strong>Credits:</strong> The CSS was partially borrowed from the <a href="http://mtdewvirus.com/archives/2004/09/28/wordpress-plugin-card-converter/">Card Converter Plugin</a>, which I believe was partially borrowed from <a href="http://www.wptfan.com/">The (Unofficial) World Poker Tour Fan Site</a>.
</ul>
<p>Feel free to edit the CSS if you&#8217;re so inclined.</p>
<p>Leave a comment or a trackback if you find the plugin useful, please!<br />
 <hr/>Copyright &copy; 2008 <strong><a href="http://www.oddsblogs.com">oddsblogs</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact www.oddsblogs.com so we can take legal action immediately.
<p class="akst_link"><a href="http://www.oddsblogs.com/?p=18&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_18" class="akst_share_link" rel="nofollow">Share This</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oddsblogs.com/2007/02/10/playing-card-hand-a-wordpress-plugin-for-displaying-cards/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Password Recovery in the Epiphany Browser (Mozilla)</title>
		<link>http://www.oddsblogs.com/2007/02/09/password-recovery-in-the-epiphany-browser-mozilla/</link>
		<comments>http://www.oddsblogs.com/2007/02/09/password-recovery-in-the-epiphany-browser-mozilla/#comments</comments>
		<pubDate>Fri, 09 Feb 2007 11:18:17 +0000</pubDate>
		<dc:creator>Billy</dc:creator>
		
		<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://www.oddsblogs.com/2007/02/09/password-recovery-in-the-epiphany-browser-mozilla/</guid>
		<description><![CDATA[At some point, I was using the Epiphany web browser for Gnome on my linux workstation. I&#8217;m using Firefox now, but I had one obscure identity number that was hidden in the saved passwords that I needed to reveal. There was no option to show the saved password, and I couldn&#8217;t find any documentation for [...]]]></description>
			<content:encoded><![CDATA[<p>At some point, I was using the Epiphany web browser for Gnome on my linux workstation. I&#8217;m using Firefox now, but I had one obscure identity number that was hidden in the saved passwords that I needed to reveal. There was no option to show the saved password, and I couldn&#8217;t find any documentation for recovering the password.<!--adsensestart--></p>
<p>I couldn&#8217;t find a Spy++ clone for linux (maybe it&#8217;s not possible&#8230;I don&#8217;t know) to reveal the value of the password field.</p>
<p>After a little searching, it seems Epiphany is Mozilla based (or uses the same directory structure). I found <a href="http://burntelectrons.org/moz/moz-passwords.html">this page</a> for recovering the password saved in Mozilla; it&#8217;s very similar in Epiphany. The password was saved in<br />
<code><br />
~/.gnome2/epiphany/mozilla/epiphany/[random number].s<br />
</code></p>
<p>I guess it was base-64 encoded. I plugged the password in (minus the ~) to the javascript to decode it, worked like a charm. So frustrating when this simple stuff isn&#8217;t documented anywhere&#8230; <hr/>Copyright &copy; 2008 <strong><a href="http://www.oddsblogs.com">oddsblogs</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact www.oddsblogs.com so we can take legal action immediately.
<p class="akst_link"><a href="http://www.oddsblogs.com/?p=17&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_17" class="akst_share_link" rel="nofollow">Share This</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oddsblogs.com/2007/02/09/password-recovery-in-the-epiphany-browser-mozilla/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Shuffling Cards (Randomizing Arrays) the RIGHT Way!</title>
		<link>http://www.oddsblogs.com/2007/02/04/shuffling-cards-randomizing-arrays-the-right-way/</link>
		<comments>http://www.oddsblogs.com/2007/02/04/shuffling-cards-randomizing-arrays-the-right-way/#comments</comments>
		<pubDate>Sun, 04 Feb 2007 12:46:46 +0000</pubDate>
		<dc:creator>Billy</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.oddsblogs.com/2007/02/04/shuffling-cards-randomizing-arrays-the-right-way/</guid>
		<description><![CDATA[A while back, I was writing a blackjack simulator where I needed to model shuffling a deck of cards (randomizing the elements of an array). This problem seemed simple; so simple that I made a big mistake. The code I was writing was in Java, but the examples here are in C.
The simple, logical approach [...]]]></description>
			<content:encoded><![CDATA[<p>A while back, I was writing a blackjack simulator where I needed to model shuffling a deck of cards (randomizing the elements of an array). This problem seemed simple; so simple that I made a big mistake. The code I was writing was in Java, but the examples here are in C.<!--adsensestart--></p>
<p>The simple, logical approach to randomizing arrays is to loop through the array, and swap each element with some random element. This might look something like below.</p>
<textarea name="code" class="c:showcolumns" cols="60" rows="10">
void shuffle(int *array, int length) {
  for(int i=0; i<length; i++)
    swap(array,i,rand()%length); //BAD CODE
}
</textarea>
<p>Here, swap interchanges two array elements (brilliant, I know).</p>
<p>While this does indeed &#8220;mix up&#8221; the elements of the array, it doesn&#8217;t model true card shuffling. To shuffle a deck of cards, we want to produce one out of all the possible <a href="http://en.wikipedia.org/wiki/Permutations">permutations</a> (different arrangements or orderings) of the deck, where each occurs with equal probability. How many different permutations are there of n cards? For the first position, there are n choices, times (n-1) choices for the second, and so on, so n! (n <a href="http://en.wikipedia.org/wiki/Factorial">factorial</a>).</p>
<p>So whatever method we use to shuffle the array, we want there to be n! different orderings. Now, back to the piece of code above. For the first position, there are n possibilities (where n=length). For the second position, there are also n possibilities, and the same for every other position. This gives us n<sup>n</sup> possibilities. This is too many!</p>
<p>Fortunately, this is an easy fix. At each iteration, we want one less possibility to choose from. The for loop counter is handy for this.</p>
<textarea name="code" class="c:showcolumns" cols="60" rows="10">
void shuffle(int *array, int length) {
  for(int i=0; i<length; i++)
    swap(array,i,rand()%(length-i)+i); //GOOD CODE
}
</textarea>
<p>I think this is a great example of how simple algorithm analysis can improve code. <hr/>Copyright &copy; 2008 <strong><a href="http://www.oddsblogs.com">oddsblogs</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact www.oddsblogs.com so we can take legal action immediately.
<p class="akst_link"><a href="http://www.oddsblogs.com/?p=9&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_9" class="akst_share_link" rel="nofollow">Share This</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oddsblogs.com/2007/02/04/shuffling-cards-randomizing-arrays-the-right-way/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Converting time from 24-hour (military) to 12-hour (AM/PM) in PHP</title>
		<link>http://www.oddsblogs.com/2007/01/26/converting-time-from-24-hour-military-to-12-hour-ampm-in-php/</link>
		<comments>http://www.oddsblogs.com/2007/01/26/converting-time-from-24-hour-military-to-12-hour-ampm-in-php/#comments</comments>
		<pubDate>Fri, 26 Jan 2007 19:44:55 +0000</pubDate>
		<dc:creator>Billy</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.oddsblogs.com/2007/01/26/converting-time-from-24-hour-military-to-12-hour-ampm-in-php/</guid>
		<description><![CDATA[Today I was writing some code in PHP for a weekly schedule and found a need to convert an integer equivalent of an hour in 24-hour format to 12-hour format. So there was some table layout, and each cell represented an hour period of one day of the week.
I searched the PHP forums, but this [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was writing some code in PHP for a weekly schedule and found a need to convert an integer equivalent of an hour in 24-hour format to 12-hour format. So there was some table layout, and each cell represented an hour period of one day of the week.<!--adsensestart--></p>
<p>I searched the PHP forums, but this really isn&#8217;t a &#8220;date and time&#8221; issue (as far as PHP functions for real dates and times are concerned). It could be that a solution is listed there, but I couldn&#8217;t find it quickly. What can I say, my attention span is measured in nanoseconds.</p>
<p>I was using integers for the hour loop, so they were in military time. I needed a quick and dirty function to convert these integers to 12-hour format. This is what I ended up with.</p>
<textarea name="code" class="php:showcolumns" cols="60" rows="10">
function miltoampm($hour) {
$ampm = ($hour &gt;=12 &amp;&amp; $hour &lt;24) ? "PM" : "AM";
$newhour = ($hour % 12 === 0) ? 12 : $hour % 12;
return $newhour . ' ' . $ampm;
}
</textarea>
<p>I&#8217;m a big fan of ternary operators, they can really make your code compact. <hr/>Copyright &copy; 2008 <strong><a href="http://www.oddsblogs.com">oddsblogs</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact www.oddsblogs.com so we can take legal action immediately.
<p class="akst_link"><a href="http://www.oddsblogs.com/?p=7&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_7" class="akst_share_link" rel="nofollow">Share This</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oddsblogs.com/2007/01/26/converting-time-from-24-hour-military-to-12-hour-ampm-in-php/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
