<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>VisezTrance</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/" />
    <link rel="self" type="application/atom+xml" href="http://viseztrance.com/atom.xml" />
    <id>tag:viseztrance.com,2008-10-15://1</id>
    <updated>2010-08-03T22:46:19Z</updated>
    <subtitle>The wonderful world of Lorem Ipsum</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 5.02</generator>

<entry>
    <title>Generating a unique identifier</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2010/08/generating-a-unique-identifier.html" />
    <id>tag:viseztrance.com,2010://1.39</id>

    <published>2010-08-03T22:31:42Z</published>
    <updated>2010-08-03T22:46:19Z</updated>

    <summary>Generating a unique string value is a fairly common idiom. I always thought the fastest/easiest way to do so was by merging a timestamp with a random value. Not really unique, but fairly close nevertheless. Yet, there&apos;s better way by...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[Generating a unique string value is a fairly common idiom. I always thought the fastest/easiest way to do so was by merging a timestamp with a random value. Not really unique, but fairly close nevertheless. <br />Yet, there's better way by using <a href="http://en.wikipedia.org/wiki/Universally_unique_identifier">UUID</a> which provides a more reliable unique identifier. Most languages either have it build in or there's a library available.<br /><br />For example, in php I could use the build in <a href="http://php.net/manual/en/function.uniqid.php">uniqid() </a>function:<br /><br /><blockquote>print uniqid();<br />&gt; "4c5896b421e54"<br /></blockquote><br />or in ruby with the help of the <a href="http://rubygems.org/gems/uuid">uuid gem</a>:<br /><br /><blockquote>UUID.generate<br />&gt; "73f93750-817b-012d-5ea3-00242165bf55"<br /></blockquote>]]>
        
    </content>
</entry>

<entry>
    <title>Visual bookmarks with mywebsit.es</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2010/06/visual-bookmarks-with-mywebsites.html" />
    <id>tag:viseztrance.com,2010://1.37</id>

    <published>2010-06-26T13:39:35Z</published>
    <updated>2010-06-26T14:02:44Z</updated>

    <summary>I&apos;m happy to announce mywebsit.es, a visual bookmarks directory. It&apos;s similar to opera&apos;s quick dial or chrome&apos;s thumbnail start page but has a larger degree of flexibility. By using open id it shouldn&apos;t take more than 10 seconds to create...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="bookmark" label="bookmark" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mywebsites" label="mywebsit.es" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="qtwebkit" label="qt webkit" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="rails" label="rails" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="startpage" label="start page" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[<img alt="mywebsit.es.png" src="http://viseztrance.com/mywebsit.es.png" width="356" height="325" class="mt-image-left" style="float: left; margin: 0 20px 20px 0;" />I'm happy to announce <a href="http://mywebsit.es">mywebsit.es</a>, a visual bookmarks directory. It's similar to opera's quick dial or chrome's thumbnail start page but has a larger degree of flexibility. By using open id it shouldn't take more than 10 seconds to create an account.<div><br /></div><div>From a technical standpoint it combines a qt webkit ruby class that's being called through xvfb by a sinatra app which acts as an api. This api is being called by a rails application that manages the actual bookmarks and saved screenshots.</div><div><br /></div><div>I would appreciate it if you would try it out.</div>]]>
        
    </content>
</entry>

<entry>
    <title>Timing out</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2010/04/timing-out.html" />
    <id>tag:viseztrance.com,2010://1.34</id>

    <published>2010-04-30T20:40:44Z</published>
    <updated>2010-04-30T20:49:33Z</updated>

    <summary>I was running a rake task that launched a third party proprietary binary that handled some files. The process was usually fast, lasting about two or three seconds per file although sometimes it would just lock up and become unresponsive...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="defensiveprogramming" label="defensive programming" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="timeout" label="timeout" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[<div>I was running a rake task that launched a third party proprietary binary that handled some files. The process was usually fast, lasting about two or three seconds per file although sometimes it would just lock up and become unresponsive while still pegging the cpu at 100%.</div><div>While I love a good challenge, there are times when a battle proven solution is preferable.</div><div>Fortunetly for me, there was a *nix command named timeout, that did exactly what I was looking for.</div><div><br /></div><div>The following would kill a running command with signal 9 (the equivalent of powering off the computer) if it runs longer than 30 seconds:</div><div><br /></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div>timeout --signal=9 30s /some/command</div></blockquote><div><br /></div><div>Suffice to say, that I was so pleased of this solution that I'm going to use it everytime I can.</div><div>A slight warning - the timeout command is provided by the coreutils package. While it was avaiable in Fedora, it wasn't on the staging machine I deployed it to, running CentOS. I did managed to get it working (without any problems) using the binary from my desktop machine.</div> ]]>
        
    </content>
