2017年12月28日 星期四

Map keyboard mapping software


https://github.com/tekezo/Karabiner-Elements





JS 處理 number 和一些簡單的 helpers

這一陣子開發前端比較多,少了很多 rails 的 helper 可以用,光是要簡單的 floor 一個 number 到特定的 precision 就得自己寫 function 實作,實作時就還得考慮各種 edge case (WTF...),最後還是偷懶用了 lodash,真的挺省心的

https://github.com/lodash/lodash

之前看到有人說自己實作 lodash 的 functions 很適合拿來練 JS 手感,有空也來練練好了

另外 JS 處理數字真的很悲劇,字串相加是字串,字串相減是數字...我操...


```js
"1" + "1"
// => "11"

"1" - "1"
// => 0
```

我也是醉了...

加上我現在的工作是在做數字貨幣相關,數字貨幣動輒小數點後八九位,最小到 18 位,JS 的 number 根本是悲劇,後來找了一個叫做 mathjs 的 library 有 math.bignumber 可以用,就先湊合著用了





git ignore globally


➜  ~ touch . gitignore_global
➜  ~ vim . gitignore_global
➜  ~ git config --global core.excludesfile '~/.gitignore_global'


https://gist.github.com/subfuzion/db7f57fff2fb6998a16c

讓 VSCode 識別 .js 成 JavascriptReact jsx 這樣才可以 autocomplete

因為上網找好幾次了很煩,註記一下


在設定裡面加上

```
{
"files.associations": {
"*.js": "javascriptreact"
}
}
```

以 rails + webpacker 為例

```
{
  "files.associations": {
    "**/app/javascript/**/*.js": "javascriptreact"
  }
}
```

https://github.com/Microsoft/vscode/issues/81



2017年12月26日 星期二

sass override bootstrap var


$grid-columns: 24;
$grid-gutter-width: 30px;


$body-bg: #ffffff;

$brand-primary: #394a5c;
$brand-success: #87c599;



類似這樣,可以輕易的把 grid 改成 24 欄,也可以重新定義基本色和 margin, padding 等等,對於要做theme 是很實用的技巧

2017年12月18日 星期一

TLDR 系列 - Why I find Iota deeply alarming


https://hackernoon.com/why-i-find-iota-deeply-alarming-934f1908194b

Etherium 的 core developers 之一提出認為 IOTA 的技術上問題點:

1. 不好的技術決策
戰 IOTA 使用三進位制的決策,認為弊大於利
2. IOTA 用了自己的加密技術
原 PO 認為使用加密技術的 best practice 就是不要自己發明新的加密技術
3. 對開源不友好
 IOTA cofounder 針對第二點的回應是「他們是故意的」,為的是防止抄襲,也就是說真正最重要的地方(加密)是沒有公開的
4. 認為現在 POW 的機制是有安全問題的
細節沒看懂

2017年12月16日 星期六

deploy rails 前如何在 production 環境設好 redis

幾個重點

1. 安裝 redis
2. 根據官方建議做好設定 https://redis.io/topics/quickstart
3. 設防火牆
4. 確定sidekiq 是用你剛剛設定的 port
5. 確定 sidekiq 是用 redis https://github.com/mperham/sidekiq/wiki/Using-Redis
6. 把 sidekiq 加到  systemd
7. 讓 capistrano 重啟 sidekiq




1, 2
```
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make

sudo cp src/redis-server /usr/local/bin/
sudo cp src/redis-cli /usr/local/bin/

sudo mkdir /etc/redis
sudo mkdir /var/redis
sudo cp utils/redis_init_script /etc/init.d/redis_6379
sudo cp redis.conf /etc/redis/6379.conf
sudo mkdir /var/redis/6379
sudo vim /etc/redis/6379.conf
```
編輯:

  • Set daemonize to yes (by default it is set to no).
  • Set the pidfile to /var/run/redis_6379.pid (modify the port if needed).
  • Change the port accordingly. In our example it is not needed as the default port is already 6379.
  • Set your preferred loglevel.
  • Set the logfile to /var/log/redis_6379.log
  • Set the dir to /var/redis/6379 (very important step!)

```
sudo update-rc.d redis_6379 defaults
```



3. 前五步驟 https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-16-04

```
sudo vim /etc/default/ufw
# => check ipv6
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow 22
```












config/initilaize/sidekiq.rb
```
schedule_file = "config/schedule.yml"

if File.exists?(schedule_file) && Sidekiq.server?
  Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
end
```

config/sidekiq.yml
```
---
:concurrency: 4
:queues:
  - critical
  - high
  - default
  - low
  - mailers

```


https://medium.com/@thomasroest/properly-setting-up-redis-and-sidekiq-in-production-on-ubuntu-16-04-f2c4897944b5