Giter Club home page Giter Club logo

blog's Introduction

Hello, there 👋👋

    

blog's People

Contributors

kevinw3i avatar

Watchers

 avatar

blog's Issues

[微波爐相關知識]波爐要怎麼買...? 買了怎麼用...?

那些關於 微波爐 的事

微波爐輸出功率 (瓦數)?

輸出功率指的是加熱能力,微波爐輸出功率越大,加熱速度越快。

輸出功率大耗電多?

實際上耗電量是按功率乘以時間計算的,小功率微波爐加熱時間長,其實並不會比較省電喔!!相較之下烹飪同樣的食物大功率微波爐不僅省時還省電。

如何看輸入功率(消耗電功率)?

微波爐的輸入功率一般標在機器後面,輸入功率(消耗電功率)和輸出功率的差值越小越好,越小說明微波爐的有效功率越大

不同強度微波瓦數,如何轉換?

簡單的算法 例如:食物包裝上面寫要用700W熱2分鐘

  • 若你家的是900W
    700 (W) * 120 (秒) / 900(W) =93.3…秒
    差不多抓1分33秒
  • 若你家的是500W
    700 (W) * 120 (秒) / 500(W) = 168秒
    差不多抓2分48秒

微波爐的突沸現象

突沸現象的影片

那些關於 Ruby 的事情

那些關於 Ruby 的事情

Ruby Coding Style

https://github.com/rubocop-hq/ruby-style-guide

Install Ruby

RVM

全名 Ruby Version Manager 再同一系統安裝多種不同的 Ruby

RVM.IO
Install RVM:

\curl -sSL https://get.rvm.io | bash -s stable

Ruby 輸出方式 "Hello World"

在 Ruby 想印出值會用到三種

print / put / p

# Hello, World
print "Hello, World"

# Hello, World 後面加上換行
puts "Hello, World"

# "Hello, World" 字樣(含雙引號), 且結尾加上換行
p "Hello, World"

%Q / %q

%Q 效果等同雙引號

%q 效果等同單引號

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

Ruby 套件管理

Gem

Rubygems

變數(variable)

區域變數 (local variable)

name

全域變數 (global variable)

$name

實體變數 (instance variable)

@name

類別變數 (class variable)

@@name

虛擬變數(Pseudo Variable)

這是在 Ruby 內部定義的,例如 nil、self、true、false,虛擬變數通常有特別的用途或意義,內容不能被改變。

變數預設值

沒有初始化的全域變數以及實體變數的預設值是 nil,但一般的區域變數是沒有預設值的:

p @name  # => nil
p $name  # => nil
p name   # => 發生 undefined local variable or method 錯誤

常數(Constant)

Ruby 對常數有特別的命名規定,就是「常數必須要是大寫英文字母開頭」

Orange = 123
Who = "alice"

常數可修改

在 Ruby 的常數的內容是可以修改而且不會發生錯誤

Myage = "eddie"      # => eddie
MyName << " kao"      # => eddie kao
MyName.prepend "j"    # => jeddie kao

命名習慣

在 Ruby 世界命名的不成文規定

是使用小寫英文字母以及底線來組合變數名稱,例如像是 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

註解(Comment)

單行註解

當行使用 # 來註解

# 這是註解

多行使用 =begin =end

=begin
這裡的內容全部都是註解
=end

Ruby假假真真

在各式各樣的程式語言中,有的會把數字 0、數字 -1 或是空陣列當做 false。

在 Ruby 裡因為所有的東西都是物件,只有 nilfalse 會被當假的(false),除此這兩個之外,其它都是真的(true),包括數字 0、數字 -1、空陣列、空字串都會被做是 true。

if .. else ..

age = 20

if age >= 18
  puts "你是大人了"
else
  puts "快快長大吧!"
end

if .. elsif .. else ..

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 倒裝句寫法

if age >= 18
  puts "你是大人了"
end


puts "你是大人了" if age >= 18

迴圈及迭代(Loop and Iteration)

Ruby 中主要幾種迴圈寫法

  1. while 迴圈
  2. for..in 迴圈
  3. times, upto, downto 方法
  4. 迭代(iteration)

while 迴圈

counter = 0

while counter < 5
  puts "hi, #{counter}"
  counter += 1
end

# 執行後得到結果:
# hi, 0
# hi, 1
# hi, 2
# hi, 3
# hi, 4

for..in 迴圈

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

times, upto, downto 方法

times

在 Ruby 的世界裡,幾乎所有的東西都是物件,包括數字也是。而在 Ruby 的數字物件裡有一個 times 方法,可以讓我們指定迴圈要跑幾次:

5.times do
  puts "hello, ruby"
end

# 執行後得到結果:
# hello, ruby
# hello, ruby
# hello, ruby
# hello, ruby
# hello, ruby

upto

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

downto

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

迭代(iteration)

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>

【Coding Note】2020/10/01

2020/10/01

Ajax 問題

<%= 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')
  }
});

select_tag

API DOCK
直接看API檔案最快

Jquery

  $('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();

那些關於 Github Page 的事

這是關於Github Page 創建的一些事

Github 部分

  1. 先開一個 Repositories
  2. 推一份或是直接新增一份 README.md
  3. Settings > GitHub Pages

    選擇主分支

如果有自己的Domain可以新增

Domain 部分

  1. 使用的是 freenom 有提供免費的網域
  2. 然後找個免費的網域
  3. 再把它買下來
  4. 記得要調整成12 Months@FREE
  5. 最後完成
  6. 點選 Services > My Domains
  7. 進入頁面後點選 Manage Domain
  8. 點選 Manage Freenom DNS
  9. 設定
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


10. 完成 可以轉到自己的Domain看看了~

睡前的 Rspec 系列

Rspec Day 1

Rspec 基礎

  • 【 角色區別 】 describe / it / expect
  • 【 使用方法 】 context
  • 【 使用方法 】 before
  • 【 使用方法 】 let / let! / subject
  • 【 使用方法 】 pending / skip

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 的括號可省略

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.