2008年7月31日 星期四

一本RAILS的好書

碼上就會:Rails敏捷開發網

看了三本ROR的書,這一本最為津津有味,目前雖然只看了三分之一,跳著章節看,每一章都會很仔細的看,因為每一段,作者都會寫一些有用的例子、重點或相關觀念,整本書的章節排序的很通暢,可以連著看,每一章節也都很獨立,可以跳著看,該整理的資料就列出來,該給範例的地方也不吝嗇,該給觀念的時機也洽到好處,真是一本不錯的書。

原價600,光華商埸買,75折

RUBY雖然強大,但也意味著很多東西要學,不像一般的程式語言,只是學學程式邏輯,學學元件用法就可以了,在這裡,要學的是架構,每個觀念都是架構,學不完的架構。還好,它有一個基本原則,就是MVC--Model View Control,是整個ROR中的最高原則。也是REST的實現者,容易做到。最不方便的地方大概就是它不易架在現有的WEB SERVICE上,不過,我想那不是我的問題,很多人一定已經在決解此一問題了。

2008年7月29日 星期二

最近看的RUBY

最近看RUBY,覺得它是一個不錯的程式語言,如果以前還沒有寫過這些REST、資料結構、軟體工程,不會覺感它有什麼了不起。以現在的眼光來看,它是一個滿了不起的設計,可以很快速的上手,已不是學程式語言的問題,該學的是它整個的FRAMEWORK,很像我在PHP寫出來的那一套,只是以前沒有參考別人的理論,都是自己亂寫,自己訂規格。它真的是一套真正的軟體工程程式。

2008年5月20日 星期二

eddie108 wants to keep up with you on Twitter

To find out more about Twitter, visit the link below:

http://twitter.com/i/4d395159e4951505faeab8967fa4e9d9ae972a73

Thanks,
-The Twitter Team

About Twitter

Twitter is a unique approach to communication and networking based on the simple concept of status. What are you doing? What are your friends doing—right now? With Twitter, you may answer this question over SMS, IM, or the Web and the responses are shared between contacts.

This message was sent by a Twitter user who entered your email address. If you'd prefer not to receive emails when other people invite you to Twitter, click here:
http://twitter.com/i/optout/c32253edc4374910e74f033086add81e32a294f7

2008年2月13日 星期三

URL加解碼

JAVASCRIPT : encodeURIComponent
PHP: rawurldecode

2008年1月30日 星期三

我的SCRIPT有二個主要核心程式

我的SCRIPT有二個主要核心程式
一是AJAX
二是ELEMENTS

AJAX是做一個簡單的FUNCTION,讓我可以讀取資料
它的主要FUNCTION只有二個
getData和getText 同步和非同步
使用方法
var menu1=new awp_tablemaker();
var k1=menu1.getData("&username=eddie","getusername.php");
alert(k1.responseXML);
alert(k1.responseText);

ELEMENTS也是只有二個FUNCTION
getvalue和set 讀取資料和設定資料
使用方法(INCLUDE後)
var e1=new awp_elements();
e1.set("sid","123");
var k1=e1.getvalue("sid");

sida是欄位名稱(name),例如下面六項都可以讀到






後來又加了一項
<span id="span_sid">

awp_ajax.js
if (typeof(chkAjaBrowser)=="undefined"){

function chkAjaBrowser()
{
var a,ua = navigator.userAgent;
this.bw= {
safari : ((a=ua.split('AppleWebKit/')[1])?a.split('(')[0]:0)>=124 ,
konqueror : ((a=ua.split('Konqueror/')[1])?a.split(';')[0]:0)>=3.3 ,
mozes : ((a=ua.split('Gecko/')[1])?a.split(" ")[0]:0) >= 20011128 ,
opera : (!!window.opera) && ((typeof XMLHttpRequest)=='function') ,
msie : (!!window.ActiveXObject)?(!!awp_ajax.createHttpRequest):false
}
return (this.bw.safari||this.bw.konqueror||this.bw.mozes||this.bw.opera||this.bw.msie)
}

}