</entry>

<entry>
    <title>Rails flash upload using active record session store</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2009/12/rails-flash-upload-using-active-record-session-store.html" />
    <id>tag:viseztrance.com,2009://1.30</id>

    <published>2009-12-13T13:56:06Z</published>
    <updated>2009-12-13T14:00:58Z</updated>

    <summary>In one of the projects I had been working on, I needed to upload a file with flash. Unfortunately flash doesn&apos;t pass any session information to the upload request, so it never got passed the authentication filter set up in...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="activerecord" label="active record" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="rubyonrails" label="ruby on rails" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="session" label="session" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[In one of the projects I had been working on, I needed to upload a file with flash. Unfortunately flash doesn't pass any session information to the upload request, so it never got passed the authentication filter set up in the application controller.<br />The obvious solution was to pass the necessary session information along with the requested url as a get param. Rails 2.x+ uses a cookie based session store, which I wasn't too found of, as it meant I had to pass the entire session.<br /><br />So I switched to an active record store to pass only the session id (request.session_options[:id]):<br /><br /><blockquote>rake db:sessions:create<br /></blockquote><br />Then added the following to the environment.rb file:<br /><br /><blockquote style="white-space: nowrap">config.action_controller.session_store = :active_record_store<br /></blockquote><br />And in the controller where the upload took place:<br /><br /><blockquote style="white-space: nowrap">prepend_before_filter :create_session_from_params, :only =&gt; [:my_flash_upload_method]<br /><br />def my_flash_upload_method<br />&nbsp; # save file for the logged in user<br />end<br /><br />private<br /><br />&nbsp; def create_session_from_params<br />&nbsp;&nbsp;&nbsp; session_data = ActiveRecord::SessionStore::Session.find_by_session_id(params[:sid]).data<br />&nbsp;&nbsp;&nbsp; session_data.each{ |k,v| session[k] = v }<br />&nbsp; end<br /></blockquote><br />And that's it. I can now read the session information as if it's a normal request.<br /><br /> ]]>
        
    </content>
</entry>

<entry>
    <title>Mysql connection encoding in php</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2009/10/mysql-connection-encoding-in-php.html" />
    <id>tag:viseztrance.com,2009://1.29</id>

    <published>2009-10-18T17:04:06Z</published>
    <updated>2009-10-18T17:21:40Z</updated>

    <summary>Do you have a php website powered by a mysql database that doesn&apos;t render your utf8 characters properly?Changed the table encoding from the default latin1 to utf8 and it&apos;s still not working?Well, you have to change the mysql connection encoding...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="mysql" label="mysql" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="php" label="php" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="utf8" label="utf8" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[Do you have a php website powered by a mysql database that doesn't render your utf8 characters properly?<br /><br />Changed the table encoding from the default latin1 to utf8 and it's still not working?<br /><br />Well, you have to change the mysql connection encoding as well:<br /><br /><blockquote>mysql_query("SET NAMES 'utf8'");<br /></blockquote><br />Run this after connecting to the database. ]]>
        
    </content>
</entry>

