Elvuel

善战者无赫赫之功

  • Home
  • Atom
  • About Elvuel

ejabberd mod_archive

辛卯[兔]年 十一月十一

以下配置在ubuntu下测试通过,使用PGSQL为存储数据库

Install ejabberd

apt-get install ejabberd

Checkout ejabberd modules

svn checkout https://svn.process-one.net/ejabberd-modules /usr/local/src/ejabberd-modules

Complie mod_archive

cd mod_archive/trunk

./build.sh

cp ebin/*.beam /usr/lib/ejabberd/ebin

Compile pgsql

cd pgsql/trunk

./build.sh

cp ebin/*.bea

read more >>

Tags: ejabberd mod_archive   Posted in Ruby & Rails

Capybara get session in cuke step

辛卯[兔]年 十一月初五

Capybara.current_session.driver.browser.current_session.last_request.env["rack.session"]["user_id"]

真的很长!

read more >>

Tags: capybara cucumber   Posted in Ruby & Rails

Juggernaut & Rails

辛卯[兔]年 八月初二

Juggernauthttps://github.com/maccman/juggernaut

安装配置

1. nodejs http://nodejs.org

获取 0.4.11稳定版

以下: sudo

wget http://nodejs.org/dist/node-v0.4.11.tar.gz

〉tar zxvfnode-v0.4.11.tar.gz

〉cd node-v0.4.11

〉./configure

〉make

〉make install

2. npm(需NODEJS 0.4以上版本)

以下: sudo

curl http://npmjs.org/install.sh | sh

安装模块

〉npm install socket.io

〉npm install redis

〉npm install optimist

〉npm install node-static-maccman

3. 安装并启动redis-server

〉redis-server /etc/redis/redis.conf

4. 启动 juggernaut

〉git clone https://github.com/maccman/juggernaut.git

〉cd juggernaut

〉node server.js

4. 创建RAILS应用

〉rails new juggernaut_demo

〉cd juggernaut_demo

vim Gemfile:

gem 'juggernaut'

〉bundle install

〉rails g controller welcome index publish

vim routes.rb

root :to =〉 "welcome#index"

get "welcome#publish"

vim application.html.erb

〈script src="http://localhost:8080/application.js" type="text/javascript" charset="utf-8"〉〈/script〉

vim welcome#index.html.erb

〈script type="text/javascript" charset="utf-8"〉 var jug = new Juggernaut; jug.subscribe("demo_channel", function(data){ alert(data); }); 〈/script〉

vim welcome_controller#publish

def publish

Juggernaut.publish"demo_channel", "juggernaut demo msg"

end

〉rails s

访问: http://localhost:3000/

http://localhost:3000/welcome/publish

Ok,结束。


read more >>

Tags: juggernaut rails   Posted in Ruby & Rails

RottenEgg发布

辛卯[兔]年 七月十七

RottenEgg文件上传:将基于版本管理(SVN或GIT)得文件通过FTP上传到指定位置。

还得从目前在使用中的JUSTHOST主机说起,部署不便,需要FTP。变更多或是频繁,操作起来就够呛。

RottenEgg最初是在命令行下使用的脚本。经过工作之余断断续续的增补,才滚出来。

Thin + Sinatra + ExtJS4

GitHub:https://github.com/elvuel/rottenegg

RubyGems:http://rubygems.org/gems/rottenegg

目前BETA版本。

read more >>

Tags: scm ftp   Posted in Ruby & Rails

ruby rmagick 生成DM

辛卯[兔]年 三月廿五

本月的DM手册的生成,到今天结束。高兴的是DM版式总算是确定了,相关的程序不用再做频繁的调整;以后生活就轻松了。

贴几张DM中生成的图上来:

DM目录彩色 DM目录黑


附: dpi和像素、厘米、英寸之间的关系和换算

1 厘米 =0.3937 英寸 1 英寸=2.54 厘米 1点 = 1/72英寸

photoshop中两种分辨率换算 72像素/英寸=28.346像素/厘米 300像素/英寸=118.11像素/厘米

像素不能直接换算成英寸、厘米, 要在dpi下才能换算 一张1024*768像素的图片在300像素/英寸的dpi下打印出的大小就是 3.413英寸*2.56英寸

1024像素=3.413英寸=8.67厘米 (在300像素/英寸的dpi下) 21cm×29.7cm,300DPI的图片,用像素表示的话,是多少乘以多少? 1厘米 = 0.393700787 英寸 21*29.7cm=8.267716527*11.6929133739英寸 每英寸300点 =(8.267716527*300)*(11.6929133739*300)=2480*3508点

ruby代码 毫米在300DPI下 转为像素值: def dpi(mm);mm / 10.0 * 118.11;end

read more >>

Tags: ruby rmagick   Posted in Ruby & Rails

ActiveResource for no restful style

辛卯[兔]年 三月十九

上周群里有朋友在rails应用中需调用某api,不过接口非restful风格的,如要成功实现调用可以自行编写模块或引用第三方库,不过既然是在rails下,也可以拿AtciveResource来改动一下。

以下代码是个人做的一些小变更扩展来适应其api接口的调用--以下代码纯属实践娱乐,贴出来备忘。

# File config/initializers/active_resource_ext.rb

module ActiveResource

 module Formats
 module NoneFormat
 extend self

 def extension
 ""
 end

 def mime_type
 ""
 end

 def encode(hash, options = nil)
 # 具体处理看实际需要
 #ActiveSupport::JSON.encode(hash, options)
 ""
 end

 # to Base.instantiate_collection
 def decode(json)
 # 具体处理看实际需要
 json
 end
 end
 end
 # ActiveResource::Base
 class Base
 
 class 〈〈 self
 def element_path(id, prefix_options = {}, query_options = nil)
 prefix_options, query_options = split_options(prefix_options) if query_options.nil?
 if format.extension == ""
 "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}#{query_string(query_options)}"
 else
 "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}"
 end
 end

 def new_element_path(prefix_options = {})
 if format.extension == ""
 "#{prefix(prefix_options)}#{collection_name}/new"
 else
 "#{prefix(prefix_options)}#{collection_name}/new.#{format.extension}"
 end
 end
 
 def collection_path(prefix_options = {}, query_options = nil)
 prefix_options, query_options = split_options(prefix_options) if query_options.nil?
 if format.extension == ""
 "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
 else
 "#{prefix(prefix_options)}#{collection_name}.#{format.extension}#{query_string(query_options)}"
 end
 end

 def instantiate_collection(collection, prefix_options = {})
 if collection.is_a? Array
 collection.collect! { |record| instantiate_record(record, prefix_options) }
 else
 collection.to_s
 end
 end
 end
 end
 
 # ActiveResource::Connection
 class Connection
 private
 def build_request_headers(headers, http_method, uri)
 if format.mime_type == ""
 authorization_header(http_method, uri).update(default_header).update(headers)
 else
 authorization_header(http_method, uri).update(default_header).update(http_format_header(http_method)).update(headers)
 end
 end
 end
end

read more >>

Tags: activeresource rails restful api   Posted in Ruby & Rails

Rails生成Model文档

辛卯[兔]年 二月十七

rails model文档生成(beta version)

包含: table schema, table index, model associations etc...

== TODO LIST

1. 关联处理完善

2. 查找model定义多平台处理

3. 转为GEM发布

存放路径:https://github.com/elvuel/rails-model-doc-generator

code:

require 'fileutils'
namespace :elvuel do

 # Fetch all has*** :as =〉 item polymorphic associations
 def store_polymorphic_as_associations(models)
 reflects = []
 models.each do |model|
 model.reflections.each do |key, association|
 reflects 〈〈 association if association.send(:options).has_key?(:as) #only polymorphic
 end
 end

 @polymorphic_as_reflections = reflects
 end

 # Model belongs_to :item, :polymorphic =〉 true, get all item's class
 def get_polymorphic_as_associations_classes(model, reflection)
 classes = []
 @polymorphic_as_reflections.each do |poly_as_reflection|
 if poly_as_reflection.send(:options)[:as] == reflection.send(:name)
 if poly_as_reflection.active_record.send(:compute_type, poly_as_reflection.send(:class_name)).to_s == model.to_s
 classes 〈〈 poly_as_reflection.active_record.to_s.constantize
 end
 end
 end
 classes
 end

 # Simple quoting for the default column value
 def quote(value)
 case value
 when NilClass then
 "NULL"
 when TrueClass then
 "TRUE"
 when FalseClass then
 "FALSE"
 when Float, Fixnum, Bignum then
 value.to_s
 # BigDecimals need to be output in a non-normalized form and quoted.
 when BigDecimal then
 value.to_s('F')
 else
 value.inspect
 end
 end

 # Use the column information in an ActiveRecord class
 # to create a comment block containing a line for
 # each column. The line contains the column name,
 # the type (and length), and any optional attributes
 def get_schema_info(klass, options)
 info = []
 klass.columns.each do |col|
 attrs = []
 attrs 〈〈 "default(#{quote(col.default)})" unless col.default.nil?
 attrs 〈〈 "not null" unless col.null
 attrs 〈〈 "primary key" if col.name == klass.primary_key

 col_type = col.type.to_s
 if col_type == "decimal"
 col_type 〈〈 "(#{col.precision}, #{col.scale})"
 else
 col_type 〈〈 "(#{col.limit})" if col.limit
 end

 # Check out if we got a geometric column
 # and print the type and SRID
 if col.respond_to?(:geometry_type)
 attrs 〈〈 "#{col.geometry_type}, #{col.srid}"
 end

 # Check if the column has indices and print "indexed" if true
 # If the indice include another colum, print it too.
 if options[:simple_indexes] # Check out if this column is indexed
 indices = klass.connection.indexes(klass.table_name)
 if indices = indices.select { |ind| ind.columns.include? col.name }
 indices.each do |ind|
 ind = ind.columns.reject! { |i| i == col.name }
 attrs 〈〈 (ind.length == 0 ? "indexed" : "indexed =〉 [#{ind.join(", ")}]")
 end
 end
 end
 info 〈〈 { :name =〉 col.name, :type =〉 col_type, :attrs =〉 attrs.join(", "), :human_name =〉 klass.respond_to?(:human_attribute_name) ? klass.human_attribute_name(col.name) : col.name }
 end
 info
 end

 # Get table indexes info
 def get_index_info(klass)
 index_info = []
 indexes = klass.connection.indexes(klass.table_name)
 indexes.each do |index|
 index_info 〈〈 { :name =〉 index.name, :columns =〉 index.columns.join(", "), :unique =〉 (index.unique ? "UNIQUE" : "NO") }
 end
 index_info
 end

 # Get association info
 def get_association_info(klass)
 reflections = klass.reflections
 associations = []
 unless reflections.empty?
 reflections.each do |key, association|
 begin
 info = {}

 info[:name]= key.to_s
 info[:type]= association.class.to_s.gsub(/ActiveRecord|Reflection|::/, "")
 info[:macro]= association.send(:macro).to_s

 # ActiveRecord::Reflection::ThroughReflection[::AssociationReflection|::AggregateReflection]
 association_classes = []

 case info[:type

read more >>

Tags: rails model doc generator   Posted in Ruby & Rails

转-Method triggers:instead before after

庚寅[虎]年 腊月廿二

原文:http://snippets.dzone.com/posts/show/3620

class Object

 def self.__rules__
 # container for defined rules, each item is:
 # [class, event_name, method_name, alias_for_original_method, caller, comment]
 @@rules ||= []
 end

 def self.__create_rule_instead( method, comment = '', &block) # creates and returns new rule
 b_id = "%04x" % block.object_id
 old_method_n

read more >>

Tags: ruby redefine   Posted in Ruby & Rails

招聘-Ruby on Rails软件工程师

庚寅[虎]年 腊月十七

上海智涌信息科技有限公司招聘 Ruby on Rails软件工程师

详情登陆 http://www.scilearn.com.cn/
招聘职位:Ruby on Rails软件工程师

工作汇报对象:高级软件开发经理

工作性质:全职

联系方式:resumes@scilearn.com.cn

职位概述:

Ruby on Rails软件工程师将负责我们 Web 应用程序产品主要组件的设计、开发、维护和监督工作
read more >>

Tags: rails jobs hr 招聘   Posted in Jobs

Ruby汉字转拼音gem发布

庚寅[虎]年 腊月初一

前话:原本hz2py是elvuel blog上开发使用的插件,初始考虑不多也没有以gem发布。

今天有事请假在家,闲下来,上了github关闭了汉字转拼音(hz2py)repo打开的issue。(打开有段时间了未能及时响应,望请多多谅解)花点时间build一个gem,同时修正了在ruby 1.9版本下的编码问题。

具体使用详见github readme.

GitHub: https://github.com/elvuel/hz2py

RubyGems: https://rubygems.org/gems/hz2py

read more >>

Tags: ruby rails 汉字转拼音   Posted in Ruby & Rails

  • Search

  • Categories

    • Ruby & Rails
    • Jobs
    • Uncategorized
  • Recent Posts

    • Prawn使用Annotation坐...
    • ejabberd mod_archive
    • Capybara get session in ...
    • Juggernaut & Rails
    • RottenEgg发布
    • ruby rmagick 生成DM
    • ActiveResource for no r...
    • Rails生成Model文档
    • 转-Method triggers:inst...
    • 招聘-Ruby on Rails软件...
  • Links

    • RailsCasts
    • The Ruby Reflector
    • Alltop Ruby
    • Command Line Refer
    • Ruby Code Snippets
    • GitHub
    • API Dock
    • OpenSourceRails
    • RailsPlugins
    • RailsLab
    • 15DaysOfJQuery
  • Archives

    • 2012年(1)

    • 2012年01月(1)
    • 2011年(10)

    • 2011年12月(1)
    • 2011年11月(1)
    • 2011年08月(2)
    • 2011年04月(2)
    • 2011年03月(1)
    • 2011年01月(3)
    • 2010年(27)

    • 2010年12月(1)
    • 2010年11月(2)
    • 2010年10月(4)
    • 2010年09月(7)
    • 2010年08月(1)
    • 2010年07月(5)
    • 2010年06月(1)
    • 2010年04月(6)
    • 2009年(13)

    • 2009年10月(1)
    • 2009年05月(2)
    • 2009年04月(1)
    • 2009年03月(2)
    • 2009年02月(7)
    • 2008年(19)

    • 2008年08月(1)
    • 2008年07月(1)
    • 2008年06月(1)
    • 2008年05月(3)
    • 2008年04月(1)
    • 2008年03月(2)
    • 2008年02月(10)

Copyright © 2010 elvuel.com Powered by Elvuel.