12/16/2011

synchronize between your git and svn repository

'git svn' is good to help on this,
if you don't have a git repository yet, you could get a cloned git
repository right from your svn repository by running this following command
git svn clone [YOUR-SVN-REPOSITORY-URL]
if you've got a git repository in hand, just try
git svn init [YOUR-SVN-REPOSITORY-URL]
this may help you set the 'svn-remote' of your git repository

after any of above two steps, you could simply use these commands to
synchronize between your git and svn repository:
git svn fetch
git svn rebase
git svn dcommit

12/08/2011

custom email when generating new ssh public/private key pairs

in your shell:
ssh-keygen -t rsa -P "" -C <your email address>

11/13/2011

how to enable AIRDROP on your old mac

just a simple command to go:
defaults write com.apple.NetworkBrowser BrowseAllInterfaces 1
restart your Finder, or your mac, there you have it!

11/04/2011

Rspec won't run - Error: In `bin_path': can't find executable spec for rspec-2.x (Gem::Exception)

here is a useful tip for people who just migrate from rspec 1.x to 2.x
first of all, the 'spec' command was renamed to 'rspec' in 2.x.
if you're still able to run it, that may because the 1.x gem is still
on your system, it's just "hidden" by bundler when you specify 2.x in
your 'Gemfile'
in this case, you may use the 'rake spec' command instead
for people who are working with outdated projects suffering from this
problem, you can fix this error by doing:
'which spec'
then open that file in your favorite file editor and change line 11
which looks like
version = '>= 0'
TO
version = '< 2'
and your spec command will work again :)

10/26/2011

Sharing session under sub-domains in ruby on rails

this could be done by just add the content below to your
RAILS_ROOT/config/initializers/session_store.rb file
ActionController::Base.session = {
:key => 'YOUR_KEY',
:secret => 'YOUR_SECRET',
:expire_after => 180.minutes,
:domain => '.DOMAIN_NAME.com'
}

10/25/2011

app to sd card for android focusing on the Huawei S7

Note: this how to expects some unix or gnu/linux know how.

Things that need to be done before starting.

Have the Android SDK installed (or droidexplorer if you're on windows for adb, as I've got the sdk this howto uses adb on the command line.)

Root the device. This goes without saying, Z4Root is recommend.

Install busybox, this could be done by simple download a busybox installer from the android market

Step 1: Prepairing the SD card.

Note: I have an 8gb sd card, so my examples use this in mind.

Using which ever partitioning program you wish to use, create two partitions on your sd card.

Partition 1 is 7GB and is fat 32 formatted.
Partition 2 is 1GB and is not formatted (we will do this later on the device.)*

*in my case I've mucked up and my ext2 partition is only 400Mb

Now place the sdcard back into the device and boot.

We need to make an ext2 file system on the second partition. This is done via the command line on
the device. So fire up the adb shell

./adb shell

Type the command su to get root privilages, then type the following command:
busybox mke2fs /dev/block/vold/179:2
This will output some data. Once done on the second partition we now have an ext2 file system.

Once this is all done the SD Card is ready.

Step2: Mounting the card, and moving data to the card.

For this step we need to mount the /system partition as read write as this partition is normally
mounted read only. To do this run the following command:
mount -o rw,remount -t yaffs2 /dev/block/mtdblock1 /system
mkdir /system/sd
Then we need to mount the ext2 partition and we can do this via this command:
mount -t ext2 /dev/block/vold/179:2 /system/sd
We need to now copy the data from the data directory to the ext2 partition, as we want to preserve
permissions we're going to use the command tar (cp can preserve partitions, but I've had more issues
with cp not working correctly in busybox I prefer tar:
cd /data/
tar -cvf /system/sd/app.tar app
tar -cvf /system/sd/data.tar data
tar -cvf /system/sd/dalvik-cache.tar dalvik-cache

cd /system/sd

tar -xvf app.tar
tar -xvf data.tar
tar -xvf dalvik-cache.tar

rm *.tar

Step 3: scripts and cleanup.

To mount the ext2 filesystem at boot, we need two scripts. These both go into /system/etc

