IceskYsl@1sters!

程序员…

Archive for the ‘技术归总 | Technic’ Category

安装gem:

[root@iceskysl]# gem install spreadsheet –no-ri –no-rdoc
Successfully installed ruby-ole-1.2.10.1
Successfully installed spreadsheet-0.6.4.1
2 gems installed

[root@iceskysl]# gem install spreadsheet –no-ri –no-rdocSuccessfully installed ruby-ole-1.2.10.1Successfully installed spreadsheet-0.6.4.12 gems installed

使用:

require ‘rubygems’

require ‘spreadsheet/excel’

SUM_SPREADSHEET = ‘test.xls’

workbook = Spreadsheet::Excel.new(SUM_SPREADSHEET)

worksheet = workbook.add_worksheet(‘Random numbers and their sum.’)

# sum = 0

# random_numbers = (0..9).collect { rand(100) }

#

# puts “random_numbers=#{random_numbers.size}”

# worksheet.write_column(0, 0, random_numbers)

# worksheet.write_column(0, 1, random_numbers)

worksheet.update_row 4, ‘Hannes Wyss’, ‘Switzerland’, ‘Author’

row = worksheet.row(1)

row.push ‘Creator of Ruby’

row.unshift ‘Yukihiro Matsumoto’

# format = workbook.add_format(:bold => true)

# worksheet.write(10, 0, “Sum:”, format)

# worksheet.write(10, 1, random_numbers.inject(0) { |sum, x| sum + x })

workbook.close

参考:

http://sg552.javaeye.com/blog/701428

