May 24, 2012

Symfony - Disable sf_web_debug in your web page

In our development environment, there some way we need to programmaticall disable the Web Debug. In some instance like we are retrieving text data on out controller.
  public function executeGetText(sfWebRequest $request)
  {
     sfConfig::set('sf_web_debug', false); // Here to disable web debug only and hase html response
     // Some code here.. Good luck =)
  }
You can also do this one, this will return you the plain text.
  public function executeGetText(sfWebRequest $request)
  {
     $this->getResponse()->setHttpHeader('Content-type', 'text/plain', true);
     // Some code here.. Good luck =)
  }

May 14, 2012

Struts - Calculating on struts tags

We need to initilaize variable.
<s:set var="total" value="%{0.00}"/>
Calculation
<s:set var="total" value="%{amount + #attr.total}" />

May 11, 2012

Swapping Algorithm without extra variable.

One way to this is by using the Exclusive OR (XOR)

Sample Code

$x = $x ^ $y;
$y = $y ^ $x;
$x = $x ^ $y;

Explanation

Lets try to use X=5 and Y=15; Now let convert the value of X and Y to each Binary data. Here's is, X=0101 and Y=1111

  • Lets see first statement.
    $x = $x ^ $y; Binary: 1010 ^ 1111 ------ 0101 ( X now has value of 10)
  • Second Statement
  • Last statement