This file contains 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
#当你把照相机接入电脑时,照片文件夹为F盘。下面的程序对照片进行批量重命名。 | |
pic_names = Dir['F:/**/*.{JPG,jpg}'] | |
puts 'What would you like to call this batch?' | |
batch_name = gets.chomp | |
puts | |
print "Downloading #{pic_names.length} files: " | |
pic_number = 1 #这是计数器,我们从1开始计数 | |
pic_names.each do |name| | |
print '.' # 这是进度条. |
This file contains 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
#JSON is frequently used to exchange data between JavaScript running in browsers and server-based applications | |
#把hash或array的数据结构转换成字符,并把字符写入文件 | |
>> require 'json' | |
=> true | |
>> data = { :name => 'louis', :address => ['Suzhou', 'China'], :age => 30} | |
=> {:address=>["Suzhou", "China"], :age=>30, :name=>"louis"} | |
>> serialized = data.to_json | |
=> "{"address":["Suzhou","China"],"age":30,"name":"louis"}" | |
>> File.open('data.txt', 'w') do |f| |
This file contains 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
#http://github.com/mislav/will_paginate | |
>> a = Array.new(100) {|n|n} | |
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99] | |
>> require 'will_paginate/array' | |
=> true | |
#WillPaginate默认为每页30个对象 | |
>> a.paginate | |
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] | |
#显示第二页 |
This file contains 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 Stack | |
attr_reader :stack | |
def initialize | |
@stack = [] | |
end | |
def peek(obj) | |
@stack.push(obj) | |
end | |
def pop | |
@stack.pop |
This file contains 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 'rubygems' | |
require 'stemmer' | |
require 'classifier' | |
class LedeClassifier | |
attr :classifier | |
def initialize(sections, n) | |
@classifier = Classifier::Bayes.new(*sections) |
This file contains 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
# 2010-10-01 | |
# | |
# Mac OS X 10.6.3 | |
# Homebrew 0.7 | |
# Xcode 3.2.4 | |
# Git 1.7.3.1 | |
# RVM 1.0.12 | |
# Ruby 1.9.2, 1.8.7 | |
# Rails 3.0.0 | |
# Passenger 3.0.0.pre4 |
This file contains 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
#content | |
.left.column | |
%h2 Welcome to our site! | |
.right.column | |
#users | |
{{#users}} | |
%p {{user}} | |
{{/users}} |
OlderNewer