kevinw3i / blog Goto Github PK
View Code? Open in Web Editor NEW用於記錄個人筆記或生活
Home Page: https://k3vinwei.tk/
用於記錄個人筆記或生活
Home Page: https://k3vinwei.tk/
輸出功率指的是加熱能力,微波爐輸出功率越大,加熱速度越快。
實際上耗電量是按功率乘以時間計算的,小功率微波爐加熱時間長,其實並不會比較省電喔!!相較之下烹飪同樣的食物大功率微波爐不僅省時還省電。
微波爐的輸入功率一般標在機器後面,輸入功率(消耗電功率)和輸出功率的差值越小越好,越小說明微波爐的有效功率越大。
簡單的算法 例如:食物包裝上面寫要用700W熱2分鐘
https://github.com/rubocop-hq/ruby-style-guide
全名 Ruby Version Manager 再同一系統安裝多種不同的 Ruby
RVM.IO
Install RVM:
\curl -sSL https://get.rvm.io | bash -s stable
在 Ruby 想印出值會用到三種
# Hello, World
print "Hello, World"
# Hello, World 後面加上換行
puts "Hello, World"
# "Hello, World" 字樣(含雙引號), 且結尾加上換行
p "Hello, World"
puts %q{Hello world!\n This is David's pen}
# => Hello world!\nThis is David's pen
puts %Q{Hello world!\n This is David's pen}
# => Hello world!
# => This is David's pen
name
$name
@name
@@name
這是在 Ruby 內部定義的,例如 nil、self、true、false,虛擬變數通常有特別的用途或意義,內容不能被改變。
沒有初始化的全域變數以及實體變數的預設值是 nil,但一般的區域變數是沒有預設值的:
p @name # => nil
p $name # => nil
p name # => 發生 undefined local variable or method 錯誤
Ruby 對常數有特別的命名規定,就是「常數必須要是大寫英文字母開頭」
Orange = 123
Who = "alice"
在 Ruby 的常數的內容是可以修改而且不會發生錯誤
Myage = "eddie" # => eddie
MyName << " kao" # => eddie kao
MyName.prepend "j" # => jeddie kao
是使用小寫英文字母以及底線來組合變數名稱,例如像是 my_shopping_cart,稱之蛇形命名法(Snake Case)
多個變數指定值
a = 1
b = 2
c = 3
可以改用Ruby變數多重指定的特性,改寫成這樣
x, y, z = 1, 2, 3
等號的右邊是一個陣列也可以自動拆解出來
x, y, z = [1, 2, 3]
優先左邊,左邊有就塞
如果變數有星號,左邊全塞進陣列
# 右邊比較多的情況:
a, b = 1, 2, 3, 4
# => a = 1, b = 2, 其它的內容被丟掉了
a, *b = 1, 2, 3, 4
# => a = 1, 變數 b 前面的星號會讓 b 接收剩下的數值變成一個陣列 [2, 3, 4]
x, y, z = [1, 2, 3, 4, 5]
# => x = 1, y = 2, z = 3, 剩下的被忽略
x, y, *z = [1, 2, 3, 4, 5]
# => x = 1, y = 2, 同上,z 會接受其它的值變成陣列 [3, 4, 5]
# 左邊比較多的情況
a, b, c = 1, 2
# => a = 1, b = 2, c 因為分不到值而變成 nil
x, y, z = [1, 2]
# => x = 1, y = 2, z 因為分不到值而變成 nil
# 這是註解
=begin
這裡的內容全部都是註解
=end
age = 20
if age >= 18
puts "你是大人了"
else
puts "快快長大吧!"
end
age = 10
if age > 0 && age <= 3
puts "Baby"
elsif age > 3 && age <= 10
puts "Kids"
elsif age > 10 && age <= 17
puts "Teenager"
else
puts "Adult"
end
if age >= 18
puts "你是大人了"
end
puts "你是大人了" if age >= 18
counter = 0
while counter < 5
puts "hi, #{counter}"
counter += 1
end
# 執行後得到結果:
# hi, 0
# hi, 1
# hi, 2
# hi, 3
# hi, 4
friends = ["eddie", "joanne", "john", "mark"]
for friend in friends
puts friend
end
# 執行後得到結果:
# eddie
# joanne
# john
# mark
for i in 1..5 do
puts i
end
# 執行結果
# 1
# 2
# 3
# 4
# 5
在 Ruby 的世界裡,幾乎所有的東西都是物件,包括數字也是。而在 Ruby 的數字物件裡有一個 times 方法,可以讓我們指定迴圈要跑幾次:
5.times do
puts "hello, ruby"
end
# 執行後得到結果:
# hello, ruby
# hello, ruby
# hello, ruby
# hello, ruby
# hello, ruby
1.upto(5) do |i|
puts "hi, ruby #{i}"
end
# 執行後得到結果:
# hi, ruby 1
# hi, ruby 2
# hi, ruby 3
# hi, ruby 4
# hi, ruby 5
5.downto(1) do |i|
puts "hi, ruby #{i}"
end
# 執行後得到結果:
# hi, ruby 5
# hi, ruby 4
# hi, ruby 3
# hi, ruby 2
# hi, ruby 1
friends = ["eddie", "joanne", "john", "mark"]
friends.each do |friend|
puts friend
end
在 Rails 專案中,陣列的 each 方法使用頻率也相當高
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.name %></td>
<td><%= user.email %></td>
<td><%= user.tel %></td>
<td><%= link_to 'Show', user %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
<%= csrf_meta_tag %>
$.ajax({ url: 'YOUR URL HERE',
type: 'POST',
**beforeSend**: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))},
data: 'someData=' + someData,
success: function(response) {
$('#someDiv').html(response);
}
});
最重要的大概就是 beforeSend
或是
$.ajaxSetup({
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
}
});
API DOCK
直接看API檔案最快
$('select').change(function(e){
let id = e.target.id
var status = $(this).find(":selected").text();
$.ajax({
url: "/item/groupupdate",
beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))},
type: "PATCH",
data: {
"id": id,
"status": status
},
success: () =>{
console.log('完成')
}
})
});
用這個來選取當前的id
let id = e.target.id
用這個來選取當前selected的文字
$(this).find(":selected").text();
185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
(關於設定的部分)可以看 Configuring a custom domain for your GitHub Pages site
不做事後記錄,下次只記得好像叫什麼,一點用都沒有
describe 可以描述要測的行為(以字串表示,比如下例的四則運算):
describe "Arithmetic" do
it "1 + 1 equals 2" do
expect(1 + 1).to eq 2
end
end
describe “描述”一組測試,用 it 來寫一條測試。it 內的 expect 則是用來檢查“左值”是否與“右值”相等:
expect(“左值”).to eq(“右值”) # eq 的括號可省略
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.