The first one is called install-recovery.sh and contains the following:
#!/system/bin/sh
#
/system/etc/init-sd.sh&

The next is called init-sd.sh and contains the following:

#!/system/bin/sh
#
MYLOG=/data/install-recovery.log
echo "$(date) Starting install-recovery.sh" > $MYLOG
echo "$(date) Waiting SD to become ready..." >> $MYLOG
sleep 10
mount -t ext2 /dev/block/vold/179:2 /system/sd 1>>$MYLOG 2>>$MYLOG
mount -o bind /system/sd/app /data/app 1>>$MYLOG 2>>$MYLOG
mount -o bind /system/sd/data /data/data 1>>$MYLOG 2>>$MYLOG
mount -o bind /system/sd/dalvik-cache /data/dalvik-cache 1>>$MYLOG 2>>$MYLOG
mount >> $MYLOG
echo "$(date) Finishing install-recovery.sh" >> $MYLOG
now you need to use a decent text editor (I like vi) on windows I reccomend notepad++

copy both of these into /system/etc

for example:

cp /sdcard/install-recovery.sh /system/etc
cp /sdcard/init-sd.sh /system/etc

Now we need to make sure these files are executable with the following commands:
chmod 755 /system/etc/install-recovery.sh
chmod 755 /system/etc/init-sd.sh
Finally, we need to remove everything in the existing /data/app /data/data/ and /data/dalvik-cache
with the following commands:
cd /data/app
busybox rm -rf *
cd /data/data/
busybox rm -rf *
cd /data/dalvik-cache
busybox rm -rf *
now you will notice some odd things happening on the screen of your tablet but that will be fixed
with the command:
reboot
and if all went well you now have all your applications on the sdcard.

9/23/2011

IPSEC/L2TP VPN with OSX client: xl2tpd reports “maximum retries exceeded”

set up a vpn server for my own use, everything went just fine at the beginning,
but these days vpn dial-in don't work on my Mac OS X client, every
time I'm trying to connect my vpn the OS X client keep saying "can not
make connection to the server blah blah.."
here is my server side info:
Ubuntu 10.04 server
IPSEC supported by openswan: Linux Openswan U2.6.23/K2.6.32-317-ec2 (net key)
L2TP supported by xl2tpd v1.3.0
after the connection get failed, I found there's something like this
in my auth.log:
......

Sep 22 16:07:36 ip-xx pluto[14024]: "L2TP-PSK-NAT"[16] 114.xx.193.xx
#57: transition from state STATE_QUICK_R0 to state STATE_QUICK_R1
Sep 22 16:07:36 ip-xx pluto[14024]: "L2TP-PSK-NAT"[16] 114.xx.193.xx
#57: STATE_QUICK_R1: sent QR1, inbound IPsec SA installed, expecting
QI2
Sep 22 16:07:36 ip-xx pluto[14024]: "L2TP-PSK-NAT"[16] 114.xx.193.xx
#57: transition from state STATE_QUICK_R1 to state STATE_QUICK_R2
Sep 22 16:07:36 ip-xx pluto[14024]: "L2TP-PSK-NAT"[16] 114.xx.193.xx
#57: STATE_QUICK_R2: IPsec SA established transport mode
{ESP=>0x0687f589 <0x85b637f3 ......="......" dpd="none}" natd="114.xx.193.xx:4500" natoa="none" pre="pre" xfrm="AES_256-HMAC_SHA1">
it seems like the client made the ipsec connection successfully, so I
tried to restart the xl2tpd server with the "-D" parameter, then I got
the error like this:
.....
xl2tpd[17006]: Listening on IP address 0.0.0.0, port 1701
xl2tpd[17006]: control_finish: Peer requested tunnel 16 twice,
ignoring second one.
xl2tpd[17006]: control_finish: Peer requested tunnel 16 twice,
ignoring second one.
xl2tpd[17006]: Maximum retries exceeded for tunnel 28197. Closing.
xl2tpd[17006]: Connection 16 closed to 114.xx.193.xx, port 53911 (Timeout)
xl2tpd[17006]: control_finish: Peer requested tunnel 16 twice,
ignoring second one.
xl2tpd[17006]: Unable to deliver closing message for tunnel 28197.
Destroying anyway.
xl2tpd[17006]: control_finish: Peer requested tunnel 16 twice,
ignoring second one.
xl2tpd[17006]: Maximum retries exceeded for tunnel 4768. Closing.
xl2tpd[17006]: Connection 16 closed to 114.xx.193.xx, port 53911 (Timeout)
xl2tpd[17006]: Unable to deliver closing message for tunnel 4768.
Destroying anyway.
.....
I tried google the error message then got this article: http://serverfault.com/questions/178309/ipsec-l2tp-vpn-with-osx-client-xl2tpd-reports-maximum-retries-exceeded saying that just need to add the following lines to the conn L2TP-PSK-noNAT section of ipsec.conf:
leftnexthop=%defaultroute
rightnexthop=%defaultroute
now my vpn works great!


8/23/2011

MySQL with ruby on rails on Mac OS X Lion

1, download a 64bit version of mysql for mac at
http://dev.mysql.com/downloads/mysql/
2, install mysql
3, add the following into your .bash_profile:
export PATH="$PATH:/usr/local/mysql/bin"
export ARCHFLAGS="-arch x86_64"
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
4, install mysql gem by this command:
gem install -mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

when I was doing all this, I forgot to export the DYLD_LIBRARY_PATH,
and either for the fourth step, I got the following error when running
'rake db:create':
Couldn't create database for {"reconnect"=>false, "encoding"=>"utf8",
"username"=>"root", "adapter"=>"mysql", "database"=>"xxx",
"host"=>"127.0.0.1", "pool"=>5, "password"=>"xxx",
"socket"=>"/tmp/mysql.sock"}, charset: utf8, collation:
utf8_unicode_ci (if you set the charset manually, make sure you have a
matching collation)