if (typeof(awp_ajax)=="undefined"){
awp_ajax=function(){
this.createHttpRequest=function(){
if(window.XMLHttpRequest){
return new XMLHttpRequest() ;
} else if(window.ActiveXObject){
try {
return new ActiveXObject("Msxml2.XMLHTTP") ;
} catch (e) {
try {
return new ActiveXObject("Microsoft.XMLHTTP") ;
} catch (e2) {
return null ;
}
}
} else {
return null ;
}
}

this.sendRequest=function(callback,data,method,url,async,sload,user,password){

var oj = this.createHttpRequest();
if( oj == null ) return null;
var sload = (!!this.sendRequest.arguments[5])?sload:false;
if(sload || method.toUpperCase() == 'GET')url += "?";
if(sload)url=url+"t="+(new Date()).getTime();

var bwoj = new chkAjaBrowser();
var opera = bwoj.bw.opera;
var safari = bwoj.bw.safari;
var konqueror = bwoj.bw.konqueror;
var mozes = bwoj.bw.mozes ;
if(typeof callback=='object'){
var callback_onload = callback.onload;
var callback_onbeforsetheader = callback.onbeforsetheader;
} else {
var callback_onload = callback;
var callback_onbeforsetheader = null;
}
if(opera || safari || mozes){
oj.onload = function () { callback_onload(oj); }
} else {

oj.onreadystatechange =function ()
{
if ( oj.readyState == 4 ){
callback_onload(oj);
}
}
}
data = this.uriEncode(data,url);
if(method.toUpperCase() == 'GET') {
url += data;
}
oj.open(method,url,async,user,password);
if(!!callback_onbeforsetheader)callback_onbeforsetheader(oj);
this.setEncHeader(oj);
oj.send(data);
return oj
}

this.setEncHeader=function(oj){

var contentTypeUrlenc = 'application/x-www-form-urlencoded; charset=UTF-8';
if(!window.opera){
oj.setRequestHeader('Content-Type',contentTypeUrlenc);
} else {
if((typeof oj.setRequestHeader) == 'function')
oj.setRequestHeader('Content-Type',contentTypeUrlenc);
}
return oj
}
this.uriEncode=function(data,url){
var encdata =(url.indexOf('?')==-1)?'?dmy':'';
if(typeof data=='object'){
for(var i in data)
encdata+='&'+encodeURIComponent(i)+'='+encodeURIComponent(data[i]);
} else if(typeof data=='string'){
if(data=="")return "";
var encdata = '';
var datas = data.split('&');
for(i=1;i {
var dataq = datas[i].split('=');
encdata += '&'+encodeURIComponent(dataq[0])+'='+encodeURIComponent(dataq[1]);
}
}
return encdata;
}
this.getText=function(){
if (arguments.length >= 3){
var temp_argu="";
for (var tempi=3;tempi < arguments.length; tempi++){
temp_argu=temp_argu + ",'" + arguments[tempi] +"'" ;
}
var temp_func1=arguments[2] + "(arguments[0]" + temp_argu + ");";

var temp_func2=new Function(temp_func1);
this.sendRequest(temp_func2,arguments[0],'POST',arguments[1],true,true);
}
}
this.getData=function(){
if (arguments.length == 2){
var temp_func2=new Function("return false;");
return this.sendRequest(temp_func2,arguments[0],'POST',arguments[1],false,true);
}else{
alert("null");
return null;
}
}
}//awp_ajax


}//typeof


awp_elements.js
if (typeof(awp_elements)=="undefined"){
awp_elements=function(){
this.noexist=1;
this.sourcedocument=document;
this.sp=", ";
this.getFromXML=function(theXML)
{
if (theXML.hasChildNodes())
{
var tempt2=theXML.childNodes;
for (var tempi2=0;tempi2 < tempt2.length;tempi2++)
{
if (tempt2[tempi2].nodeType==1)
{
tempt1=tempt2[tempi2].childNodes;
for (var tempi=0;tempi < tempt1.length;tempi++)
{
if (tempt1[tempi].nodeType==1)
{
if (tempt1[tempi].getAttribute("addition")!="yes")
{
var tempvalue=(tempt1[tempi].hasChildNodes()) ? tempt1[tempi].firstChild.nodeValue :"";
this.set(tempt1[tempi].nodeName,tempvalue);
}
}
}
}
}
}
}
this.putinXML=function(theXML)
{
if (theXML.hasChildNodes())
{
var tempt2=theXML.childNodes;
for (var tempi2=0;tempi2 < tempt2.length;tempi2++)
{
if (tempt2[tempi2].nodeType==1)
{
tempt1=tempt2[tempi2].childNodes;
for (var tempi=0;tempi < tempt1.length;tempi++)
{
if (tempt1[tempi].nodeType==1)
{
if (tempt1[tempi].getAttribute("addition")!="yes")
{
tempt1[tempi].firstChild.nodeValue=this.getvalue(tempt1[tempi].nodeName);
}
}
}
}
}
}
}
this.setvalue=function(fname,fvalue){
return this.set(fname,fvalue);
}
this.set=function(fname,fvalue){

//不是input標簽的欄位要顯示前面要加span_
//此段程式會先做一次
//但是欄位如果要儲存會抓不到值,需增加一個隱藏欄位
var temp_k0=document.getElementById("span_"+fname);
if (temp_k0!=null) {temp_k0.innerHTML=fvalue;}

var temp_k1=this.elements(fname);
if (temp_k1==null){return false;}

if (fvalue==null){fvalue="";}
for (f_i=0;f_i < temp_k1.length; f_i++)
{

var tempa1=temp_k1[f_i].getAttribute("beforeset");
if (tempa1!=null && tempa1!="")
{
tempa1=tempa1.replace(/\{fname}/g,fname);
try{
var tempf1= new Function(tempa1);
tempf1();
}catch(e){alert(fname + " function error:\n" + tempa1);}
}
//input type
if (temp_k1[f_i].type=='text'){this.input_text(temp_k1[f_i],fvalue);}
else if (temp_k1[f_i].type=='radio'){this.input_radio(temp_k1[f_i],fvalue);}
else if (temp_k1[f_i].type=='checkbox'){this.input_checkbox(temp_k1[f_i],fvalue);}
else if (temp_k1[f_i].type=='hidden'){this.input_hidden(temp_k1[f_i],fvalue);}
else if (temp_k1[f_i].type=='password'){this.input_password(temp_k1[f_i],fvalue);}
else if (temp_k1[f_i].type=='select-one'){this.selectone(temp_k1[f_i],fvalue);}
else if (temp_k1[f_i].type=='textarea'){this.textarea(temp_k1[f_i],fvalue);}

var tempa1=temp_k1[f_i].getAttribute("afterset");
if (tempa1!=null && tempa1!="")
{
tempa1=tempa1.replace(/\{fname}/g,fname);
try{
var tempf1= new Function(tempa1);
tempf1();
}catch(e){alert(fname + " function error:\n" + tempa1);}
}
}

}
this.input_text=function(felement,fvalue){
felement.setAttribute("value",fvalue);
felement.value=fvalue;
}
this.input_password=function(felement,fvalue){
this.input_text(felement,fvalue);
}
this.input_hidden=function(felement,fvalue){
this.input_text(felement,fvalue);
}
this.textarea=function(felement,fvalue){
//felement.innerHTML=fvalue;
this.input_text(felement,fvalue);
}
this.selectone=function(felement,fvalue){
var temp_t4=(arguments.length > 2) ? arguments[2]:this.sp;
var fvalue2=fvalue;
fvalue2=fvalue2 + temp_t4;
var temp_k3=felement.options;
for (var f_j=0;f_j < temp_k3.length; f_j++){
temp_t3=temp_k3[f_j].value;
if (temp_t3==""){temp_t3=temp_k3[f_j].text;}
temp_t3=temp_t3 + temp_t4;
if (fvalue2.indexOf(temp_t3,0) > -1){
temp_k3[f_j].setAttribute("selected","true");
temp_k3[f_j].selected=true;
}else{
temp_k3[f_j].selected=false;
}
}
}
this.input_radio=function(felement,fvalue){
var fvalue2=fvalue;
var temp_k3=felement.value;
if (fvalue2==temp_k3){
felement.setAttribute("checked","true");
felement.checked=true;
}else{
felement.checked=false;
}
}
this.input_checkbox=function(felement,fvalue){
var temp_t4=(arguments.length > 2) ? arguments[2]:this.sp;

var fvalue2=fvalue + temp_t4;
var temp_k3=felement.value + temp_t4;

if (fvalue2.indexOf(temp_k3,0) > -1){
felement.setAttribute("checked","");
felement.checked=true;
}else{
felement.removeAttribute("checked");
felement.checked=false;
}
}

this.add=function(fname,fvalue,ftext){
var temp_k1=this.elements(fname);
if (temp_k1==null){return false;}
if (temp_k1.type!="select-one"){
var temp_k3=fvalue;
var temp_t3=(ftext!=null)?ftext:temp_k3;
var temp_t4=temp_k1[0].options;
temp_t4.add(new Option(temp_k3,temp_t3));
temp_k1[0].options[temp_k1[0].options.length-1].value=temp_k3;
temp_k1[0].options[temp_k1[0].options.length-1].text=temp_t3;

}else{
if (this.noexist==1){alert("This element is not select--" + fname)};
}
}
this.add_select=function(url,attr,elem)
{
//SELECT的資料從XML寫入
var a1=new awp_ajax();
var e1=new awp_elements();
var ob=a1.getData(attr,url);
//alert(ob.responseText);
var temp1=ob.responseXML.getElementsByTagName("data");
for (var tempi=0;tempi < temp1.length;tempi++)
{
var temp2=temp1[tempi].getElementsByTagName("fname");
var fname="";
if (temp2.length >0) {fname=temp2[0].firstChild.nodeValue;}
var temp2=temp1[tempi].getElementsByTagName("fvalue");
var fvalue="";
if (temp2.length >0) {fvalue=temp2[0].firstChild.nodeValue;}
else {fvalue=fname;}
if (fname !="")
{
e1.add(elem,fname,fvalue);
}
}

}


this.getvalue=function(fname){
var temp_k1=this.elements(fname);
if (temp_k1==null){return false;}
var temp_t4=(arguments.length > 1) ? arguments[1]:this.sp;
var temp_t5="";
for (f_i=0;f_i < temp_k1.length; f_i++){
var temp_k3=temp_k1[f_i].type;
var k9=temp_k1[f_i];
var temp_t3="";
if (temp_k3=='text' || temp_k3=='password' || temp_k3=='hidden' || temp_k3=='textarea'){
temp_t3=k9.value;
}else if (temp_k3=='radio' || temp_k3=='checkbox'){
if (k9.checked==true){
temp_t3=k9.value;
}
}else if (temp_k3=='select-one'){
for (f_j=0;f_j < k9.options.length; f_j++){
if (k9.options[f_j].selected==true){
if (temp_t3 !=""){temp_t3=temp_t3 + temp_t4;}
temp_t3=temp_t3 + k9.options[f_j].value;
}
}
}
if (temp_t3!="")
{
if (temp_t5 !=""){temp_t5=temp_t5 + temp_t4;}
temp_t5=temp_t5 + temp_t3;
}
}
return temp_t5;
}

this.elements=function(fname){
var temp_k1=this.sourcedocument.getElementsByName(fname);
if (temp_k1.length <1){
if (this.noexist==1){ alert("can not fine this element--" + fname); }
return null;
}else{
return temp_k1;
}

}

this.setbox=function(fname,fflag){
var temp_k1=this.elements(fname);
if (temp_k1==null){return false;}
for (f_i=0;f_i < temp_k1.length; f_i++){
switch(fflag){
case 0:
temp_k1[f_i].checked=false;break;
case 1:
temp_k1[f_i].checked=true;break;
case 2:
temp_k1[f_i].checked=(temp_k1[f_i].checked)?false:true;
break;
}
}
}

}//awp_elements

}//typeof