Monday, June 6, 2011
Javascritpt: Get Your Class Object Name
<script>
function getObjectClass(obj){
if (typeof obj != "object" || obj === null) return false;
else return /(\w+)\(/.exec(obj.constructor.toString())[1];}
function myObj(){
this.shout=function(mywords){
alert(mywords);
}
}
var x=new myObj();
x.shout('good day');
var myClassname=getObjectClass(x);
x.shout('My JS Class Name is '+ myClassname);
x.shout('My Object Constructor:' + x.constructor.toString());
</script>
Thursday, April 21, 2011
外行人吃燕窩,內行人吃白木耳
转载。参考
『外行人吃燕窩,內行人吃白木耳』
通常一些老化現象都是膠質缺乏才會引發。
白木耳是養顏秘方,卻鮮少人知道。
人隨著年齡的增長,皮膚內膠質(膠原蛋白)
會漸漸流失,然後皮膚漸漸鬆弛,失去彈性。
至於如何補充膠質(膠原蛋白),用擦的是沒用的,因為膠原蛋白是大分子,用擦的只能到表皮層增加皮膚保濕度,無法補充到真皮層失去彈性的肌膚。
所以要用吃的補充膠質(膠原蛋白)像是豬腳,雞腳,牛筋,白木耳,燕窩都是富含膠質的食物 ,如果以現在女性在乎身材為前題,白木耳 絕對是補充膠質的最佳食物首選。
白木耳富含的植物膠質絕不輸燕窩,之前是 聽人家說:『有錢人吃燕窩,沒錢人吃白木耳』。
但最近有本雜誌說,辜家二少爺辜仲瑩也是
早上吃一碗,煮爛不加糖的白木耳,保養皮膚。
所以應該改成:『外行人吃燕窩,內行人吃白木耳』。
至於如何煮白木耳:
1.去超市買盒裝 "黃"木耳,(! 千萬不要買純白木耳 ,因為純白木耳煮不爛)。
3.倒掉前兩次泡黃木耳的水,因為有些腥味。
4.然後將黃木耳加水放進果汁機打爛。
5.再將打爛的黃木耳放進鍋裡煮約一個小時。(水加多少自己斟酌)
加蓮子糖水,單加糖水,加蜂蜜,加果糖,或冰糖! ...)
一天吃一碗,照上面方法,用果汁機打爛黃木耳去煮,會發現:
吃起來根本跟外面賣的即食燕窩一模一樣。
所以愛美的人,愛美不假手他人,自己來煮 白木耳養顏吧!
白木耳是一種營養豐富的滋補品,被譽為[菌中之冠],有滋陰補腎,潤肺生津,強心健腦,提神補氣等功能,對陰虛火旺不受 參茸等溫熱滋補的病人是一種良好的補品。
因其含有天然特性膠質,加上它的滋陰作用 ,女性長期服用可以潤膚,並有祛除臉部 黃褐斑、雀斑的功效。
黑木耳味道鮮美,含有豐富的營養素,可與動物性食物相媲美,被譽為[素中之葷]。
黑木耳含鐵量極高,是豬肝的5倍,為天然的 補血佳品,適宜女性常吃,能養血駐顏烏發 、防治缺鐵性貧血。
黑木耳中所含膠質具有極強的吸附作用,可以把殘留在人體消化系統內的雜質吸附集中起來排出體外,可以說是'身體清道夫。
黑木耳對於中老年人有特別的好處,其中含有的磷脂類化合物,可以幫助延緩記憶力減退及減少老年痴呆症的發生﹔豐富的纖維素能促進胃腸蠕動,減少食物中脂肪的吸收,起到防止肥胖和減肥作用,對冠心病、動脈硬化、心腦血管病頗為有益。
從營養上來說,黑木耳更勝一籌,這也契合了最近吃黑色食品的風尚。
但吃黑木耳貴在堅持,最好每天都有一道木耳菜,不論涼拌或者炒食都不錯!
Wednesday, April 6, 2011
Changing HTML Form Element Type with Javascript
With following example, once the select box has been changed to a text box, you can assign any value you like to it(of course,alternative way is to create new Option with your desired value, and set the selectedIndex ).
Here's javascript function:
<form method='post'>
<select name='myselect'>
<option value='1'>Option1</option>
<option value='2'>Option2</option>
</select>
<input type='button' onclick='changeInputType(this.form.myselect, "text");'>
</form>
<script>
function changeInputType(oldObject, oType) {
var newObject = document.createElement('input');
newObject.type = oType;
if(oldObject.size) newObject.size = oldObject.size;
if(oldObject.value) newObject.value = oldObject.value;
if(oldObject.name) newObject.name = oldObject.name;
if(oldObject.id) newObject.id = oldObject.id;
if(oldObject.className) newObject.className = oldObject.className;
oldObject.parentNode.replaceChild(newObject,oldObject);
return newObject;
}
</script>
The javascript was copied from this website
Monday, March 21, 2011
JQuery Dialog Remove Form Elements
JQuery Dialog seems removed the form element out from the original dom structure, thus causing the problem. The solution will be
1) Add an additional DIV or SPAN before your closing FORM tag(give it an ID),
2) Before the form submit, append the Dialog DIV back to the above created DIV or SPAN
Here's the sample code:
<!DOCTYPE html>
<html lang="en">
<?php
if($_POST['username']) echo "<br/> Username is " . $_POST['username'];
if($_POST['outerfield']) echo "<br/> Username is " . $_POST['outerfield'];
?>
<head>
<meta charset="utf-8">
<title>jQuery demo</title>
</head>
<body>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css" type="text/css" media="screen">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
<script>
//google.load("jquery", "1.5.1");
//google.load("jqueryui", "1.8.11");
</script>
<form id="form1" method='post'>
<input type="button" class="button" value="go dialog" onclick="GoDialog()" />
<input type='button' class='button' value='Check Value1' onclick='checkvalue("outerfield");'>
<input type='button' class='button' value='Check Value2' onclick='checkvalue("username");'>
<input type='button' class='button' value='Put It Back' onclick='putitback("username");'>
<br/> OuterField <input type='text' name='outerfield' size='20'>
<div class="dlg" id="msgDlg" style='display:none;'>
<br/>Name: <input type="text" name='username' />
<br/><input type="button" class="button" value="OK" onclick="$('#msgDlg').dialog('close');" />
</div>
<script>
$(function () {
$('#msgDlg').dialog({
autoOpen: false,
modal: false,
width: 450,
height: 300,
draggable: true,
resizable: true
});
});
function GoDialog() {
var msgDlg = $('#msgDlg').dialog('open');
}
</script>
<br/><input type='submit' value='Submit'>
</form>
</body>
</html>
<script>
function checkvalue(fieldname){
if(document.forms[0][fieldname]==undefined){
alert(fieldname+' Undefined detected');
}else{
alert(fieldname+' - Okay');
}
}
</script><
Friday, September 3, 2010
分享: 般若波罗蜜多心经
缘起,小时候大概是初中一二左右,每星期都有两三天会梦见自己半梦半醒之中和灵体有所接触,甚至到来抚摸我的额头,恐怖到极点。
在机缘巧合之下,和般若波罗蜜多心经结下了缘,除了背上了心经,还在房间里贴上了心经。说也奇怪,自从房间里贴上了心经后,那些灵体有关的梦就结束了。
最记得一次的怪遇是有一次我在谁梦中被灵体骚扰,弯起了我的手往自己的喉咙捉去,结果在最紧张的时刻,我心里只念了一句“观自在菩萨”, 整个世界突然什么也没了,我的手也松了下来,心经实在是太不可思议了。如果你有缘看到这篇文章,希望你也赶快的背诵心经,好好的感受心经的胜殊。记得哦,背诵心经会开智慧的哦!
般若波罗蜜多心经
唐三藏法师玄奘译
观自在菩萨 行深般若波罗蜜多时 |
Tuesday, June 15, 2010
青木瓜泡茶 痛風不見了 治療尿酸效果更佳
Monday, June 14, 2010
[Backup for peronal reference]
Process Forking with PHP
Posted March 4th, 2004 in PHP
Unix supports the process of forking which allows a parent process to spawn a subprocess and continue running both processes concurrently. It is possible to do this in PHP using the PHP Process Control Functions. Note that you should never attempt to use these process control forking functions when using a webserver; you shuld only fork applications when using the PHP command line client.
Before you can use the PHP process control functions you must compile the PCNTL extensions into PHP using the --enable-pcntl configure option (ie ./configure --enable-pcntl along with all the other configuration options you would like to compile into the PHP binary). No additional libraries need to be pre-installed. Note that these process control extensions will not work on non-Unix platforms (ie Microsoft Windows).
Basic Forking Example
A very basic and commonly used example for forking a process in PHP is as follows:
$pid = pcntl_fork();
if($pid) {
// parent process runs what is here
print "parent\n";
}
else {
// child process runs what is here
print "child\n";
}
Running this will output the following:
child
parent
Child process is a copy of the parent process
What actually happens when you call the pcntl_fork() function is that a child process is spawned which is exactly the same as the parent process and continues processing from the line below the function call. All variables and objects etc are copied into the child process as-is but these are new copies which belong to the new process. Modifying them in the child process does not affect the values in the parent (or any other forked) process.
The parent process will have a value assigned to $pid whereas the child process will not, hence the if test. Note that in the above example, both processes would continue running whatever code is after the if statement, something which is rarely mentioned in examples of PHP process forking on the web.
To illustrate this, we'll modify the example above slightly to add additional output as follows:
$pid = pcntl_fork();
print "start\n";
if($pid) {
// parent process runs what is here
print "parent\n";
}
else {
// child process runs what is here
print "child\n";
}
print "end\n";
Running this will display the following:
start
child
end
start
parent
end
Making the parent process wait until the child has finished
So ideally you want to let either the child or parent continue processing the rest of the script and make the other process exit after the process is forked. If you exit from the parent process, however, you'll end up with "zombie" processes running which do not belong to any process. Therefore the parent process needs to wait until all the child processes have finished running before exiting itself. You can do this using the pcntl_waitpid() function, which will cause the parent process to wait until the child process has completed. You can then either just let the parent process exit, or do any tidy up code that is required.
An example of doing this is as follows:
$pid = pcntl_fork();
if($pid) {
// this is the parent process
// wait until the child has finished processing then end the script
pcntl_waitpid($pid, $status, WUNTRACED);
exit;
}
// the child process runs its stuff here and then ends
...
The exit call in the parent process ensures that processing stops at that point and the parent does not execute any of the code intended for the child. Another way of doing the same thing without the exit code would be as follows:
$pid = pcntl_fork();
if($pid) {
// this is the parent process
// wait until the child has finished processing then end the script
pcntl_waitpid($pid, $status, WUNTRACED);
}
else {
// the child process runs its stuff here
}
Exit codes from the child process
You could optionally have an exit call at the end of the child part of the if statement.
The $status parameter passed to pcntl_waitpid() stores the return value from the child process. If the child process returns 0 (ie success) then it will also be zero. On my Linux desktop the value returned as $status would be the value returned from the exit call multipled by 256. So if the child process ended with exit(2) my system returned 512 as the $status value. Whether this is the same across all Unix systems I do not know.
Getting the parent process to wait until the child process has completed is useful for then doing something else based on the return value of the child process as shown in the following example:
$pid = pcntl_fork();
if($pid) {
// this is the parent process
// wait until the child has finished processing then end the script
pcntl_waitpid($pid, $status, WUNTRACED);
if($status > 0) {
// an error occurred so do some processing to deal with it
}
}
else {
// the child process runs its stuff here
...
if(...successful condition...) {
exit(0); // this indicates success
}
else {
exit(1); // this indicates failure
}
}
Forking multiple child processes
This final example illustrates how you could fork several children from the parent process with PHP. The loop runs three times and forks a child process for each loop, storing the child pids into an array. After running the stuff for the child process the child then exits. A second loop runs in the parent after the first to ensure all child processes have finished running before resuming its own process.
Note it is very important in this sort of process that the child explicitly exits in its section of the script, otherwise each child will continue running through the first, and then second, loop.
$pids = array();
for($i = 0; $i < 3; $i++) {
$pids[$i] = pcntl_fork();
if(!$pids[$i]) {
// child process
...
exit();
}
}
for($i = 0; $i < 3; $i++) {
pcntl_waitpid($pids[$i], $status, WUNTRACED);
}
// complete parent processing now all children have finished
...
The PHP manual pages for process control functions can be found at www.php.net/manual/en/ref.pcntl.php. There are a number of user contributed notes for each of the functions which should also help with your understanding of process forking in PHP.