GoDaddy域名续费

赶在7月1号之前续费了我这个域名,因为7月1号之后GoDaddy就要涨价了

续了两年,使用优惠码节省了6$,最后支付了15$

google搜索出来的第一个link超有用:Godaddy promo code and coupons list for 2010

tips: 要选取适合的优惠码,有的是百分比的,有的是注册域名打折的,有的是全场通用型的

还有就是信用卡网上美元支付很方便,就是很没安全感

用户的输入总是很有创意的

有时候看似天衣无缝的代码遇到极具创意的用户是不得不低头的

且看下面一段简单的shell代码,检查用户输入如果是合法的文件,然后做一个copy

-r 测试文件存在且可读

-d 检测是否是目录

如果文件存在且可读而且不是目录,(这里不关心文件内容),那么这个输入是否合法呢?

#!/bin/sh
echo "Enter the name of the new licence key file"
echo "licencekeyfile=\c"
read _afile

if [ ! -r $_afile ]
then
	echo "File does not exist"
	exit 1
fi

if [ -d $_afile ]
then
	echo "Licence key file must be a regular file"
	exit 1
fi

#Copy new licenceKey to /var/sog/etc/.licenses/licenseKey
if [ "$_afile" != "/var/sog/etc/.licenses/licenseKey" ]
then
	cp $_afile /var/sog/etc/.licenses/licenseKey
fi

...

用户如何break这个貌似天衣无缝的条件检测的?

Enter the name of the new licence key file
licencekeyfile=/home/user/.licenses/lic*

如果 /home/user/.licenses/lic* 匹配多个文件的情况下,-r 和 -d 判断都能通过,接下来运行到cp 就杯具了

会报下面这个错:


cp: Target /var/sog/etc/.licenses/licenseKey must be a directory
Usage: cp [-f] [-i] [-p] [-@] f1 f2
 cp [-f] [-i] [-p] [-@] f1 ... fn d1
 cp -r|-R [-H|-L|-P] [-f] [-i] [-p] [-@] d1 ... dn-1 dn

真的佩服用户输入的创意啊,为了避免匹配多个文件的情况,不得不用下面的代码来修bug


matches=`ls $_afile | wc -l | sed 's/ //g'`
if [ $matches != 1 ]
then
 echo "Your input of the new licence key file is not valid, it matches $matches files :"
 ls $_afile
 exit 1
fi

My Latest News in 7 Days Vacation

Today is the fifth day of my 7 days vacation.

This was a great holiday for sure.


Having watched the E3 press conferences, I add N3DS to my wish list

Have to say Nintendo press conference was the most successful one compare to Microsoft and SONY.


In Nintendo World:

Still the Nintendo official games was the best ones in its consoles like always.

For me, I almost do not care about the 3rd party games, even Kojima’s Metal Gear Solid, because I can play Metal Gear Solid in another console with amazing screen effects. This point might change later since N3DS offers unique 3D experience now.

Reggie… gorilla …

Miyamoto was not so good at playing Zelda.

Iwata’s English sounds familiar…


In XBOX World:

The new XBOX 360 looks OK, kinda cool, but not still so attractive to me.

Maybe it was caused by the feeling that XBOX games always gets Windows version. (Maybe wrong)

As a matter of fact Microsoft press conference was also great, inherited the fantastic gaming show style, the great games heated the atmosphere.

The Project Natal renamed to Kinect, the full body motion sensor enables you to play with your body, no additional game controllers needed.

I can’t go to E3 to try the Kinect myself, so I have a little bit doubt about the gaming experience.

When will Microsoft design a portable game device?


In SONY World:

PS move did’t bring so much surprise for SONY fans. It is just learning from Wii, plus it gets a stupid light in the front. I don’t like that design.

No new console update, which is reasonable, PS3 is still the most advanced console till now.

In this 3D year, SONY played the card of 3D gaming which is reasonable too, but still feels like not so close to us.


In WorldCup season, everyone is excited, I do watched several matches.

Argentina was the brightest team with the world’s brightest stars.

The two Koreas did played tough role in the field. I think every opponent can never underestimate the two Koreans. 


NBA Final champion finally won by LAKERS this moring!  

Fall behind in the first three quarters, but take the lead in the last quarter.

This was a great show even in the NBA history.