hope this may help you :)

8/19/2011

Way to switch your ruby gem version

Here is a common way to upgrade or downgrade your ruby gem
just two simple commands:

1, sudo gem install rubygems-update -v THE_VERSION_YOU_WANT
this will download and install a specified version of ruby gems
2, sudo update_rubygems
this will execute the ruby gems update script to actually update
your ruby-gems

7/15/2011

Command for network state and details

On Windows: netstat -an
On Linux: netstat -tnlp

7/07/2011

Little useful commands of linux

grep is for grep out some line from an input, for some specified keywords

lsof will give you a list of the running processes maps to their ports
which are using

kill is for killing a process, with paramater "-9 [PROCESS_NAME]"

ps will handle the process listing job, often be used with "aux" parameters

3/03/2011

在 Mac OS X Leopard 10.5.6 上安装配置 Oracle 10.2.0.4

第一个步骤自然是下载 Oracle Database 10g Release 2 (10.2.0.4.0) for MAC OS X on Intel x86-64 ,然后解压缩。URL: http://www.oracle.com/technetwork/database/10204macsoft-x86-64-092720.html

之后就是为安装Oracle建立用户组和用户。一般需要建立一个安装用户组oinstall,一个DBA用户组dba,用户oracle,它们都应当具有admin组的权限。在官方文档和一些帖子里都是推荐用dscl增加用户,这需要root权限。更简单的方法就是在系统偏好设置——账户里添加。记得确保该用户的shell是/bin/bash
# dscl . -append /users/oracle shell /bin/bash

安装过Linux平台Oracle的可能知道Oracle对组件和Java环境有一些要求。Leopard上就简单很多,只需要安装DVD里自带的Xcode(当然也可以下载最新版本),并将Java 1.4.2环境放到Java应用程序第一优先顺序就可以了。[MAC OS X 10.6以后没有了1.4.2,后续需要修改一些内容,将在方括号中提示]

下面就是准备系统内核参数了。这里建议大家还是开启root用户。在应用程序——实用工具——目录实用工具——编辑中启用。命令行su到root用户,然后建立/etc/sysctl.conf:
kern.sysv.shmmax=1073741824
kern.sysv.shmall=2097152
kern.maxfiles=65536
kern.maxfilesperproc=65536
kern.maxproc=2068
kern.maxprocperuid=2068
net.inet.ip.portrange.first=1024

