Xar

他和他的人

The Real Case - running YCSB with HBase

leave a comment »

  1. Download YCSB and deploy it as mentioned here.
  2. HBase should be compactible with HDFS(Hadoop), e.g., addBlock() method.
  3. Set the variable $CLASSPATH:
    1. a rough script:

jarpath=”${HOME}/YCSB/db/hbase/conf”

for dir in `cat ${HOME}/YCSB/db/hbase/lib/*.jar`

do

export jarpath=$jarpath:$dir

done

echo $jarpath

  1. run the script above and set the $CLASSPATH with the output.

put “export CLASSPATH=BLABLA…” in your .profile/.bashrc/.bash_profile/.zshrc, depending on your shell, would be fine. But if you want to set the variable via `. SCRIPT’ in cmd line, the shell session probably would be killed. Perhaps the variable $CLASSPATH contains too much things…

  1. “${HOME}/YCSB/db/hbase/conf” should be added into the $CLASSPATH, if you want YCSB to load your HBase’s configuration. Otherwise, YCSB would use default, hard-coded, configuration(resides in HBase’s jars) to connect to Zookeeper server, which would definitely failed if your HBase does not use the default settings.

  1. Before running the benchmark, create a ‘usertable’ in HBase, e.g. via it’s shell:
    1. ./hbase shell
      1. hbase> create ‘usertable’, ‘col’

‘usertable’ is the table name, while ‘col’ is the column family name.

  1. When invoking YCSB, in the cmd line or a property file, you should specify the column family name, e.g:
    1. cmd line

      “-p columnfamily=col”

      property file

      columnfamily=col

if you do not want to use table ‘usertable’, you should create one manually, and tell YCSB your specification, too.

  1. Do NOT use ‘-cp’ parameter, since it would override your pre-set variable $CLASSPATH temporarily.
    1. so, load section would be like this:

java com.yahoo.ycsb.Client -load -db com.yahoo.ycsb.db.HBaseClient -P workloads/workloada_test -p columnfamily=col -s >load.dat

  1. and transaction section would be like this:

java com.yahoo.ycsb.Client -t -db com.yahoo.ycsb.db.HBaseClient -P workloads/workloada_test -p columnfamily=col -s -threads 10 -target 100 -p measurementtype=timeseries >transaction2.dat

Written by lebannen

Saturday, July 31, 2010 at 22:08

Posted in Distributed

Tagged with ,

Demo of MyIP Seekr

leave a comment »

不解释


#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <iconv.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <sys/mman.h>

#define MYIPFILE "MyIP.dat"
//#define DEBUG
#define prints(string) {printf("##DEBUG##\t");int i=0; while(string[i] != 0x20 ){printf("%c", string[i++]);} endl();}
#define endl() printf("\n")
#define init(id, fp) {																			\
					char *pt; 																	\
					/*FIRST = *(uint16_t *)(fp + 0x8); 		*/									\
					/*RDLEN = *(uint16_t *)(fp + 0xa);*/											\
					pt = (char *)(fp + FIRST);													\
					/*while(*pt == 0x20) {++pt;++FIRST;} */											\
					/*while(*(pt-1) != 0x20) {--pt;--FIRST;}	/*in case that FIRST was not exac*/	\
					id = (pseudo_t *)pt;														\
					}

#define update(idx, pseudo) {\
					idx.pse = pseudo;\
					int a, b, c, d;\
					sscanf(pseudo->startip, "%d.%d.%d.%d", &a, &b, &c, &d);\
					idx.startip = a<<24|b<<16|c<<8|d;\
					sscanf(pseudo->endip, "%d.%d.%d.%d", &a, &b, &c, &d);\
					idx.endip = a<<24|b<<16|c<<8|d;\
					}

#define printip(intt) {\
					printf("%d.%d.%d.%d ", (intt&0xFF000000)>>24, (intt&0xFF0000)>>16, (intt&0xFF00)>>8, intt&0xFF);\
}

#define demo(index) 	{																	\
						rd_gbk_t rd_gbk;													\
						rd_uni_t rd_uni;													\
						memset(&rd_gbk, 0, sizeof(rd_gbk_t));								\
						memset(&rd_uni, 0, sizeof(rd_uni_t));								\
						memcpy(rd_gbk.country, index.pse->country, 13);						\
						memcpy(rd_gbk.area, index.pse->area, 60);							\
						int i;																\
						for(i=0; i<13; ++i){												\
							if(rd_gbk.country[i] == 0x20) rd_gbk.country[i] = 0x00;			\
						}																	\
						for(i=0; i<60; ++i){												\
							if(rd_gbk.area[i] == 0x20) rd_gbk.area[i] = 0x00;				\
						}																	\
						enconv(rd_gbk.country, rd_uni.country);								\
						enconv(rd_gbk.area, rd_uni.area);									\
						printip(index.startip); printip(index.endip);printf("\t");			\
						printf("%s %s\n", rd_uni.country, rd_uni.area);						\
					}

typedef struct record_gbk_t {
	char country[16];
	char area[64];
	}rd_gbk_t;

typedef struct record_uni_t {
	char country[32];
	char area[128];
	}rd_uni_t;

typedef struct pseudo_t {
	char startip[16];
	char endip[16];
	char country[10];
	char area[92];
	}pseudo_t;//each size should be adjusted
	//used to point to each record in FILE

typedef struct index_t {
	uint32_t startip;
	uint32_t endip;
	pseudo_t *pse;
	}index_t;

uint16_t FIRST = 0xc2;//initialize location/p of the first record
uint16_t RDLEN = 0x86;//initialize length of record

int enconv(char *pin, char *pout){
	size_t inleft, outleft;
	iconv_t cd;
	if((cd = iconv_open("UTF-8", "GBK")) == (iconv_t) -1) return -1;
	if(iconv(cd, &pin, &inleft, &pout, &outleft) == (size_t) -1) return -1;
	iconv_close(cd);
	return 0;
}

int main(int argc, char **argv){
	if(argc != 2){
		//print version info;
		return 1;
	}
	int fd;
	if((fd=open(MYIPFILE, O_RDONLY))<0){
		fprintf(stderr, "file not exists.\n");
		exit(1);
	}
	struct stat filestat;
	if(fstat(fd, &filestat)<0){
		fprintf(stderr, "fstat error.\n");
		exit(1);
	}
	//void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset);

	void *fp;
	if((fp = mmap(NULL,filestat.st_size, PROT_READ, MAP_PRIVATE, fd, 0))==MAP_FAILED){
		fprintf(stderr, "mmap error.\n");
		exit(1);
	}

	pseudo_t *pseudo;
	init(pseudo, fp);//locate the *pseudo to point the first record

#ifdef DEBUG
	printf("##DEBUG##\tsizeof(pseudo_t): 0x%x\n", sizeof(pseudo_t));
	printf("##DEBUG##\tFIRST = 0x%x\n##DEBUG##\trecord starts from %p\n", FIRST, pseudo);
	prints(pseudo->startip);
	prints(pseudo->endip);
	index_t idx;
	update(idx, pseudo);
	printf("##DEBUG##\tfirst record: start_ip==%08x\tend_ip==%08x\n", idx.startip, idx.endip);
	endl();
#endif

	index_t index;
	update(index, pseudo);//initialized
	uint32_t span = index.endip - index.startip;
	int j=0, count = (filestat.st_size - FIRST)/RDLEN;
	//printf("%d, %d, %d\n", count, RDLEN, (int)filestat.st_size);
	int a, b, c, d;
	uint32_t startip, endip, target;
	sscanf(argv[1], "%d.%d.%d.%d", &a, &b, &c, &d);
	target = a<<24|b<<16|c<<8|d;
	//printf("%x\n", target);
	while(j<count){
		++j;
		sscanf(pseudo->startip, "%d.%d.%d.%d", &a, &b, &c, &d);
		startip = a<<24|b<<16|c<<8|d;
		sscanf(pseudo->endip, "%d.%d.%d.%d", &a, &b, &c, &d);
		endip = a<<24|b<<16|c<<8|d;
		if(startip <= target && target <= endip && span > endip - startip) {
			update(index, pseudo);
			span = endip - startip;
		}
		pseudo++;
	}

	demo(index);

	close(fd);
	munmap(fp, filestat.st_size);
	return 0;
}

Written by lebannen

Friday, July 16, 2010 at 19:58

Posted in Programming

Tagged with

Memo List [I]

leave a comment »

[1] Benjamin Lee Whorf,
language imprisons the mind
grammatical pattern in a language can produce far-reaching consquences for the culture of a society

  1. ^ “Whorf versus Socrates, round 10″. Trends in Cognitive Sciences 10 (9): 394-396. 2006.
  2. ^ Voelker, Marcy L., ed. “Benjamin Whorf 1897-1941. http://www.mnsu.edu/emuseum/information/biography/uvwxyz/whorf_benjamin.html. Retrieved 2009-03-27.
  3. ^ Birch, David (1989-04). Language, Literature and Critical Practice: Ways of Analysing Text. Taylor & Francis, Inc.. pp. 132. ISBN 9780415029414.
  4. ^ Whorf, Benhamin Lee; Caroll, John B., eds (1964-03). Language, Thought, and Reality: Selected Writings. Cambridge, Massachusetts: MIT Press. ISBN 9780262730068.
  5. ^ Little, Daniel (1991-01). Varieties of Social Explanation: An Introduction to the Philosophy of Social Science. Boulder, Colorado: Westview Press. pp. 204. ISBN 9780813305660.
  6. ^ Maxwell, Mary (1984). Human Evolution: A Philosophical Anthropology. Sydney, Australia: Law Book Co of Australasia. pp. 283-284. ISBN 0709917929.
  7. ^ Chapman, Siobhan; Routledge, Christopher, eds (2005-07-21). Key Thinkers in Linguistics and the Philosophy of Language. USA: Oxford University Press. ISBN 0195187687.
  8. ^ Language Thought and Reality: Selected Writings of Benjamin Lee Whorf, edited by John B. Carroll, MIT Press, Boston, Massachusetts, 1956, ISBN 0262730065
  9. ^ a b The Relation of Habitual Thought and Behavior to Language,“, Benjamin Whorf, 1956, 1997
Darnell, Regna (2001). Invisible Genealogies: A History of Americanist Anthropology. Critical studies in the history of anthropology series, vol. 1. Lincoln: University of Nebraska Press. ISBN 0-8032-1710-2. OCLC 44502297.
  • B. L. Whorf, “The Relation of Habitual Thought and Behavior to Language”PDF.
  • Some ebooks related available on ED2K network:
    Whorf, Benjamin Lee - Language, Thought and Reality[MIT Press, 288p].djvu
    Whorf - Language, Thought and Reality (MITPress).pdf
    Language, Literature and Critical Practice. Ways of Analysing Text (Interface Series).zip

    [2] dbebooks.biz 7.13
    [3] filebook.net 8.29
    [4] avaxhome.ws 11.15, Programmer en Java

    [5] ./configure for aMule

    
    patch -p0 < ../aMule.patch
    ./configure --disable-systray --disable-gtk --enable-mbedded_crypto \
    --with-wx-config=/opt/build/Building/wxMac-2.8.10/wx-config --enable-cas \
    --enable-webserver --enable-amulecmd --enable-optimize \
    --with-crypto-prefix=/usr/local/cryptopp/ --enable-profile --enable-wxcas \
    --enable-alc --enable-alcc --disable-rpath --enable-amulecmdgui \
    --enable-amule-daemon --enable-webservergui \
    --with-libupnp-prefix=/opt/local/include/upnp/ \
    --enable-geoip --enable-mmap \
    --with-geoip-headers=/opt/local/include --with-geoip-lib=/opt/local/lib/ --with-geoip-static
    

    Written by lebannen

    Wednesday, December 9, 2009 at 02:42

    Posted in Memo

    Tagged with ,

    SMPlayer.app on OSX, again

    leave a comment »

    我是一个updater。在用Arch Linux的时候,我坚持每隔几天sudo pacman -Syu;在Mac下则一直sudo port -v sync ; sudo port -v upgrade outdated来更新MacPorts并且用AppFresh.app来更新App。

    在我之前写的”SMPlayer.app on Leopard“(中文版)一文中提过如何在OSX下编译SMPlayer。当然作为一个updater,还会去更新它。因为没人在OSX下维护SMPlayer.app,所以一切还得自己动手。(如果有人维护的话,请告诉我:))

    这里只提一些简单tips。

    1. 首先需要一个命令行的mplayer,来给SMPlayer调用。可以用MacPorts编译,或者从SVN下载源码编译。[1]

    2. 需要Qt4-mac。
    同样可以用MacPorts编译,也可以从Qt的官网Nokia下载 (Qt: Framework Only)。我没有试过Qt4-X11, 不知道SMPlayer.app能否在X11下融合mplayer的播放窗口。当然在Qt4-mac下是不行的。

    3. 当然还需要smplayer的源代码比如smplayer-0.6.8.tar.bz2 。[2]

    4. 编译。首先要确认一下安装的Qt4-mac的qmake, 如果是qmake-mac的话,那么修改smplayer的Makefile:

    
    QMAKE=qmake-mac
    LRELEASE=lrelease-mac
    

    从某个版本的smplayer开始,已经不需要修改src/core.cpp里面的”disable_screensaver”部分。
    但是还是要修改src/core.cpp的关于aspect参数部分:
    找到

    proc->addArgument("-nokeepaspect");
    

    然后把它注释掉。等会解释这么做的意图。
    修改好代码,直接make。编译会花上几分钟,如果一切顺利[3],结束之后会在src/ 下生成可执行文件smplayer以及一个Mac的bundle: smplayer.app。现在可以直接在Term里执行./smplayer, 或者在Finder里双击(or CMD+DownArrow)smplayer.app。一切顺利的话,会看到smplayer的窗口。

    5. 配置。不配置smplayer/mplayer 是没法直接用的。首先需要在~/.mplayer 下建一个config文件内容如下:
    monitoraspect=16:10 [4]
    这就是前面在smplayer的src/core.cpp里面注释掉那行代码的原因。
    然后是配置smplayer.app了。以前的smplayer的配置都保存在~/.smplayer下,而某个版本之后的smplayer配置都保存在~/.config/smplayer/ 下。当然并不需要关心它的位置,直接在当前打开的smplayer.app窗口下按CMD+,(这应该归功于Qt4-mac)进入配置窗口,也可以点击OSX的menubar中的菜单。
    在General选项卡下,首先要给它指定”MPlayer executable”的位置,根据mplayer的安装位置填写(有多个mplayer的话,填写偏好的那个),比如/usr/local/bin/mplayer。然后是在Video和Audio子选项卡中分别指定Video和Audio的”Output driver”, 请选择”corevideo”, “coreaudio”。如果没有的话,选择user defined,然后手动指定。主要是根据mplayer支持的driver参数来填写,参考编译mplayer时候的configure输出。至于是否在Audio下勾选”AC3/DTS pass-through S/PDIF” 要根据视频文件具体选择。
    然后是Subtitles和Font的问题。到Subtitles选项卡下,选择适合的Subtitle encoding。比如我会手动转换所有的.srt类字幕文件到UTF-8编码,那么我就会默认选择UTF-8编码。在”Font and colors”子选项卡下,按照喜好设置。中文字体可以Hei体或者Monaco之类的。
    在Advanced选项卡下,勾选”Run MPlayer in its own window”,否则smplayer会根据视频大小重绘自己的窗口。好了,可以试着用它来播放视频文件。

    6. 美化。是的,默认的bundle的ICON相当的简陋。在源代码的根目录下面有个icons目录,可以用里面的smplayer_icon64.png生成一个icns文件[5],然后复制到bundle里面的Contents/Resources/ ,并修改Contents/Info.plist 指定该icns文件为默认的ICON。[6]
    现在可以把它复制到程序目录,比如/Applications/

    SMPlayer.app之后
    现在来谈谈一点其他的东西。
    当前Mac OS X下的免费视频播放器已经比较丰富了,有Movist.appPlex.appVLC.appMPlayer OSX Extended.app 等等。
    Plex.app是目前暴力解(软解)效率最高的,比如eMule上拖下来的”The Sky Crawlers”(1080p) [7] 只有Plex.app才能流畅的播放,其他播放器都会有不同程度的“音画不同步”、“卡壳”等现象。当然Plex.app暴力解的代价就是风扇的疯狂运行。Plex.app的“缺点”就是界面不友好,不支持UTF-8编码的字幕;配置麻烦……
    其他三个用下来效率都差不多,比较偏好Movist.app一点,MPlayer OSX Extended.app似乎也不错,不过第一次运行会用fontconfig生成字体cache好像,比较耗时。VLC.app曾经的配置是最麻烦的,新版似乎好点了。
    关于OSX下视频解码,可以看看jjgod的博文《Mac OS X 视频解码技术之现状》

    那么SMPlayer.app的意义何在?
    其实没什么意义,折腾呗。它只是MPlayer的一个frontend,封装好一堆参数[8],方便调用。不过要是视频播放遇到问题,需要不断的调试、配置参数,折腾的够呛。易用性真是糟糕。当然在一两年之前,VLC.app的配置非常折磨人,Plex.app和MPlayer OSX Extended.app还没出现,Movist.app刚刚崭露头角,那个时候折腾一下SMPlayer.app,用来播放非高清视频还是具有现实意义的。而现在,我自己都快没有兴趣去折腾SMPlayer.app了。
    鉴于此,也就不难理解为什么没人在Mac OS X下维护SMPlayer.app了:显然它或许真能成为Linux、BSD下最好的MPlayer的GUI Frontend;但是在OS X下非native的GUI App(除非没有竞争对手)基本上是没有前途的。

    __________________________________________________________________________________
    [1] svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
    [2] 请自行跟随smplayer的latest release
    [3] 没记错的话,某个SVN版本的smplayer在make过程中会出错,还需手动改src/Makefile。也许是我记错了……
    [4] 根据Mac的屏幕定制合适的长宽比
    [5] 转ICNS的软件推荐img2icns.app,用它生成普通的icns文件是免费的
    [6] 或者自行定制其他的ICON。kde-look之类的网站有很多素材
    [7] The.Sky.Crawlers.001.mkv The.Sky.Crawlers.002.mkv
    [8] 想看看SMPlayer调用MPlayer时用了哪些参数?Term下执行ps -ef | grep mplayer就能看到了

    Written by lebannen

    Monday, November 30, 2009 at 09:09

    Posted in Macintosh

    Tagged with , , ,

    Correction for quickSort_modified algorithm

    leave a comment »

    清华大学出版社《数据结构习题与解析(B级第3版)》 Page 418


    改写快速排序算法,要求采用排序的序列两端取中的方式选择划分的基准记录。

    书上给的算法有误[1] (已改写成实际CPP代码)

    
    int Partition(int a[], int i, int j){
    	int pivot, tmp;
    	int mid=(i+j)/2;
    	pivot = a[mid];
    	while(i < j){
    		while(i<j && a[j]>=pivot) --j;
    		while(i<j && a[i]<=pivot) ++i;
    		if(i<j){
    			tmp=a[j];
    			a[j]=a[i];
    			a[i]=tmp;
    			++i; --j;
    		}
    	}
    	tmp = a[mid];
    	a[mid]=a[i];
    	a[i]= tmp;
    	return i;
    }
    
    void Qsort(int b[], int low, int high){
    	int pivotloc;
    	pivotloc= Partition(b, low, high);
    	if(low < pivotloc-1)
    		Qsort(b, low, pivotloc -1);
    	if(pivotloc+1 < high)
    		Qsort(b, pivotloc+1, high);
    
    }
    

    修改如下
    qSort.cpp

    
    #include <cstdio>
    #include <cstdlib>
    int Partition(int a[], int i , int j){
    	int pivotkey=a[i];
    	int tmp=a[i];
    	while(i<j){
    		while(i<j && a[j]>=pivotkey) --j;
    		a[i]=a[j];
    		while(i<j && a[i]<=pivotkey) ++i;
    		a[j]= a[i];
    	}
    	a[i]=tmp;
    	return i;
    }
    
    void Qsort(int a[], int low, int high){
    	int pivotloc;
    	if(low < high){
    		pivotloc= Partition(a, low, high);
    		Qsort(a, low, pivotloc-1);
    		Qsort(a, pivotloc+1, high);
    	}
    }
    int main(int argc, char **argv){
    	//int num[10]={9,8,5,3,1,0,6,7,2,4};
    	if(argc > 1){
    		int i=0;
    		int n=argc-1;
    		int *num = (int *)malloc(n * sizeof(int));
    		while(i<n){
    			num[i]=atoi(argv[i+1]);
    			printf("%d\t", num[i++]);
    		}
    		i=0;
    		printf("\n");
    		Qsort(num, 0, n-1);
    		printf("\n");
    		while(i<n){
    			printf("%d\t", num[i++]);
    		}
    		printf("\n");
    		free(num);}
    	else{
    		printf("Where is the data?\n");
    	}
    	return 0;
    }
    

    _________________________________________________________________________________________________________
    [1] 分析以后写

    Written by lebannen

    Sunday, November 8, 2009 at 08:54

    在Terminal下操作文件属性的Tips

    leave a comment »

    说一下背景:
    U盘被打印店染毒,根目录下有许多和文件夹同名的.exe。如果有文件夹名是.开头的,比如在OSX下用过U盘一般会被自动写入.Trash/, .Spotlight-V100/, .TemporaryItems/ 诸如此类的文件夹。那么以.开头的文件/文件夹在Finder中是不会显示出来的。在Terminal下可以用ls -a

    $ ls -al

    total 461616
    drwxrwxrwx 1 marcus staff 8192 8 Jun 21:20 .
    drwxrwxrwt@ 4 root admin 136 8 Jun 21:19 ..
    drwxrwxrwx 1 marcus staff 4096 25 Sep 2008 .Spotlight-V100
    -rwxrwxrwx 1 marcus staff 460288 5 Feb 10:14 .Spotlight-V100.exe
    drwxrwxrwx@ 1 marcus staff 4096 3 Feb 20:51 .TemporaryItems
    -rwxrwxrwx 1 marcus staff 460288 5 Feb 10:14 .TemporaryItems.exe
    drwxrwxrwx@ 1 marcus staff 4096 8 Jun 21:19 .Trashes
    -rwxrwxrwx 1 marcus staff 460288 5 Feb 10:14 .Trashes.exe

    这个时候是无法直接rm掉这些.exe的,因为病毒在复制时用了fat32文件系统的“只读”,在Mac下表现为“locked”。如果在Finder下可以看到一个只读的文件,用cmd+i,可以在getFileInfo下看到此属性。
    那么我们首先要做的就是去掉这个locked属性。如果文件在finder下可见,那么用cmd+i就可以了。如果文件不可见,那么我们可以用terminal来做。
    用SetFile这个命令。(注意大小写,当然你可以用bash/zsh的tab补全)
    先看它的help:

    Usage: SetFile [option...] file…
    -a attributes # attributes (lowercase = 0, uppercase = 1)*
    -c creator # file creator
    -d date # creation date (mm/dd/[yy]yy [hh:mm[:ss] [AM | PM]])*
    -m date # modification date (mm/dd/[yy]yy [hh:mm[:ss] [AM | PM]])*
    -P # perform action on symlink instead of following it
    -t type # file type

    Note: The following attributes may be used with the -a option:
    A Alias file
    B Bundle
    C Custom icon*
    D Desktop*
    E Hidden extension*
    I Inited*
    M Shared (can run multiple times)
    N No INIT resources
    L Locked
    S System (name locked)
    T Stationery
    V Invisible*
    Z Busy*

    Note: Items marked with an asterisk (*) are allowed with folders
    Note: Period (.) represents the current date and time.
    Note: [yy]yy < 100 assumes 21st century, e.g. 20yy

    它在哪里?
    $ which SetFile
    /usr/bin/SetFile

    好,言归正传,根据它的manual我们只要对这些.exe执行如下操作:
    $ SetFile -a l $FILENAME
    然后就可以用rm了。

    除了SetFile我们还可以用chflags
    具体的manual就不贴了,大家可以自己man
    $ chflags uchg $FILENAME //lock 一个file
    $ chflags nouchg $FILENAME //unlock 一个file

    另外提一下,/usr/bin下还有一些其他的大写字母开头的可执行文件,比如GetFileInfo
    私猜测是OSX独有的跟GUI下的那些东西相关。

    Written by lebannen

    Monday, June 8, 2009 at 22:58

    Posted in Macintosh

    Tagged with , , ,

    一些系统有关的脚本 [from Quicksilver]

    leave a comment »

    以下所有脚本内容来自Quicksilver自带。

    force restart, 其实就是sudo reboot:
    [AppleScript][1]

    do shell script "reboot" password "43046721" with administrator privileges
    

    force shutdown, 其实就是sudo halt; sudo /sbin/shutdown now:
    [AppleScript]

    do shell script "/sbin/shutdown now" with administrator privileges
    

    restart, 后面也可以跟 shut down, logout之类的:
    [AppleScript]

    tell application "System Events" to restart
    

    获得本机的I公网IP:
    [AppleScript]

    set theIP to do shell script "curl -sf http://checkip.dyndns.org/|cut -d \
     ':' -f 2 | cut -d '<' -f 1 | sed -e 's/ //g'"
    tell application "Quicksilver" to show large type theIP
    return theIP
    

    获得本机的本地IP:
    [AppleScript]

    set theIP to do shell script "ifconfig | grep 'broadcast' |awk '{print $2}'"
    tell application "Quicksilver" to show large type theIP
    return theIP
    

    强制注销:
    [Fast Logout.sh]

    #!/bin/sh
    if [[-z $1]]; then
        /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend > /dev/null
    else
        USERID=`id -u $1`;
        if [[ -z $USERID ]]; then
            exit -1;
        fi;
        /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID $USERID > /dev/null
    fi;
    

    切换至根用户:
    [Switch To Root.sh]

    #!/bin/sh
    /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 0
    

    _____________________________________________________________________
    [1] 我不知道这里为什么会有这样一个神奇的数字作为password

    Written by lebannen

    Sunday, August 24, 2008 at 18:37

    Posted in Macintosh

    Tagged with , , ,

    mldonkey + sancho on Mac

    leave a comment »

    mldonkey是另一个电驴软件,口碑比aMule好,据说。
    mldonkey可以用MacPorts安装

    $ sudo port -d install mldonkey

    mldonkey是命令行工具,有很多GUI前端,不过mac下的gui却不多,很多还是废弃很久没更新。前段时间找到sancho,虽然是用java写的,还不错。
    先看图
    1218439794-2087

    sancho可以自动加载mldonkey的core [1] 如图
    1218439798-1567
    Read the rest of this entry »

    Written by lebannen

    Monday, August 11, 2008 at 16:00

    Posted in Macintosh

    Tagged with , ,

    Tips on Building aMule.app on Mac

    leave a comment »

    aMule是跨平台的,早先有2.1.3的官方编译版本,后来一直只提供源代码,没有Bin

    aMule 的主页为 http://www.amule.org/
    Aug 08, 2008 发布了2.2.2版。
    源代码下载地址:

    ed2k://|file|aMule-2.2.2.tar.bz2|4669549|9E0CA7FA56560B079E92D1D47CD3FF4E|/
    or
    http://www.amule.org/files/download.php?file=172

    当然你也可以从svn下载最新的snapshot的代码。[1]
    编译amule可以参考官方的wiki_en [2] (没有中文啦~)
    也可以参考macx.cn上的一个帖子《要玩就玩最新的amule》 [3]
    编译之前,你需要先安装一下工具和lib

    1. Xcode
    2. MacPorts (非必须,但可以帮助解决安装库依赖,当然牛人都是手动的。。)
    3. 需要提一下libupnp,新版aMule似乎支持UPnP, 并要求其版本>=1.6.6

    有MacPorts的就
    $ sudo port -d install libupnp
    即可
    编译aMule时加上参数 --with-libupnp-prefix=/opt/local/include/libupnp
    不安装libupnp的话,UPnP在编译的时候自动disable

    4. 其他需要安装的库,参见[2] 和 [3]

    wxMac只需make 无需make install. 当然记住存放wxMac的目录。编译aMule时要用到。

    等前期工作都做完,就可以编译aMule了。
    cd到aMule所在目录

    
    ./configure --disable-systray --disable-gtk --enable-mbedded_crypto \
    --with-wx-config=../wxMac-2.8.7/build/wx-config --enable-cas \
    --enable-webserver --enable-amulecmd --enable-optimize \
    --with-crypto-prefix=/usr/local/cryptopp/ --enable-profile --enable-wxcas \
    --enable-alc --enable-alcc --disable-rpath --enable-amulecmdgui \
    --enable-amule-daemon --enable-webservergui \
    --with-libupnp-prefix=/opt/local/include/upnp/
    

    以上是我在configure时的选项。[3]
    Read the rest of this entry »

    Written by lebannen

    Monday, August 11, 2008 at 15:30

    Posted in Macintosh

    Tagged with , , , ,

    SMPlayer.app on Leopard

    leave a comment »

    I would say nothing more about SMPlayer’s introduction, but just one sentence, ‘the best front-end of MPlayer in linux, based on Qt’.

    The initial purpose of porting smplayer to Mac OS X Leopard is that, no video player satisfied me, even, it would be more troublesome when playing those videos with subtitles. For instance, changing subtitles in VLC is rather messy, and the display of subtitles is ugly, when default. I even didn’t know how to configure it and make it better. I don’t like QuickTime. It seems to stream video to cache, but works slowly on my macbook, especially when using the optical driver. Playing high quality video would be probably slide. In addition, I could not find where to configure or display the subtitle in MPlayer OSX’s preference, and what’s worse, it didn’t support .flv format even.

    SMPlayer intends to be a complete front-end for MPlayer, from basic features like playing videos, DVDs, and VCDs to more advanced features like support for MPlayer filters and more.

    smplayer does not provide the OS X version yet. And the project holders did not have the plan to do it, although there exists smplayer for Windows. Building or compiling smplayer is simple, when you have installed qt for mac.

    MacPorts provides qt4-mac port. so, open your Terminal:
    $sudo port -d build qt4-mac

    Or just package it:
    $sudo port -d pkg qt4-mac

    Also, you can just install it, when .pkg is not needed:
    $sudo port -d install qt4-mac
    Read the rest of this entry »

    Written by lebannen

    Tuesday, June 17, 2008 at 23:39

    Posted in Macintosh

    Tagged with , ,