Bowen's Blog

Respect My Authorita.

Reset Commit Author

| Comments

在如下两种情况下,你需要重新配置git commit 的author。

  • 在一个新的repo上面工作;
  • 用别人的机器(或者pair machine上)提交代码,而关于你的author信息并未添加在git配置中;

假设你global git config ~/.gitconfg 中配置信息如下:

1
2
3
[user]
     name = example
     email = example@example.com

别人的机器(或者pair机器)的repo中git 配置信息如下:

1
2
3
[user]
     name = pair
     email = pair@pair.com

而你期望的提交信息为:

1
2
name = serious
email = serious@serious.com

在第一种情况下,当你修改完代码提交后,log中对应的author信息为:

1
Author: example <example@example.com>

在第二种情况下,当你修改完代码提交后,log中对应的author信息为:

1
Author: pair <pair@pair.com>

两种情况下,想要修改提交中的author信息,都可以通过:

1
git commit --amend --author=“serious <serious@serious.com>”

来重新设置。

第一种情况,如果你需要将来长期在这个repo上工作的话。首先,修改repo下的.git/config文件,添加

1
2
3
[user]
     name = serious
     email = serious@serious.com

然后重新设置提交的author信息:

1
git commit --amend -C HEAD --reset-author

Done

Ubuntu 12.04 Compile Ruby Enterprise Error Fix

| Comments

Recently I’ve been learn to use Vagrant. to set up a production like env under ubuntu 12.04. However, when I tried to compile REE- ruby enterprise version, I caught into the following error:

1
2
3
4
5
6
7
8
./libtool: line 983: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8)
src/tcmalloc.cc:1672:54: error: conflicting declaration 'void * (* __memalign_hook)(size_t, size_t, const void *)'
/usr/include/malloc.h:183:39: error: "__memalign_hook" has a previous declaration as 'void * (* volatile __memalign_hook) (size_t, size_t, const void *)'
src/tcmalloc.cc: In function 'void PrintStats(int)':
src/tcmalloc.cc:523:47: warning: ignoring return value of 'ssize_t write(int, const void *, size_t)', declared with attribute warn_unused_result (-Wunused-result)
src/tcmalloc.cc: In function 'void {anonymous}::ReportLargeAlloc(Length, void *)';
src/tcmalloc.cc:1010:47: warning: ignoring return value of 'ssize_t write(int, const void *, size_t)', declared with attribute warn_unused_result [-Wunused-result]
make: *** (libtcmalloc_minimal_la-tcmalloc.lo) Error 1

I dig a little throught google and it turns out to be a very easy solution. Just redefine the fucntion name

1
void *(* __memalign_hook) (size_t, size_t, const void *)

to be

1
void *(*  volatile  __memalign_hook) (size_t, size_t, const void *)

in the tcmalloc.cc src file . To declare it to be volatile type function can solve that issue and keep the compiling on. Actually, I could have found the reason because as to what the log says, the issue is pretty clear. Seems like I depend on google too much….. it’s not good.

Using Go Tutorial

| Comments

Just trying to use Go for I find it looks like C, and the cost of writing a hello world is quite small, plus the tutorial is petty easy to fetch. Just list what I’ve done to get the tutorial and write the hello world example, which already posted thousands time in the internet.

Install hg:

# brew install hg (mac)

#_ apt-get install mercurial (ubuntu)

Download go:

# wget https://go.googlecode.com/files/go1.0.3.darwin-amd64.tar.gz

#_ wget https://go.googlecode.com/files/go1.0.3.linux-amd64.tar.gz

Install go:

1
   *  tar -C /usr/local/ -zxf go1.0.3.darwin-amd64.tar.gz

Export path:

1
   * export PATH=$PATH:/usr/local/go/bin

Get go tutorial:

1
   * go get code.google.com/p/go-tour/gotour

Run go tour:

1
   *  gotour

After run the hello world program, you can leave this alone and declare that you can actually play with go now…………………….

Using Watch to Excecute Commands in Cycle

| Comments

项目的集成测试环境以及UAT环境都部署在亚马逊的虚拟云节点上面,早上9点之前,一个cron job会自动将这些节点启动。有时候会遇到当前可用的节点不足而导致节点创建失败, 需要不停的尝试启动节点的命令,看看什么时候运气垂青,碰到有其他节点被destroy时,可以抢到这样的“token”去启动我们的节点。 这个effort显然过大了,作为懒人是不能接受的,同事介绍了watch这个工具,它可以周期性的执行一个命令,同时将结果输出,轻松的解决了问题。

