2017年5月19日 星期五

非常詳細且很棒的 hypermedia api 介紹


讓 client side 知道下一步做什麼,進而可以寫出像 call method 一樣的 client helper。


https://robots.thoughtbot.com/writing-a-hypermedia-api-client-in-ruby

2017年4月27日 星期四

About testing

unit test, integration test, acceptance test 有什麼不同呢?

unit test 就是 test 最基本的東西,例如一個 function ,藉由確定每個 function 的正確性來確保程式正常運作
integration test 則有點像是橫跨不同 unit 的 test,意即 integration test 測的是某個行為,而這個行為會觸發很多 funcitons,雖然每個 function 都有 unit test,但藉由 integration test 我們可以確保這個行為是正常發生的
acceptance test 則是更宏觀一點的測試,通常是更口語一點,更 feature 導向的測試,例如「我點擊了A按鈕後應該進入B頁面」這類的測試,不用考慮程式實作的細節只考慮行為產生出的結果



http://stackoverflow.com/questions/4904096/whats-the-difference-between-unit-functional-acceptance-and-integration-test

https://martinfowler.com/articles/microservice-testing/

2017年4月25日 星期二

About Redis

In memory, key-value store. 所以其實 redis 就是一個 database,只是他所有的東西都存在 memory 而且是屬於 NoSQL 的 database。

最常用的場景就是拿來快取東西。

In memory 表示是直接存在記憶體上不是存在硬碟裡,由於記憶體上有實作更簡單的演算法所以需要的 CPU 資源較少,而且在 query 資料的時候可以減少搜尋硬碟的時間所以讀寫很快,這也是為什麼大家常常拿 Redis 當 Cache server 的原因
https://en.wikipedia.org/wiki/In-memory_database

當然 Redis 也有提供讓資料存寫進硬碟的功能,關鍵字:Expire
http://huli.logdown.com/posts/926762-redis-introduction



http://stackoverflow.com/questions/7888880/what-is-redis-and-what-do-i-use-it-for

延伸閱讀
https://medium.com/ruby-on-rails/easy-caching-with-rails-4-heroku-redis-5fb36381628

2017年4月24日 星期一

React native layout with flexbox


flex 基本上就是填充
https://facebook.github.io/react-native/docs/height-and-width.html#content

flexDirection 就是主要的方向,如果是橫向就是 row 縱向就是 column, default 是 column

justifyContent 就是根據主要方向(flexDirection)分佈元件的方式,Available options are flex-start, center, flex-end, space-around, and space-between.

space-between:在元件之間安插一樣長的空白區塊
space-around:在元件旁邊安插一樣長的空白區塊,跟 space-between 不同的是 space-around 即使是最外圍的元件的外側也會安插空白區塊
flex-start:放在 flex direction 的前端
flex-end:放在 flex direction 的後端
center:放在 flex direction 的中間

alignItems 則是根據次要方向(flexDirection 的相反)排列元件的方法,Available options are flex-start, center, flex-end, and stretch.
flex-start, center, flex-end 就不用多做解釋了,如果 flexDirection 是 column 而 alignItems 是 center 代表水平置中,flex-end 代表靠右
stretch 則代表延展,如果元件本身沒有設定次要方向的長度的話就把次要方向延展至底,例如 flexDirection 是 column 的情況下不設元件的 width 就會將元件平行拉長到底


https://facebook.github.io/react-native/docs/flexbox.html#content

2017年4月13日 星期四

DNS-cache-poisoning or DNS Spoofing, Pharming Attack

很清楚的影片:
https://www.checkpoint.com/defense/advisories/public/dnsvideo/


簡單解釋:
Local 的 DNS Server 通常會有 Cache,如果能夠找到對應的網址就不會問網路上的 DNS Server,攻擊原理就是趁 Local DNS Server 問網路上的 Master DNS Server 而 response 還沒回來時假造 Master DNS Server 的 Response 讓 Local DNS Server cache 起來,這樣就可以把 User 導到自己假造的位置去,進而實行網址轉嫁攻擊(Pharming Attack)

Pharming Attack 跟 網路釣魚(Phishing)的不同在於後者是利用 email 騙受害者,而 Pharming Attack 是專指將使用者導向錯誤網站釣魚方式
http://searchsecurity.techtarget.com/answer/Phishing-vs-Pharming-attacks


Pharming Attack 還有另外一種常見的攻擊方式是修改 hosts 檔,因為電腦會先找 /etc/hosts 的設定,如果找到就不會去問 DNS,所以只要攻擊者藉由木馬或是任何方式改了 hosts 的設定,就一樣可以把使用者轉嫁到惡意網站去。
http://www.informationsecurity.com.tw/article/article_detail.aspx?tv=&aid=6813&pages=2






http://blog.miniasp.com/post/2008/10/22/Be-careful-DNS-cache-poisoning-attack.aspx

HTTP Slowloris Denial Of Service

上一篇文章Reference 延伸閱讀學到的東西

這種攻擊主要是拿來攻擊 Server 讓 Server 連線數滿載沒辦法回應新的 Request

兩種攻擊模式, GET 和 POST
攻擊基本原理:Hold 住連結不放開,佔用 Server 連線

1. GET: 送 Request 的時候故意不送完整的 HTTP Header,慢慢送完
2. POST: 送 Request 的時候送很大的 content-length,然後很慢的速度送,例如每十秒送一個字


P.S./ Denial Of Service 就是阻斷式服務攻擊的意思,常見寫法為 DoS


http://www.piao2010.com/%E4%B8%80%E6%AC%A1%E5%88%86%E4%BA%AB%E5%BC%95%E5%8F%91%E7%9A%84%E8%A1%80%E6%A1%88-http-slowloris-denial-of-service

2017年4月12日 星期三

Mac Spoofing - 竄改 MAC Address 使用付費 Wifi



原理很簡單,先查查看有哪些人在使用付費 Wifi,把自己的 MAC Address 改成他們的,Boom! 開始上網。

查自己 MAC (之後改回來):ifconfig en1 | grep ether
查哪些人在使用付費 Wifi:arp -a
改 MAC Address:sudo ifconfig en1 ether [mac address to spoof]

Bonus:
用 https://www.torproject.org/ 瀏覽

這做法可能會造成 MAC Conflit,這就要看Switch 的硬體怎麼實作的了,也許會把封包同時送給兩個位置或是只送一個或是都不送...


P.S./ 這裡指的付費 Wifi 是指沒有設密碼的 Public WIFI,連進去後要求提供信用卡資訊或是帳密登入才可以使用的 WIFI Hotpot。


https://www.youtube.com/watch?v=Agodg3dmwaQ
https://www.quora.com/Is-a-MAC-address-conflict-possible