<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>GR[ae]YSCALE</title>
	<atom:link href="http://sudrien.net/feed" rel="self" type="application/rss+xml" />
	<link>http://sudrien.net</link>
	<description>This site may contain content that causes thought. We apologize.</description>
	<pubDate>Mon, 03 Nov 2008 20:28:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Change file character encoding</title>
		<link>http://sudrien.net/technical/ruby/change-file-character-encoding</link>
		<comments>http://sudrien.net/technical/ruby/change-file-character-encoding#comments</comments>
		<pubDate>Mon, 03 Nov 2008 20:28:59 +0000</pubDate>
		<dc:creator>Sudrien</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://sudrien.net/?p=232</guid>
		<description><![CDATA[I have a few files in EUC-JP that I want to edit - unfortunately for me, text editors these days, while having good unicode support, do not necessarily have support for other codepages.
A long time ago (computer-wise), iconv was created to handle just this situation. the only problem is that it&#8217;s only a library.
PHP has [...]]]></description>
			<content:encoded><![CDATA[<p>I have a few files in EUC-JP that I want to edit - unfortunately for me, text editors these days, while having good unicode support, do not necessarily have support for other codepages.</p>
<p>A long time ago (computer-wise), <a href="http://www.gnu.org/software/libiconv/">iconv</a> was created to handle just this situation. the only problem is that it&#8217;s <em>only</em> a library.</p>
<p>PHP has an <a href="http://us.php.net/manual/en/function.iconv.php">Iconv interface</a>. and so does Ruby.</p>
<p>Here is an example of using the latter; I will read in a file (hardcoded, in this case), convert the codepage, change the encoding specified (well, it could be more sophisticated), and write the result out to disk.</p>
<p><code>require 'iconv'<br />
input = ""<br />
File.open("C:/2879.html","r") { |file| input &lt;&lt; file.read }<br />
r = Iconv.new("UTF-8","euc-jp").iconv(input)<br />
r.gsub!("EUC-JP", "UTF-8")<br />
outfile = File.new("C:/2879.1.html","w")<br />
outfile.print r</code></p>
<p>Note that I&#8217;m using one of those unusual windows paths that ruby allows. I could have also used &#8220;C:\\2879.html&#8221; instead; but I hate having to do escaping on paths.</p>
]]></content:encoded>
			<wfw:commentRss>http://sudrien.net/technical/ruby/change-file-character-encoding/feed</wfw:commentRss>
		</item>
		<item>
		<title>Rails and Normalizing Phone Numbers</title>
		<link>http://sudrien.net/technical/ruby/rails-and-normalizing-phone-numbers</link>
		<comments>http://sudrien.net/technical/ruby/rails-and-normalizing-phone-numbers#comments</comments>
		<pubDate>Tue, 28 Oct 2008 14:12:03 +0000</pubDate>
		<dc:creator>Sudrien</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://sudrien.net/?p=220</guid>
		<description><![CDATA[Rails has this interesting function number_to_phone. Given the correct data, the string &#8220;19876543210&#8243;), it can format it nicely (to the string &#8220;1 (987) 654-3210&#8243;).
Problem is, how do you correctly format (aka normalize) people&#8217;s input? People will enter phone numbers with whatever format they feel is appropriate.
First, lets show them the preferred format.
app/views/yourmodel/new.rb &#038;&#038; app/views/yourmodel/edit.rb
  [...]]]></description>
			<content:encoded><![CDATA[<p>Rails has this interesting function <a href="http://api.rubyonrails.com/classes/ActionView/Helpers/NumberHelper.html#M001271">number_to_phone</a>. Given the correct data, the string &#8220;19876543210&#8243;), it can format it nicely (to the string &#8220;1 (987) 654-3210&#8243;).</p>
<p>Problem is, how do you correctly format (aka normalize) people&#8217;s input? People will enter phone numbers with whatever format they feel is appropriate.</p>
<p>First, lets show them the preferred format.</p>
<p><em>app/views/yourmodel/new.rb &#038;&#038; app/views/yourmodel/edit.rb</em><br />
<code>  &lt;dl class="form"&gt;<br />
    &lt;dt&gt;&lt;%= f.label :phone %&gt;&lt;/dt&gt;<br />
    &lt;dd&gt;&lt;%= f.text_field :phone, :value =&gt; number_to_phone(@yourmodel.phone, :area_code =&gt; true) %&gt;&lt;/dd&gt;<br />
  &lt;/dl&gt;</code></p>
<p>Now, We need to intercept it at some point before it gets into the database (See <a href="http://woss.name/2006/04/04/rails-normalizing-data-in-the-model/">Graeme Mathieson</a>&#8217;s writup for the other possible way to do this)</p>
<p><em>app/models/yourmodel.rb</em><br />
<code>  before_validation :normalise<br />
&nbsp;<br />
  def normalise<br />
    phone.gsub!(/[^\d]/, &#8220;&#8221;) if !phone.nil?<br />
  end<br />
&nbsp;<br />
  validates_format_of :phone,<br />
    :with =&gt; /^1?(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/i,<br />
    :message =&gt; &#8220;Invalid Phone number&#8221;,<br />
    :if =&gt; :phone?</code></p>
]]></content:encoded>
			<wfw:commentRss>http://sudrien.net/technical/ruby/rails-and-normalizing-phone-numbers/feed</wfw:commentRss>
		</item>
		<item>
		<title>Hide form sections in Prototype: &#8220;.display-switch&#8221;</title>
		<link>http://sudrien.net/technical/javascript/hide-form-sections-in-prototype-display-switch</link>
		<comments>http://sudrien.net/technical/javascript/hide-form-sections-in-prototype-display-switch#comments</comments>
		<pubDate>Wed, 22 Oct 2008 14:08:45 +0000</pubDate>
		<dc:creator>Sudrien</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://sudrien.net/?p=216</guid>
		<description><![CDATA[I had an issue with some rather complex forms I was making - There were times that I wanted to hide multiple sections of a form based on the selection of radio button or select drop-down.
As both of these have only one active option&#8230; well, I wanted to hide all other options.
The following code (dependent [...]]]></description>
			<content:encoded><![CDATA[<p>I had an issue with some rather complex forms I was making - There were times that I wanted to hide multiple sections of a form based on the selection of radio button or select drop-down.</p>
<p>As both of these have only one active option&#8230; well, I wanted to hide all other options.</p>
<p>The following code (dependent on prototype 1.6.x) does just this. Hopefully I&#8217;ll be able to explain it better soon.</p>
<p><code>  $(document).observe("dom:loaded", function() {<br />
    /* generic show/hide section function */<br />
    activate_display_switch();<br />
    }<br />
&nbsp;<br />
&nbsp;<br />
  /* a select/input with class of display-switch  will show() all classes with currently selected value (select_name)_(value), and hide() others */<br />
  function activate_display_switch() {<br />
    var signal = Prototype.Browser.IE ? 'focus' : 'change';<br />
    $$('select.display-switch').invoke('observe','change', function(){<br />
      var x = this;<br />
      x.childElements().each(function(y){ x.up('form').select("." + x.id + "_" + y.value).invoke('hide'); });<br />
      x.up('form').select("." + x.id + "_" + x.value).invoke('show');<br />
      });<br />
    $$('input.display-switch').invoke('observe',signal, function(){<br />
      var x = this;<br />
      switch(x.type.toUpperCase()) {<br />
        case "RADIO":<br />
          x.up('form').descendants().collect( function(s) { if (s.tagName.toUpperCase() == "INPUT" &#038;&#038; s.type.toUpperCase() == "RADIO" &#038;&#038; s.name == x.name ) return s; }).compact().each(function(y){ x.up('form').select('.' + y.id + "_" + y.value).invoke('hide'); });<br />
          x.up('form').select("." + x.id + "_" + x.value).invoke('show');<br />
          break;<br />
        default:<br />
        alert("Display Switch unimplemented for " + x.tagName + "[" + x.type.toUpperCase() + "], &#8221; + x.id);<br />
        break;<br />
        }<br />
      });<br />
    }</code></p>
]]></content:encoded>
			<wfw:commentRss>http://sudrien.net/technical/javascript/hide-form-sections-in-prototype-display-switch/feed</wfw:commentRss>
		</item>
		<item>
		<title>Being nice to Windows in a Dual Boot Setup</title>
		<link>http://sudrien.net/oss/linux/being-nice-to-windows-in-a-dual-boot-setup</link>
		<comments>http://sudrien.net/oss/linux/being-nice-to-windows-in-a-dual-boot-setup#comments</comments>
		<pubDate>Thu, 02 Oct 2008 05:16:11 +0000</pubDate>
		<dc:creator>Sudrien</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://sudrien.net/?p=213</guid>
		<description><![CDATA[Well, My Windows Server 2008 trial period ran out. And as I still have not found a license for a resonable amount, WinXP SP3 is now the operating system I use the most.
&#8230;Because I am waiting for Kubuntu 8.10 to stabilize. Because the Alpha I installed definitely was not stable.
However, I do want the two [...]]]></description>
			<content:encoded><![CDATA[<p>Well, My Windows Server 2008 trial period ran out. And as I still have not found a license for a resonable amount, WinXP SP3 is now the operating system I use the most.</p>
<p>&#8230;Because I am waiting for Kubuntu 8.10 to stabilize. Because the Alpha I installed definitely was not stable.</p>
<p>However, I do want the two to play nice; And by play nice, I mean &#8220;have windows act less stupid about it&#8221;. So here&#8217;s what I did.</p>
<p><strong><a href="http://www.fs-driver.org/">Let windows see my Ext2 Partitions</a></strong><br />
&#8230;Previously, I was using a FAT32 partition for sharing files between OSes, as Linux has supported it for a long time. However, <em><a href="http://thepiratebay.org/torrent/4335972/Beijing.Olympics.2008.Opening.Ceremony.720p.HDTV.x264-ORENJi">certian things</a></em> convinced me I needed a more capable format.</p>
<p><strong><a href="http://www.acc.umu.se/~bosse/">Let Windows use my Linux Swap partition</a></strong><br />
If I already have gigabytes reserved for swap, why am I not using it? I mean, for a good while, I intentionally was not using swap with Linux, and it was awesome - until my box outright crashed under heavy load. Of course, after you install this diver under windows, you still have to edit your system properties to use the newly mounted drive, but information on how to do that is readily available.</p>
<p><strong><a href="http://www.canerten.com/dual-boot-linux-and-windows-with-windows-boot-manager/">Use Windows Boot Manager to boot to Linux</a></strong><br />
This goes back to the fact that Windows does not play nice with others - and the fact that I seem to have a non-booting <em>somthing</em> under GRUB rather frequently. During the Ubuntu setup, there is a point where you are asked to confirm the details of your installation - and an &#8220;Advanced&#8221; button. THis button gives you an option to install GRUB somewhere other than the MBR - so, as I had just specified Linux be installed on SDA1, I used (hd0,0) for GRUB - specifying a partition, not a disk. Windows Boot Manager is pointed to that disk, and you have a solution that keeps getting you into windows no matter how many times you &#8220;broke&#8221; Linux.</p>
<p>&#8230; So that&#8217;s my setup as of now. Because of it, thankfully I no longer have to rely on a networked SANE setup for my scanner - or a samba-mounted cdrom drive for copy protection purposes. ^_^; But that&#8217;s beside the point.</p>
]]></content:encoded>
			<wfw:commentRss>http://sudrien.net/oss/linux/being-nice-to-windows-in-a-dual-boot-setup/feed</wfw:commentRss>
		</item>
		<item>
		<title>Firefox Addons (preferred set)</title>
		<link>http://sudrien.net/oss/firefox/firefox-addons-preferred-set</link>
		<comments>http://sudrien.net/oss/firefox/firefox-addons-preferred-set#comments</comments>
		<pubDate>Tue, 12 Aug 2008 16:02:01 +0000</pubDate>
		<dc:creator>Sudrien</dc:creator>
		
		<category><![CDATA[Firefox]]></category>

		<guid isPermaLink="false">http://sudrien.net/?p=210</guid>
		<description><![CDATA[I&#8217;m a web developer, though most of my current paid work will only be seen on corporate Intranets.
I still want the best page possible, so most of my Add-ons are web development tools. Most.
This is as much a reference list for when I have a new setup as a pat on the back for developers [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a web developer, though most of my current paid work will only be seen on corporate Intranets.</p>
<p>I still want the best page possible, so most of my Add-ons are web development tools. Most.</p>
<p>This is as much a reference list for when I have a new setup as a pat on the back for developers of these add-ons. Thanks!</p>
<dl>
<dt><a href="https://addons.mozilla.org/en-US/firefox/addon/1843">Firebug</a></dt>
<dd>The de-facto web development tool. Highlights include; Dom inspection(for catching what Firefox is interpreting you page as, updates with ajax calls), rendered style information (including whwere the css is), and network transfer info (is that generated image a 500 Server error? or a 404 Not Found?)</dd>
<dt><a href="https://addons.mozilla.org/en-US/firefox/addon/5369">YSlow</a></dt>
<dd>Developing on your own workstation is not a good testing environment - in terms of users&#8217; speed. Yahoo&#8217;s Yslow gives ratings and tips of how your page could be improved in this aspect. Requires Firebug.</dd>
<dt><a href="https://addons.mozilla.org/en-US/firefox/addon/1865">Adblock Plus</a></dt>
<dd>Of course I don&#8217;t want to deal with ads. However, there is always the option to temporarily disable ad blocking, if there is an actual problem.</dd>
<dt>AVG Safe Search</dt>
<dd>Disabled. Enough said.</dd>
<dd>No, wait - why can&#8217;t I uninstall this?</dd>
<dt><a href="https://addons.mozilla.org/en-US/firefox/addon/60">Web Developer</a> Toolbar</dt>
<dd>I always end up dragging the the contents to the Bookmarks toolbar to save screen space. Highlights include: Disable cache, Display Form Details (on same page), View form Information (in a new tab), Replace images with ALT attributes, presets for window sizing, shortcuts for html validation (Ctrl+Shift+A is the best)</dd>
<dt><a href="https://addons.mozilla.org/en-US/firefox/addon/3408">Abduction!</a></dt>
<dd>Better than &#8220;Print Screen&#8221;, because it will take a shot of the whole webpage (no scrolling issues). Only problem is that it does not seem to work on embedded items (like Adobe Flash) - but as I no longer have to deal with flash, this is not my issue. (this statement was true as of version 2.026)</dd>
<dt><a href="http://www.foxmarks.com/">Foxmarks</a></dt>
<dd>A centralized server to keep your bookmarks on, and an add-on to integrate it with Firefox. The only plugin that is worth a login (hey, you want your bookmarks behind a password, right?)</dd>
<dt><a href="http://www.downloadhelper.net/">Video DownloadHelper</a></dt>
<dd>Detects those FLVs with pesky dynamically generated names and allows you to save with somthing more sane. Hey, if there is no way to protect <em>my</em> content on the Internet, why should they get to protect theirs?</dd>
<dt><a href="https://addons.mozilla.org/en-US/firefox/addon/3977">Google Reader Notifier</a></dt>
<dd>I was using Firefox&#8217;s built-in &#8220;live bookmark&#8221; functionality when I had only a dozen rss feeds to check. This is obviously a step up.</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://sudrien.net/oss/firefox/firefox-addons-preferred-set/feed</wfw:commentRss>
		</item>
		<item>
		<title>Use the Name and Action of the Current Rails Controller for CSS Hooks</title>
		<link>http://sudrien.net/technical/ruby/name-and-action-of-the-current-rails-controller-for-css</link>
		<comments>http://sudrien.net/technical/ruby/name-and-action-of-the-current-rails-controller-for-css#comments</comments>
		<pubDate>Thu, 07 Aug 2008 19:29:55 +0000</pubDate>
		<dc:creator>Sudrien</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://sudrien.net/?p=204</guid>
		<description><![CDATA[I&#8217;ve started a few projects - and finished none of them - in Ruby on Rails 2.1. I got a little bit of experience in 1.2.x, enough to grow dependant on using scaffolding - though I have one major issue with the default scaffolding:
app/
  views/
    layouts/
      [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started a few projects - and finished none of them - in <a href="http://www.rubyonrails.org/">Ruby on Rails</a> 2.1. I got a little bit of experience in 1.2.x, enough to grow dependant on using scaffolding - though I have one major issue with the default scaffolding:</p>
<p><code>app/<br />
  views/<br />
    layouts/<br />
      wow.html.erb<br />
      that.html.erb<br />
      is.html.erb<br />
      a.html.erb<br />
      lot.html.erb<br />
      of.html.erb<br />
      layouts.html.erb</code></p>
<p>&#8230; when it could be</p>
<p><code>app/<br />
  views/<br />
    layouts/<br />
      application.html.erb</code></p>
<p>&#8230; without any other code modification; it results in a lot less markup to update if you have regular features.</p>
<p>But I want different CSS for different controllers, too. So I&#8217;ll add in some attributes to the body tag:</p>
<p><code>&lt;body<br />
  id='&lt;%= controller.class.controller_name %&gt;_&lt;%= controller.action_name %&gt;'<br />
  class='&lt;%= controller.class.controller_name %&gt; &lt;%= controller.action_name %&gt;'&gt;</code></p>
<p>If I was getting really specific, I&#8217;d add some prefixes; but this is enough for rules like:</p>
<p><code>#sidebar { background: blue; }<br />
body.index #sidebar { background: red; }<br />
body.customer #sidebar { background: green; }<br />
body#customer_index #sidebar { display: none; }</code></p>
]]></content:encoded>
			<wfw:commentRss>http://sudrien.net/technical/ruby/name-and-action-of-the-current-rails-controller-for-css/feed</wfw:commentRss>
		</item>
		<item>
		<title>Use the PrototypeJS Browser Detect</title>
		<link>http://sudrien.net/technical/javascript/use-the-prototypejs-browser-detect</link>
		<comments>http://sudrien.net/technical/javascript/use-the-prototypejs-browser-detect#comments</comments>
		<pubDate>Thu, 07 Aug 2008 16:02:30 +0000</pubDate>
		<dc:creator>Sudrien</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://sudrien.net/?p=196</guid>
		<description><![CDATA[Browser hacks are a necessary evil. In some areas, like css, exploiting other browser limitations is inevitable. In JavaScript, you can actually detect what a browser supports. 
Prototype.js, trying to cover these browsers, has some solid detects in it. 
Here is a snippet from Version 1.6.0.2:
  Browser: {
    IE:   [...]]]></description>
			<content:encoded><![CDATA[<p>Browser hacks are a necessary evil. In some areas, <a href="http://www.webdevout.net/css-hacks">like css</a>, exploiting other browser limitations is inevitable. In JavaScript, you can actually detect what a browser supports. </p>
<p><a href="http://www.prototypejs.org/">Prototype</a>.js, trying to cover these browsers, has some solid detects in it. </p>
<p>Here is a snippet from Version 1.6.0.2:</p>
<p><code>  Browser: {<br />
    IE:     !!(window.attachEvent &#038;&#038; !window.opera),<br />
    Opera:  !!window.opera,<br />
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,<br />
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 &#038;&#038; navigator.userAgent.indexOf('KHTML') == -1,<br />
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)<br />
  }</code></p>
<p>If you need a browser detect for some reason, you can access the result from your own scripts. For example: I needed a radio button that reacted to selection by triggering another function,and IE triggers the &#8216;onChange&#8217; event at a later point than all the other browsers:</p>
<p><code>&lt;input type='radio' id='my_radio' /&gt;<br />
...<br />
&lt;script type='text/javascript'&gt;<br />
//&lt;![CDATA[<br />
    var signal = Prototype.Browser.IE ? 'focus' : 'change';<br />
    Event.observe('my_radio',signal,function(){<br />
      react();<br />
      });<br />
//]]&gt;<br />
&lt;/script&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://sudrien.net/technical/javascript/use-the-prototypejs-browser-detect/feed</wfw:commentRss>
		</item>
		<item>
		<title>Hex escape everything</title>
		<link>http://sudrien.net/technical/php/hex-escape-everything</link>
		<comments>http://sudrien.net/technical/php/hex-escape-everything#comments</comments>
		<pubDate>Wed, 30 Jul 2008 02:15:05 +0000</pubDate>
		<dc:creator>Sudrien</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://sudrien.net/?p=187</guid>
		<description><![CDATA[I like Unicode. And use parts of it you probably haven&#8217;t seen. Like trying to transliterate runes.
I&#8217;ve frequently run into cases between these diffrenet languages and document encodings that utf-8 will not do the whole job. So I&#8217;ve made the following set of php functions to convert a utf-8 sting into an (ASCII? ISO-8859-1?) hex-escaped [...]]]></description>
			<content:encoded><![CDATA[<p>I like Unicode. And use parts of it you probably haven&#8217;t <em>seen</em>. Like trying to <a href="/technical/php/runic_transliteration">transliterate runes</a>.</p>
<p>I&#8217;ve frequently run into cases between these diffrenet languages and document encodings that utf-8 will not do the whole job. So I&#8217;ve made the following set of php functions to convert a utf-8 sting into an (ASCII? ISO-8859-1?) hex-escaped string that I don&#8217;t have to worry about displaying.</p>
<p><code>function _utf8_to_html ($data) {<br />
    $ret = 0;<br />
    foreach((str_split(strrev(chr((ord($data{0}) % 252 % 248 % 240 % 224 % 192) + 128) . substr($data, 1)))) as $k => $v)<br />
        $ret += (ord($v) % 128) * pow(64, $k);<br />
    return "&amp;#x" . base_convert($ret,10,16) . ";";<br />
    }<br />
&nbsp;<br />
&nbsp;<br />
function cleanstring($string) {<br />
        return stripslashes(preg_replace("/([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)/e&#8221;, &#8216;_utf8_to_html(&#8221;\\1&#8243;)&#8217;, $string));<br />
        }</code></p>
]]></content:encoded>
			<wfw:commentRss>http://sudrien.net/technical/php/hex-escape-everything/feed</wfw:commentRss>
		</item>
		<item>
		<title>Runic Transliteration</title>
		<link>http://sudrien.net/technical/php/runic_transliteration</link>
		<comments>http://sudrien.net/technical/php/runic_transliteration#comments</comments>
		<pubDate>Wed, 30 Jul 2008 02:05:45 +0000</pubDate>
		<dc:creator>Sudrien</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://sudrien.net/?p=190</guid>
		<description><![CDATA[I won&#8217;t get into why I was thinking about runes. But I was. Of course, you don&#8217;t need to translate to another language to use runes, at least in English&#8217;s case.
runes.sudrien.net
It still needs work - it does not handle, dashes, the letter &#8220;i&#8221;, and so many other things.
-Sud.
]]></description>
			<content:encoded><![CDATA[<p>I won&#8217;t get into why I was thinking about runes. But I was. Of course, you don&#8217;t need to translate to another language to use runes, at least in English&#8217;s case.</p>
<p><a href="http://runes.sudrien.net/">runes.sudrien.net</a></p>
<p>It still needs work - it does not handle, dashes, the letter &#8220;i&#8221;, and so many other things.</p>
<p>-Sud.</p>
]]></content:encoded>
			<wfw:commentRss>http://sudrien.net/technical/php/runic_transliteration/feed</wfw:commentRss>
		</item>
		<item>
		<title>Ordinal Suffixes and PHP&#8217;s Switch Statement</title>
		<link>http://sudrien.net/technical/ordinal-suffixes-and-phps-switch-statement</link>
		<comments>http://sudrien.net/technical/ordinal-suffixes-and-phps-switch-statement#comments</comments>
		<pubDate>Tue, 01 Jul 2008 16:50:20 +0000</pubDate>
		<dc:creator>Sudrien</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://sudrien.net/?p=183</guid>
		<description><![CDATA[I had a integer I wanted to suffix - 1st, 2nd, 13011th, and so on. 
So, I saw This code. And it was a lot of code for a simple problem.
So I wrote somthing shorter.
echo " the {$count}";
&#160;
switch ( $count ) {
  case ($count % 10 == 1 &#038;&#038; $count % 100 != 11 [...]]]></description>
			<content:encoded><![CDATA[<p>I had a integer I wanted to suffix - 1st, 2nd, 13011th, and so on. </p>
<p>So, I saw <a href='http://www.talkphp.com/tips-tricks/204-tutorial-getting-th-st-rd-ordinal-suffixes-numbers-dates.html'>This code</a>. And it was a lot of code for a simple problem.</p>
<p>So I wrote somthing shorter.</p>
<p><code>echo " the {$count}";<br />
&nbsp;<br />
switch ( $count ) {<br />
  case ($count % 10 == 1 &#038;&#038; $count % 100 != 11 ): echo "st"; break;<br />
  case ($count % 10 == 2 &#038;&#038; $count % 100 != 12  ): echo "nd"; break;<br />
  case ($count % 10 == 3 &#038;&#038; $count % 100 != 13  ): echo "rd"; break;<br />
  case "0":<br />
  case 0: echo " lack"; break;<br />
  default: echo "th"; break;<br />
  }<br />
&nbsp;<br />
echo " of whatever";</code></p>
<p>Most of the time in PHP, I&#8217;ve used the case statement for simple comparison; <em>if $count = 1, do this, if $count = 2, do that</em>, and so on. Here I am using its full capacity for logic; all this can be written as if..else statements. If not for the option of zero, I could have used <em>switch(true)</em>. </p>
<p>-Sud.</p>
<p>You can, of course, put this in a function.</p>
]]></content:encoded>
			<wfw:commentRss>http://sudrien.net/technical/ordinal-suffixes-and-phps-switch-statement/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
