2011年10月27日星期四

check periodically if port is open from windows

因为远端的机器问题莫名其妙就连接不上了,各种原因。用netcatschtasks来定期检查本机上的端口是不是开着,没开着就重启。netcat的Windows版本见文末链接。

把以下代码存为文件test-7771.bat

@echo off

nc -z 10.17.17.177 7771
if ERRORLEVEL 1 shutdown -r -t 180

exit %RANDOM%

用以下命令添加任务计划,每10分钟执行test-7771.bat一次。

schtasks /sc MINIUTE /mo 10 /tn test-7771 /tr C:\test-7771.bat

有用的链接:
netcat (Windows), http://www.securityfocus.com/tools/139

2011年10月13日星期四

netsh portproxy not working within windows xp

netsh interface portproxy在Windows XP上边不起作用,一直报"connection refused"。因为缺少IPV6MON.DLL。需要使用ipv6 install来安装IPv6协议。如果还是不行,记得使用reset来重置之前所设置的项。具体请见文末链接。

SSH真的是非常好。今天拿到一个从路由器到内网机器的端口映射,只此一个。除去偶尔VNC来查看一下,还想要在里边多装几个Linux虚拟机,山寨一个词语,我需要“TCP port multiplexer”。嗯,SSH很好用。

参考链接
NETSH INTERFACE PORTPROXY do not work when doing port redirection between IPv4 and IPv4 addresses., http://support.microsoft.com/kb/555744/en-us
win7-xsnews.txt, http://psfreedom.com/win7-xsnews.txt

2011年8月21日星期日

Co-existence of python 2.x and python 3.x

此文用于备忘两个命令:ASSOCFTYPE

先安装的是2.7,然后再安装的3.2,3.2后来居上成为默认的.py文件解释器。如果平时都是使用2.x版本工作的话,这样就不行了。以下是解决方法演示


F:\>assoc .py
.py=Python.File

F:\>ftype Python.File
Python.File="C:\Python32\python.exe" "%1" %*

F:\>ftype Python.File="C:\Python27\python.exe" "%1" %*
Python.File="C:\Python27\python.exe" "%1" %*

F:\>ftype Python.File
Python.File="C:\Python27\python.exe" "%1" %*


这样就让2.7成为默认的解释器了。

发觉Python核心的开发流程应该很不错,之前对Python源代码的简单接触也让我对其兴趣渐增,应该要学习一下了。特别是关于测试、项目流程和组织方面,嗯。

2011年8月13日星期六

FFmpeg Notes

记录一下常用的选项,经常去ffmpeg-doc.html去翻那一大坨选项满不好的。

首先,Sheldon的“吓死喔了”

ffmpeg -i "The.Big.Bang.Theory.1x17.The.Tangerine.F
actor.720p.HDTV.x264-DIMENSION.[tvu.org.ru].mkv" -ss 00:11:02.450 -t 00:00:01.70
0 nearly_scared_me_to_death.mp3
-i:指定输入文件(input)
-ss:选择起始时间点(seek start point),格式HH:MM:SS[.xxx]
-t:指定时长(duration)


参考链接
FFmpeg Documentation, http://ffmpeg.org/ffmpeg-doc.html

2011年8月10日星期三

yszhou's First Haskell Function

这个暑假在杭州实习,前天晚上用手机翻到Haskell的主页,看到《Learn You a Haskell for Great Good》,很轻松的那种。之前尝试过《Real World Haskell》,也许英语水平不行?反正很挫。

今天晚上在CPyUG上看到有pyer感慨函数式编程,便把毕设时开小差下载下来的HaskellPlatform安装上,写了以下函数,用于实现Descartesian Product。算是一步一步更General吧。高级语言表达思维,硬件来确认,他们接起来的细节是什么?

enum :: Int -> [[Char]]
enum 1 = ["A", "T", "C", "G"]
enum n = [ x:enum_decr | x <- "ATCG", enum_decr <- enum (n - 1) ]

enum' :: [Char] -> Int -> [[Char]]
enum' init_value 1 = [ [x] | x <- init_value ]
enum' init_value n = [ x:enum_prev | x <- init_value, enum_prev <- enum' init_value (n - 1) ]

enum'' :: [a] -> Int -> [[a]]
enum'' init_value 1 = [ [x] | x <- init_value ]
enum'' init_value n = [ x:enum_prev | x <- init_value, enum_prev <- enum'' init_value (n - 1) ]

2011年7月25日星期一

type And object in Python

首先笔记以下在解释器中的记录:
>>> isinstance(type, type)
True
>>> isinstance(type, object)
True
>>> isinstance(object, object)
True
>>> isinstance(object, type)
True
>>>
在文章《Python Types and Objects》分析的初始阶段,有如下图。所以:
1. type是type的实例,在图中已经体现;
2. 由于type是object的子类,加上条件1,所以type是object的实例;
3. 由于ojbect是type的实例,type又是object的子类,所以object也是object的实例;
4. 在图上已经体现。

另外,"type"或者"class"在Python中有如下特点:
1. 能被子类化(subclassed),或者说被继承(inherited);
2. 能被实例化(instantiated),即“创造出实体”来。由“人”创出“张三”,由“int”创出“2”;
3. 它们的type(调用type())或者__class__都为<type 'type'>。即使是层次很深的继承亦如此。


参考链接:
Shalabh Chaturvedi, Python Types and Objects

2011年7月23日星期六

Using gogoc's IPv6 DNS Server

/etc/NetworkManager/dispatchter.d/下新添加一个文件,命名为99dnsgogoc。当NetworkManager探知新的网络事件时,就会按文件名的字典序依次执行目录里的那些脚本,见man NetworkManager。往99dnsgogoc里添加如下内容:

#!/bin/sh -e

GOGOC_DNSSERVER="nameserver 2001:5c0:1000:11::2"
# Insert disco.gogo6.com's AAAA record to /etc/resolv.conf's first line
sed -i "1i$GOGOC_DNSSERVER" /etc/resolv.conf
这样就会优先使用gogoc具有IPv6解析功能的DNS服务器,比如BlogSpot和Youtube就可以很方便的访问了。

参考链接
http://gogonet.gogo6.com/forum/topics/installing-gogoc-in-ubuntu?commentId=3731159%3AComment%3A118744