<entry>
    <title>A defensive approach on integrating api based widgets</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2009/09/a-defensive-approach-on-integrating-api-based-widgets.html" />
    <id>tag:viseztrance.com,2009://1.28</id>

    <published>2009-09-20T23:29:23Z</published>
    <updated>2009-09-20T23:51:15Z</updated>

    <summary>It&apos;s pretty common these days to integrate widgets from several sources and aggregate them to your website.In an ideal world you would simply parse your api response(an xml for example) and display it on your page.While this doesn&apos;t include javascript...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="api" label="api" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="defensiveprogramming" label="defensive programming" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[It's pretty common these days to integrate widgets from several sources and aggregate them to your website.<br />In an ideal world you would simply parse your api response(an xml for example) and display it on your page.<br /><br />While this doesn't include javascript widgets, these are some thoughts I gathered which may prove useful:<br /><br /><b>Always cache</b><br />Cache the api response or the page fragment being rendered, otherwise your website will load slowly. It's not only about speed, but most api providers request this. So while you may get away without caching for a while, you may find your self banned after a traffic spike.<br /><br /><b>Make sure you write the code efficient</b><br />While I consider this a newbies tip, I wouldn't had mentioned it if I had not encounterd it.<br /><br />Never do this:<br /><br /><blockquote>foreach(getFeedContent() as $entry) {<br />&nbsp; // display code<br />}<br /></blockquote><br />At each iteration the server would try to fetch and parse the feed.<br />So at a basic level you should have something in the lines of:<br /><br /><blockquote>$entries = getFeedContent();<br />foreach($entries as $entry) {<br />&nbsp; // display code<br />}<br /></blockquote><br /><b>Don't assume that you'll get a valid response</b><br />Sometimes your provider may send you an invalid/blank response. If this is happening often make sure you check its integrity before caching it. This way you won't be stuck with an empty section in your page for the period the page has been cached. Additionally make sure this check is done inside your actual code as well so that you don't display the affected section or at least have it degrade to a nice custom error message.<br /><br /><b>Protect your layout</b><br />If you have images inside your response and intend to use them, scale them to a predefined maximum size and store them on your server. If they always have fixed proportions make sure that they actually stay fixed by adding the width and height attributes. This will also keep the page elements size constant, avoiding the erratic text rearrangement while the page loads. <br /><br />If your widgets are user driven - be it latest comments or what your cat twitted it's always a good idea to hide long words. <br />So when someone writes Hellooooooo (and multiply that "o" ten fold), simply use: "overflow: hidden" on your text container. To add a touch of finesse because everyone loves IE, use "overflow: ellipsis" in it's conditional stylesheet.<br /><br /><b>Escape outputted text</b><br />From a security standpoint it's good to escape everything you output on the page (where possible).<br />From a w3c compliance standpoint your code may not always validate. For example: http://website.org/?param=x&amp;param2=y; &amp; should be escaped into &amp;amp; Or you may have something more serious such as an unclosed tag, yet it's very unlikely.<br /><br />Hopefully this advice will leave your widgets to a boring yet stable experience.<br /> ]]>
        
    </content>
</entry>

<entry>
    <title>Simple gnome process completion monitoring</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2009/08/simple-gnome-process-completion-monitoring.html" />
    <id>tag:viseztrance.com,2009://1.27</id>

    <published>2009-08-18T00:53:07Z</published>
    <updated>2009-08-18T01:06:59Z</updated>

    <summary>Sometimes I run a command on my machine which may take quite some time until completion. I used to check out its status in the terminal I launched it from periodically. Yet there&apos;s an easier way by queueing a message...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="gnome" label="gnome" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="linux" label="linux" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[Sometimes I run a command on my machine which may take quite some time until completion. I used to check out its status in the terminal I launched it from periodically. Yet there's an easier way by queueing a message via notify-send or something more obtrusive with zenity.<br /><br /><blockquote>sleep 5 &amp;&amp; notify-send "Finished task"<br /></blockquote> <br /><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="notify-send.png" src="http://viseztrance.com/notify-send.png" class="mt-image-none" style="" height="117" width="489" /></span><br /><div><br /><blockquote>sleep 15 &amp;&amp; zenity --info --text="Finished long task"<br /></blockquote><br /><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="zenity.png" src="http://viseztrance.com/zenity.png" class="mt-image-none" style="" height="199" width="281" /></span><br /><br />You may take it literally as well, but sleep is obviously my time consuming task.<br /></div>]]>
        
    </content>
</entry>

<entry>
    <title>Creating a static website with XSLT</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2009/07/creating-a-static-website-with-xslt.html" />
    <id>tag:viseztrance.com,2009://1.26</id>

    <published>2009-07-25T17:51:07Z</published>
    <updated>2009-07-25T18:11:35Z</updated>

    <summary>A static website usually has a common layout and unique content across pages. Changing the layout means changing every page - and it does happen, perhaps you have to add a javascript tracking code or correct a minor typo -...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="xml" label="xml" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="xsl" label="xsl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="xslt" label="xslt" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[A static website usually has a common layout and unique content across
pages. Changing the layout means changing every page - and it does
happen, perhaps you have to add a javascript tracking code or correct a
minor typo - a daunting task for something so trivial. It's really no
wonder that most developers use SSI or php includes to ease this task.<br />I'm
going to show you an alternate way of separating your content from the
actual layout without using any server side code, by using XSLT.<br />Before venturing any further, here is what you should know:<br /><br />Pros:<br />-
No server side coding. Just copy the code on any server and it will
work. Your server will still have to display the proper index file
though (index.xml).<br />- It's fast. Especially if you're running a server that handles static files very fast such as lighttpd or nginx<br /><br />Cons:<br />-
SEO impaired. It's xml so it's easier to parse, yet it will probably
rank lower because the XSL code may not be properly parsed by all
search engines<br />- limited to browsers that support XSLT. Unless you
are concerned about Links or Konqueror this is a non issue. Major
browsers that support it include: Firefox, IE6+, Safari, Chrome, Opera<br /><br />If you're still with me let's begin.<br /><br />Create an xml file named index.xml. Paste the following code:<br /><br /><blockquote>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />&lt;?xml-stylesheet type="text/xsl" href="layout.xsl"?&gt;<br /><br />&lt;page&gt;<br />&nbsp; &lt;content&gt;<br />&nbsp; &lt;p&gt;<br />&nbsp;&nbsp;&nbsp; Welcome.&lt;br /&gt;<br />&nbsp;&nbsp;&nbsp; This is the default home page.<br />&nbsp; &lt;/p&gt;<br />&nbsp; &lt;/content&gt;<br />&lt;/page&gt;<br /></blockquote><br />The
content tag represents the unique code that it will change from page to
page while the actual layout will be handled by the xsl file defined on
the second row.<br /><br />Create a file named layout.xsl and paste the following code:<br /><br /><blockquote>&lt;?xml version="1.0"?&gt;<br /><br />&lt;xsl:stylesheet version="1.0" <br />&nbsp; xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;<br />&nbsp;
&lt;xsl:output method="html"
<br />&nbsp;&nbsp;&nbsp; doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<br />&nbsp;&nbsp;&nbsp; doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" /&gt;<br /><br />&nbsp; &lt;xsl:template match="/"&gt;<br />&nbsp;&nbsp;&nbsp; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;<br />&nbsp;&nbsp;&nbsp; &lt;head&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;meta http-equiv="Content-type" content="text/html; charset=utf-8" /&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/head&gt;<br />&nbsp;&nbsp;&nbsp; &lt;body&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;div id="container"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;div id="header"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;h1&gt;My Website&lt;/h1&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ul class="navigation"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;li&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;a href="index.xml"&gt;Home&lt;/a&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/li&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;li&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;a href="about.xml"&gt;About&lt;/a&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/li&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;li&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;a href="contact.xml"&gt;Contact&lt;/a&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/li&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/ul&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/div&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;div id="content"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:copy-of select="page/content" /&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/div&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;div id="footer"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;p&gt;Lorem ipsum dolor sit. &amp;#169; 2009&lt;/p&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/div&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/div&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/body&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/html&gt;<br />&nbsp; &lt;/xsl:template&gt;<br /><br />&lt;/xsl:stylesheet&gt;<br /></blockquote><br />Look
over the xsl output statement. It's set to html in order for the
browsers to render the xml file as an html; additionaly we set a
doctype. This is particulary important for Internet Explorer. Omitting
the doctype will trigger quirks mode.<br />Inside the content div we get
the actual page content. You probably noticed the use of the "copy-of"
element. The difference between it and "value-of" is that it copies the
entire node, preserving the html tags inside, unlike the latter.<br /><br />Let's style the page.<br /><br /><blockquote>* {<br />&nbsp; margin: 0;<br />&nbsp; padding: 0;<br />}<br /><br />a {<br />&nbsp; color: #00f;<br />}<br /><br />ul li {<br />&nbsp; list-style-type: none;<br />}<br /><br />body {<br />&nbsp; background-color: #fff;<br />&nbsp; font-family: arial, sans-serif;<br />&nbsp; line-height: 18px;<br />&nbsp; font-size: 12px;<br />&nbsp; color: #333;<br />}<br /><br />#container {<br />&nbsp; width: 940px;<br />&nbsp; margin: 20px auto;<br />&nbsp; padding: 15px 10px;<br />&nbsp; border: 1px solid #ccc;<br />&nbsp; background-color: #eee;<br />}<br /><br />&nbsp; #container #header h1 {<br />&nbsp;&nbsp;&nbsp; font-size: 50px;<br />&nbsp;&nbsp;&nbsp; margin: 10px 0 30px 0;<br />&nbsp; }<br />&nbsp; #container #header ul.navigation li {<br />&nbsp;&nbsp;&nbsp; display: inline;<br />&nbsp; }<br />&nbsp;&nbsp;&nbsp; #container #header ul.navigation li a {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; display: block;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float: left;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; padding: 10px;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; border: 1px solid #000;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; margin-right: 10px;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text-decoration: none;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color: #000;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; #container #header ul.navigation li a:hover,<br />&nbsp;&nbsp;&nbsp; #container #header ul.navigation li a.selected {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; background-color: #fff;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp; &nbsp;<br />&nbsp; #container #content {<br />&nbsp;&nbsp;&nbsp; clear: left;<br />&nbsp;&nbsp;&nbsp; padding: 30px 0;<br />&nbsp; }<br />&nbsp; <br />&nbsp; #container #footer {<br />&nbsp;&nbsp;&nbsp; font-style: oblique;<br />&nbsp; }<br /></blockquote>&nbsp; <br />As
it turns out static layouts are not that static. The page title should
change across pages, and the navigation menu should highlight the
current page item.<br /><br />Inside our index.xml file, we'll add these
properties. I'm assigning them as attributes, but these could had very
well been tags.<br /><br /><blockquote>&lt;page title="Welcome" selected-navigation-item="home"&gt;<br /></blockquote><br />Next, back in our xsl file, inside the head tags add the title:<br /><br /><blockquote>&lt;title&gt;&lt;xsl:value-of select="page/@title"/&gt;&lt;/title&gt;<br /></blockquote><br />For the menu we'll have to add the selected class for current navigation item:<br /><br /><blockquote>&lt;ul class="navigation"&gt;<br />&nbsp; &lt;li&gt;<br />&nbsp;&nbsp;&nbsp; &lt;a href="index.xml"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:if test="page/@selected-navigation-item = 'home'"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:attribute name="class"&gt;selected&lt;/xsl:attribute&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsl:if&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Home<br />&nbsp;&nbsp;&nbsp; &lt;/a&gt;<br />&nbsp; &lt;/li&gt;<br />&nbsp; &lt;li&gt;<br />&nbsp;&nbsp;&nbsp; &lt;a href="about.xml"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:if test="page/@selected-navigation-item = 'about'"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:attribute name="class"&gt;selected&lt;/xsl:attribute&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsl:if&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; About<br />&nbsp;&nbsp;&nbsp; &lt;/a&gt;<br />&nbsp; &lt;/li&gt;<br />&nbsp; &lt;li&gt;<br />&nbsp;&nbsp;&nbsp; &lt;a href="contact.xml"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:if test="page/@selected-navigation-item = 'contact'"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:attribute name="class"&gt;selected&lt;/xsl:attribute&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsl:if&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Contact<br />&nbsp;&nbsp;&nbsp; &lt;/a&gt;<br />&nbsp; &lt;/li&gt;<br />&lt;/ul&gt;<br /></blockquote><br />Create the about.xml and contact.xml files by using the index.xml file. <br /><br />This wraps it up.<br /><br />- <a href="http://viseztrance.com/code/xsl/index.xml">The final result</a><br />- <a href="http://viseztrance.com/code/xsl/xsl.zip">Download files</a><br /><br />While
this approach does have it's fair share of downsides I think it's an
interesting way of code separation that may be worth taking a closer
look. <br />]]>
        
    </content>
</entry>

<entry>
    <title>Alternate favicon with a non IE comment tag</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2009/07/alternate-favicon-with-a-non-ie-comment-tag.html" />
    <id>tag:viseztrance.com,2009://1.25</id>

    <published>2009-07-14T23:23:27Z</published>
    <updated>2009-07-14T23:27:58Z</updated>

    <summary><![CDATA[Quite often I look at the html source of some of the websites I visit. Last night I found this interesting snippet while browsing Deviantart:&lt;link href="http://st.deviantart.net/icons/favicon.ico" rel="icon"/&gt;&lt;![if ! IE]&gt;&lt;link href="http://i.deviantart.net/icons/favicon.png" rel="shortcut icon"/&gt;&lt;![endif]&gt;A brilliant use of the non IE comment tag,...]]></summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="favicon" label="favicon" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="html" label="html" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[Quite often I look at the html source of some of the websites I visit. Last night I found this interesting snippet while browsing <a href="http://www.deviantart.com/">Deviantart</a>:<br /><br /><blockquote>&lt;link href="http://st.deviantart.net/icons/favicon.ico" rel="icon"/&gt;<br />&lt;![if ! IE]&gt;<br />&lt;link href="http://i.deviantart.net/icons/favicon.png" rel="shortcut icon"/&gt;<br />&lt;![endif]&gt;<br /></blockquote><br />A brilliant use of the non IE comment tag, forcing browsers that support it to use an alternate higher quality png image while degrading gracefully to a generic ico file. ]]>
        
    </content>