http://sunfengcheng.javaeye.com/blog/240130

  • 0 Comments
  • Filed under: Ruby&Rails
  • ruby文件操作大全

    参考:

    http://pleac.sourceforge.net/pleac_ruby/filecontents.html

    ruby文件操作大全 http://www.javaeye.com/topic/517410

    用ruby读写文本文件 http://www.albertsong.com/read-87.html

    Ruby 读取目录(Diretories),文件(files), 网页的几个方法小结

    http://weixuhong.com/rubyruby-on-rails/2008/10/06/ruby-%E8%AF%BB%E5%8F%96%E7%9B%AE%E5%BD%95%EF%BC%88diretories%EF%BC%8C%E6%96%87%E4%BB%B6files-%E7%BD%91%E9%A1%B5%E7%9A%84%E5%87%A0%E4%B8%AA%E6%96%B9%E6%B3%95%E5%B0%8F%E7%BB%93/

  • 0 Comments
  • Filed under: Ruby&Rails
  • Ruby on Rails 3 的相关资料

    1.Rails 3.0 Release Notes – Rails导册对所有Ruby on Rails开发者来说都是很宝贵的资源,这个发布文档介绍了很多API的改进和新特性。

    2.RailsPlugins.org – 提供了很多 Rails 3的插件.

    3.Having Ruby on Rails 3 My Way – Rails 3与Mongoid, Haml, jQuery等的安装

    4.The Rails Module (in Rails 3) -在Rails模块中一些有用的方法

    5.Rails 3 I18n changes – I18n的改变.

    6.Ruby on Rails 3 Screencast series

    ActionController / Rack

    7.Embracing REST with mind, body and soul - José Valim 介绍了 RESTful responders与Rails 3 controller的使用。

    8.Railscasts #224 Controllers in Rails 3 – Rails 3 controllers的新特性.

    9.Render Options in Rails 3 –  Rails 3的渲染的变化.

    10.Adding Routes for tests / specs with Rails 3

    11.32 Rack Resources to Get You Started –  rack相关资源的整合.

    ActionMailer

    12.New ActionMailer API in Rails 3.0 - 如何使用新的ActionMailer.

    13.A Whole New ActionMailer –  ActionMailer的特性.

    ActiveRecord/ActiveModel

    14.ActiveModel: Make Any Ruby Object Feel Like ActiveRecord – ActiveModel的模块化.

    15.Railscasts #219 Active Model - 如何正确的添加ActiveModel 模块到tableless模块.

    16.ActiveRelation: ActiveRecord Gets a Facelift -新的ActiveRecord finder API.

    17.Active Record Query Interface – 自Rails 2以来,ActiveRecord query接口的变化.

    Bundler

    18.Gembundler.com -官方的 Bundler文档,包含一些扩展的文档.

    19.Library Management Gets an Update in Rails 3

    20.Railscasts #201 Bundler - 在Rails 3中,如何使用bundler.

    21.AdventuresInCoding.com screencast on Bundler

    Railties

    22.Rails 3 Internals: Railtie & Creating Plugins –  Railties in Rails 3.

    23.rails-templater – 如何生成一个 greenfield Rails 3 应用.

    24.Making generators for Rails 3 with Thor – 如何使用新的generators ,以及在gem中如何去处理.

    Routes

    25.The Lowdown on Routes in Rails 3 -在 Rails 3创建routes的几个不同的方法.

    26.Rails Routing from the Outside In - 新的 router介绍.

    Plugins

    27.Plugin Authors: Toward a Better Future – Rails 3中创建插件的改变.

    28.Customizing Rails Apps with Plugins - 使用responders, form, devise以及mail form的插件.

    29.Devise 1.1 is out and ready to rock with Rails 3 – Devise 1.1的新特性。

    Books

    30.Beginning Rails 3 – Cloves Carneiro Jr 和 Rida Al Barazi 撰写的 Rails 3 入门书籍,其中有很多实例.

    31.The Rails 3 Way .

    32.Rails 3 In Action - BDD with Cucumber

    33.Rails 3 Upgrade Handbook – Jeremy McAnally的书籍,教你如何从Rails 2 应用升级到Rails 3.

    34.Ruby on Rails Tutorial: Learn Rails by Example – 一步一步的教学习 Rails.

  • 0 Comments
  • Filed under: Ruby&Rails
  • malformed format string on rails~

    在rails中使用find进行模糊查询时,出现了malformed format string输入为字符)或非法字符(输入为数字)的提示。
    (1) @vendors  = Vendor.find(:all,:conditions=>[@sql])
    (2) @vendors = Vendor.find_by_sql(“select * from vendor where “+@sql)
    错误发生在按(1)方式查询过程中,采用(2)方式可以避免这个错误,这间接说明了find_by_sql确实相当不安全。
    查阅了一下资料,对于这个问题的说法如下:Rails uses sprintf (%) on the inside. So, Escape your % with %,因此只要将模糊查询的地方一个百分号全部换成两个便可以解决问题。

  • 0 Comments
  • Filed under: Ruby&Rails
  • ChartsOnRails

    这几天需要找到漂亮的Charts类库,找了几个,发现一个很不粗的,mark下待使用,介绍如下:

    Highcharts is a charting library written in pure JavaScript, offering an easy way of adding interactive charts to your web site or web application. Highcharts currently supports line, spline, area, areaspline, column, bar, pie and scatter chart types.

    有兴趣的可以参考如下连接去看看:

    http://highcharts.com/

    http://railscasts.com/episodes/223-charts

    http://www.spritle.com/blogs/?p=859

  • 1 Comment
  • Filed under: Ruby&Rails
  • Munin LogoIf your running Munin in WHM they you may have noticed the passive netstat connections have been rising steadily over the last couple of weeks. This isn’t a problem with your server, its a Munin bug that can be easily fixed.

    Passive netstat  connection - Munin

    Apparently the problem stemms from Munin counting the passive connections rejected. You can fix this problem quite easily by following the instructions below

    Edit the following file:
    /usr/share/munin/plugins/netstat

    and change the line

    netstat -s | awk ‘/active connections/ { print “active.value ” $1 } /passive connection/ { print “passive.value ” $1 } /failed connection/ { print “failed.value ” $1 } /connection resets/ { print “resets.value ” $1 } /connections established/ { print “established.value ” $1 }’
    to
    netstat -s | awk ‘/active connections/ { print “active.value ” $1 } /passive connection openings/ { print “passive.value ” $1 } /failed connection/ { print “failed.value ” $1 } /connection resets/ { print “resets.value ” $1 } /connections established/ { print “established.value ” $1 }’

    ref:

    http://markmaunder.com/2008/how-to-fix-munins-netstat-passive-connections-increasing-constantly/

    http://www.silverark.co.uk/knowledge/hosting/fix-the-passive-netstat-connections-in-munin

  • 0 Comments
  • Filed under: *UNIX & Mac, Tips
  • def parse_rails_log_file(file)
      # Remove all empty lines
      lines = file.each_line.map(&:strip).reject(&:empty?)
    
      # Use +Enumerable#slice_before+ to slice log file into sections for each request
      lines.slice_before(/Started (GET|POST|PUT|DELETE)/).each_with_object({}) do |request_log, totals|
        # Only include successfully finished actions in report
        if duration = request_log.last[/Completed 200 OK in (?<duration>\d+)ms/, :duration]
          action_name = request_log.first[/Started (GET|POST|PUT|DELETE) "(?<action>.+?)" for/, :action]
          totals[action_name] ||= 0
          totals[action_name] += duration.to_i
        end
      end
    end
    
    if __FILE__ == $PROGRAM_NAME
      require "pp"
      puts "Parsing Rails 3 log file (extracting cumulative running time per request path):"
      puts "================="
    
      log_file = <<-LOG_FILE
      Started GET "/index" for 192.168.74.1 at 2010-03-09 11:37:40
        Processing by UpdatesController#index as HTML
        Update Load (0.5ms)  SELECT `updates`.* FROM `updates` ORDER BY created_at DESC
      Rendered updates/index.html.erb (16.7ms)
      Completed 200 OK in 71ms (Views: 44.3ms | ActiveRecord: 0.5ms)
    
      Started POST "/updates" for 192.168.74.1 at 2010-03-09 11:37:43
        Processing by UpdatesController#create as HTML
        Parameters: {"commit"=>"Save changes"}
        Update Load (0.4ms)  SELECT `updates`.* FROM `updates` ORDER BY created_at DESC
      Rendered updates/index.html.erb (1.3ms)
      Completed 200 OK in 60ms (Views: 32.1ms | ActiveRecord: 0.4ms)
    
      Started GET "/updates" for 192.168.74.1 at 2010-03-09 11:45:51
        Processing by UpdatesController#index as HTML
    
      TypeError (exception class/object expected):
        app/controllers/updates_controller.rb:3:in `raise'
        app/controllers/updates_controller.rb:3:in `index'
    
      Rendered /usr/local/rvm/gems/ruby-1.9.2-head/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.6ms)
      Rendered /usr/local/rvm/gems/ruby-1.9.2-head/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.9ms)
      Rendered /usr/local/rvm/gems/ruby-1.9.2-head/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within /usr/local/rvm/gems/ruby-1.9.2-head/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb (23.9ms)
    
      Started GET "/updates" for 192.168.74.1 at 2010-03-09 11:45:58
        Processing by UpdatesController#index as HTML
        Update Load (0.3ms)  SELECT `updates`.* FROM `updates` ORDER BY created_at DESC
      Rendered updates/index.html.erb (1.1ms)
      Completed 200 OK in 100ms (Views: 29.3ms | ActiveRecord: 0.3ms)
      LOG_FILE
    
      pp parse_rails_log_file(log_file) # => {"/index"=>71, "/updates"=>160}
    end
  • 0 Comments
  • Filed under: Ruby&Rails
  • MO,MT,Linkid的关系

    做移动互联网的过程中,有这样一些词是必须知道的,如MO,MT,GSM,LINKID
    上行(MO)上行的意思就是短信发送到服务器端 MO又称 Mobile Original
    下行(MT)下行的意思就是短信从服务器端发回到手机上,MT又称Mobile Terminated
    简单的说,从手机发起一个的过程叫上行(MO),到手机结束的过程叫下行(MT),比如,平时给你的朋友发送一条短信,对你来说就是上行(MO),而对你的朋友来说,就是下行(MT)。在企业、行业应用中,从系统给手机发送信息的过程叫下行(MT),而手机发送信息给系统的过程叫上行(MO)。

    所有用户点播的业务,用户MO(上行)消息通过网关送到MISC鉴权批价后,MISC会自动生成一个随机数linkid随后通过网关传给SP,当SP收到MO(上行)消息后下发MT(下行)消息给用户时必须在Submit包的linkid字段填上MO(上行)消息包里面带的linkid信息(Reserve值:设定的回复内容)。

  • 0 Comments
  • Filed under: Tips
  • http://www.eoeandroid.com/attachments/month_1006/100628151169669bb4f7b7d8c5.jpg
    2010年6约27日,周日下午,由CSDN和《程序员》杂志联合策划组织,旨在与业界人士分享IT产品背后的技术和用户体验故事的线下活动TUP(Technology, User Experience, Product)系列活动日前在北京丽亭华苑酒店成功举办,首期活动以“移动开发实践”为主题。
    受CSDN&《程序员》总编刘江邀请,我去分享了自己对android方面的一些体会和心得,本来预期200人参加的活动,从wudi那边看到报名的有500多人,最终选了300多人参与了活动,场面还是比较火爆的,到处站的都是人,CSDN在国内技术圈还是有不错影响力的;
    活动从下午1电30分正式开始,刘江主持,介绍了TUP的核心价值,然后我是第一个演讲的,我和大家分享的题目是《Google Android盈利模式探析及其应用突围之道》,和大家分享了android目前的市场;可行的一些盈利模式,我的观点是现阶段,广告和应用中收费(注意不是收费应用)是两个比较成熟的模式,除此之外还有做平台,做培训,咨询等等模式可以尝试;借着和大家分享了应用突围之道,举了两个例子,说明如何让你的应用在众多应用中脱颖而出(分析数据很重要),最后和大家分享了android的发展趋势,我个人觉得android终端多元化,终端网络化的趋势很明显,那么带来的就是应用的巨大需求(个性化,国际化,本地化的),从而使得android人才缺口非常大。
    从大家的提问和会后的交流来看,很多人还是比较迷茫的,对现况的迷茫,对市场的迷茫,比如国内外大大小小的软件商店很多人就看不明白,原因很简单,看到的都是表表象,透过表象,把握住本质就很清晰了。
    比较冏的是名片带少了,后来给不少人手工写了联系方式,本来后面还有个互动交流的环节,由于临时有些事情,没来得及参加就撤退了,有些遗憾。
    今天各大媒体的报道都出来,看到基本商都是用的我topic里的一个观点“andoid应用突”》做为报道点,希望大家能顺利突围!

  • 1 Comment
  • Filed under: Android
  • TEXT fields in MySQL

    MySQL TEXT fields have a limit of 65,000 bytes. If you insert anything larger than that in to a normal TEXT field mySQL will silently truncate your data without telling you (meaning software checks are probably a good idea). MEDIUMTEXT will store 16 million characters and LONGTEXT can handle over 4 trillion, but this information does not appear to be readily available in the online mySQL manual (although it is hinted at in this table). Something to bare in mind when designing database applications.

    MyISAM tables in MySQL have a maximum size of a row of 65,535 bytes, so all the data in a row must fit within that limit. However, the TEXT types are stored outside the table itself and only contribute 9 to 12 bytes towards that limit. (For more information about this refer to the MySQL Manual – Data Storage Requirements chapter).

    ref::http://www.electrictoolbox.com/maximum-length-mysql-text-field-types/
    TEXT data types are also able to store much more data than VARCHAR and CHAR text types so TEXT types are what you need to use when storing web page or similar content in a database.

    The maximum amount of data that can be stored in each data type is as follows:

    TINYTEXT 256 bytes
    TEXT 65,535 bytes ~64kb
    MEDIUMTEXT 16,777,215 bytes ~16MB
    BIGTEXT 4,294,967,295 bytes ~4GB
    In most circumstances the TEXT type is probably sufficient, but if you are coding a content management system it’s probably best to use the MEDIUMTEXT type for longer pages to ensure there are no issues with data size limits.

  • 0 Comments
  • Filed under: Mysql
  • Page::页面

    Calendar::日历

    September 2010
    M T W T F S S
    « Aug    
     12345
    6789101112
    13141516171819
    20212223242526
    27282930  

    RSSTwitter: iceskysl