<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2titles.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemtitles.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>The Data Asylum</title>
    <link>http://thedataasylum.com</link>
    
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Programming, Databases and People</description>
    <feedburner:info uri="thedataasylum" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://thedataasylum.com/feed" /><feedburner:emailServiceId>TheDataAsylum</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://thedataasylum.com/feed" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsalloy.com/?rss=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://www.newsalloy.com/subrss3.gif">Subscribe with NewsAlloy</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://download.attensa.com/app/get_attensa.html?feedurl=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://www.attensa.com/blogs/attensa/WindowsLiveWriter/BadgeredintoBadges_10C02/attensa_feed_button5.gif">Subscribe with Attensa for Outlook</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.flurry.com/pushRssFeed.do?r=fb&amp;url=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://www.flurry.com/images/flurry_rss_logo2.gif">Subscribe with Flurry</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Fthedataasylum.com%2Ffeed" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item>
      <title>What I learned about IE7 text-shadows and opacity</title>
      <description>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Yes you can have reasonably good text-shadows.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;But only on a &lt;a href="http://www.useragentman.com/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/"&gt;solid color background&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Yes you can fadeIn and fadeOut text.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;But only on a &lt;a href="http://stackoverflow.com/questions/3247333/jquery-fadein-text-in-ie7-ie8-text-aliased-during-animation"&gt;solid color background&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Yes you can even fadeIn and fadeOut transparent PNGS.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;But only once you&amp;#8217;ve applied a &lt;a href="http://www.sitepoint.com/forums/showthread.php?590295-jQuery-fadein-fadeout-of-transparent-png-in-IE7-and-Chrome&amp;amp;s=76c69f65b9eeab5322be704d23c92795&amp;amp;p=4722567&amp;amp;viewfull=1#post4722567"&gt;transparent background&lt;/a&gt;. Even then it looks a bit awful.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;&lt;p&gt;&lt;small&gt;Original article writen by Lang Sharpe and published on &lt;a href='http://thedataasylum.com'&gt;The Data Asylum&lt;/a&gt; | &lt;a href='http://thedataasylum.com/articles/what-i-learned-about-ie7-text-shadow-and-opacity.html'&gt;direct link to this article&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=bafUolnf2ZA:VxX-dA9I5xY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=bafUolnf2ZA:VxX-dA9I5xY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?i=bafUolnf2ZA:VxX-dA9I5xY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheDataAsylum/~4/bafUolnf2ZA" height="1" width="1"/&gt;</description>
      <pubDate>Wed, 05 Oct 2011 02:26:00 -0000</pubDate>
      <guid isPermaLink="false">urn:uuid:57101a54-9be2-43b1-8e05-99a8c9ea6578</guid>
      <comments>http://thedataasylum.com/articles/what-i-learned-about-ie7-text-shadow-and-opacity.html#comments</comments>
      <category>Css</category>
      <trackback:ping>http://thedataasylum.com/trackbacks?article_id=35</trackback:ping>
      <link>http://feedproxy.google.com/~r/TheDataAsylum/~3/bafUolnf2ZA/what-i-learned-about-ie7-text-shadow-and-opacity.html</link>
    <feedburner:origLink>http://thedataasylum.com/articles/what-i-learned-about-ie7-text-shadow-and-opacity.html</feedburner:origLink></item>
    <item>
      <title>Css margin and padding shorthand</title>
      <description>&lt;p&gt;Css provides short hand properties for margin and padding which let you define multiple properties at once. For example:-&lt;/p&gt;




&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;  &lt;span class="ty"&gt;p&lt;/span&gt;
  {
    &lt;span class="c"&gt;/*&lt;/span&gt; &lt;span class="c"&gt;Shorthand&lt;/span&gt; &lt;span class="c"&gt;*/&lt;/span&gt;
    &lt;span class="ke"&gt;margin&lt;/span&gt;: &lt;span class="fl"&gt;20px&lt;/span&gt; &lt;span class="fl"&gt;5px&lt;/span&gt; &lt;span class="fl"&gt;5px&lt;/span&gt; &lt;span class="fl"&gt;10px&lt;/span&gt;;

    &lt;span class="c"&gt;/*&lt;/span&gt; &lt;span class="c"&gt;The&lt;/span&gt; &lt;span class="c"&gt;Long&lt;/span&gt; &lt;span class="c"&gt;Equivalent&lt;/span&gt; &lt;span class="c"&gt;*/&lt;/span&gt;
    &lt;span class="ke"&gt;margin-top&lt;/span&gt;: &lt;span class="fl"&gt;20px&lt;/span&gt;;
    &lt;span class="ke"&gt;margin-right&lt;/span&gt;: &lt;span class="fl"&gt;5px&lt;/span&gt;;    
    &lt;span class="ke"&gt;margin-bottom&lt;/span&gt;: &lt;span class="fl"&gt;5px&lt;/span&gt;;
    &lt;span class="ke"&gt;margin-left&lt;/span&gt;: &lt;span class="fl"&gt;10px&lt;/span&gt;;
   }&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="Diagram of clockwise box" src="/files/MarginAndPaddingShorthand.png" style='float:right' /&gt;  &lt;p&gt;There are four variations of the shorthand property. You can specify 1, 2, 3 or 4 values, which are applied to the top, bottom, left and right margins. The problem that I had was trying to determine which value is applied to which side, especially if there are 2 or 3 values. There is an easy way to remember however.&lt;/p&gt;&lt;p&gt;
&lt;strong&gt;Start at the top and go clockwise. If you run out of values, use the value already set for that axis.&lt;/strong&gt;
&lt;/p&gt;&lt;/p&gt;

