Fork me on Github

LiangWenke

Is a web developer with Ruby on Rails and jQuery


query oracle cursor sql

Created at 2012-02-07 15:06:19
Tags oracle database Category Database
select sid, count(sid) cc from v$open_cursor where user_name='USER' group by sid order by cc desc;
select * from v$open_cursor where user_name='USER' and sid=1043;

Getting Started with Rails on Mac Lion 10.7

Created at 2012-01-08 19:11:29
1. Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
2. Install Git and sqlite
brew install git sqlite
3. Install RVM
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
4. Install Ruby and Rails
Notice: Xcode Version 4.2.x for OS X Lion works only for ruby 1.9.3-p0 (or higher)

rvm install 1.9.3 --with-gcc=clang
rvm use 1.9.3 --default

gem install rails
http://railscasts.com/episodes/310-getting-started-with-rails?view=asciicast

Install PostgreSQL with Homebrew on Mac OS

Created at 2011-11-20 19:29:33
1) Install PostgreSQL
brew install postgresql
2) Init Database
initdb /usr/local/var/postgres
3) Run/Stop Database
pg_ctl -D /usr/local/var/postgres
Or
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start &amp;

Start manually with:
  pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

And stop with:
  pg_ctl -D /usr/local/var/postgres stop -s -m fast
4) Create a Database
createdb mydb
5) Open the mydb database
psql mydb

中英文混合字符串截取

Created at 2011-11-18 16:58:56
Tags ruby rails Category Ruby
rails truncate方法把一个中文作为和英文相同的长度来截取,使用同样的length参数,会导致截取的英文字符串比中文字符串在视觉上短很多, truncate_u方法是把一个中文大约视为2个英文的宽度
def truncate_u(text, length = 30, truncate_string = "...")
  l=0
  char_array=text.unpack("U*")
  char_array.each_with_index do |c,i|
    l = l+ (c<127 ? 0.5 : 1)
    if l>=length
      return char_array[0..i].pack("U*")+(i1 ? truncate_string : "")
    end
  end
  return text
end

truncate_u("english string", 2)  
# 截取2个中文字宽,所以是返回4个英文加上"..."  
# => engl...  
  
truncate_u("中文字符串", 2)  
# => 中文...  
  
truncate_u("中文 and english", 6)  
# 截取6个中文字宽,所以是返回2个中文,8个ascii字符,以及truncate_string  
# => 中文 and eng ...  
  
truncate_u("中文 and english", 8)  
# 完整截取,返回和输入一致的字符串  
# => 中文 and english  
转载自http://www.iteye.com/topic/201531

oracle函数中文排序

Created at 2011-11-17 15:58:15
按照拼音、部首、笔画排序功能
Tags database oracle Category Database
拼音
SELECT * FROM TEAM ORDER BY NLSSORT(排序字段,'NLS_SORT = SCHINESE_PINYIN_M')   
笔划
SELECT * FROM TEAM ORDER BY NLSSORT(排序字段,'NLS_SORT = SCHINESE_STROKE_M')
部首
SELECT * FROM TEAM ORDER BY NLSSORT(排序字段,'NLS_SORT = SCHINESE_RADICAL_M')
转载自 http://zhuguo-guo.iteye.com/blog/1153335

解决rails应用程序使用Oracle数据库数据出错乱码问题

Created at 2011-11-03 18:18:13
在/etc/profile或其它配置文件加上如下内容:
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.UTF8"(or NLS_LANG=AMERICAN_AMERICA.UTF8)

install ruby gem without rdoc and ri

Created at 2011-09-26 13:42:13
install gem without rdoc and ri
just add following line to file ~/.gemrc
gem: --no-rdoc --no-ri

Install ruby with RVM on MAC readline or compiles error

Created at 2011-09-23 15:24:18
Tags ruby rails rvm Category Ruby on Rails
install ruby 1.9.2 have compiles 32 bit error
to resolve it, before installing the ruby add following line to file ~/.rvmrc
rvm_archflags="-arch x86_64"
install ruby 1.8.7 or ree have readline error
rvm package install readline
rvm install 1.8.7(or ree) -C --with-readline-dir=$rvm_path/usr
OR
ruby extconf.rb --with-readline-dir=$rvm_path/usr
make clean
make
rvm install 1.8.7(or ree) -C --with-readline-dir=$rvm_path/usr

select duplicate records by sql

Created at 2011-09-22 14:54:57
Tags database sql Category Database
select id, count(*) from users group by id having count(*) > 1

产品设计摘录

Created at 2011-09-20 09:48:33
Tags design Category Design
产品和业务模式,市场和运营策略,用户体验和界面设计都必须围绕着用户进行,且三者缺一不可,必须融为一体.产品设计是一份综合性工作,只做好任何一块都不会成变好的产品.

互联网的竞争:粗放型综合化竞 > 精细型分庭抗拒 > 开放,协作,分享. 得入口者得天下 > 得平台者得天下 > 得用户者得天下.

产品设计所有的过程必须都把用户放在第一位.