Sunday, January 24, 2010

Unlimited Categories Implementation by Recursively

  1. MySQL Table Definition:
    CREATE TABLE `categories` (
    `id` int(10) unsigned NOT NULL auto_increment,
    `name` varchar(50) NOT NULL,
    `parent_id` int(10) unsigned zerofill NOT NULL,
    `type` int(10) unsigned zerofill NOT NULL default '0',
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;
  2. Implementation for DataObject
    public static function get_all($type = NULL, $parent_id = 0, $depth = 3, $count = 0){
    if($count == $depth) return;
    $condition = is_int($type) ? "AND type=$type" : '';

    $categories = Database::instance()->query("SELECT * FROM categories WHERE parent_id = '$parent_id' $condition")->result_array(FALSE);

    if(count($categories) == 0) return NULL;
    foreach ($categories as &$category) {
    $category['parent_id'] = intval($category['parent_id']);
    $category['type'] = intval($category['type']);
    $subcategories = self::get_all($type, $category['id'], $depth, $count+1);
    if($subcategories) $category['subcategories'] = $subcategories;
    }

    return $categories;
    }
  3. Implementation for Logical UI
    public static function output_options($categories,  $depth = 2, $level = 0, $nest = 0){
    if($nest == $depth || !is_array($categories)) return '';

    $html = '';
    foreach($categories as $category){
    $html .= "<option value=\"{$category['id']}\"";
    if($nest < $level) $html .= ' disabled="disabled"';
    $html .= '>';
    for($i=0,$j=$nest;$i<$j;$i++) $html .= ' ';
    $html .= "{$category['name']}</option>\n";

    if(isset($category['subcategories'])) {
    $html .= self::output_options($category['subcategories'], $depth, $level, $nest+1);
    }
    }
    return $html;
    }
  4. Usage
    $categories = category::get_all(0,0,2); // All Type, Parent Id = 0, MaxDepth = 2
    echo category::output_options($categories, 2);

Saturday, January 23, 2010

Firefox Extensions of Mine

Generated: Sat Jan 23 2010 22:31:39 GMT+0800 (China Standard Time)
User Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)
Build ID: 20100115144158

Enabled Extensions: [23]
Disabled Extensions: [18]
Total Extensions: 41

Installed Themes: [1]
Installed Plugins: (6)
  • Adobe Acrobat
  • Mozilla Default Plug-in
  • Shockwave Flash
  • Silverlight Plug-In
  • Thunder DapCtrl Plugin
  • WPI Detector 1.1

Best Fonts for Web Design

Arial

  • 12px – 16px (text, tips, title)
  • 12px+, Smooth (text, title)

BitStream vera Sans

Calibri

  • 14px+, Smooth (text, title)

Comic Sans MS

  • 12px+, Smooth (text, title)

Consolas (Monospaced)

  • 12px+, Smooth (text)

Courier / Courier New (Monospaced)

  • 11px+ (text, tips, title, code)
  • 12px+, Smooth (text, title)

Ebrima

  • 14px+, Smooth

Georgia

  • 14px+
  • 14px+, Smooth

Helvetica Neue / Helvetica

Lucida Grande / Lucida Sans Unicode / Lucida Sans

Luxi Sans

Monaco (Monospaced)

Segoe UI

  • 14px+, Smooth

Tahoma

  • 11px+ (text, tips)
  • 12px+, Smooth (text, title)

Simple Arabic / Simple Arabic Fixed (Monospaced)

  • 12px+
  • 14px+, Smooth

Verdana

  • 11px+
  • 12px+, Smooth

Last updated @ 2010.1.23

Sunday, January 17, 2010

A simple implementation for alternate output in PHP

This function was original from Kohana’s Text Helper.

/**
* Alternates between two or more strings.
*
* @param string strings to alternate between
* @return string
*/
public static function alternate()
{
static $i;

if (func_num_args() === 0)
{
$i = 0;
return '';
}

$args = func_get_args();
return $args[($i++ % count($args))];
}



Saturday, January 2, 2010

Engineering mode in DELL Laptop

  1. Press and hold Fn+Shift, then input 15324 (The number lock led will turning)
  2. Press Fn+r, it will show up the temporary of modules.
p.s. This is works on my inspiron 1420.

Monday, December 21, 2009

Contact

Email: billy [at] dreammx.com
MSN: billychow [at] live.com
Gtalk: billychou [at] gmail.com
Google Voice: (209) 677-7783
Skype: billychow.dreammx
Google Wave: billychou [at] googlewave.com
If you have PGP/GnuPG, you can use my public key for email.

K.I.S.S

KISS 原则不仅仅适用于计算机领域,也同样适用于任何其它的事物。尤其是对一些比较偏执的人或事物,他(它)们不断追求完美,却不断被完美本身所打败。当这一切接近极限,并超过极限时,便会回归原点,重新开始,往往复复。

也许,你是时候该稍微停下来思考一下了。如果前路已不再长,你还会继续前行吗?或是调个头,选择一条更短,但是更好的路来走?

这是个问题。

Sunday, December 20, 2009

使用 Windows Live Writer + Tor + Provixy 发布 Blogger

之前便有通过 Tor + WLW 更新 Blogger 的想法,但是因为一个 HTTP Header 的问题,一直没有成功,也没有去寻找原因。今天突然心血来潮想起这事,便网上搜索一番,果然是有解决方案的……也真的是佩服自己,有些事情本来一下就可以解决的,却总是为了省那么一点儿力却浪费大把的时间啊!

相关方法请自行 Google 之。