macports换axel下载
MacPorts
只要你最近一直在用Linux的主流发行版本(Ubuntu、Fedora、Debian、Gentoo等等),或者有过BSD使用经验,一定对*nix平台上的软件包管理机制不陌生。不管是Apt-get、rpm、pkg等等,对于普通用户的体验来说,都是一键安装(一条命令)软件,不用考虑不同软件之间复杂的依赖关系,也不用考虑去哪儿下载软件比较靠谱,更不用担心软件的自动更新问题。依托开源社区的强大支持,海量软件随用随装。
Mac作为BSD系统商业化的最成功代表,继承了BSD系统稳定、可靠的传统和特性,但没有经过调教的Mac OS X不是为程序员而定制的。这和乔帮主一贯的产品设计理念是分不开的:苹果的产品能够让一个小学二年级教育文化水平的人,无需说明书即可开始使用。程序员嘛,受教育文化水平肯定是要高于小学二年级教育文化水平的。所以,程序员需要控制台,用键盘的时间要多于用鼠标。非程序员,不需要控制台,最好连键盘都不要用到。
MacPorts可以看做是BSD系统上的ports机制在苹果系统上的移植版本,关于MacPorts的安装,如果你是用的Snow Leopard或者其他较新的苹果系统版本的话,官方网站上提供了直接可用的二进制dmg版本,下载双击安装即可。
下面重点介绍安装好MacPorts后的几个关键环节:
MacPorts改良
MacPorts的默认安装版本(1.9.2)有两个对于我来说非常不爽的“缺陷”:
不支持多线程下载
下载过程没有任何进度提示
经过一段时间的hack之后,我找到了上述两个问题的改良方法。
搜索curl
新增:
set currentTTy [exec "tty"] |
把其中的代码换成以下
if {![catch {system "/opt/local/bin/axel -n 10 -o ${distpath}/${distfile}.TMP $file_url > $currentTTy"} result] && ![catch {file rename -force "${distpath}/${distfile}.TMP" "${distpath}/${distfile}"} result]} { |
如果报错了就用下面这个吧
[catch {system "/opt/local/bin/axel -n 20 -o ${distpath}/${distfile}.TMP $file_url"} result]
上述代码使用axel,20线程并发下载。根据自己的网速情况,可以增加或减少并发线程数。只要下载速度还可以,就别设置太多并发下载线程了,为服务器节约点带宽给其他人用,呵呵。
看官看到这里请注意了,axel不是系统默认中就有的,正好可以先通过安装axel来体验一把给力的MacPorts。
MacPorts速成
以上述axel安装为例来体验MacPorts。
首先是更新MacPorts的本地软件列表
$ sudo port selfupdate
然后是在MacPorts中查找是否有axel这个软件
$ port search axel
axel @2.4 (net, www)
A light Unix download accelerator
安装
$ sudo port install axel
MacPorts安装软件的过程可以简单分为:下载代码、编译代码、安装二进制程序、配置程序,实际的安装软件过程还包含代码依赖性问题的解决过程。
关于MacPorts的常用命令,我整理了一个列表,如下:
更新port: port selfupdate
升级port里面的所有软件包:port -d sync
查询port里面是否有该软件:port search xxx
用port安装某软件:port install xxx
查看port里面的软件是否有升级:port outdated
查看某个软件是否有升级:port outdated xxx
升级某个软件: port upgrade xxx
升级某个软件(不升级依赖软件): port -n upgrade xxx
升级所有能升级的软件: port upgrade installed
禁用某个软件(但不删除): port uninstall xxx
彻底清除某个软件: port clean –all xxx
查看某个软件的详细信息:port info xxx
查看某款软件的备注信息:port notes xxx (例如启动dbus的方法:port notes dbus)
查看软件在系统上安装了哪些文件:port contents xxx
查看已安装的软件列表:port installed [xxx]
查看软件的可选安装组件或编译参数:port variants xxx
以安装curl为例:
$ port variants curl
curl has the variants:
ares: Add support for resolving names asynchronously
gnutls: Allow secure connections using GNU TLS
* conflicts with ssl
gss: Support the Generic Security Service API
openldap: Support performing Lightweight Directory Access Protocol queries with
OpenLDAP
sftp_scp: Add SFTP/SCP support via libssh2
spnego: Enable SPNEGO authentication support
[+]ssl: Allow secure connections using OpenSSL
universal: Build for multiple architectures
有[+]的选项表示非默认组件或编译参数,如果需要安装或启用则需要在安装时显式的指定,如:
$ sudo port install curl +ssl
sql 2008 清除日志脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | use master go ALTER DATABASE [edupress.news] SET RECOVERY SIMPLE WITH NO_WAIT use [edupress.news] go select name from sys.database_files where type_desc = 'log' DBCC SHRINKFILE([shedunews_log], 1) USE [master] GO ALTER DATABASE [edupress.news] SET RECOVERY FULL WITH NO_WAIT |
[HOWTO] Build OpenWRT Trunk from svn on Mac OS X
I recommend following these steps
1) Install XCode & Macports
2) Getting a build environment ready
3) Grabbing sources
4) Modifying Makefiles (e2fsprogs really doesn't like 64-bit Lion, and qemu refuses to compile)
5) Installing the missing dependancies
6) Building OpenWRT (from Updating Feeds on)
1. XCode & Macports
a. You will need to install Xcode 4.0 from the Apple developers' webpage, which will redirect you to the App Store entry for Xcode where you will follow the instructions on that page to install.
b. Then, grab the latest MacPorts .pkg installer for Lion.
Mount the disk image and install MacPorts with the .pkg file. Open the Terminal.app from /Applications/Utilities
sudo port -v selfupdate && sudo port install subversion
Follow these directions if the above command does not work after mounting the dmg and installing.
Then:
port select --list gcc
Should give you an output similar to
air:~ alex$ port select --list gcc
Available versions for gcc:
apple-gcc42
gcc42
llvm-gcc42
mp-gcc44 (active)
none
I do not believe the version of gcc matters, but if it does, here's how to replicate my set up:
sudo port install gcc44 && sudo port select --set gcc mp-gcc44
Don't follow the above step unless you run into trouble later in the HOWTO when we try to compile OpenWRT. The above command will build gcc-4.4 from scratch and that takes time. A lot of time.
2. Set up the build environment
a. Now install the packages needed to manipulate the OpenWRT source (horizontal scroll to see entire command, its long):
sudo port install coreutils asciidoc binutils bzip2 fastjar flex getopt gtk2 intltool jikes zlib openssl p5-extutils-makemaker python26 rsync ruby sdcc unzip gettext libxslt bison gawk autoconf wget gmake ncurses
While this is compiling the packages for your system, continue on to 2b and 3a since they don't depend on any of the above packages.
b. The OpenWRT source is case-sensitive, unfortunately HFS+ drives formatted by Apple are not set to be case-sensitive; so we're going to create a .sparseimage workspace by opening Disk Utility in the /Applications/Utilities directory.
Click File -> New -> Blank Disk Image...
On the top of the dialog that just came up fill in "OpenWRT" without the quotes in the Save As: field and in the lower Name: field.
Choose a size larger than 3GB. My disk image is ~8G and will reach it's limit after compiling the packages and firmware images more than a few times.
IMPORTANT: In the Format: drop down, select Mac OS Extended (case-sensitive)
In the Image Format: drop down select "sparse disk image". Then click Create. The newly created disk image will be on the left panel of the Disk Utility, double clicking it will mount it on /Volumes/OpenWRT
3.Grabbing the source tree
a. Open the Terminal and type:
cd /Volumes/OpenWRT && svn co svn://svn.openwrt.org/openwrt/trunk/
Give it a few minutes while it pulls the source from the repository.
4. Modifying Makefiles
Open TextEdit.app and open /Volume/OpenWRT/trunk/tools/Makefile
cd /Volume/OpenWRT/trunk && open tools/Makefile
On line 17 erase the "e2fsprogs entry so it should look like this:
tools-y += sstrip ipkg-utils genext2fs mtd-utils mkimage
Comment out line 22 like so:
#tools-$(CONFIG_TARGET_x86) += qemu
Then go on to comment out line 50, line 52, line 58; they are the build dependencies for mtd-utils (dep: e2fsprogs), qemu (dep: e2fsprogs), and e2fsprogs respectively.
5. Installing the missing dependencies
Now let's install and copy MacPort's e2fsprogs and osso-uuid's libraries and headers so we can build tools/mtd-utils correctly
sudo port install e2fsprogs osso-uuid
Followed by:
cd /Volumes/OpenWRT/trunk;
mkdir -p staging_dir/host/include/e2fsprogs;
cp -R /opt/local/include/ossp staging_dir/host/include/e2fsprogs/;
cp /opt/local/lib/libuuid* staging_dir/host/lib
Then follow this manual on how to build OpenWRT now that you have successfully built the necessary tools to compile OpenWRT images on Mac OS X 10.7 Lion.
Start from the section titled "Updating Feeds" and follow the wiki in it's entirety. Do not select any 'qemu' entries when you reach the make menuconfig step; qemu will not build on 64-bit Lion.
fixed gevent/libevent.h:9:19: error: event.h: No such file or directory on mac os
1 2 3 4 | sudo port install libevent CFLAGS="-I /opt/local/include -L /opt/local/lib" pip install gevent 如果上述方法还是不行,请下载gevent源码解压后 sudo python setup.py install -I /opt/local/include/ -L /opt/local/lib |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 以下内容可忽略。。。。 sudo easy_install python_memcached sudo easy_install mysql-python brew install pil brew install gevent sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib sudo easy_install pil sudo easy_install sqlobject sudo easy_install apnswrapper |
1 | sudo easy_install sqlalchemy |
1 | sudo pip install mysql-python |
1 | wget http://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.4c1.zip#md5=a05925412cd824104da064db6a889613 |
1 | unzip -d ./ MySQL-python-1.2.4c1.zip |
1 | vi setup_posix.py |
1 | mysql_config => /usr/local/mysql/bin/mysql_config |
1 |
生成APNS Service证书的步骤
要进行推送服务的第一件事就是获取推送证书。它用来对你通过SSL与APNS通讯进行识别。
在Mac上生成 Apple推送通知SSL证书:
- 登录到 iPhone Developer Connection Portal 并点击 App IDs
- 创建一个不使用通配符的 App ID 。通配符 ID 不能用于推送通知服务。例如,我们的iPhone程序ID像这样: AB123346CD.com.serverdensity.iphone
- 点击App ID旁的“Configure”,然后按下按钮生产 推送通知许可证。根据“向导”指导的步骤生成一个签名并上传,最后下载生成的许可证。此步骤在 Apple文档中 也有谈到。
- 通过双击.cer文件将你的 aps_developer_identity.cer 引入Keychain中。
- 在Mac上启动 Keychain助手,然后在login keychain中选择 Certificates分类。你将看到一个可扩展选项“Apple Development Push Services”
- 扩展此选项然后右击“Apple Development Push Services” > Export “Apple Development Push Services ID123”。保存为 apns-dev-cert.p12 文件。
- 扩展“Apple Development Push Services” 对“Private Key”做同样操作,保存为 apns-dev-key.p12 文件。
- 需要通过终端命令将这些文件转换为PEM格式:
openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12 openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12
- 如果你想要移除密码,要么在导出/转换时不要设定或者执行:
openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem
- 最后,你需要将键和许可文件合成为apns-dev.pem文件,此文件在连接到APNS时需要使用:
cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem
将此文件保存为一个易记的名字,你有可能以后会用到它。上述步骤同样适合于生成产品证书。
OS X Mountain Lion下Eclipse+opencv的C++开发编译环境配置
1.下载源码编译安装opencv
http://opencv.org/
我下载的是2.4.3 for Linux/Mac版本,编译环境需要cmake,可通过brew进来安装
1 2 3 4 5 | cd OpenCV-2.4.3 mkdir build cmake -G "Unix Makefiles" .. make -j8 sudo make install |
opencv的库到此已经安装完成,接下来开始配置eclipse
新建一个c++的空白项目,从opencv源代码的samples/cpp目录下复制drawing.cpp到项目里,然后试一下编译,看看会不会人品爆发编译成功:)
先看一下我的项目结构,main.cpp是我自己把文件名改了,无所谓了
选中项目,按command+i键,进入项目属性对话框
设置完毕后应该可以编译了,还有错误的话根据错误提示慢慢找原因吧。
opencv识别物体,初步实验结果
【转】如何用摄像头来测距(opencv)
最近一直忙着找工作,blog都长草了,今天把以前作的一个东西放上来充充门面吧。记得在哪看到过老外做的这个东西,觉得很好玩,就自己也做了一个。在摄像头下面固定一个激光笔,就构成了这个简易的测距装置。看一下图吧。
原 理
假设激光束是与摄像头的光轴完全平行,激光束的中心落点在在摄像头的视域中是最亮的点。激光束照射到摄像头视域中的跟踪目标上,那么摄像头可以捕捉到这个点,通过简单的图像处理的方法,可以在这侦图像中找到激光束照射形成的最亮点,同时可以计算出Y轴上方向上从落点到图像中心的象素的个数。这个落点越接近图像的中心,被测物体距离机器人就越远。由下图图可以计算距离D:
(1)
等式中h是一个常量,是摄像头与激光发射器之间的垂直距离,可以直接测量获得。


