class Loop
{
private $index;
private $elements;
private $numElements;
public function __construct()
{
$this->index = 0;
$this->elements = func_get_args();
$this->numElements = func_num_args();
}
public function __tostring()
{
return (string) $this->get();
}
public function get()
{
if($this->numElements == 0) return null;
$val = $this->elements[$this->index];
if(++$this->index >= $this->numElements)
$this->index = 0;
return $val;
}
public function rand()
{
return $this->elements[array_rand($this->elements)];
}
}
$color = new Loop('white', 'black');
echo "<tr class='$color'>"; // white
echo "<tr class='$color'>"; // black
echo "<tr class='$color'>"; // white
by Yada on January 17, 2011
Wow. Haven’t updated the blog in a while.
by Yada on April 22, 2010
I find Tim Hortons coffee too hot to hold especially while drinking and driving. Yes, I drink coffee and drive. It’s not against the law.
When I make my coffee order at Tim Horton’s drive thru in the morning I would ask for ‘Double Cup’. The optimum brewing temperature of coffee is 90′c which is pretty much close to boiling. This is too hot for me to hold.
I often wondered why Tim Horton’s doesn’t have coffee sleeves. Today I think I figured out why.
IT’S NOT COST EFFECTIVE. It’s better to employ double cup. Take a look at this price chart at a restaurant supplies store.

Look at the price of Coffee sleeves. It’s is $37.99 for a box of 1000s. Take a look at the price of 1000s cups. It around the same price! Therefore, if Tim Hortons have coffee sleeves in the store probably about 25%* of the patrons would use it. Currently, probably about 5% of the patrons would ask for Double Cup. Hence, it’s better to not use sleeves and let the customers ask for Double Cup.
*number is educated guess. When I worked at Starbucks, 95% of patrons use coffee sleeves. 25% is a low end guess.
1. Gmail doesn’t look at ‘period’ in the email.
johnsmith@gmail.com
john.smith@gmail.com
j.o.h.n.smith@gmail.com
Is all the same emails. Email sent to any of the address will be forwarded to the same email account.
This is a neat way to sign up for multiple accounts at some other service that requires unique email. I found that out on my own because I have a period in my email and saw some email coming to me without the period.
2. The second trick, I read on lifehacker is to use the plus sign trick.
Example: You could use
johnsmith+nytimes@gmail.com for nytimes.com
johnsmith+freestuff@gmail.com for freestuff.com
Gmail will automatically remove everything including the plus sign.
by Yada on February 24, 2010
A developer was trying to compute the average of the first 100 records with LIMIT:
SELECT
avg(con_hits) as avg_hits
FROM
content
WHERE
con_type = 1
AND con_posttime < $twelve_hrs_ago
AND con_refresh = 0
ORDER BY
con_posttime DESC
LIMIT 100
Can you spot the subtle bug in the above query?
LIMIT is applied to the resultset, after AVG is calculated. The correct way is to use a subselect and apply the aggregate function:
SELECT avg(con_hits) as avg_hits
FROM (
SELECT con_hits
FROM content
WHERE
con_type = 1
AND con_posttime < $twelve_hrs_ago
AND con_refresh = 0
ORDER BY con_posttime DESC
LIMIT 100
) x;