</entry>

<entry>
    <title>Returning an nginx status code</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2009/04/returning-an-nginx-status-code.html" />
    <id>tag:viseztrance.com,2009://1.15</id>

    <published>2009-04-28T23:11:54Z</published>
    <updated>2009-04-28T23:21:57Z</updated>

    <summary>I really grew tired of having an old rss feed hit 404s on my website. From what I&apos;ve read the best way to retire it is to respond with a 410 message, and the program that makes all those requests...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="nginx" label="nginx" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[I really grew tired of having an old rss feed hit 404s on my website. From what I've read the best way to retire it is to respond with a 410 message, and the program that makes all those requests will stop, in theory any way.<br />I've added the following lines in my nginx conf:<br /><br /><blockquote>location ~ /&nbsp; {<br />&nbsp; if ($uri ~ "/my/old/url") {<br />&nbsp;&nbsp;&nbsp; return 410;<br />&nbsp; }<br />&nbsp; ..<br />}<br /></blockquote><br />To make it prettier, I also added:<br /><blockquote>error_page 410 /410.html<br /></blockquote>The syntax is a bit odd though, because the 410 ("<i>It's gone</i>") is not an http error code. <br />You can add additional codes such as 502 (bad gateway) or 503 (service not available) and style them to your hearts content. ]]>
        
    </content>