安装: 大部分的linux发行版应该都包括了这个应用,MAC下面需要自己安装,用brew也很方便。

+brew install watch+

用法介绍:

1
Usage: watch [-dhntv] [--differences[=cumulative]] [--help] [--interval=<n>] [--no-title] [--version] <command>

+-n, –interval = + : 设定相隔多长时间重新运行下监控的命令并输出结果 +-d, –differences[=cumulative]+ : 高亮显示监控的命令输出相比上次输出变化的区域 +-v, –version+ : 显示watch的版本号 注: mac 下的watch版本略低,0.3.0的版本提供了更多的功能,比如彩色输出,退出响铃之类的 使用场景:

watch 的帮助文档中,给出了一些使用的场景, 比如:

# 监控当前目录中某些用户的文件变化: @watch -d ‘ls -l | grep root’@

#_ 偷窥其他用户的窗口行为: @watch tty7@ (假设tty7有用户登陆)

能想到的还有一个,当时还想自己实现这样的一个脚本,后来看到watch,就放弃了……:

#_ 正在编辑haml文件,同时想在浏览器上面看到更改后的html文件: @watch -d ‘haml input.haml input.html’@

Way to Deal With "Transaction Log for Database Is Full" Issue

| Comments

Recently, the ci build has failed with the following error message:

1
2
3
_ODBC::Error: 37000 (9002) [unixODBC][FreeTDS][SQL Server]The transaction log for
database 'Warehouse' is full. To find out why space in the log cannot be reused,
see the log_reuse_wait_desc column in sys.databases (Sequel::DatabaseError)_*%

The reason is, so far as I known, that firstly the database has the log recorded and when the volume of log increasing, it would cause the “out of space” error if it exceeds the threshold of log size limit.

The knowledge that we should know is:

# Scheme of way to record transaction log is store in log_reuse_wait_desc # column of sys.databases, check “this”:http://msdn.microsoft.com/en-us/library/ms178534.aspx, it gives all the choices of how to deal with the transaction log

A little bit log for this document, I will just cut the cliche and show how I solve this issue with the knowledge I found from Internet.

Given our current build is using data warehouse “Warehouse” and such error happens

First thing is to connect to the data warehouse, and check whether the log is full by using DBCC tools.

Check log spaces used:

1
DBCC SQLPERF(LOGSPACE) //from the output information you can also see the log name of corresponding database

Then you will see the log size for “Warehouse” is 100% After knowing it is the right reason as the error message shows, we have two steps to go:

set the data warehouse into recovery mode and set the log_reuse_wait_desc using no backup for reserving logs

truncate the currently logs and shrink its size

Way to change the database recovery mode and set backup scheme:

1
2
3
4
5
USE Warehouse
GO
ALTER DATABASE Warehouse SET RECOVERY full
GO
ALTER DATABASE Warehouse SET RECOVERY SIMPLE WITH NO_WAIT

way to shrink the log file:

1
2
USE Warehouse
DBCC SHRINKFILE('Warehouse_log', 0, TRUNCATEONLY)

Then you will get new log scheme with no backup and a log size less than 1MB. Of course, the most important thing is that the ci build won’t fail….

Simple Introduction About Vimium and Some Comments

| Comments

Vimium 是Chrome下的一个插件,可以让你用类似vim的方式用全键盘的方式浏览网页。其所有快捷键如下(web页面下按?也可以查看):

Vimium Help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
vigating the page
j, <c-e>: Scroll down
k, <c-y>: Scroll up
h:the Scroll left
l: Scroll right
gg: Scroll to the top of the page
G:Scroll Scroll to the bottom of the page
zH: Scroll all the way to the left
zL: Scroll all the way to the right
d: Scroll a page down
u: Scroll a page up
r: Reload the page
gs: View page source
yy: Copy the current URL to the clipboard
yf: Copy a link URL to the clipboard
post: Open the clipboard's URL in the current tab
P: Open the clipboard's URL in a new tab
gu: Go up the URL hierarchy
i: Enter insert mode
gi: Focus the first (or n-th) text box on the page
f: Open a link in the current tab
F: Open a link in a new tab
<a-f>: Open multiple links in a new tab
o: Open URL, bookmark, or history entry
O: Open URL, bookmark, history entry, in a new tab
T: Search through your orpen tabs
b: Open a bookmark
B: Open a bookmark in a new tab
[[: Follow the link labeled previous or <
]]: Follow the link labeled next or >
gf: Cycle forward to the next frame on the page