&lt;p&gt;
So for example&amp;#8230;
&lt;/p&gt;


&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;  &lt;span class="ty"&gt;p&lt;/span&gt;
  {
    &lt;span class="ke"&gt;margin&lt;/span&gt;: &lt;span class="fl"&gt;20px&lt;/span&gt;   &lt;span class="fl"&gt;5px&lt;/span&gt;      &lt;span class="fl"&gt;5px&lt;/span&gt;       &lt;span class="fl"&gt;10px&lt;/span&gt;;
    &lt;span class="c"&gt;/*&lt;/span&gt;      &lt;span class="c"&gt;top&lt;/span&gt; &lt;span class="c"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;right&lt;/span&gt; &lt;span class="c"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;bottom&lt;/span&gt; &lt;span class="c"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;left&lt;/span&gt;    &lt;span class="c"&gt;*/&lt;/span&gt;  

    &lt;span class="ke"&gt;margin&lt;/span&gt;: &lt;span class="fl"&gt;20px&lt;/span&gt;   &lt;span class="fl"&gt;5px&lt;/span&gt;      &lt;span class="fl"&gt;5px&lt;/span&gt;;
    &lt;span class="c"&gt;/*&lt;/span&gt;      &lt;span class="c"&gt;top&lt;/span&gt; &lt;span class="c"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;right&lt;/span&gt; &lt;span class="c"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;bottom&lt;/span&gt; 
                   &lt;span class="c"&gt;left&lt;/span&gt;                       &lt;span class="c"&gt;*/&lt;/span&gt;  

    &lt;span class="ke"&gt;margin&lt;/span&gt;: &lt;span class="fl"&gt;20px&lt;/span&gt;   &lt;span class="fl"&gt;5px&lt;/span&gt;;
    &lt;span class="c"&gt;/*&lt;/span&gt;      &lt;span class="c"&gt;top&lt;/span&gt; &lt;span class="c"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;right&lt;/span&gt;
            &lt;span class="c"&gt;bottom&lt;/span&gt; &lt;span class="c"&gt;left&lt;/span&gt;                       &lt;span class="c"&gt;*/&lt;/span&gt;  

    &lt;span class="c"&gt;/*&lt;/span&gt; &lt;span class="c"&gt;the&lt;/span&gt; &lt;span class="c"&gt;expection&lt;/span&gt; &lt;span class="c"&gt;is&lt;/span&gt; &lt;span class="c"&gt;for&lt;/span&gt; &lt;span class="c"&gt;a&lt;/span&gt; &lt;span class="c"&gt;single&lt;/span&gt; &lt;span class="c"&gt;value.&lt;/span&gt; &lt;span class="c"&gt;This&lt;/span&gt; &lt;span class="c"&gt;applies&lt;/span&gt; &lt;span class="c"&gt;to&lt;/span&gt; &lt;span class="c"&gt;all&lt;/span&gt; &lt;span class="c"&gt;sides.&lt;/span&gt; &lt;span class="c"&gt;*/&lt;/span&gt;
    &lt;span class="ke"&gt;margin&lt;/span&gt;: &lt;span class="fl"&gt;20px&lt;/span&gt;;
    &lt;span class="c"&gt;/*&lt;/span&gt;      &lt;span class="c"&gt;all&lt;/span&gt; &lt;span class="c"&gt;(top,&lt;/span&gt; &lt;span class="c"&gt;right,&lt;/span&gt; &lt;span class="c"&gt;bottom&lt;/span&gt; &lt;span class="c"&gt;and&lt;/span&gt; &lt;span class="c"&gt;left)&lt;/span&gt; &lt;span class="c"&gt;*/&lt;/span&gt;
  }
