Wednesday, November 28, 2007

Regular Expression -- In Thai

I used to use Regular Expression since first year of my web programming experience in perl and continually use in other languages (e.g. PHP, JavaScript and Java). It's useful for matching text. I usually got question for its patterns. Many people said it's too difficult to make understand on it. It just a easy pattern to check your string!!

Today, I saw a web that writing about this topic (in Thai) and I thought it's too many useful for any people who're coder/programmer or interesting.

Friday, November 16, 2007

Help me!!

I can not install multi OS on my notebook, They're Windows XP, Windows Vista and Ubuntu.

Now, I'm already installed Windows XP and Window Vista. but I cannot complete Ubuntu Installation because It can not install Grub!!!

How can I???

Tuesday, November 13, 2007

I've got Gutsy Gibbon CD from Canonical

today when I go back home. I found and 3 envelopes sent to me. One of its from canonical!! It Gutsy Gibbon Install CD :)

The Package


Its including with Gutsy Gibbon Desktop i386, amd64 and ubuntu sticker


Red one is Ubuntu 7.10 desktop for i386 computer


And Yellow is Gutsy gibbon for amd64 dektop


Closed up to the cover

Thursday, November 8, 2007

PHP lite-weight themes

Hello! It's too long time that I didnt update this blog. Today I have new custom lib for php programmer. It's lite-weight themes system (for anyone who dont want to use smarty). It may not as good as smarty can do but it's easy for designer, They didnt know any structure. just mark where is for content with "${}".

<?php

/*
write by. mrKrich (Bhanu Thangpulphol)
email: mrkrich@msn.com
*/

class themes{

private $filename = "";
private $rawdata = "";
private $cache = "";
private $cachemd5 = "";
private $mapping = Array();

public function __construct($filename){
$this->setTemplate($filename);
}

public function setTemplate($filename){
$this->filename = $filename;
$this->rawdata = join("", file($filename));
$this->cachemd5 = md5($this->rawdata);
preg_match_all("/\\$\{([^\}]+)\}/Ui", $this->rawdata, $res);
foreach($res[1] as $r){
$this->mapping[$r] = "";
}
}

public function setMap($key, $value){
$this->mapping[$key] = $value;
}

public function clearMap(){
$this->mapping = Array();
}

public function clearCache(){
$this->cache = "";
$this->cachemd5 = "";
}

private function map(){
$res = $this->rawdata;
foreach($this->mapping as $i=>$d){
$res = str_replace("\${" . $i . "}", $d, $res);
}
return $res;
}

private function checkversion(){
$md5 = md5($this->rawdata . print_r($this->mapping, true));
return ($this->cachemd5 == $md5);
}

private function merge(){
if(!$this->checkversion() && $this->cache==""){
$res = $this->map();
$this->cache = $res;
$this->cachemd5 = md5($this->rawdata . print_r($this->mapping, true));
}
return $this->cache;
}

public function __toString(){
return $this->merge();
}


}

?>
you also can download , modify or use anywhere but please reference to me (for the based code) and you (for your changed code).