查找:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/: Enter find mode
n: Cycle forward to the next find match
N: Cycle backward to the previous find match
Navigating history
H: Go back in history
L: Go forward in history
Manipulating tabs
K, gt: Go one tab right
J, gT: Go one tab left
g0: Go to the first tab
g$: Go to the last tab
t: Create new tab
x: Close current tab
X: Restore closed tab
Miscellaneous
?: Show help

觉得比较有用的几个快捷键:

  • 滚到网页底部和顶部: 和vim一样 G,gg
  • 向下(上)移一页: d/u (vim 得加 ctrl键)
  • 拷贝当前地址栏url: yy, chrome对应的快捷键是command + alt + c(- 但是最新的chrome不知道为什么和develop工具的快捷键冲突了)
  • 拷贝网页中某链接到剪贴板中:yf 之后选择你需要拷贝的链接,用 p键在当前页面打开,大P在新的tab中打开
  • 打开书签、地址或者历史记录: o/O在当前页面/新页面打开,如果只想打开书签中记录的url,可以用b/B
  • 查找模式: / 后输入搜索关键字,用n/N在搜索结果中向前或者向后查询,用的不多……,比浏览器默认的搜索稍微方便点
  • 查找tab: T,输入关键字,跳转到相关的tab,这个很方便
  • tab间移动: K/gt 移到右边的tab, J/gT移到左边的tab。不是很方便,一般都用浏览器默认的快捷键,shift+tab或者是alt+command+方向键
  • 创建/关闭/恢复前一个关闭掉的tab: t/x/X, 用的也不多,浏览器默认的快捷键用习惯了

使用vimium有好处也有不好的地方,我自己的使用感觉如下:

好处:

系统无关,在任何系统下只要是使用chrome浏览器,不需要再去记忆快捷键; 对于键盘控来说,无疑是一个好东西,比默认的浏览器快捷键要强大,基本可以免去触摸板和鼠标操作;

坏处:

页面如果没有load, vimium也不会被加载,所有的快捷键也都失效了,这个时候还是需要浏览器默认的快捷键才可以继续撸键盘; 有时候vimium的js会和某些页面的js冲突,比如googlereader页面,而且在浏览器上调试的时候如果遇到js冲突还是挺讨厌的, 这种情况就得禁用vimium; Firefox下据说有更强大的工具,叫做vimoperator,听说功能更加强大,不过我基本只用,所以没怎么尝试过。Anyway,如果你只相信啪啪啪的,可以试试这个插件。

How Source Works Under Shell

| Comments

Well, it’s a fare long story.During the trainning, Aimee asked me a question about how the source command works under shell. Haven’t done a deep search at that time though it does not seem like a tough question. Now, i figure out how this stuff work, but the trainning is over and Aimee is gone.

It’s really simple for the function of source. It helps the current shell reload the variables from script file so that they could be recongnized.In another word–read and execute commands from the filename argument in the current shell context. Let’s just cut the crap and try some examples.

1
2
3
touch test.sh
chmod +x test.sh
vi test.sh

And input the following content

1
A = "shit happens"

We just define an variable named A in the script file. ok,let’s run this script with

1
sh test.sh && echo $A

which will show nothing even shit because it creates a new subshell and the invariables created in the subshell will not show in the parent shell. Then you use

1
2
source test.sh
echo $A

now you can see the shit by yourself.

So? What’s the difference between source and .?Well,basically, they are the same. Instead of using source, you can use . test.sh to get the same effect of using source even the file test.sh is not executable.It is said that use .test.sh means execute the hidden file, definetly not working on osx.

Introduction of Virtualenv

| Comments

什么是 virtualenv: virtualenv 是一款用来创建隔离的Python开发环境的工具,有点类似ruby下的rvm.通过virtualenv,可以为不同的python项目定制所需要的环境.

