Skip to content

Instantly share code, notes, and snippets.

@MitsunChieh
MitsunChieh / terminal.sh
Created March 31, 2017 07:17
clearly remove Xcode
sudo rm -rf /Applications/Xcode.app
sudo rm -rf /Library/Preferences/com.apple.dt.Xcode.plist
rm -rf ~/Library/Preferences/com.apple.dt.Xcode.plist
rm -rf ~/Library/Caches/com.apple.dt.Xcode
rm -rf ~/Library/Application\ Support/Xcode
rm -rf ~/Library/Developer/Xcode
rm -rf ~/Library/Developer/CoreSimulator
rm -rf ~/Library/Developer/XCPGDevices
@MitsunChieh
MitsunChieh / devise.zh-TW.yml
Created June 21, 2016 11:07
for devise 4.1.1
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
zh-TW:
devise:
confirmations:
confirmed: "您的帳號已通過驗證,現在您已成功登入。"
send_instructions: "您將在幾分鐘後收到一封電子郵件,內有驗證帳號的步驟說明。"
send_paranoid_instructions: "如果我們有您的信箱,您將會收到一封驗證您的帳號的電子郵件。"
failure:
already_authenticated: "您已經登入。"
@MitsunChieh
MitsunChieh / devise.zh-TW.yml
Created June 21, 2016 11:07
devise.zh-TW.yml
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
zh-TW:
devise:
confirmations:
confirmed: "您的帳號已通過驗證,現在您已成功登入。"
send_instructions: "您將在幾分鐘後收到一封電子郵件,內有驗證帳號的步驟說明。"
send_paranoid_instructions: "如果我們有您的信箱,您將會收到一封驗證您的帳號的電子郵件。"
failure:
already_authenticated: "您已經登入。"
@MitsunChieh
MitsunChieh / mysqldump.sh
Created November 30, 2015 07:04
backup mysql on server
# 資料庫備份
mysqldump -u[user] -p -P[port] -h[host] db_name > back_up.sql
# 資料庫備份,但排除特定資料表
mysqldump -u[user] -p -P[port] -h[host] db_name --ignore-table=db_name.table_name > back_up.sql
# 壓縮成 tgz
tar zcf filename.tgz filename1 filename2
# 解壓縮從 tgz
@MitsunChieh
MitsunChieh / random_string.rb
Last active November 26, 2015 07:52
產生隨機字串
# 09azAZ
# n = 字串的長度
range = [*0..9,*'a'..'z',*'A'..'Z'];Array.new(n){ range.sample }.join
# 09az
# 長度 128
rake secret
# 好玩的寫法
# 09az
@MitsunChieh
MitsunChieh / #presence.md
Last active August 27, 2015 06:34
Rails API Tips
foobar = foo.presence || bar
=== foobar = (foo if foo.present?) || bar

結果上來說跟下述等價。

foobar = foo
foobar = bar if foobar.blank?
@MitsunChieh
MitsunChieh / rake db.md
Last active August 29, 2015 14:14
[Rails] rake db:

db:create creates the database for the current env

db:create:all creates the databases for all envs

db:drop drops the database for the current env

db:drop:all drops the databases for all envs

db:migrate runs migrations for the current env that have not run yet

@MitsunChieh
MitsunChieh / Array.new.md
Last active August 29, 2015 14:13
Dimension-array creating

Just find out some problem in assigning array.

arr3 = Array.new(2, Array.new(2, 0))
arr4 = [[0, 0], [0, 0]]

puts arr3 == arr4	 # >> true
puts arr3 === arr4  # >> true

arr3[0][0] = "/"
print arr3 # >> [["/", 0], ["/", 0]]
@MitsunChieh
MitsunChieh / benchmark.rb
Last active August 29, 2015 14:12
[Ruby] Benchmark
# Benchmark 是一個記錄程式運算時間的 Module
# 兩個基本指令 :measure, :bm, :bmbm
# 更多:http://www.ruby-doc.org/stdlib-2.0/libdoc/benchmark/rdoc/Benchmark.html#method-c-measure
require 'benchmark'
puts Benchmark.measure{ method_name }
# user system total real <- 不會有這一行
# 1.033333 0.016667 1.016667 ( 0.492106)