</entry>

<entry>
    <title>Divide et impera - using IDs to define code sections</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2009/04/divide-et-impera---using-ids-to-define-code-sections.html" />
    <id>tag:viseztrance.com,2009://1.8</id>

    <published>2009-04-06T21:13:37Z</published>
    <updated>2009-04-06T21:32:31Z</updated>

    <summary>This happened to everyone at least once when working on a large application - a minor change to a stylesheet can break the layout on one or more pages. What&apos;s worse is that this usually goes unnoticed until the website...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="css" label="css" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="html" label="html" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[This happened to everyone at least once when working on a large application - a minor change to a stylesheet can break the layout on one or more pages. What's worse is that this usually goes unnoticed until the website hits production. <br />I think this is happening mostly because the bug affects only a seldom accessed page or a specific browser, the page is different from what the frontend developer envisioned (zero length text, variable picture width, etc) or a mixture of these issues.<br />You can easily avoid this situation by using inline styles as they affect just the current page, but then again it really defeats the advantage of an external stylesheet. Some CSS frameworks can ease the use of styling markup, but what would be really nice is not to touch the html at all if possible.<br />Since CSS doesn't have namespaces you can use an id as a point of reference.<br /><br />For example in order to target the fieldsets and legend tags only on the contact page, you have something like this:<br /><br /><blockquote>&nbsp; #contact-page-wrapper fieldset {<br />&nbsp; ..<br />&nbsp; }<br />&nbsp; <br />&nbsp; #contact-page-wrapper fieldset legend {<br />&nbsp; ..<br />&nbsp; }<br /></blockquote>&nbsp; <br />Every class name is similar to a global variable. When you have thousands and thousands of lines of css, name clashes occur but cascaded selectors with a parent id can easily prevent this.<br />Placing an id on the container of the page (ex. the body tag) is a reliable method to target a specific page. For extra points, move that code into its own stylesheet and have a function dynamically load it.<br /><br />While I'm sure you dear reader are thinking <i>"I'm master over my own code"</i>, it's always nice to allow others add a line or two, while you're enjoying your much earned vacation without worrying about them breaking anything :-) <br />]]>
        
    </content>
</entry>

<entry>
    <title>Fixing the png color mismatch on mac os x</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2009/02/fixing-the-png-color-mismatch-on-mac-os-x.html" />
    <id>tag:viseztrance.com,2009://1.7</id>

    <published>2009-02-06T09:11:26Z</published>
    <updated>2009-02-06T09:25:22Z</updated>

    <summary>When it comes down to work, most of the times I get my graphics from a talented designer that worked on a mac. If the files happen to be in the PNG image format things get slightly confusing. Mac OS...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="macosx" label="mac os x" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="png" label="png" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[When it comes down to work, most of the times I get my graphics from a talented designer that worked on a mac. If the files happen to be in the PNG image format things get slightly confusing. Mac OS X will render the images using the color profile they got stored, actually png gamma correction would be more exact. This is not immediately apparent because at a glance the files may look identical but using the pngs over a CSS background color often reveals an unpleasant sight on the mac, especially on Safari.<br />To prevent such a color mismatch either use a different image format or strip the png gamma correction. In the case of the latter, <a href="http://pmt.sourceforge.net/pngcrush/">pngcrush</a> does a pretty good job.<br />I was pleasantly surprised that I could install it with ease on <a href="http://fedoraproject.org/">Fedora</a> (<i>"yum install -y pngcrush</i>"). To use it run:<br /><br /><blockquote>pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB &lt;png-file-name&gt; \ &lt;optimized-png-file-name&gt;<br /></blockquote><br />Removing that unnecessary meta data will also save you a few KBs, which is quite useful regardless if you have any problems with pngs or not. ]]>
        
    </content>
