用 Ruby 實作 Elixir 的 cond statement
## Elixir: ``` defmodule Validator do def validate_age(age) do if age < 18 do "Under 18" else if age < 21 do ...
Capistrano forward agent
Capistrano forward agent 可以讓我們不用把 server 上的key 加到 github 也能拉 private repo 今天遇到 permission deny 的問題,結果是因為 mac 重開機就清空了 ssh agents ,導致沒有 ...
在 Linode 跑 lending bot
Ubuntu 16.04 LTS 先參考裝機筆記 https://everyday1percent.blogspot.hk/2017/10/blog-post.html 把基本的機器安全設定設好 把機器加到github https://help.github.com/...
加速 git clone
最近網速慢到快死,尤其是 git clone,竟然不到 10kb/s 所以 google 了一下加速的方法 https://codeyarns.com/2016/01/12/slow-speed-on-git-clone/
Ruby keyword arguments
TL;DR: ```ruby def log_operator(operator: nil, **options) self.operator = operator end ``` 可以: ```rb log_operator(operator: ...
用 ActiveModel::Callbacks 做 before, around, after callbacks
extend ActiveModel::Callbacks ```ruby class Test extend ActiveModel::Callbacks define_model_callbacks :execute before_execute :log_som...
rails before_actoin design pattern - Aspect-oriented_programming (AOP)
想要對 ruby class 實作 before_action ,查到 https://stackoverflow.com/questions/23444964/is-it-possible-to-do-a-before-action-in-ruby-like-in-ra...
ActiveSupport::Callbacks
延續上一篇,這邊用 ActiveSupport::Callbacks 來做 callbacks 官方教學: http://api.rubyonrails.org/classes/ActiveSupport/Callbacks.html 下一個問題: 所以怎麼做到下...
前端怎麼透過 API 送 file 到後端比較好呢?
這幾天在做前端的 form,遇到了不知道該怎麼樣讓 JS 透過 API 送 file 比較好的問題,當然答案是「It depends」在這裡把我的想法記錄下來 送 file 的方法直覺想到會有幾種: https://imququ.com/post/four-ways-t...
rails 在 database 有 connection 的情況下清空所有 tables
rake db:schema:dump RAILS_ENV=staging rake db:schema:load RAILS_ENV=staging
database 到底要不要對 boolean 值打 index 呢?
真實情況是: it depends but depends on what? 主要可以根據以下兩個基本的原則來 depends boolean index 會有效能上幫助的時機: 1. 跟其他欄位一起打 index 2. 某一部分的 records 暫少數的時候,...
摘要算法和對稱加密算法
摘要算法不可逆,對稱加密可逆 所謂對稱加密就是用私鑰(也就是密碼)幫訊息加密,所以只要再用私鑰就能解密,例如 AES 算法 而摘要算法呢?就是沒有私鑰的概念,只要是一樣的字串加密出來的內容就會是一樣的,但是摘要算法會確保加密出來的字串無法(應該說:很難)被逆推回原本的值...
整理 SASS 的方法
教了很多整理 SASS 的方法,主要是用 mixins https://www.toptal.com/css/sass-mixins-keep-your-stylesheets-dry 偷懶也可以直接使用 Sass mixin libraries,例如文中提到的 bou...
SASS 做 theme 的起手式
不錯的文章 * 最外層的 container 控制 theme 基本元素 * 加上 themable 的 mixin 並設參數讓 theme 更彈性 * 用 each 方法 loop 參數,讓 themable 更彈性,只需要接受 name 和 map 兩個參數 * li...
Server 安裝 zsh
不能 autocomplete 太痛苦了 ``` apt-get install zsh curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh ``` 然後默...
deploy nodejs to server using capistrano and nvm and pm2
這給了大概流程 http://jameshuynh.com/nextjs/react/capistrano/nvm/pm2/2017/10/07/deploy-nextjs-app-with-capistrano-3-nvm-and-pm2/
Host key verification failed.
問題: ``` @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@...
read only active record model
```rb def readonly? true end ``` https://til.hashrocket.com/posts/7cd7e55929-read-only-models https://stackoverflow.com/questions/56...
rails singleton class
```rb # File activesupport/lib/active_support/core_ext/object/singleton_class.rb, line 3 def singleton_class class << self ...
rails console 的實用技巧
``` reload! app app.get "/movies" helper helper.link_to("Movies", app.movies_path) ``` https://pragmaticstudio.com/blog/2014/3/11...
react functional setState
```js this.setState((prevState, props) => ( { hello: "world" } )) ``` 這是很重要的,不然 setState 有可能會一起執行,變成 Object.assign({}, {hello: "world...
用 nvm 裝 nodejs
裝 nvm ``` curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash nvm install v8.7.0 npm install pm2 -g `...
裝機筆記
## 裝機器 https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16-04 * Ubuntu 16.04LTS Local ``` ssh root@...
不錯的 project prioritise 公式 - RICE
RICE 是四個詞的縮寫 最後的公式是:( R * I * C ) / E = RICE Reach 代表可以接觸到的 users 量,可以用季或是月當標準單位 Impact 對公司能造成的影響 3 for “massive impact”, 2 for “high...