About neohope

一直在努力,还没想过要放弃...

ANT出现“命令语法不正确”

昨天用ant编译代码时,报了一个很诡异的错误:
“命令语法不正确。”

分析了半天发现,原来是我在bat文件中多了””,悲剧啊。

set JAVA_HOME="D:\JavaJDK\jdk1.6.0_34_x86"
set ANT_HOME="D:\JavaTools\apache-ant-1.9.0"
set PATH=%ANT_HOME%\bin;%JAVA_HOME%\bin;%PATH%

将引号去掉就好了

set JAVA_HOME=D:\JavaJDK\jdk1.6.0_34_x86
set ANT_HOME=D:\JavaTools\apache-ant-1.9.0
set PATH=%ANT_HOME%\bin;%JAVA_HOME%\bin;%PATH%

开源IM软件

近期研究了下开源的IM软件:

软件名 源码语言 开源协议 网站地址
PIDGIN c,gcc/MinGW,gtk+ GPL v2 http://www.pidgin.im/
Instantbird c+MozillaBuild MPL1.1 https://wiki.instantbird.org/Main_Page
RetroShare c,cpp,QT MPL1.1 http://retroshare.sourceforge.net/downloads.html
OneTeam JS, C++ XPCOM, Mozilla/XUL MPL1.1 https://github.com/processone/oneteam
Coccinella TCL GPLv3 http://coccinella.im/
OpenFire+Spark java GPLv2 http://www.igniterealtime.org/downloads/index.jsp
iQQ java LGPL https://github.com/im-qq
ipmsg(飞鸽传书) vc no control http://ipmsg.org/
ipmsg .Net C# GPLv3 http://code.google.com/p/ipmessagernet/
freeeim(飞秋) vc no control http://freeeim.com/

VC fix .pch file missing

表现:

Error   1   fatal error C1083: Cannot open precompiled header file: 'Debug\????.pch': No such file or directory

解决方法:
1、保证stdafx.h及stdafx.cpp在项目的最顶层,stdafx.h用于保存需要的头文件,stdafx.cpp中只有对stdafx.h的引用;
2、在VS中,右击需要修改的工程,选择”Properties”;
3、在左上角,选择“ All Configurations”;
4、在左边,找到“C/C++”,并定位到“Precompiled Headers”;
5、将选项Precompiled Header修改为: “Use (/Yu)”;
6、将选项“Precompiled Header File”修改为:“stdafx.h”;
7、保存设置;
8、保证#include “stdafx.h”为所有需要预编译的cpp文件的第一行;
9、VS中,右击stdafx.cpp,选择”Properties”;
10、在左上角,选择“ All Configurations”;
11、将选项Precompiled Header修改为: “Create (/Yc).”;
12、保存设置,重新编译。

第一次拆iPhone4(后记)

过了两周,液晶的花屏慢慢好了,感觉相当不错。

但最近发下,液晶花屏的地方,有一道比较明显的折痕,锁屏界面看不出来,解锁界面十分明显。

估计花屏就是它的原因吧。

🙂

PS:
今天早上又摔了,直接关机了,开不开。
插上数据线后,又可以用了,我可怜的iphone4啊。

JavaScript checking for null vs. undefined

JS中undefined表示变量没有定义或从来没有赋值,而null是空对象,是有值的。
例如:

var a;
alert(typeof a);
//"undefined"

a = null;
alert(typeof null);
//"object"

JS中==比较为弱类型比较,JS会自动进行类型转换,然后返回值的比较结果。
而===为强类型比较,即必须类型与值同时相同,才会相等。
例如:

alert(0 == "0");
//true

alert(0==="0");
//false

alert(undefined == null);
//true

alert(undefined === null);
//false

判断变量为null:

if (a === null)
// or
if (a == null)

第一种方法,当a为undefined时返回false,
第二种方法,当a为undefined时返回true。

判断变量为undefined:

if (typeof a === "undefined")
// or
if (a === undefined)
// or
if (a == undefined)

第一、二种方法,当a为null时返回false,
第三种方法,当a为null时返回true。

还有一种使用falsey进行检查的方法:

if (!a) {
    // `a` is falsey, which includes `undefined` and `null`
    // (and `""`, and `0`, and `false`)
}

大部分翻译自stackoverflow:
JavaScript checking for null vs. undefined and difference between == and ===

GitHub03SSH授权

用低版本的github做上传的时候,会有提示

Permission denied (publickey). 

最简单的方法,就是安装新版本的GitHub。

如果你实在不愿意升级,那可以用以下步骤来进行:

#1、测试ssh,会提示Permission denied (publickey). 
ssh -T git@github.com 
#2、生成新的授权文件,如果你没有改过配置,那文件名为github_rsa,密码保持为空即可
ssh-keygen -t rsa -C "neohope@yahoo.com"
#3、查看新的key
ssh-add -l
#4、登录GitHub网站,到管理SSH Keys的地方,上传public key
#~/.ssh/github_rsa.pub
#5、测试ssh,会提示成功
ssh -T git@github.com 

搞定!

Prolog101(08)