OSX下安装的过程: 本来想自己写,但是这位阿三哥写的太好了,就节省下体力……: “猛击这里”:http://blog.praveengollakota.com/47430655 OSX系统自带的python版本是2.6,而我们开发使用的版本是2.7,直接升级很容易,但是其中有些配置会稍微麻烦一些。 主要的步骤:

安装 Python 2.7

_ 下载 easy_install,安装对应python2.7的 easy_install:

@sh setuptools-0.6c11-py2.7.egg@

_ 使用easy_install 安装 pip, pip是一个python下的包管理工具:

@easy_install pip@

_ 使用pip 去安装 virtualenv 以及 virtualenvwrapper :

1
2
pip install virtualenv
pip install virtualenvwrapper

_ 配置 .bashrc/.bash_profile 文件使得 virtualenvwrapper 的命令可以在bash下运行:

1
2
3
mkdir ~/.virtualenv
export WORKON_HOME=$HOME/.virtualenvs
source /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh

之后 source ~/.bash_profile ,就可以在命令行中使用 vritualenvwrapper 中的命令了.

如何使用virtualenv:

创建一个虚拟环境:

mkvirtualenv test

_ 查看当前的虚拟环境的列表:

workon

_ 使用某一个虚拟环境:

workon test

之后就回看到shell的提示符前面出现了环境的名称,这里就可以大胆的去做各种环境配置了,用pip去安装所有你需要的python包。 想退出的话,可以直接 command + d 或者用 deactivate 命令即可.

Invalid Gemspec Because of the Date Format in Specification

| Comments

In the morning, i was writing a automation sql script for QA. And after move the source file from mac mini to my machine. It met such warning as i tried to run the file.

1
Invalid gemspec in [/Users/twer/.rvm/gems/ree-1.8.7-2011.03@development/specifications/childprocess-0.2.1.gemspec]: invalid date format in specification: "2011-08-11 00:00:00.000000000Z"

It’s ok because it’s just warning. But i am just a little bit agnoied by the message. So i decided to kill this warning message. After search in google, i found the answer.

And the steps should be:

1
/Users/twer/.rvm/gems/ree-1.8.7-2011.03@develoment/specifications/childprocess-0.2.1.gemspec
  • Find the spec that is causing the problem, search it in vi with string “2011” and i found that line.
  • Change s.date = %q{2011-08-11 00:00:00.000000000Z} to s.date = %q{2011-08-11}

Cool, done, no more bothering information.

Mysql--on Duplicate Key Update

| Comments

On duplicate key update is to stop the duplication in unique index or primary key, and try to update the row with new value.And it only functions with mysql because it is not standard SQL grammar.

Create database and choose it

1
2
3
4
mysql> create database test;
Query OK, 1 row affected (0.00 sec)
mysql> use test;
Database changed

Create a table with primary key

1
2
mysql> create table pet(a CHAR(1), b CHAR(1), primary key(a));
Query OK, 0 rows affected (0.06 sec)

And initialize a row

1
2
mysql> insert into pet values('1', '2');
Query OK, 1 row affected (0.00 sec)

insert new value with the same primary key

1
2
mysql> insert into pet values('1', '3');
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'

drop primary key property

1
2
3
mysql> alter table pet drop PRIMARY KEY;
Query OK, 1 row affected (0.06 sec)
Records: 1  Duplicates: 0  Warnings: 0

insert again, cool, done

1
2
mysql> insert into pet values('1', '3');
Query OK, 1 row affected (0.00 sec)

what we have now? values with duplicated key

1
2
3
4
5
6
7
mysql> select * from pet;
+---+------+
| a | b    |
+---+------+
| 1 | 2    |
| 1 | 3    |
+---+------+

change the primary key back

1
2
3
mysql> alter table pet add primary key(b);
Query OK, 2 rows affected (0.11 sec)
Records: 2  Duplicates: 0  Warnings: 0

insert the value with on duplicate key update

1
2
mysql> insert into pet values('4', '3') on duplicate key update a = values(a);
Query OK, 2 rows affected (0.00 sec)

the result:

1
2
3
4
5
6
7
8
mysql> select * from pet;
+---+---+
| a | b |
+---+---+
| 1 | 2 |
| 4 | 3 |
+---+---+
2 rows in set (0.00 sec)