</entry>

<entry>
    <title>Nginx rewrite to a different domain</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2009/01/nginx-rewrite-to-a-different-domain.html" />
    <id>tag:viseztrance.com,2009://1.6</id>

    <published>2009-01-25T22:14:15Z</published>
    <updated>2009-01-25T22:27:58Z</updated>

    <summary>A few days ago I&apos;ve received an email from someone regarding my earlier post on Nginx subdomain rewrites with some questions on rewriting to a different domain. For example each request on subdomain.domain1.com to be forwarded as a request to...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="nginx" label="nginx" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[A few days ago I've received an email from someone regarding <a href="http://viseztrance.com/2008/12/dynamic-subdomains-with-nginx.html">my earlier post on Nginx subdomain rewrites</a> with some questions on rewriting to a different domain. For example each request on subdomain.domain1.com to be forwarded as a request to subdomain.domain2.com. <br />The rewrite module wasn't meant for such requests, just having a string starting with "http://" will trigger a redirection. The problem can be solved however, by proxying the request to the appropriate domain:<br /><br /><blockquote>location / {<br />&nbsp; if ($host ~* "^(.+)\.domain1\.com$") {<br />&nbsp;&nbsp;&nbsp; proxy_pass http://$1.domain2.com;<br />&nbsp; }<br />&nbsp; proxy_redirect off;<br />&nbsp; # Some other code..<br />}<br /></blockquote>]]>
        
    </content>
</entry>

<entry>
    <title>Avoiding Linux wireless problems</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2009/01/avoiding-linux-wireless-problems.html" />
    <id>tag:viseztrance.com,2009://1.5</id>

    <published>2009-01-06T22:31:52Z</published>
    <updated>2009-01-06T22:51:37Z</updated>

    <summary>If you happen to shop for a notebook or just a plain wireless card to use Linux with, you should really take in mind that connecting to an access point doesn&apos;t really mean that your device is working properly.You may...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="linux" label="linux" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="wireless" label="wireless" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[If you happen to shop for a notebook or just a plain wireless card to use Linux with, you should really take in mind that connecting to an access point doesn't really mean that your device is working properly.<br /><br />You may have been blessed with at least one of the following issues:<br /><br /><ul><li><b>Crippling slow transfer rate</b>. Forget about copying a 700MB file, or stream a movie to your PS3. It will be painful.</li></ul><br /><ul><li><b>Latency spikes</b>. It's likely to affect you only if you're playing a fast paced
multiplayer game. The problem is that once in a while packages arrive
too slow, or get lost on their way, even with full signal strength.
Usually setting a higher fragmentation rate will alleviate this
problem, yet this is not the case.</li></ul><br /><ul><li><b>Failure to use encryption</b>. I think this is what everyone gets  sore about - can't use WEP or/and WPA encryption.</li></ul><br /><ul><li><b>I</b><b>nternet sharing</b>. People can't connect directly to your wireless computer. Take in mind
that your hardware may simply not have this feature at all.</li></ul><br />Having this said, I strongly believe that the best deal is to buy a
notebook with quality wireless Linux drivers. Over optimistic hardware
reviews are simply misleading and should really be read with a grain of
salt - I'm actually going to assume that you're googleing the
information.]]>
        
    </content>
</entry>

<entry>
    <title>Dynamic subdomains with Nginx</title>
    <link rel="alternate" type="text/html" href="http://viseztrance.com/2008/12/dynamic-subdomains-with-nginx.html" />
    <id>tag:viseztrance.com,2008://1.4</id>

    <published>2008-12-13T15:32:52Z</published>
    <updated>2008-12-13T22:25:06Z</updated>

    <summary>I had to implement dynamic subdomains for a large Ruby On Rails application we had been developing. While the most straightforward way of doing this is to code the functionality within your application, I decided on trying a different approach...</summary>
    <author>
        <name>Daniel</name>
        <uri>http://viseztrance.com</uri>
    </author>
    
    <category term="nginx" label="nginx" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="subdomains" label="subdomains" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://viseztrance.com/">
        <![CDATA[I had to implement dynamic subdomains for a large Ruby On Rails application we had been developing. While the <a href="http://railscasts.com/episodes/123-subdomains">most straightforward way</a> of doing this is to code the functionality within your application, I decided on trying a different approach by doing everything server side.<br />For example, each time I access <b>http://daniel.myapp.com</b>, this would send a request to the rails instance that may look like <b>http://myapp.com/profiles/daniel</b>. On the other hand other static resources such as stylesheets and images, must still point to their original locations.<br />On Nginx my code resembled this:<br /><br /><blockquote>location / {<br />&nbsp; set $subdomain "";<br />&nbsp; set $subdomain_root "";<br />&nbsp; set $doit "";<br />&nbsp; if ($host ~* "^(.+)\.myapp\.com$") {<br />&nbsp;&nbsp;&nbsp; set $subdomain $1;<br />&nbsp;&nbsp;&nbsp; set $subdomain_root "/profiles/$subdomain";<br />&nbsp;&nbsp;&nbsp; set $doit TR;<br />&nbsp; }<br />&nbsp; if (!-f $request_filename) {<br />&nbsp;&nbsp;&nbsp; set $doit "${doit}UE";<br />&nbsp; }<br />&nbsp; if ($doit = TRUE) {<br />&nbsp;&nbsp;&nbsp; rewrite ^(.*)$ $subdomain_root$1;<br />&nbsp;&nbsp;&nbsp; break;<br />&nbsp; }<br />&nbsp; # root ..<br />&nbsp; # proxy_set_header ..<br />&nbsp; # etc..<br />}<br /></blockquote><br />The $doit thing is just a hack meant to allow multiple if conditions on Nginx.<br /> ]]>
        
    </content>
</entry>

</feed>