Somthing goes on in my life:

Finally I get the driving license. For the last time the coach ‘Blackmailed’ us 60RMB for its paper fee.

We invite the coach to dinner for teaching us how to drive.

I got so tongue-tied that the coach also brings his concubine – 40-50 year old, heavy makeup, shows cleavage, looks good…

Our coach was definitely an ugly looking guy. Surprisingly unbelievable !!!


I matched a new pair of glasses, when choose the frame I just go for the good looking one, didn’t ask for the price.

When everything was decided, the price scared me a little.

After paid 1211RMB in cash desk, felt like my legs went weak.

This should be an impulsive buying, normally I do not do that.


At last I want to note one important thing, Helen and I choose 35度创意摄影 to take our wedding-photos.

Everything was decided, we just waiting for the day to film, will show photos when it’s ready.

Just I can’t get used to all my moustache shaved.

jQuery Tips : 给AJAX回调函数传递额外参数

讨论这个问题基于如下场景:点击页面上某个按钮之后,触发click事件,事件处理函数内部发送一个AJAX请求,AJAX回调函数更新页面的某一个部分

具体到这个例子,我们希望button1和button2点击之后,用AJAX的方式取example.html的内容,然后动态更新页面的id=callbackdemo3的div

HTML如下: 

<div id="callbackdemo1">
	<button id="button1">ajax load1</button><br/>
</div>
<div id="callbackdemo2">
	<button id="button2">ajax load2</button><br/>
</div>

<div id="callbackdemo3" class="log"></div>

<button onclick="$('.log').html('');">clear</button>

第一种做法:

适用于最简单的情况,也是比较直观的做法,就是在ajax回调函数中,使用jQuery的id选择器$(“#callbackdemo3″)得到id为callbackdemo3的div后更新其HTML内容

$("#callbackdemo1>#button1").click(
function load(){
	$.get("example.html",{ 'param[]': ["var1", "var2"] },
		function f1(data, textStatus, XMLHttpRequest)
		{
			$("#callbackdemo3").html(data);
		}
		);
}
);

 

第二种做法:

定义好一个接受额外参数的回调函数,然后在默认回调函数的内容调用这个预先定义好的回调函数

 这样就能达到传递额外参数的目的了,较之第一种方法,此方法能比较方便的利用各个回调函数的上下文

function callback_with_extraParam(data,param)
{
	param.html(data);
}
$("#callbackdemo2>#button2").click(
function load(){
	var extraParam = $("#callbackdemo3")
	$.get("example.html",{ 'param[]': ["var1", "var2"] },
		function f2(data)
		{
			callback_with_extraParam(data,extraParam);
		}
		);
}
);

 

对于额外参数的重要性,不妨看一个稍微复杂一点点的HTML情况,我们希望更新button3下面的那个div的HTML,这个div没有id,那么如何做呢? 

<div id="callback_complexdemo">
  <button id="button3">ajax load3</button><br/>
  <button onclick="$('div',$(this).closest('div')).html('');">clear</button><br/>
  <div></div>
</div>

当然使用#callback_complexdemo>div也是可以的,但是如果是更加复杂的HTML页面呢?如果没有id=callback_complexdemo呢?嵌套很深呢?

这种情况下,我们就需要有效利用上下文参数这个特性了。

在click的事件处理函数load()中,我们可以方便的获得当前元素的位置var whereAmI = $(this);
这个whereAmI是个jQuery对象,然后在AJAX回调函数f3中,我们利用whereAmI即被点中的这个button想办法去获得想要的div

这一行代码新手有的人看不懂:$(‘div’,$(whereAmI).closest(‘div’))

首先$closest_parent_div = $(whereAmI).closest(‘div’)即查询获得whereAmI最近的父div对象

然后$(‘div’,$closest_parent_div) 即在最近的父div对象这个上下文中,查找内部的div对象

$("#callback_complexdemo>#button3").click(
function load(){
	var whereAmI = $(this);
	$.get("example.html",{ 'param[]': ["var1", "var2"] },
		function f3(data)
		{
			console.log(whereAmI);
			$('div',$(whereAmI).closest('div')).html(data);
		}
		);
}
);

 

 希望通过这个小例子,能让大家学会如何给AJAX回调函数传递额外参数,以及实用且重要的上下文参数。