{
public:
struct RangeResult * GetRange(IplImage * imgRange,IplImage * imgDst);
LaserRange();
virtual ~LaserRange();
unsigned int maxW;
unsigned int maxH;
unsigned int MaxPixel;
RangeResult * strctResult;// Values used for calculating range from captured image data
const double gain; // Gain Constant used for converting pixel offset to angle in radians
const double offset; // Offset Constant
const double h_cm; // Distance between center of camera and laser
unsigned int pixels_from_center; // Brightest pixel location from center
};
{
maxW=0;
maxH=0;
MaxPixel=0;pixels_from_center=0;
// Brightest pixel location from center
strctResult->maxRow=0;
strctResult->maxPixel=0;
strctResult->Range=0.0;
}
{
if(NULL!=strctResult) delete strctResult;
}
{
if(NULL==imgRange) return strctResult;
Preprocess(imgRange,imgDst);pixels_from_center = abs(120-maxH);
strctResult->Range= h_cm/tan(pixels_from_center * gain + offset);strctResult->PixfromCent=pixels_from_center;
strctResult->maxCol=maxW;
strctResult->maxRow=maxH;
strctResult->maxPixel=MaxPixel;
//strctResult->Range=0.0;
return strctResult;
}
{
MaxPixel=0; //处理下一帧前 最大像素值清零;
IplImage* image = reinterpret_cast<IplImage*>(img);cvCvtPixToPlane( image,0 ,0 ,imgTemp , 0);
for( int j=((imgTemp->width-60)/2-1); j<(imgTemp->width-40)/2+59; j++)
{
for(int i=5; i<imgTemp->height-5; i++)
{
if((imgTemp->imageData[i*imgTemp->widthStep+j])>MaxPixel)
{
if( ((imgTemp->imageData[(i-1)*imgTemp->widthStep+j])>MaxPixel) && ((imgTemp->imageData[(i-1)*imgTemp->widthStep+j+1])>MaxPixel) &&((imgTemp->imageData[(i-1)*imgTemp->widthStep+j-1])>MaxPixel) )
{
if( ((imgTemp->imageData[(i+1)*imgTemp->widthStep+j])>MaxPixel) && ((imgTemp->imageData[(i+1)*imgTemp->widthStep+j+1])>MaxPixel) &&((imgTemp->imageData[(i+1)*imgTemp->widthStep+j-1])>MaxPixel) )
{
if((imgTemp->imageData[i*(imgTemp->widthStep)+j+1])>MaxPixel)
{
if((imgTemp->imageData[i*(imgTemp->widthStep)+j-1])>MaxPixel)
{
MaxPixel=imgTemp->imageData[i*imgTemp->widthStep+j] ;
maxW=j;
maxH=i;
}
}
}
}
}
}
}
{
// CvCapture* capture = 0;// capture = cvCaptureFromCAM(0); //0表示设备号
if( !capture )
{
fprintf(stderr,"Could not initialize capturing.../n");
return -1;
} // cvNamedWindow( "LaserRangeImage", 1 );
// cvvNamedWindow( "image", 1);
cvvNamedWindow( "Dimage", 1);
for(;;)
{
IplImage* frame = 0;
if(isStop) break;
if( !frame )
break;
{
//allocate all the buffers
imgOrign = cvCreateImage( cvGetSize(frame), 8, 3 ); //创建一副图像
imgOrign->origin = frame->origin;}
//cvShowImage("LaserRangeImage",imgOrign);if(!imgDest)
{
imgDest=cvCreateImage( cvSize( imgOrign->width,imgOrign->height),8,1);
cvZero( imgDest );
}
struct RangeResult * temp= laservsion.GetRange(imgOrign,imgDest);
cvLine( imgOrign,cvPoint(0,temp->maxRow), cvPoint(imgOrign->width,temp->maxRow),cvScalar(100,100,255,0),1,8,0);
// cvvShowImage( "image", imgOrign);
cvSaveImage("image.bmp", imgOrign);cvvShowImage( "Dimage", imgDest);
//在PictureBox上显示图片
CDC* pDC = GetDlgItem(IDC_Picture)->GetDC();
CDC dcmemory;
BITMAP bm;
dcmemory.CreateCompatibleDC(pDC);
CBitmap* pBmp;
CString szFileName = "image.bmp";
HBITMAP hBk = (HBITMAP)::LoadImage(NULL,szFileName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
if(NULL!=hBk)
{
pBmp=CBitmap::FromHandle(hBk);
pBmp->GetObject(sizeof(BITMAP), &bm);
dcmemory.SelectObject(pBmp);
pDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcmemory, 0, 0, SRCCOPY);
CDC *pDCp= GetDC();
char str2[80];
// Display frame coordinates as well as calculated range
sprintf(str, "Pix Max Value=%d At x= %u, y= %u, PixfromCent= %d",temp->maxPixel,temp->maxCol, temp->maxRow, temp->PixfromCent);
sprintf(str2, "Range= %f cm ",temp->Range);
pDCp->TextOut(30, 33, str);
pDCp->TextOut(50, 50, str2);
ReleaseDC(pDCp);
int c = cvWaitKey(10);
// if( c == 'q' )
// break;
//cvDestroyWindow("LaserRangeImage");
// cvDestroyWindow( "image");
cvDestroyWindow( "Dimage");
return 0;
}
Setup a Git server on Windows machine, with MSysGit and CopSSH(使用msysgit与copssh搭建基于windows的git服务器)
On Server Box
Be sure to install it to a folder without space in its name. I used C:\SSH. Then just press next until it finishes.
2. install MSysGit
net user git userspassword /add

d. Goto C:\SSH\home\git\.ssh folder, create a file named authorized_keys. Open this file using wordpad.

f. (Re)Start SSH Server. You can either reboot your PC, or use below command line:
net stop opensshserver
net start opensshserver
g. Now it's ready to test SSH connection. Invoke Putty.EXE, put localhost as host name, if you changed port in step c, don't forget to change it here. Navigate to Connection/SSH/Auth node, press the "Browse" button to select the private file you generated and stored in step e, as shown below:


h. invoke a command window if you have not (where have you executed those "net xxx" commands?), and type
cd /d %USERPROFILE%
echo export HOME=/c/SSH/home/git > .bashrc
i. goto C:\SSH\home\git folder, open the .bashrc file (yes, the same name as in the above line). Insert below line to the first line: (AGAIN, THIS IS A UNIX FILE!)
export PATH=/cygdrive/c/Git/bin:/cygdrive/c/Git/libexec/git-core:$PATH
goto C:\SSH\home\git and make a folder named test.git. Right click the folder and select "Git Bash" from context menu. (What? You did not choose the explorer integration? Goto start menu, find Git|Git Bash, and use command line to goto this folder). Then input below lines:
$ git init --bare
Initialized empty Git repository in C:/SSH/home/git/test.git/
Now the server setup is DONE. You might need a cup of coffee of a cake to ease your nerve.
On Client PC
2. Test connection, using Putty. Change the host name and port as in your environment. Don't forget the Connection | SSH | Auth node setting. Copy the private key file to client machine and point the file in this node. Then press "Open" button, you should find it similar to what you have experienced at step g above. But this time, after you logged in, you are actually logged in to another computer! After you logged in, type "git", and see if you have the familiar git help screen before you. If you see
-bash: git: command not found
then please check if you have step i done correctly.
3. Opne a command window, type
Then use windows explorer to open this folder. create a files (id_rsa.pub) if they don't exist.
4. Fire up PuttyGen.EXE again, load the private key you used at step 2. Paste the content of the text box to file id_ras.pub, and use menu "Conversions | Export OpenSSH key" to save to the folder you created at step 3, in name "id_rsa". Now the folder %USERPROFILE"\.ssh should have at least 2 files: id_rsa and id_rsa.pub
ssh git@your.remote.host "echo something"
input "yes" to accept the remote key. Then you should get an echo "something"

6. Now we are ready to clone the empty project we created at server
$ git clone ssh://git@tst/SSH/home/git/test.git
Initialized empty Git repository in D:/g/gt/test/.git/
warning: You appear to have cloned an empty repository.
Now you can make some change and push it back
Counting objects: 3, done.
Writing objects: 100% (3/3), 236 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://git@oti-tst/SSH/home/git/test.git
* [new branch] master -> master
Congratulations, you can clone and push back. It's not as hard as it sounds, after all 😀
