This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 拷贝于 https://github.com/calebx/number_to_cn | |
| module NumberToCn | |
| CN_T_TRANS = [ "", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" ] | |
| CN_T_TRANS_WITH_ZERO = [ "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" ] | |
| CN_T_POSITION = [ "", "拾", "佰", "仟" ] | |
| CN_T_BIG = [ "", "萬", "亿", "萬"] | |
| def to_cn_words | |
| if self.class == Fixnum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def try(title, options = { }, &p) | |
| tried_times = 0 | |
| max_times = options[:max_times] || 3 | |
| exceptions = options[:on] || Exception | |
| exceptions = [exceptions] if !exceptions.is_a?(Array) | |
| rescue_text = <<-EOF | |
| begin | |
| # 不能用yield | |
| p.call | |
| rescue #{exceptions.join(',')} => e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # simulate template rendering | |
| class Template < Struct.new(:name) | |
| def render | |
| puts "#{name}_begin" | |
| r = "#{name}_begin\n" | |
| r << yield if block_given? | |
| puts "#{name}_end\n" | |
| r << "#{name}_end\n" | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby1.9 | |
| require 'fiber' | |
| require 'benchmark' | |
| class Ring | |
| attr_reader :id | |
| attr_accessor :attach | |
| def initialize(id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'dig' | |
| # Dig.set :host, 'localhost:3000' | |
| # Dig.set :host, 'fchk.dev' | |
| namespace :api do | |
| task :get_user_bio => :environment do | |
| res = Dig.get 'getUserBio', user_sn: 'ddd' | |
| puts res |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Avatar < ActiveRecord::Base | |
| attr_accessor :content_type, :original_filename, :image_data | |
| before_save :decode_base64_image | |
| has_attached_file :image, | |
| PAPERCLIP_CONFIG.merge( | |
| :styles => { | |
| :thumb => '32x32#', | |
| :medium => '64x64#', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| # entities的数据结构, [{name: name, image: <File:image>}, ...] | |
| class CreateEntitySet < Dun::Activity | |
| data_reader :entities, :contest | |
| def call | |
| entities.map {|e| | |
| entity = Entity.new | |
| entity.sn = SecureRandom.uuid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UploadBase64Image < Dun::Activity | |
| data_reader :file_data, :as, :file_name | |
| set :server_address, 'http://xx.xx.xx.xx' | |
| set :client, RestClient | |
| def initialize(data) | |
| super | |
| default :as, 'image' | |
| default :file_name, SecureRandom.urlsafe_base64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function(){ | |
| var Validator = { | |
| submit_fields: [], | |
| errors: [], | |
| nameTitleMapper: { | |
| 'contest[title]': '比赛标题', | |
| 'contest[description]': '比赛描述', | |
| 'contest[category_names][]': '比赛类别', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def rand_find(num=1, &p) | |
| scope = p.call | |
| items = [] | |
| rand_numbers = (0...scope.count).to_a | |
| num.times do | |
| break if rand_numbers.size == 0 | |
| rand_number = rand_numbers.delete_at(rand rand_numbers.size) | |
| items << scope[rand_number] | |
| end |