列表:
放在用方括号中的一组项目的集合,各项目之间使用逗号分割。

空表:
没有项目的列表,用[]表示。

表头与表尾:
[X|Y]可以与任意的列表匹配,匹配成功后,X绑定为列表的第一个项目的值,我们称之为表头(head)。
而Y则绑定为剩下的列表,我们称之为表尾(tail)。
表尾(tail)一定是列表,而表头(head)则是一个项目,该项目可以是表,也可以是其他的任何数据结构。
看下这个例子就清楚了:

1 ?- [a|[b,c,d]] = [a,b,c,d]. 
true.

2 ?- [a|b,c,d] = [a,b,c,d].
ERROR: Syntax error: Unexpected comma or bar in rest of list
...

3 ?- [H|T] = [a]. 
H = a,
T = [].
 
4 ?- [H|T] = [a,b,c,d]. 
H = a,
T = [b, c, d].

5 ?- [H|T] = [a,[b,c,d]]. 
H = a,
T = [[b, c, d]].

6 ?- [H|T] = [].
false.

7 ?- [A,B|T] = [a,b,c,d].
A = a,
B = b,
T = [c, d].

8 ?- [a|[b|[c|[d|[]]]]] = [a,b,c,d].
true.

检查数据是否存在:

1 ?- member(a, [a,b,c]). 
true .

2 ?- member(d, [a,b,c]). 
false.

3 ?- member(d, [a,b,c,[d],e]). 
false.

4 ?- member([d], [a,b,c,[d],e]).
true .

5 ?- member(X, [a,b,c]). 
X = a ;
X = b ;
X = c.

追加

1 ?- append([a,b,c],[d,e,f],X).
X = [a, b, c, d, e, f].

2 ?- append([],[d,e,f],X).
X = [d, e, f].

3 ?- append([a,b],Y,[a,b,c,d]).
Y = [c, d].

4?- append(X,Y,[a,b,c]).
X = [],
Y = [a, b, c] ;
X = [a],
Y = [b, c] ;
X = [a, b],
Y = [c] ;
X = [a, b, c],
Y = [] ;

删除

1 ?- delete([a,b,c,d,e], c, X).
X = [a, b, d, e]

not in 优化为 not exists

最近迁移数据库的时候,发现not in比not exists效率差太多了

--not in 直接卡死
insert into table1(
select * from table2 t2@oraclegate where t2.pk not in (select pk from table3 t3));

--not exist则很快处理完成
insert into table1(
select * from table2 t2@oraclegate where not exists (select pk from table3 t3 where t3.pk=t2.pk));

其实数据量并不大,不知道是不是用gateway的问题。

Prolog101(07)

联合(Unification)

变量与任何项目: 变量可以与任何项目绑定,其中也包括变量
原始项目与原始项目: 两个原始项目(原子或整数)只有当它们相同时才能联合。
结构与结构: 如果两个结构的每个相应的参数能联合,那么这两个结构可以联合。

1 ?- (1,2,3)=(X,Y,Z).
X = 1,
Y = 2,
Z = 3.

2 ?- (1,2,3)=(X,X,Z).
false.

3 ?- (1,1,3)=(X,X,Z).
X = 1,
Z = 3.

4 ?- (1,X,3)=(X,1,Z).
X = 1,
Z = 3.

5 ?- (1,X,3)=(X,2,Z).
false.
1 ?- (1,2,X)=(1,2,(3,4,5)).
X = (3, 4, 5).

2 ?- (1,2,X)=(1,2,(3,4,Y)),Y=5.
X = (3, 4, 5),
Y = 5.

%_表示不关心匹配内容
3 ?- (1,2,X,Y,7)=(1,2,(3,4,5),6,_).
X = (3, 4, 5),
Y = 6.

4 ?- X = Y, Y = hi, write(X).
hi
X = Y, Y = hi.
%swipl -s objs.pl
%Hansen

%room
room(kitchen).

%objects and location
%object(Name, Color, Size, Weight).
location(object(candle, red, small, 1), kitchen).
location(object(apple, red, small, 1), kitchen).
location(object(apple, green, small, 1), kitchen).
location(object(table, blue, big, 50), kitchen).

%current room
here(kitchen).

%can take something?
can_take(Thing) :-  
here(Room), 
location(object(Thing, _, small, _), Room). 
can_take(Thing) :- 
here(Room), 
location(object(Thing, _, big, _), Room), 
write('The '), write(Thing),  
write(' is too big to carry.'), nl, 
fail. 
can_take(Thing) :- 
here(Room), 
not(location(object(Thing, _, _, _), Room)), 
write('There is no '), write(Thing), write(' here.'), nl, 
fail.

%out put the weight
write_weight(1) :- write('1 pound').  
write_weight(W) :- W > 1, write(W), write(' pounds').

%list all things in a room
list_things(Place) :-  
location(object(Thing, Color, Size, Weight), Place), 
write('A '),write(Size),tab(1), 
write(Color),tab(1), 
write(Thing), write(', weighing '), 
write_weight(Weight), nl, 
fail.