重新启动系统就生效了。其他参数在Leopard(10.5.6)下不用更改。具体还可以参考安装文档(在下载的db.zip里就有)。特别提醒一点,如果真的完全按照安装文档上进行修改,有可能会出现这个错误:
TNS-01114: LSNRCTL could not perform local OS authentication with the listener
TNS-01115: OS error 22 creating shared memory segment of 127 bytes with key xxxxxxx
这个问题困扰了我很久,最后进行广泛搜索,受到一个Linux安装求助贴的启发,将kern.sysv.shmmin重新修改为1,就恢复了(文档上要求修改为4096)。

继续看文档,又会发现IPServices是找不到的,不管了,改/etc/rc.common咯,在最后增加:
ulimit -Hu 2068
ulimit -Su 2068
ulimit -Hn 65536
ulimit -Sn 65536

现在把db.zip解压的文件夹放到oracle用户下,并chown给oracle,su – oracle。给自己建立一个.bash_profile吧,可以参照下面内容设定环境参数:
ORACLE_BASE=/Users/oracle/oracle
ORACLE_SID=macora
ORACLE_HOME=/Users/oracle/oracle/product/10.2.0
PATH=/usr/local/bin:/Users/oracle/oracle/product/10.2.0/bin:$PATH
export ORACLE_BASE
export ORACLE_SID
export ORACLE_HOME
export PATH
DYLD_LIBRARY_PATH=$ORACLE_HOME/lib
export DYLD_LIBRARY_PATH
DISPLAY=127.0.0.1:0
export DISPLAY
ulimit -Hn 65536
ulimit -Sn 65536
export NLS_LANG="AMERICAN_AMERICA.UTF8"

如果最后不设置DISPLAY,就会在启动runInstaller的时候报错,提示无法创建窗口。如果不设置DYLD_LIBRARY_PATH就会在创建数据库中提示没有监听器等错误。这些参数需要重启shell环境生效,比如重新su – oracle。



到这里基本就完成了准备工作,命令行进入目录,运行./runInstaller[10.6以后,请手工修改runInstaller,将其中的/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2改为/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0。另一种解决思路是

sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0 /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2
./runInstaller -J-d32

。后面就和其他平台安装一样了,安装到最后,需要开一个窗口以root权限运行$ORACLE_HOME/root.sh。

安装完成之后可以安装client.zip

安装后配置
(1)如果你的网络配置使用的是DHCP
修改\oracle\product\10.2.0\db_1\network\admin目录下的tnsnames.ora文件
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)

对应的listener.ora也要做相应的更改
可以直接 netca 来配置, netmgr运行不起来不知道为什么

如何指定'listener.ora'存放的目录?不要默认目录($ORACLE_HOME/network/admin)
方法: 在 '.profile' 中加入(例)
TNS_ADMIN=/f01/oracle11/app/oracle/product/8.0.6/network/admin
export TNS_ADMIN


sqlplus连接: sqlplus "/ AS SYSDBA"


[最后补充10.6一些问题:
如果链接时遇到调用目标 ‘all_no_orcl ipc_g ihsodbc32' 错误,那么不要退出安装程序,直接打开终端,修改文件$ORACLE_HOME/rdbms/lib/ins_rdbms.mk,用#号注释掉$(HSODBC_LINKLINE)开头的行,然后返回安装程序,点击 “Retry”。

Java GUI工具(NETCA和DBCA)运行时也可能出错。那么修改 $ORACLE_HOME/jdk/bin/java脚本,将"java -Xbootclasspath…"改成"java -d32 -Xbootclasspath…"

安装时还可能提示ORA-3113错误,此问题Raimonds Simanovskis通过提供补丁文件解决了。

cd $ORACLE_HOME/bin
curl -O http://rayapps.com/downloads/oracle_ee.zip
unzip oracle_se.zip
chmod ug+s oracle
rm oracle_se.zip

]

2/24/2011

今天开了个巨长无比的会! 居然饿到晚上8点多才让走, 简直是绑架
屋里真热-.-
希望午饭不是面条, 阿弥驼佛!