“In any situation, the best thing you can do is the right thing; the next best thing you can do is the wrong thing; the worst thing you can do is nothing.”
– Theodore Roosevelt

12
Feb

I wasn’t playing at work :D , just found this picture of a lego star wars trooper creeping out under the ’s’ key.

Lego star wars trooper

Posted in me stuff, not about code | by Marvin No Comments »

09
Feb

This was sent to me over IM :D

Posted in me stuff, not about code | by Marvin No Comments »

03
Feb

This product page inspired me to write this post. It was launched around February last year (uh oh time flies!) and the first successful order was made around that time too. By then, there were only about 20 products or less, and really short attributes i.e. volumes in 8, 12 or 16 oz. strength like mild, regular, etc. Last monday, new products came in for addition to the site and they have quite longer attributes. It could have had a liquid width on the attribute and cart buttons but they had a really good design advisers and wanted to follow the design to the pixel.

Initially, this html code composes the product attribute and cart button, notice that <span class="c">Cherry</span> is a one word attribute for scent

<div class="cartbutton" style="background-image: url(images/button-long-add-to-bag.gif);">
  <span class="c">Cherry</span>
  <span class="c">8 oz.</span>
  <span class="c">$5.99</span>
  <span class="d">
    <a class="e" href="cart.php?product=5|33404&amp;as=5">Add to bag</a>
  </span>
  <span class="e">» ITEM: 33404</span>
</div>

And the new ones came with the colors “Casino Red”, “Golden Chestnut” and “Orchid Black” – long attributes, and two others “Copper” and “Spice” – short and manageable, as the column width will fit the entire word.

I was really planning to rewrite the whole attribute and cart button section, but I didn’t had much time. I figured I can make the font smaller and paddings or margins can go smaller than the regular so that two lines would fit in the box if the attribute value is a word longer. But I cannot be in PHP, its not really the way to go. So, if I can add another class that would override existing font-size and parent margin/padding, that would work. Here, I thought, word count doesn’t really need be in the PHP side and since I’m using Smarty, I found in it a variable modifier that can print the number of words in a variable, and that’s it. I can add another class in the column span like words-10 or countwords-3 in my template by the number of words that is present in the variable. Below is the generated code

<div class="cartbutton" style="background-image: url('images/button-long-add-to-bag.gif');">
  <span class="c col-color words-2">Casino Red</span>  	  	  	  	  	  	
  <span class="c col-volume">8 oz.</span>  	  	
  <span class="c">$11.39</span>
  <span class="d">
    <a href="cart.php?product=28|33825&amp;as=14" class="e">Add to bag</a>
  </span>
  <span class="e">&raquo; ITEM: 33825</span>
</div>

CSS rules

/* default rules */
.cartbutton { height: 23px; background: url('/images/button-add-to-bag.gif') no-repeat left center; color: #333; }
.cartbutton span { display: block; text-align: center; float: left; font-weight: bold; font-size: 10px; padding-top: 5px; }
.cartbutton span.c { width: 45px;  }
.cartbutton span.d { width: 80px;}
.cartbutton span.d a { color: #fff; text-decoration: none; }
.cartbutton span.e { margin-left: 10px; width: 100px; }
/* special rule for two word attribute */
span.words-2 { padding-top: 3px; line-height: 98%; font-size: 9px; }

And this is how it is setup in the template.

<div class="cartbutton" style="background-image: url('images/button-long-add-to-bag.gif');">
{if $attr[at].color}
  <span class="c col-color words-{$attr[at].color|count_words}">{$attr[at].color}</span>
{/if}
{if $attr[at].strength}
  <span class="c col-strength words-{$attr[at].strength|count_words}">{$attr[at].strength}</span>
{/if}
{if $attr[at].scent}
  <span class="c col-scent">{$attr[at].scent}</span>
{/if}
{if $attr[at].volume}
  <span class="c col-volume">{$attr[at].volume}</span>
{/if}
<span class="c">
  $ {if !$attr[at].amount} {$results[r].amount} {else} {math equation="x" x=$attr[at].amount format="%.2f"} {/if}
</span>
<span class="d">
  <a href="cart.php?product={$results[r].id}|{if $results[r].sku && !$attr[at].sku}{$results[r].sku}{elseif $attr[at].sku}{$attr[at].sku}{/if}&amp;as={$attr[at].pas_id}" class="e">Add to bag</a>
</span>
<span class="e">&raquo; ITEM: {if $results[r].sku && !$attr[at].sku}{$results[r].sku}{elseif $attr[at].sku}{$attr[at].sku}{/if}</span>
</div>

Those extra class names like col-volume, col-scent and col-strength are only for future use, who knows what other formatting and adjustments on the data and theme will happen. Its really fun working with MVC model. Hope it helps :)

Happy coding!

Posted in job, me stuff, work related | by Marvin 1 Comment »

23
Jan

Free accommodation gift certificate

Posted in me stuff, not about code | by Marvin No Comments »

18
Jan

I noticed this when I uploaded an entire project files from dev server to production server. Using Web Developer plugin for Firefox, I had a clue to compare the Content-Type from the response header and the one I have in <meta> tags in my HTML.

1
2
3
4
5
6
7
8
9
10
11
12
Date: Wed, 25 Nov 2009 01:32:28 GMT
Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.7 with Suhosin-Patch
X-Powered-By: PHP/5.2.4-2ubuntu5.7
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 6572
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
 
200 OK

And it was really it! Though they both have text/html, they had different character set values. Server responses with ISO-8859-1, but the <meta> instructs the browser to use utf-8, as it is declared in the document.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

And so the second load of page occurs, its sort of trying to correct page encoding on the client-side. In the script I was working, I needed to pass some session values to the next page and clear it on page load, but when it reloads the second time, the session value had been emptied.

Hope it helps.

Tags: , , Posted in me stuff, productivity | by Marvin No Comments »