一个人的天堂
nnnnon · 共 67 篇文章
mac下图片批量处理
转自 https://github.com/zhasm/scripts/raw/master/resize.py #!/usr/bin/python # -*- coding: utf-8 -*- # #author: rex #blog: http://iregex.org #filename resize.py #created: 2011-01-05 21:35 import re from sys import exit from optparse import OptionParser from os.path import abspath from os.path import …
2011-01-07 19:56 · python django学习 · 评论(0)
计算字符串长度
计算含有中文字符串的长度(同时展示如何修改已有的类) class String def count i=0 self.scan(/./u){|t| i += 1} i end end s="世界,你好!malijun" puts s.count
2010-11-05 21:18 · RORs · 评论(0)
git使用
http://hi.baidu.com/i7521/blog/item/1223883dbae09b0ebba1674a.html 具体可简化: ssh-keygen -t rsa -C "xxx@gmail.com" 将.ssh/id_rsa.pub拷贝到GitHub网站 #ssh git@github.com 如果配置正确,显示 ERROR: Hi xxx! You've successfully authenticated, but GitHub does not provide shell access Connection to github.com closed. git con…
2010-11-04 11:21 · RORs · 评论(0)
很棒的目录递归处理
原来一直是通过自己实现递归调用来处理目录,今天在《RubyProgramming》一书中看到,在ruby中居然是有专门的库“find.rb”来实现这个功能的,非常强大。 一个例子代码: require "find" IGNORES = [/^\./] #以.开头的目录不进行处理 def listdir(top) Find.find(top){ |path| if FileTest.directory?(path) dir,base = File.split(path) IGNORES.each{ |re| if re =~ base Find.prune #和next相比是整个目录都不处理,…
2010-11-03 21:54 · RORs · 评论(1)
使用railswhere插件
地址: http://code.google.com/p/railswhere/ 在dos窗口项目目录下:ruby script/plugin install http://railswhere.googlecode.com/svn/tags/railswhere 实例: @properties = Property.find(:all, :conditions => Where{|w| w.and "apply_number like ?", "%#{params[:apply_number]}%" if params['c_apply_number'] w.and "creator li…
2010-11-02 16:49 · RORs · 评论(0)
paperclip 上传文件(解决中文文件无法上传问题)
在新项目中使用了paperclip这个文件上传插件,一切都很满意,但是对于它不能自定义文件名就比较郁闷了,一直想实现这个功能,不过一直没时间去看paperclip的源代码(其实因为懒)。 我说的自定义文件名,不是网上多数教程所说的修改文件存储的文件夹路径,打个比方,我上传了一个叫做 test.gif 的文件,服务器上存储的文件的文件名同样是 test.gif ,而我希望是系统随机地指定一个文件名给上传的文件,我希望在服务器上存储的文件名不是原来的 test.gif,而是 2010070100000.gif 这种由我指定的文件,这样可以统一文件,防止用户上传的文件是一些乱七八糟的名字,而且我们…
2010-11-02 16:44 · RORs · 评论(0)
Rails 2.3.5 gem update (dependency errors fixed)
I recently updated my rails gem and realised i was getting errors trying to create new rails projects in 2.3.5, below is the error i was getting. /Library/Ruby/Site/1.8/rubygems.rb:827:in `report_activate_error’: RubyGem version error: rack(1.0.0 not ~> 1.0.1) (Gem::LoadError) from /Library/Ruby/Si…
2010-01-21 09:33 · 评论(0)
中文ruby
# encoding: utf-8 out=File.open("out.txt","w") 会议={ 主题:"科学发展观", 地点:"教务处二楼会议室" } 会议[:时间]="3月12日下午两点" 会议.each do |参数,值| out.write "#{参数} 是 #{值}\n" end 会议.delete(:地点) 会议.each do |参数,值| out.write "#{参数} 是 #{值}\n" end 会议[:地点]="教务处小会议室" 会议.each do |参数,值| out.write "#{参数} 是 #{值}\n" end 测试了一下1.9.1中的hash表现,…
2009-05-25 16:06 · RORs · 评论(0)
Excel获取汉字拼音[自定义函数]
Function PinYin(Hz As String) Dim PinMa As String Dim MyPinMa As Variant Dim Temp As Integer, i As Integer, j As Integer PinMa = "a,20319,ai,20317,an,20304,ang,20295,ao,20292," PinMa = PinMa & "ba,20283,bai,20265,ban,20257,bang,20242,bao,20230,bei,20051,ben,20036,beng,20032,bi,20026,bian,20002,biao…
2009-04-23 21:59 · 生活 · 评论(0)
朋友是什么?
Many people will walk in and out of your life, But only true friends will leave footprints in your heart. To handle yourself, use your head; To handle others, use your heart. Anger is only one letter short of danger. If someone betrays you once, it is his fault; If he betrays you twice, it is your …
2009-01-03 13:32 · 生活 · 评论(0)
导入数据到sqlite中
sqlite> .separator \t sqlite> .show echo: off explain: off headers: off mode: list nullvalue: "" output: stdout separator: "\t" width: sqlite> .import cet cet sqlite>
2008-12-05 15:58 · RORs · 评论(0)
用jruby操作excel
一、下载jruby二进制安装包,解压到相应的目录下,并将其bin目录添加到系统 的PATH变量中,则完成了安装; 二、安装java,完成安装后创建系统变量JAVA_HOME,把java的安装目录设为其值; 三、在dos窗口中运行jirb_swing,出现相应的界面,那么你的jruby就成功安装了; 四、下载jxl.jar,放到某一个目录下,并在系统的CLASSPATH变量中把它添加到其中; 五、现在就可以操作excel了,下面是一个简单的实例: require "java" include_class "jxl.Workbook" include_class "jxl.write.Label…
2008-11-28 20:39 · RORs · 评论(0)
狮子和老虎
一天,一头狮子在睡觉,突然一只老鼠开始在它的背上跳上跳下,很快吵醒了狮子。狮子抬起大爪子踩住老鼠,张开大口要吃掉它。 “求你别吃我,”小老鼠尖叫道:“原谅我这一次,我绝不会忘记:谁知道呢?也许哪天我会报答你呢?” 狮子被老鼠可能会帮他的想法逗乐了,他抬起爪子,放了它。 狮子被困在牢笼里一段时间后,使尽全力想要挣脱,但是绳子太结实了。正在这时,碰巧小老鼠路过这里,看见了狮子所处的悲惨困境。它跑上去,用锋利的小牙齿咬断了绳子,放了狮子。 “你曾经嘲笑过我,”老鼠说。“你以为我太小了不能行善报答你,但是,你瞧,全亏可怜的小老鼠你才拣条命。”
2008-11-10 16:45 · 生活 · 评论(0)
一个把紫光输入法的词库格式变为谷歌词库格式的ruby程序
outfile = File.new("out.txt","w") File.open(gets.chomp) do |file| file.each_line do |line| a,b,c=line.chomp.split(/\t/) outfile.write a+" "+c+" "+b+"\n" end end outfile.close
2008-10-11 20:52 · RORs · 评论(1)