4/27/2010

翻墙归来

自从国内被封,很久没来自己的blog了,这次终于回来了,活活

12/29/2009

b

b

in reference to: Google (view on Google Sidewiki)

5/01/2009

Install Anjuta for C.C++ development on Ubuntu 8.X

1 install anjuta


sudo apt-get install anjuta

2 install C/C++ enviroment and related packages

sudo apt-get install autogen automake build-essential indent intltool

3 install development documents

sudo apt-get install manpages-dev

4/29/2009

install ant and svn ant on ubuntu 8.X or later

1 install and config the ant(JRE has installed)


sudo apt-get install ant ant-optional
echo ‘ANT_HOME=”/usr/share/ant”‘ | sudo tee -a /etc/environment

2 download the svnant

firefox http://subclipse.tigris.org/svnant.html

3 unzip svnant-1.2.1.zip, and put lib/*.jar files to your ANT_HOME/lib directory
4 test it with the following build.xml


<?xml version="1.0"?>
<project name="svn-test" default="Main" basedir=".">
<!-- Sets variables which can be used. -->
<property name="checkout" location="./svncheckout" />
<!-- Define the classpath which includes the jars that are required for svnant.jar -->
<path id="svnant.class.path">
<pathelement location="lib/svnant.jar" />
<pathelement location="lib/svnClientAdapter.jar" />
<pathelement location="lib/svnjavahl.jar" />
<pathelement location="lib/svnkit.jar" />
</path>

<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="svnant.class.path" />


<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${checkout}" />
</target>

<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${checkout}" />
</target>


<!-- Checkout the latest source code of svnant itself-->
<target name="svn">
<svn username="guest" password="">
<checkout url="http://subclipse.tigris.org/svn/subclipse/trunk/svnant/" revision="HEAD" destPath="${checkout}" />
</svn>
</target>

<target name="Main" depends="clean, makedir, svn">
<description>Main target</description>
</target>
</project>



edwin@Castor:~/Desktop/svnTest$ ant
Buildfile: build.xml

clean:
[delete] Deleting directory /home/edwin/Desktop/svnTest/svncheckout

makedir:
[mkdir] Created dir: /home/edwin/Desktop/svnTest/svncheckout

svn:
[svn] started ...
[svn] finished.

Main:

BUILD SUCCESSFUL
Total time: 1 minute 58 seconds

Installing MySQL 5.1 on ubuntu 8.X or later using apt

First, you need to edit /etc/apt/sources.list and add the dotdeb repository. This is the line you need to add for Lenny, but just change it to Etch if you haven’t upgraded yet (see my earlier post if you want to know how to do that)


deb http://packages.dotdeb.org lenny all

Then, update…

apt-get update

And then install 5.1

apt-get install mysql-server-5.1

set password for root

sudo mysqladmin -u root password admin

4/26/2009

Tunnelling MySQL Over SSH On ubuntu

Context:
1 local PC
2 Remote PC IP:192.168.0.51
3 My SSH user name on remote PC is edwin

1 build a tunnel By ssh:
I will open a local TCP port 3333 for tunnelling mysql; The syntax of SSH is


ssh -L LOCAL_PORT:hostname:REMOTE_PORT USER_NAME@SERVER_NAME or IP_ADDRESS.

or with sshpass

sshpass -p 'YOUR_PASSWD' ssh -o StrictHostKeyChecking=no -L 3333:localhost:3306 USERNAME@REMORT_HOST -p 22

We're using localhost as the hostname because we are directly accessing the remote mysql server through ssh. You could also use this technique to port-forward through one ssh server to another server.

#ssh -L 3333:localhost:3306 edwin@192.168.0.51

2 Connect reomote mysql using mysql command

#mysql -u root -p -h 127.0.0.1 -P 3333

4/24/2009

Auto login script with expect on Ubuntu 9.04

1 install expect
sudo apt-get install expect
2 write shell script as the following:


#!/usr/bin/expect -f
# Expect script to supply root/admin password for remote ssh server
# and execute command.

# set Variables
set password "YOUR_PASSWORD"
set ipaddr "REMOTE_HOSTNAME"
set port 22

set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh $ipaddr -l root -p 22
match_max 100000
# Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof



3 save this file as edwin.ssh, and add X permission for it
4 use it

./edwin.ssh

Common Select usage:Where condation of datatime format for query rows

There are 8 different ways for select rows form table by filed formated as datatime

1. where date like '2005-01-%'
2. where DATE_FORMAT(date,'%Y-%m')='2005-01'
3. where EXTRACT(YEAR_MONTH FROM date)='200501'
4. where YEAR(date)='2005' and MONTH(date)='1'
5. where substring(date,1,7)='2005-01'
6. where date between '2005-01-01' and '2005-01-31'
7. where date >= '2005-01-01' and date <= '2005-01-31'
8. where date IN('2005-01-01', '2005-01-02', '2005-01-03', '2005-01-04', '2005-01-05', '2005-01-06', '2005-01-07', '2005-01-08', '2005-01-09', '2005-01-10', '2005-01-11', '2005-01-12', '2005-01-13', '2005-01-14', '2005-01-15', '2005-01-16', '2005-01-17', '2005-01-18', '2005-01-19', '2005-01-20', '2005-01-21', '2005-01-22', '2005-01-23', '2005-01-24', '2005-01-25', '2005-01-26', '2005-01-27', '2005-01-28', '2005-01-29', '2005-01-30', '2005-01-31')