&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;hr /&gt;&lt;p&gt;&lt;small&gt;Original article writen by Lang Sharpe and published on &lt;a href='http://thedataasylum.com'&gt;The Data Asylum&lt;/a&gt; | &lt;a href='http://thedataasylum.com/articles/css-margin-and-padding-shorthand.html'&gt;direct link to this article&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=Eg2EuEOv958:JopH9ZMB_Lo:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=Eg2EuEOv958:JopH9ZMB_Lo:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?i=Eg2EuEOv958:JopH9ZMB_Lo:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheDataAsylum/~4/Eg2EuEOv958" height="1" width="1"/&gt;</description>
      <pubDate>Sat, 01 Oct 2011 05:59:00 -0000</pubDate>
      <guid isPermaLink="false">urn:uuid:835216e8-f97e-4cae-ab9f-a8c2ac7486c3</guid>
      <comments>http://thedataasylum.com/articles/css-margin-and-padding-shorthand.html#comments</comments>
      <category>Css</category>
      <trackback:ping>http://thedataasylum.com/trackbacks?article_id=34</trackback:ping>
      <link>http://feedproxy.google.com/~r/TheDataAsylum/~3/Eg2EuEOv958/css-margin-and-padding-shorthand.html</link>
    <feedburner:origLink>http://thedataasylum.com/articles/css-margin-and-padding-shorthand.html</feedburner:origLink></item>
    <item>
      <title>How Rails, Nginx and X-Accel-Redirect work together</title>
      <description>&lt;p&gt;&lt;em&gt;TL;DR&lt;/em&gt; - To use X-Accel-Redirect to serve static files from e.g /mnt/filestorage using send_file, put this in your nginx server configuration.&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;    proxy_set_header   X-Accel-Mapping       /mnt/filestorage/=/private_files/;

    location /private_files/ {
        internal;
        alias   /mnt/filestorage/;
    }&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The need for X-Accel-Redirect (and it&amp;#8217;s sibling X-Sendfile) comes from two distinct requirements&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The need to deliver large files.&lt;/li&gt;
&lt;li&gt;The need for those files to not be available to the public.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Here we are going to see how to set up X-Accel-Redirect and Rails. This is a bit complex so I&amp;#8217;m going to run through a specific example of downloading a file. Along the way we&amp;#8217;ll see the configuration, code and HTTP headers that are used. This assumes you already have Rails and Nginx installed and working.&lt;/p&gt;

&lt;p&gt;1. Browser makes a request for a file&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;  # HTTP Headers
  GET /download/SecretSquirrel.zip HTTP/1.1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;2. Nginx receives this request. It adds on a header with configuration data that will be required by rails.&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;  #Nginx configuration
  proxy_set_header   X-Accel-Mapping       /mnt/filestorage/=/private_files/;

  # Example HTTP Headers with additional header added by nginx
  GET /download/SecretSquirrel.zip HTTP/1.1
  X-Accel-Mapping: /mnt/filestorage/=/private_files/&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;3. Nginx passes the request onto Rails and it invokes the relevant controller.&lt;/p&gt;

&lt;p&gt;4. The controller makes its authorization checks and calls send_file. Use the absolute path to the file.&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;  # controller code (e.g. app/controllers/downloads_controller.rb)
  send_file('/mnt/filestorage/SecretSquirrel.zip')&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;5. Rails (&lt;a href="http://rack.rubyforge.org/"&gt;Rack&lt;/a&gt; to be precise) then decides what to with the file. We need to tell rails to use X-Accel-Redirect in its configuration as shown below. Instead of using the file as the body of the request, it will add a header to the response. It uses the X-Accel-Mapping that nginx added earlier to change the file path.&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;  # Rails configuration (e.g. config/environments/production.rb)
  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

  # HTTP Response
  HTTP/1.1 200 OK
  X-Accel-Redirect: /private_files/SecretSquirrel.zip
  Content-Type: application/octet-stream
  Content-length: ...
  Content-Disposition: attachment; filename=&amp;quot;SecretSquirrel.zip&amp;quot;
  &amp;lt;empty body&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;6. Nginx receives this header from rails and interprets it. It finds the location directive and reverses the changes to the path that rails made in step 5.&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;  #Nginx configuration
        location /private_files/ {
      internal;
            alias   /mnt/filestorage/;
        }

  # HTTP Response
  HTTP/1.1 200 OK
  Content-Type: application/octet-stream
  Content-Length: ...
  Content-Disposition: attachment; filename=&amp;quot;SecretSquirrel.zip&amp;quot;
  &amp;lt;contents of /mnt/filestorage/SecretSquirrel.zip&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;7. Browser receives the file as if it was a normal download.&lt;/p&gt;

&lt;p&gt;Also, if you have compiled passenger into nginx, remember to &lt;a href="/articles/adding-headers-to-requests-using-nginx-and-passenger.html"&gt;use passenger&lt;em&gt;set&lt;/em&gt;cgi&lt;em&gt;param instead of proxy&lt;/em&gt;set_header&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Software Versions used&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rails 3.0.7&lt;/li&gt;
&lt;li&gt;Passenger 3.0.5&lt;/li&gt;
&lt;li&gt;Nginx 0.8.54&lt;/li&gt;
&lt;li&gt;on Ubuntu 10.04.2 LTS&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;em&gt;Resources&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://rack.rubyforge.org/doc/Rack/Sendfile.html"&gt;Rack::Sendfile documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://wiki.nginx.org/X-accel"&gt;Nginx X-Accel documemtation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://wiki.nginx.org/XSendfile"&gt;More documentation on Nginx&amp;#8217;s X-Accel-Redirect&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;&lt;p&gt;&lt;small&gt;Original article writen by Lang Sharpe and published on &lt;a href='http://thedataasylum.com'&gt;The Data Asylum&lt;/a&gt; | &lt;a href='http://thedataasylum.com/articles/how-rails-nginx-x-accel-redirect-work-together.html'&gt;direct link to this article&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=OGj6Yi6O5mc:C6Fz-nplohA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=OGj6Yi6O5mc:C6Fz-nplohA:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?i=OGj6Yi6O5mc:C6Fz-nplohA:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheDataAsylum/~4/OGj6Yi6O5mc" height="1" width="1"/&gt;</description>
      <pubDate>Tue, 05 Jul 2011 14:49:00 -0000</pubDate>
      <guid isPermaLink="false">urn:uuid:5afa8dea-1754-42e4-81be-6c15ae8445f4</guid>
      <comments>http://thedataasylum.com/articles/how-rails-nginx-x-accel-redirect-work-together.html#comments</comments>
      <category>Ruby</category>
      <category>Ruby</category>
      <category>nginx</category>
      <trackback:ping>http://thedataasylum.com/trackbacks?article_id=33</trackback:ping>
      <link>http://feedproxy.google.com/~r/TheDataAsylum/~3/OGj6Yi6O5mc/how-rails-nginx-x-accel-redirect-work-together.html</link>
    <feedburner:origLink>http://thedataasylum.com/articles/how-rails-nginx-x-accel-redirect-work-together.html</feedburner:origLink></item>
    <item>
      <title>Adding headers to requests using Nginx and Passenger</title>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; If you have compiled Passenger into Nginx, use &lt;code&gt;passenger_set_cgi_param&lt;/code&gt; instead of &lt;code&gt;proxy_set_header&lt;/code&gt; to set HTTP headers required by the rails process.&lt;/p&gt;

&lt;p&gt;There are two ways of using Passenger and Nginx together. The first is when the two are compiled into one daemon that creates many processes as required. The second is using Nginx as a proxy in front of Passenger/Apache/Nginx processes running either on the same machine or on a different server altogether.&lt;/p&gt;

&lt;p&gt;When using Nginx as a proxy, it can be configured to add or redefine http headers in the request. This is done using the &lt;code&gt;proxy_set_header&lt;/code&gt; directive.&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;proxy_set_header X-Forwarded-For 127.0.0.1;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;/p&gt;

&lt;p&gt;If you have compiled Passenger into Nginx, the above configuration will have no effect. This is because the request is not considered to be proxied by Nginx. To have the same effect you need to use the &lt;code&gt;passenger_set_cgi_param&lt;/code&gt; directive.&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;passenger_set_cgi_param HTTP_X_FORWARDED_FOR 127.0.0.1;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Notice that the header name is all upper case, and has &lt;code&gt;HTTP_&lt;/code&gt; prefixed.&lt;/p&gt;&lt;hr /&gt;&lt;p&gt;&lt;small&gt;Original article writen by Lang Sharpe and published on &lt;a href='http://thedataasylum.com'&gt;The Data Asylum&lt;/a&gt; | &lt;a href='http://thedataasylum.com/articles/adding-headers-to-requests-using-nginx-and-passenger.html'&gt;direct link to this article&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=5Jx3CPig-us:PtqFKJzgZeg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=5Jx3CPig-us:PtqFKJzgZeg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?i=5Jx3CPig-us:PtqFKJzgZeg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheDataAsylum/~4/5Jx3CPig-us" height="1" width="1"/&gt;</description>
      <pubDate>Mon, 13 Jun 2011 05:46:00 -0000</pubDate>
      <guid isPermaLink="false">urn:uuid:6401112c-eb11-4e2b-835f-70c56b1e20c5</guid>
      <comments>http://thedataasylum.com/articles/adding-headers-to-requests-using-nginx-and-passenger.html#comments</comments>
      <category>Ruby</category>
      <category>Ruby</category>
      <category>nginx</category>
      <category>passenger</category>
      <category>sysadmin</category>
      <trackback:ping>http://thedataasylum.com/trackbacks?article_id=32</trackback:ping>
      <link>http://feedproxy.google.com/~r/TheDataAsylum/~3/5Jx3CPig-us/adding-headers-to-requests-using-nginx-and-passenger.html</link>
    <feedburner:origLink>http://thedataasylum.com/articles/adding-headers-to-requests-using-nginx-and-passenger.html</feedburner:origLink></item>
    <item>
      <title>Differences between PHP Arrays and Ruby Hashes</title>
      <description>&lt;p&gt;We&amp;#39;ve looked at the &lt;a href="http://thedataasylum.com/article_207/major-differences-between-php-and-ruby-arrays.html"&gt;diferences between Ruby and PHP arrays&lt;/a&gt; before. Now lets compare PHP arrays and Ruby hashes. They should be similar as all &lt;a href="http://stackoverflow.com/questions/247467/how-are-associative-arrays-implemented-in-php" target="_blank"&gt;PHP arrays are implemented as hashes&lt;/a&gt;. There is however a cruicial difference that can trip you up if you are switching from one language to another.&lt;/p&gt;


&lt;p&gt;&amp;nbsp;&lt;/p&gt;


&lt;h3&gt;Referencing an index that hasn&amp;#39;t been set is an error in PHP, but not in Ruby.&lt;/h3&gt;


&lt;p&gt;In PHP, retreiving a value for an index that you haven&amp;#39;t used is a warning. Although warnings can be turned off it is best practice to develop with them turned on.&lt;/p&gt;


&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;&lt;span class="idl"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="lv"&gt;$a&lt;/span&gt;[&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;key1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;value1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;;
&lt;span class="lv"&gt;$a&lt;/span&gt;[&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;key2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;value2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;;

&lt;span class="pd"&gt;print&lt;/span&gt; &lt;span class="lv"&gt;$a&lt;/span&gt;[&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;key5&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;];
&lt;span class="c"&gt;/*
lang@virtualbox1:~/$ php hash.php
PHP Notice: Undefined index: key5 in /home/lang/hash.php on line 6
*/&lt;/span&gt;
&lt;span class="idl"&gt;?&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;




&lt;p&gt;In Ruby you can set a default value for all keys that have not set a value. By default this value is nil.&lt;/p&gt;


&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;a = &lt;span class="co"&gt;Hash&lt;/span&gt;.new

a[&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;key1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;value1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;
a[&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;key2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;value2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;

puts a[&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;key5&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;]
&lt;span class="c"&gt;=begin
lang@virtualbox1:~/$ ruby hash.rb
nil
=end&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;




&lt;p&gt;&amp;nbsp;&lt;/p&gt;


&lt;h3&gt;Ruby hashes are unordered (up to version 1.8). PHP arrays have an internal order seperate from their index.&lt;/h3&gt;


&lt;p&gt;When you loop through a PHP array, the values will be returned in the order they were added.&lt;/p&gt;


&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;&lt;span class="idl"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="lv"&gt;$a&lt;/span&gt;[&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;key1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;one&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;;
&lt;span class="lv"&gt;$a&lt;/span&gt;[&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;key0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;zero&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;;

&lt;span class="r"&gt;foreach&lt;/span&gt;(&lt;span class="lv"&gt;$a&lt;/span&gt; &lt;span class="r"&gt;as&lt;/span&gt; &lt;span class="lv"&gt;$value&lt;/span&gt;) {
        &lt;span class="pd"&gt;print&lt;/span&gt; &lt;span class="lv"&gt;$value&lt;/span&gt; . &lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="ch"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;;
}
&lt;span class="c"&gt;/*
lang@virtualbox1:~/$ php hash.php
one
zero
*/&lt;/span&gt;

&lt;span class="idl"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;




&lt;p&gt;In Ruby 1.8 hashes are unordered, they could be retreived in any order that ruby decides is best. Ruby 1.9 changes this so that it works in the same way as the PHP example above.&lt;/p&gt;


&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;a = &lt;span class="co"&gt;Hash&lt;/span&gt;.new

a[&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;key1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;one&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;
a[&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;key0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;zero&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;

a.each_value &lt;span class="r"&gt;do&lt;/span&gt; |value|
        puts value
&lt;span class="r"&gt;end&lt;/span&gt;
&lt;span class="c"&gt;=begin
lang@virtualbox1:~/$ ruby hash.rb
zero
one
=end&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;




&lt;p&gt;Is there anything that has been missed? Add a comment below.&lt;/p&gt;


&lt;hr /&gt;&lt;p&gt;&lt;small&gt;Original article writen by Lang Sharpe and published on &lt;a href='http://thedataasylum.com'&gt;The Data Asylum&lt;/a&gt; | &lt;a href='http://thedataasylum.com/articles/differences-between-php-arrays-and-ruby-hashes.html'&gt;direct link to this article&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=6nu-MaMI0Pc:a04NZaulvwk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=6nu-MaMI0Pc:a04NZaulvwk:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?i=6nu-MaMI0Pc:a04NZaulvwk:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheDataAsylum/~4/6nu-MaMI0Pc" height="1" width="1"/&gt;</description>
      <pubDate>Sat, 19 Mar 2011 11:03:00 -0000</pubDate>
      <guid isPermaLink="false">urn:uuid:6a72ef2c-67bc-4385-b549-07e69f47c397</guid>
      <comments>http://thedataasylum.com/articles/differences-between-php-arrays-and-ruby-hashes.html#comments</comments>
      <category>PHP</category>
      <category>Programming</category>
      <category>Ruby</category>
      <category>PHP</category>
      <category>Programming</category>
      <category>Ruby</category>
      <category>arrays</category>
      <category>hash</category>
      <trackback:ping>http://thedataasylum.com/trackbacks?article_id=19</trackback:ping>
      <link>http://feedproxy.google.com/~r/TheDataAsylum/~3/6nu-MaMI0Pc/differences-between-php-arrays-and-ruby-hashes.html</link>
    <feedburner:origLink>http://thedataasylum.com/articles/differences-between-php-arrays-and-ruby-hashes.html</feedburner:origLink></item>
    <item>
      <title>Major differences between PHP and Ruby Arrays</title>
      <description>&lt;p&gt;PHP has a single array type, where as Ruby has Array and Hash, which covers the same functionality. In this article i&amp;#39;ll go though the three major logical differences between PHPs array type and Rubys Array classs. &lt;a href="http://thedataasylum.com/article_225/differences-php-arrays-ruby-hashes.html"&gt;We compare PHP arrays and Ruby Hashes in seperate post&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Firstly,&lt;/p&gt;


&lt;h3&gt;PHP arrays have an internal order seperate from their index.&lt;/h3&gt;


&lt;p&gt;Lets look at a simple example. In php the order you insert values into an array&lt;br /&gt;
    determines the order that php will return them using foreach&lt;/p&gt;




&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;&lt;span class="idl"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="lv"&gt;$a&lt;/span&gt;[&lt;span class="i"&gt;1&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;one&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;;
&lt;span class="lv"&gt;$a&lt;/span&gt;[&lt;span class="i"&gt;0&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;zero&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;;

&lt;span class="r"&gt;foreach&lt;/span&gt;(&lt;span class="lv"&gt;$a&lt;/span&gt; &lt;span class="r"&gt;as&lt;/span&gt; &lt;span class="lv"&gt;$value&lt;/span&gt;) {
        &lt;span class="pd"&gt;print&lt;/span&gt; &lt;span class="lv"&gt;$value&lt;/span&gt; . &lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="ch"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;;
}

&lt;span class="c"&gt;/*
lang@virtualbox1:~/arrays$ php array.php
one
zero
*/&lt;/span&gt;
&lt;span class="idl"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;




&lt;p&gt;Ruby on the other hand uses the key or index of the array to determine the order, regardless of order in which the values are inserted.&lt;/p&gt;


&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;a = &lt;span class="co"&gt;Array&lt;/span&gt;.new

a[&lt;span class="i"&gt;1&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;one&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;
a[&lt;span class="i"&gt;0&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;zero&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;

a.each &lt;span class="r"&gt;do&lt;/span&gt; |value|
        puts value
&lt;span class="r"&gt;end&lt;/span&gt;
&lt;span class="c"&gt;=begin
lang@virtualbox1:~/arrays$ ruby array.rb
zero
one
=end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;




&lt;p&gt;Secondly,&lt;/p&gt;


&lt;h3&gt;Ruby arrays always start at 0 and end at the highest index. PHP arrays only contain the keys that have been entered.&lt;/h3&gt;


&lt;p&gt;In the example below, PHP will output the two array values that are set.&lt;/p&gt;


&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;&lt;span class="idl"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="lv"&gt;$a&lt;/span&gt;[&lt;span class="i"&gt;2&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;two&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;;
&lt;span class="lv"&gt;$a&lt;/span&gt;[&lt;span class="i"&gt;4&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;four&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;;

&lt;span class="r"&gt;foreach&lt;/span&gt;(&lt;span class="lv"&gt;$a&lt;/span&gt; &lt;span class="r"&gt;as&lt;/span&gt; &lt;span class="lv"&gt;$value&lt;/span&gt;) {
        &lt;span class="pd"&gt;print&lt;/span&gt; &lt;span class="lv"&gt;$value&lt;/span&gt; . &lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="ch"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;;
}

&lt;span class="c"&gt;/*
lang@virtualbox1:~/arrays$ php array.php
two
four
*/&lt;/span&gt;
&lt;span class="idl"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;




&lt;p&gt;In the ruby example, not only are the two values output, but an attempt is made to get the value from every index between 0 and the highest index set.&lt;/p&gt;


&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;a = &lt;span class="co"&gt;Array&lt;/span&gt;.new

a[&lt;span class="i"&gt;2&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;two&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;
a[&lt;span class="i"&gt;4&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;four&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;

a.each &lt;span class="r"&gt;do&lt;/span&gt; |value|
        puts value
&lt;span class="r"&gt;end&lt;/span&gt;
&lt;span class="c"&gt;=begin
lang@virtualbox1:~/arrays$ ruby array.rb
nil
nil
two
nil
four
=end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;




&lt;p&gt;This leads to another difference&amp;#8230;&lt;/p&gt;


&lt;h3&gt;Referencing an array index that hasn&amp;#39;t been set is an error in PHP, but not in Ruby.&lt;/h3&gt;


&lt;p&gt;The following code produces a PHP notice. Notices are a low severity error, and are usually turned off on production servers. However it is considered good practice to develop with notices turned on.&lt;/p&gt;


&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;&lt;span class="idl"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="lv"&gt;$a&lt;/span&gt;[&lt;span class="i"&gt;2&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;two&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;;
&lt;span class="lv"&gt;$a&lt;/span&gt;[&lt;span class="i"&gt;4&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;four&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;;

&lt;span class="pd"&gt;print&lt;/span&gt; &lt;span class="lv"&gt;$a&lt;/span&gt;[&lt;span class="i"&gt;5&lt;/span&gt;];

&lt;span class="c"&gt;/*
lang@virtualbox1:~/arrays$ php array.php
PHP Notice: Undefined offset: 5 in /home/lang/arrays/array.php on line 6
*/&lt;/span&gt;
&lt;span class="idl"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;




&lt;p&gt;Ruby on the other hand does not consider this an error. It will return the nil value which is &amp;#39;kind of&amp;#39; like PHPs null.&lt;/p&gt;


&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;a = &lt;span class="co"&gt;Array&lt;/span&gt;.new

a[&lt;span class="i"&gt;2&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;two&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;
a[&lt;span class="i"&gt;4&lt;/span&gt;] = &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;four&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;

puts a[&lt;span class="i"&gt;5&lt;/span&gt;]
&lt;span class="c"&gt;=begin
lang@virtualbox1:~/arrays$ ruby array3.rb
nil
=end&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;So what are your experiences switching between PHP and Ruby. Let me know in the comments below.&lt;/p&gt;


&lt;hr /&gt;&lt;p&gt;&lt;small&gt;Original article writen by Lang Sharpe and published on &lt;a href='http://thedataasylum.com'&gt;The Data Asylum&lt;/a&gt; | &lt;a href='http://thedataasylum.com/articles/major-differences-between-php-and-ruby-arrays.html'&gt;direct link to this article&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=blcNdhZ78Ys:6CeTDVbci3I:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=blcNdhZ78Ys:6CeTDVbci3I:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?i=blcNdhZ78Ys:6CeTDVbci3I:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheDataAsylum/~4/blcNdhZ78Ys" height="1" width="1"/&gt;</description>
      <pubDate>Thu, 10 Mar 2011 16:45:00 -0000</pubDate>
      <guid isPermaLink="false">urn:uuid:99f62a12-e38b-4370-9150-0d77b209e453</guid>
      <comments>http://thedataasylum.com/articles/major-differences-between-php-and-ruby-arrays.html#comments</comments>
      <category>PHP</category>
      <category>Programming</category>
      <category>Ruby</category>
      <category>PHP</category>
      <category>Programming</category>
      <category>Ruby</category>
      <category>arrays</category>
      <trackback:ping>http://thedataasylum.com/trackbacks?article_id=18</trackback:ping>
      <link>http://feedproxy.google.com/~r/TheDataAsylum/~3/blcNdhZ78Ys/major-differences-between-php-and-ruby-arrays.html</link>
    <feedburner:origLink>http://thedataasylum.com/articles/major-differences-between-php-and-ruby-arrays.html</feedburner:origLink></item>
    <item>
      <title>7 Habits of Highly Ineffective People</title>
      <description>&lt;p&gt;&lt;img src="http://thedataasylum.com/files/The_7_Habits_of_Highly_Effective_People.jpg" alt="The 7 Habits of Highly Effective People Cover" style="float:right; padding-left:10px;" /&gt;&lt;/p&gt;

&lt;p&gt;
My Secret Santa decided to treat me to a copy of Stephen Covey&amp;#39;s &lt;a href="http://en.wikipedia.org/wiki/The_Seven_Habits_of_Highly_Effective_People"&gt;The Seven Habits of Highly Effective People&lt;/a&gt;. Presumably because I&amp;#39;m ineffective in some way, which is completely true. Here then is my list of how to be a highly ineffective person.&lt;/p&gt;


&lt;ol&gt;
    &lt;li&gt;&lt;strong&gt;Social Networking.&lt;/strong&gt; Check Twitter/Facebook every 5 minutes. Someone might upload a photo of you at any minute. You must know ASAP.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;MSN.&lt;/strong&gt; Having personal conversations on MSN can sap anything from 10 minutes up to an hour or two from your day.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Hangovers.&lt;/strong&gt; Nothing keeps you alert like having a late night the night before. Especially if you are a &amp;quot;2 pint screamer&amp;quot; like myself.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Wikiwalk.&lt;/strong&gt; Do a Google search on how to open a file in ruby. An hour later your reading about the Boer War in South Africa. You have no idea how this happened.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;News feeds.&lt;/strong&gt; Keeping up with the world and what is happening in your industry is important. Reading every article from the 200 feeds you are subscribed too isn&amp;#39;t.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Coffee Time.&lt;/strong&gt; Making a cup of tea/coffee is a great little stretch for you. To really be ineffective, make a cup for the rest of the office as well.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Unread books&lt;/strong&gt;. Buying books and not reading them is a surefire way to feel smart. I currently have The Passionate Programmer, Linchpin and the 7 habits book waiting to be read/finished.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Is there anything missing. Do you have a favourite time waster? Let everyone know with a comment.&lt;/p&gt;


&lt;hr /&gt;&lt;p&gt;&lt;small&gt;Original article writen by Lang Sharpe and published on &lt;a href='http://thedataasylum.com'&gt;The Data Asylum&lt;/a&gt; | &lt;a href='http://thedataasylum.com/articles/7-habits-of-highly-ineffective-people.html'&gt;direct link to this article&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=qn2Q934oXdA:XR0gVbU9GKY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=qn2Q934oXdA:XR0gVbU9GKY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?i=qn2Q934oXdA:XR0gVbU9GKY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheDataAsylum/~4/qn2Q934oXdA" height="1" width="1"/&gt;</description>
      <pubDate>Thu, 06 Jan 2011 02:00:00 -0000</pubDate>
      <guid isPermaLink="false">urn:uuid:8513072a-99ef-4ffc-9539-96c3ba8bbd07</guid>
      <comments>http://thedataasylum.com/articles/7-habits-of-highly-ineffective-people.html#comments</comments>
      <category>Self Development</category>
      <category>People</category>
      <category>Programming</category>
      <category>book</category>
      <category>productivity</category>
      <link>http://feedproxy.google.com/~r/TheDataAsylum/~3/qn2Q934oXdA/7-habits-of-highly-ineffective-people.html</link>
    <feedburner:origLink>http://thedataasylum.com/articles/7-habits-of-highly-ineffective-people.html</feedburner:origLink></item>
    <item>
      <title>The best feature of VIM not in IDE's</title>
      <description>&lt;p&gt;&amp;#39;Insertion mode keyword completion&amp;#39;.&lt;/p&gt;


&lt;p&gt;Ctrl-P and Ctrl-N in insert mode to search through the text to try and complete whatever variable name you are typing. I&amp;#39;ve never seen this in any other IDE and I really miss it. Code completion in IDE&amp;#39;s just isn&amp;#39;t the same.&lt;/p&gt;


&lt;hr /&gt;&lt;p&gt;&lt;small&gt;Original article writen by Lang Sharpe and published on &lt;a href='http://thedataasylum.com'&gt;The Data Asylum&lt;/a&gt; | &lt;a href='http://thedataasylum.com/articles/the-best-feature-of-vim-not-in-ides.html'&gt;direct link to this article&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=rkUlBIWqwXM:QKbS7udKowc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=rkUlBIWqwXM:QKbS7udKowc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?i=rkUlBIWqwXM:QKbS7udKowc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheDataAsylum/~4/rkUlBIWqwXM" height="1" width="1"/&gt;</description>
      <pubDate>Mon, 11 Oct 2010 18:00:57 -0000</pubDate>
      <guid isPermaLink="false">urn:uuid:e74c9aba-05de-4445-ac2b-acf498deb108</guid>
      <comments>http://thedataasylum.com/articles/the-best-feature-of-vim-not-in-ides.html#comments</comments>
      <category>Programming</category>
      <category>Programming</category>
      <category>ide</category>
      <category>vi</category>
      <link>http://feedproxy.google.com/~r/TheDataAsylum/~3/rkUlBIWqwXM/the-best-feature-of-vim-not-in-ides.html</link>
    <feedburner:origLink>http://thedataasylum.com/articles/the-best-feature-of-vim-not-in-ides.html</feedburner:origLink></item>
    <item>
      <title>Speak the truth</title>
      <description>&lt;p&gt;Improper uses of Booleans causes headaches for people who are reviewing your code. Lets take a look at some good, and not so good uses.&lt;/p&gt;


&lt;h3&gt;Don&amp;#39;t be negative&lt;/h3&gt;


&lt;pre&gt;if $notLoggedIn then&lt;/pre&gt;


&lt;p&gt;Looks simple and readable right? Wrong. It&amp;#39;s one step away from being misused.&lt;/p&gt;


&lt;pre&gt;if ! $notLoggedin then&lt;/pre&gt;


&lt;p&gt;Not not logged in. Double negatives are a gotcha in language and coding and should be avoided. Fortunately the solution is an easy one. Remove the negative prefix (such as not, doNot, dont) from the variable name.&lt;/p&gt;


&lt;pre&gt;if $loggedIn then

if ! $loggedIn then

&lt;/pre&gt;


&lt;h3&gt;Hide Literals&lt;/h3&gt;


&lt;pre&gt;if $hidden == false then&lt;/pre&gt;


&lt;p&gt;Is it really necessary to compare the variable to false?&lt;/p&gt;


&lt;blockquote&gt;
    &lt;p&gt;Imagine this conversation. You are at Subway and they ask you&lt;/p&gt;
    &lt;p&gt;&amp;quot;Would you like your sandwich toasted?&amp;quot;&lt;/p&gt;
    &lt;p&gt;Would you reply with&lt;/p&gt;
    &lt;p&gt;&amp;quot;Toasted equals false&amp;quot;&lt;br /&gt;
        &amp;nbsp; Or&lt;br /&gt;
        &amp;quot;Not Toasted&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;Avoid comparing with a literal true or false. The correct way to express this is :-&lt;/p&gt;


&lt;pre&gt;if ! $hidden then&lt;/pre&gt;


&lt;h3&gt;A Boolean Flag?&lt;/h3&gt;


&lt;pre&gt;if $reportFlag then&lt;/pre&gt;


&lt;p&gt;$reportFlag is a little vague. In this case it is determining if an object is included in a report. So if $reportFlag is true, does that mean that the object is included or excluded? If you have to ask yourself the question then you have already failed and need to rethink what this variable should be called.&lt;/p&gt;


&lt;pre&gt;if $report then&lt;/pre&gt;


&lt;p&gt;This is okay as long we are using the word &amp;#39;report&amp;#39; as a verb. &amp;quot;If we report this then&amp;quot; is how you would read this. Some people may not be able to make that leap so if you want to be more precise you could make it :-&lt;/p&gt;


&lt;pre&gt;if $includeInReport then&lt;/pre&gt;


&lt;h3&gt;Summary&lt;/h3&gt;


&lt;p&gt;So to sum up, these three things will go a long way to making your code readable.&lt;/p&gt;


&lt;ul&gt;
    &lt;li&gt;Remove the negative prefix (such as not, doNot, dont) from variable names.&lt;/li&gt;
    &lt;li&gt;Avoid comparing with a literal true or false.&lt;/li&gt;
    &lt;li&gt;Avoid vague terms like flag for Boolean values.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Consider these ideas when choosing&lt;/p&gt;


&lt;ul&gt;
    &lt;li&gt;Variable names&lt;/li&gt;
    &lt;li&gt;Object properties&lt;/li&gt;
    &lt;li&gt;Database field names&lt;/li&gt;
    &lt;li&gt;Method or function parameter names&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Anything Else?&lt;/h3&gt;


&lt;p&gt;Is there something i&amp;#39;ve missed? A hole you could drive a double-decker bus through? Leave a comment below.&lt;/p&gt;


&lt;hr /&gt;&lt;p&gt;&lt;small&gt;Original article writen by Lang Sharpe and published on &lt;a href='http://thedataasylum.com'&gt;The Data Asylum&lt;/a&gt; | &lt;a href='http://thedataasylum.com/articles/speak-the-truth.html'&gt;direct link to this article&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=e1n5Gavu9Hw:bx_rqdgE3vk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=e1n5Gavu9Hw:bx_rqdgE3vk:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?i=e1n5Gavu9Hw:bx_rqdgE3vk:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheDataAsylum/~4/e1n5Gavu9Hw" height="1" width="1"/&gt;</description>
      <pubDate>Mon, 06 Sep 2010 12:00:00 -0000</pubDate>
      <guid isPermaLink="false">urn:uuid:6edf8448-0045-46c2-910d-e0ad8f1992aa</guid>
      <comments>http://thedataasylum.com/articles/speak-the-truth.html#comments</comments>
      <category>Programming</category>
      <category>PHP</category>
      <category>Programming</category>
      <category>best practices</category>
      <link>http://feedproxy.google.com/~r/TheDataAsylum/~3/e1n5Gavu9Hw/speak-the-truth.html</link>
    <feedburner:origLink>http://thedataasylum.com/articles/speak-the-truth.html</feedburner:origLink></item>
    <item>
      <title>Ctrl-A Delete</title>
      <description>&lt;p&gt;Usually a last resort. Often the best thing to do.&lt;/p&gt;


&lt;hr /&gt;&lt;p&gt;&lt;small&gt;Original article writen by Lang Sharpe and published on &lt;a href='http://thedataasylum.com'&gt;The Data Asylum&lt;/a&gt; | &lt;a href='http://thedataasylum.com/articles/ctrl-a-delete.html'&gt;direct link to this article&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=jylBOXDboRs:OmUHTRJ8jno:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheDataAsylum?a=jylBOXDboRs:OmUHTRJ8jno:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheDataAsylum?i=jylBOXDboRs:OmUHTRJ8jno:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheDataAsylum/~4/jylBOXDboRs" height="1" width="1"/&gt;</description>
      <pubDate>Wed, 04 Aug 2010 16:52:00 -0000</pubDate>
      <guid isPermaLink="false">urn:uuid:a059e3f7-057a-4dbf-8b74-96971d5f4e03</guid>
      <comments>http://thedataasylum.com/articles/ctrl-a-delete.html#comments</comments>
      <category>Programming</category>
      <category>shortcut keys</category>
      <link>http://feedproxy.google.com/~r/TheDataAsylum/~3/jylBOXDboRs/ctrl-a-delete.html</link>
    <feedburner:origLink>http://thedataasylum.com/articles/ctrl-a-delete.html</feedburner:origLink></item>
  </channel>
</rss>

