The document provides notes on Rails including how to generate a new Rails project, controller, and model, how to perform migrations to create or modify database tables, how to configure the database and routes, and an overview of how the Rails framework handles requests using controllers to interface with models and the database and return responses. It also defines CRUD as an acronym for create, read, update, and delete operations on data and describes Active Record as a layer that maps business objects to database tables.
This document provides a short guide to using Entrez and the E-utilities. It describes Entrez as a global query system that searches over 40 databases at NCBI, including PubMed, Nucleotide, and Protein. It also describes the E-utilities, which provide a stable interface for programmers to query and retrieve data from Entrez. The document outlines the main functions of nine E-utilities including ESearch, ESummary, EFetch, and ELink. It also provides examples of constructing pipelines using multiple E-utilities to retrieve relevant document summaries and sequences from Entrez based on search queries or lists of IDs.
This document summarizes a software testing project for a csmap program. It describes using unit testing with PyUnit, coverage testing with coverage.py, and mutation testing with PyMuTester. Testing revealed a bug that was then fixed. The results of coverage and mutation testing indicated that some test cases were insufficient and some code was unreachable.
This document discusses implementing websockets in a Rails 5 application using Action Cable to create a real-time chat application. It covers setting up Action Cable channels and subscriptions to broadcast messages to all users in real-time. Configuration details are provided for routing websockets requests, specifying the cable adapter, and allowing cross-origin requests.
Rails 5 will include several performance improvements and new features while maintaining backwards compatibility. Notable changes include faster development mode, optional belongs_to validations, support for JSON columns in MySQL, and ActionCable for real-time features. While Turbolinks 5 is included, Rails 5 will not upgrade to Turbolinks 2. The release aims to improve APIs, add Active Record query methods like or, and refine existing functionality with few breaking changes.
Since the previous LTS, JDK 17, was released in 2021, there are quite lots of features added into the Java specification. In this year, the latest JDK 21 LTS version is released and brings us many formal functions to improve our daily works. This session will focus on the new features, including String Templates, Sequenced Collections, Record Patterns, Pattern Matching for switch, Unnamed features and Virtual Threads.
5. 安裝 Ruby
• Windows
RubyInstaller for Windows
• Linux (Ubuntu)
• Linux (CentOS)
• Mac OS X
• 更多參考 https://www.ruby-lang.org/zh_tw/documentation/installation/
$ sudo apt-get install ruby
$ sudo yum install ruby
$ brew install ruby
5
6. 簡單示範
• 計算階乘
# 計算出數字的階乘
# 請把程式儲存為 fact.rb
def fact(n)
if n == 0
1
else
n * fact(n-1)
end
end
puts fact(ARGV[0].to_i)
6
20. 繼續簡單示範
• 正規表示式
01 st = "033[7m"
02 en = "033[m"
03
04 puts "Enter an empty string at any time to exit."
05
06 while true
07 print "str> "; STDOUT.flush; str=gets.chop
08 break if str.empty?
09 print "pat> "; STDOUT.flush; pat=gets.chop
10 break if pat.empty?
11 re = Regexp.new(pat)
12 puts str.gsub(re, "#{st}&#{en}")
13 end
20
22. 控制結構
• case
i=8
case i
when 1, 2..5
puts "1..5"
when 6..10
puts "6..10"
when 'aaa', 'bbb'
puts "aaa or bbb"
when /def/ # 正規表示式
puts "includes /def/"
end
22
23. 控制結構
• while
i = 0
while i < 3
puts i += 1
end
# 可以簡寫成
puts i += 1 while i < 3
23
24. 控制結構
• if
i = 0
if i == 0
puts "It's zero."
end
# 可以簡寫成
puts "It's zero" if i == 0
24
25. 控制結構
• unless: if 的否定型
• until: while 的否定型
• 何時用 if,何時用 unless?
一般來說,儘量使用正向表達,少用 ! 符號
# Good
puts "It's nil" if foo.nil?
puts "It's not nil" unless foo.nil?
# Not good
puts "It's not nil" if !foo.nil?
25
26. 控制結構
• 中斷迴圈
break: 中斷所有迴圈
next: 中斷目前迴圈,從下個迴圈開始
redo: 重新執行目前迴圈
return: 中斷迴圈並跳出迴圈所在的方法
• for
for num in (4..6)
puts num
end
for elt in [100, -9.6, "pickle"]
puts elt
end
26
27. 控制結構
• for 的另一種寫法
# 如果你習慣用 C 或 Java,你可能會比較喜歡這個。
for element in collection
...
end
# Smalltalk 程式員則可能喜歡這個。
collection.each { |element|
...
}
collection.each do |element|
...
end
27
28. 迭代器 (Iterator)
• 字串常用的迭代器
each_byte: 取出每個字元
each_line: 取出每一行
• 定義迭代器:
在 function 使用 yield ,該 function 就變成迭代器。
yield 可將控制移至傳遞往迭代器的程式碼區塊 (block of code)。
def repeat(num)
while num > 0
yield
num -= 1
end
end
repeat(3) { puts "foo" }
28