Posts

How to convert Markdown into HTML

Nice solution to convert MarkDown to html!!! Steps as follows: 1. open link StackEdit 2. draft what you intend to memo 3. menu -> import/export -> export as HTML (choose Plain HTML ) Welcome to StackEdit! Hi! I’m your first Markdown file in StackEdit . If you want to learn about StackEdit, you can read me. If you want to play with Markdown, you can edit me. Once you have finished with me, you can create new files by opening the file explorer on the left corner of the navigation bar. Files StackEdit stores your files in your browser, which means all your files are automatically saved locally and are accessible offline! Create files and folders The file explorer is accessible using the button in left corner of the navigation bar. You can create a new file by clicking the New file button in the file explorer. You can also create folders by clicking the New folder button. Switch to another file All your files and folders are presented as a tree in the file explorer. You ...

關於 object identification algorithm (1): HOG

HOG, histogram of orientation gradient, 傳統影像處理上在做 image processing/object identification/object classification 最常見的名詞, 是由 Dalal 與 Triggs 在 CVPR 2005 的發表 Histogram of Oriented Gradients for Human Detection , 主要是證明一個物件局部外觀可以透過其邊界方向分布 (或稱方向梯度)有效描述 (local object appearance can be effectively described by distribution of edge direction or orientated gradients)。網路上介紹這算法的文章太多,這裡僅是整理一下個人的認知。 skimage.feature.hog(image, orientations=9, pixels_per_cell=(8, 8), cells_per_block=(3, 3), block_norm=None, visualize=False, visualise=None, transform_sqrt=False, feature_vector=True, multichannel=None) 以上 scikit-iamge 的 hog descripter 用法,從參數上理解是   image : input image   orientations : 指的是 HOG 算法中的梯度/方向, 即 histogram 中的 bins, 9 表示將 180分成 [20,40,60,80,100,120,140,160,180].   pixels_per_cell : 定義作 convolution 時的最小單位 cell 所包含的 pixel 數, 預設[8x8] = 64   cells_per_block : 定義 block 內作 normalization 時所包含的最小單位 cell數, 預設[3x3] = 9   block_norm : 指的是針對normalization 時作 L1 或 L2. 接著是影像處...

[IOS] 學習記錄(三)-TBA

:如何引入 cocoapods 自己建一個 Podfile 後 pod install 即可 另外先前遇到 /usr/bin/xcodeproj  permission denied 的問題,  似乎是 gem 的路徑問題, 先忽略了. :如何引入存在的 projects/library (あ)直接將 folder 以「拖曳」的方式新增到 project, 然後選擇   added folder: create groups   這是因為 xcode 是以 group 抽象化的形式做 hierarchy 而非實際的 folder (い)enable 「Defines Module」 到 project > Build Settings > Packaging >  Defines Modules 切換為 Yes (う)另外要注意的是,  swift projects import to swift project 是 「no import statement」的,  可以參考 這篇說明 。

git 刪除 commit (before/after push), 刪除 remote folder, 強制 push

早上用 swift 寫了個 new feature, 想要放到 github 上, 但是遇到幾個老問題, 這裡記錄一下。 1. 上傳時忽略不必要或者敏感的 files, folder 利用 .gitignore (但他似乎沒能達到需求) 2. 步驟 1 失敗了時, 該怎麼辦 git rm -r --cached NOT_UPLOAD_FOLDER 3. 如何利用 rebase 移除不必要的 commit ***  等等,先記得備份檔案到別處!  *** >git log  先查詢想要移除的 commits 的前一個 commit_code >git rebase -i [commit_code] 這指令會列出想要修正的 commit, 直接刪除不需要的commits >git rebase --continue 運氣好的話(沒有conflict)可以直接做 rebase >git status 這表示發生 conflict 了, 查一下需要修改哪些檔案 How-to-resolve-conflict 這連結給了解決的一些方式, 我是直接 git add 解決... lol 4. 如何強制更新 remote branch 這裡是因為 3 是 local 的 rebase,  github 上仍是存在  commit, 導致 push 失敗。 *** 等等,你真的知道這在幹嘛嗎 *** >git push origin master --force

一週一記事

Image
ELM, 另一種 functional language, 是說一直沒能有機會接觸這語言,今天看到 meetup 有人開團,可惜時間是一般日,還是先上網做點功課,有興趣再去好了。 quora 上有人分享心得可以參考。 jupyter, 這是在更新 ipython 到 4.0 時因為缺少這元件, 才發現 iPython 在 2015年8月時有了重大的更新, 除了讓 iPython 脫離 python-centric 的刻板印象外,亦支援其他語顏,做到更 language-agnostic 的 interactive programming。 【原文】  Exclusive – Bloomberg Head of Data Science Gideon Mann Talks Machine Learning and Financial Data Gideon Mann, Head of Data Scientist at BloomBerg. incrunchdata News 對他的採訪, 有兩個方向    what they are focusing on in their current roles    what their interest are outside of data. 1. which of your skills do you find most relevant for success as Head of Data Science?  要成為 effective data scientist 必須具備三項   a. skill to apply techniques to utilize data   b. deep knowledge of mathematics   c. ability to listen (most important since the solution to problem is often deeply rooted in the question itself) 2. what does the first hour of your work day usually lo...

git 時不同帳戶,不同專案的管理

【緣由】原先 laptop 上都是自己的 github account, 可因為前陣子也因為需要開新 account 用來 clone 了公司的 project, 於是修改了設定。導致早上要 submit 自己的東西到自己的 github 時卻發現 account 是公司的. 這花了不少時間理解,決定還是筆記一下。 Host work.github.com HostName github.com User WORK_GITHUB_USERNAME PreferredAuthentications publickey IdentityFile ~/.ssh/id_work_rsa IdentitiesOnly yes Host personal.github.com HostName github.com User PERSONAL_GITHUB_USERNAME PreferredAuthentications publickey IdentityFile ~/.ssh/id_personal_rsa IdentitiesOnly yes (1) 首先,修改 ~/.ssh/config, 增加各自的設定 (參考上例). HOST 的 [url] 只是接下來幫你找到該設定,怎麼填並無太大關係。 $ git config user.name "John Doe" $ git config user.email johndoe@example.com (2) 接著, 設定 local repository 的帳號密碼 。很重要!因為我就耗在這裡... orz  之前就是沒改這個部分,直接跳 (3)  後,submit 的仍是公司 account... [remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = git@personal.github.com:PERSONAL_GITHUB_USERNAME/project.git (3) 修改 .git/config 的 url,...

[IOS] 如何更新 UITableview/UICollectionView 的 cell

[更新 2016/02/10 ] 不知道為什麼,在刪除 cell 時時常會遇到問題 (out of index). 目前找到下面最可靠的解法 /* ref: 自己的 github */ self.TAGS.removeAtIndex((self.collectView.indexPathForCell(cell)?.row)!) self.collectView.deleteItemsAtIndexPaths([self.collectView.indexPathForCell(cell)!]) 由於需要透過使用者 scroll up/down 時添加 UITableView/UICollectionView 中的 cell,昨晚找了些方法,這裡整理一下。 1: (1) 2: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 3: { 4: // Classic start method 5: } 6: (2) 7: - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell, forRowAtIndexPath:(NSIndexPath *)indexPath 8: { 9: // check if indexPath.row is last row 10: // Perform operation to load new Cell's. 11: } 12: (3) 13: var refreshControl:UIRefreshControl! 14: override func viewDidLoad() 15: { 16: super.viewDidLoad() 17: self.refreshControl = UIRefreshControl() 18: self.refreshControl.attrib...

[IOS] 如何在一個 UILabel 上擺不同的 font type. How to put multiple fonts on one single UILabel at a time

今天本來切好的 label 被設計師說要把字串分開,心裡只有三條線。 上網找解法,果然還真的可以。這裡就貼上解法,因為還挺簡單的。( 解法 ) 另外一個問題是 如何上傳一個 customized font 到 app上 。How to include new fonts to IOS App. 寫 app 跟解算法邏輯果然差很大。

[IOS] 學習記錄(二)

這兩週開發 iOS APP 可以說是一團糟,主要是不熟悉 IB (Interface Builder) 介面,constraint 設定以及 storyboard 跟 segue, xib 三者之間的曖昧情仇(咦?)搞的我每天都在把 view 砍掉重練(馬的),就當作是練功了.這裡記錄一些經驗跟教訓. (參考一)是關於 performance issues, memory leak, reference cycles, etc 的教學文件 1. how to determine hot-spots using time profiler instrument 2. how to detect and fix memory management issues such as strong memory reference cycles using allocations 3. TL;RL :P (參考二)也是關於 memory management 雖說 swift 也有類似 java, python 提供 garbage recycling 跟 ARC (automatic reference counting) 的機制,但是仍是有機會發生 memory issues. 1. retain cycles, 這應該是在說 strong/weak reference, 不知道 swift 能否指定. 2. unnecessary caching, 檢查代碼中的 cache 使用時機. (作者使用 library 去trace, 但不知道是哪個) note:  swift 有些 libraries的底層仍有些是用 objective-c, 所以仍需要小心 (參考三)主要是xib 跟 storyboard 之間元件跟設計上如何互動的教學,雖然我最後決定放棄了 xib ,主因是他在 segue 跟 元件的 event 上增加太多程式邏輯,本來在 storyboard 上可以輕鬆解決的事情卻搞得很累. (參考四)這篇我也忘了當初找他的目的,大概是遇到要動態更新 CHTCollectionViewWaterfallLayout 的 layout 吧,但這文章提到點我覺得很值得一提,就是他 coding 的流程: i. calculate ...

一週一語言

這兩篇挺有意思的,晚點瞧,I am in the middle of something. https://tw.voicetube.com/videos/10385?ref=embed-title&mtc=embed-title http://30plus.30.com.tw/article-content_249_6.html [ throw shade ] 早上看到TNW一則新聞寫   Edward Snowden joins Twitter and immediately throws shade at the NSA  一時還不能理解,於是上網查到大概是「公開嘲諷挖苦但又不直接點出」的意思。 Throw shade 是個近日來快速興起的俚語,意思代表著在公開場合微妙的汙辱人。從字面上的意思可以想像成”丟出一片陰影”就很好理解了。 程度可大可小,例如看到不認同的行為後翻白眼搖頭就可以算Throwing shade。 After buying the last ice cream from the vendor, the little girl behind my queue threw shade at me with her look. 買走了攤販的最後一隻冰淇淋後,排在我後面的那個小女孩用她的表情向我表達了她的鄙視。 (出自facebook  大膽說出你的破英文  ) 另外 business insider 也有提到這字源於 black, latino 的 gay community, throw shade means say something shady to someone, with terribly condescending voice (treat someone as if you are more important or intelligent than them). 文字真是奧妙阿。話說日文也是,說話的藝術,源自於對文字背後隱含的意義的理解,不過也要加上肢體動作來進一步表示,這大概也是學外語最困難的地方。 [ 読解P70例39] 運動を続けて、体調が良くなるのを実感できるのは数週間後からでしょう。 しかし、その間にさまざまな「...

關於咖啡的五四三

Image
一些 A.   好讀網 ,他的「沖泡一杯好咖啡」一系列文章值得一讀,解答我不少疑問。 像是第一篇:決定咖啡豆優劣的因素,氣味跟新鮮度。 氣味很主觀在此不論,新鮮度是自烘培後算起10-14天內是最佳賞味期限。 明顯差異就是手沖時加入熱水會看到明顯的細密氣泡!  (如圖, 出處 ) B. Mobile01選購咖啡機與入門義式咖啡機的基本知識 ,拜讀這位 就愛咖啡香 大大的文章後明顯感受到他對咖啡的熱愛以及為什麼咖啡機價差如此大,手搖與電動咖啡機的差異,又義式機跟一般咖啡機差異。也因為這文章我立馬賣掉入手三天的手搖機買了台小富士。 單品咖啡 (single-origin coffee), 精品咖啡 (specialty coffee) 與特調咖啡 (blend coffee) 的差異? 首先是精品咖啡, 網路上 說這詞翻譯的不精確,該文章作者覺得應該叫精緻咖啡,因為精品咖啡著重在整個咖啡豆生產至煮成一杯咖啡的嚴謹過程,並不光只咖啡豆本身。 其次是單品咖啡,指的是單一產區(一個地區或一個國家)的豆子,主要是享受單一豆子本身所夾帶的獨特風格所以通常不加奶,會讓人誤以為黑咖啡即單品。與單品咖啡相反的,即是混和咖啡,或叫特調咖啡。主要是讓混搭的咖啡豆能帶處更豐富的口感,也常與牛奶相伴,例如常見的摩卡。( 參考 ) 最後,今天拜讀到篇絕品咖啡中的一王二后(自己蝦取的XD),分別是亞買加的藍山、古巴的水晶山,以及夏威夷的科納。怎地說,藍山喝起來像杯水,水晶山則帶點微核桃味,科納還沒有碰到。不過最近都 是喝 kilimanjaro 的AA,強烈酸味帶點果實感。今天買了肯亞馬賽的AA,倒是被老闆唬住了,酸味稍弱,但是焦糖味偏重了些。不過到目前喝的咖啡都很中規中矩。下次應該試試淺煎手沖。

[IOS] 學習記錄(一)

原本是負責案子的後台API 制定開發,最近開始因為時間需要支援前端實現 ios app上類似 facebook like box 的頁面. 之前用 swift 寫過一個簡單的 gaming, 但對於 xcode 上寫真正的 app 還是頭一遭. anyway, 下面紀錄一下思路. 如何實現 facebook like box? 首先查了 developer.appple.com 這功能叫做 Table View  ( create a table view ) 目標:     1.  storyboard, scene, view 的定義     2.  table view, inspector (attribute, identity, etc.) 的操作     3.  customise table view cell     4. 如何使用 delegate 及 datasource     5. swift 的 data types (array, string and OOP)     6. display real data on table view 難度在於對於 view 跟 viewController 之間的 binding 的瞭解. xcode 簡化了很多,但是若沒讀一遍 manual 真的是窒礙難行.  (ex.   How to illustrate UITableViewControlller ) 關於 Error "unexpected found nil while unwrapping an Optional value" 的二三事  1. http://www.iphonelife.com/blog/31369/swift-101-working-swifts-new-optional-values  2. http://www.appcoda.com/beginners-guide-optionals-swift/ 如何 a-synchronizingly loading ...

[leetcode] #121 Best Time to Buy and Sell Stock

這題是給一個 stock price array,  要求一買一賣(*僅能先買後賣)後的最大獲益。 這題很類似 longest subsequence of Integer array, 不過僅只要記錄兩個elements 差的最大值。    profit = maximum(-BuyPrice + SellPrice ) step 1.  profit =  [ prices[i] - minimum( prices[:i-1]) if prices[i] - minimum( prices[:i-1]) > profit ][0] step 2. minimum( prices[:i-1] 可拆解為 minPrice = price[0]; ...  minPrice = min(minPrice, price[i]); 1: public int maxProfit(int[] prices) { 2: if (prices.length <= 1) { 3: return 0; 4: } 5: int profit = 0; 6: int minPrice = prices[0]; 7: for (int i=1;i<prices.length;i++) { 8: if (prices[i] - minPrice > profit) { 9: profit = prices[i] - minPrice; 10: } 11: if (minPrice > prices[i]) { 12: minPrice = prices[i]; 13: } 14: } 15: return profit; 16: }

[leetcode] #120 triangle

Image
#120 Triangle 這題是給一個 triangle 結構的 list, 每個list長度對應他的depth, ex. list[i].size() = i-th depth+1, 求從root(1st list)走到 leaf (last list) 時的最小花費. 以下給兩種解法。值得注意的是用bottom-up 的解法很漂亮, 但是(1)邊界的node處理要小心;(2)作空間最佳化的思路也不是容易懂。 1: public int minimumTotal(List<List<Integer>> a) { 2: if (a.size() == 0) { 3: return 0; 4: } 5: int c0 = 0, c1 = 0; 6: List<Integer> row = null; 7: for (int i=0; i<a.size(); i++) { 8: row = a.get(i); 9: for (int j=0; j< row.size(); j++) { 10: if (j==0) { 11: c0 = 0; 12: } else { 13: c0 = c1; 14: } 15: if (j<i) { 16: } 17: } 18: } 19: } 20: public void traverse(List<List<Integer>> a, int depth, int i, int sum, Integer ret) { 21: List<Integer> row = a.get(depth); 22: s...

[leetcode] #70 Climb stairs

這題很簡單, 題目要求給n個階梯, 若每次僅走一步或兩步, 則走到第n階的路徑有多少種。 (思路) 1. 第 i-th 階 step[i] 儘可能從 step[i-1] 或 step[i-2] 出發. 2. 要留意 1st 跟 2rd 階的算法 1: public class Solution { 2: public int climbStairs(int n) { 3: if (n<=0) 4: return 0; 5: int[] steps = new int[n+1]; 6: steps[0] = 1; 7: steps[1] = 1; 8: for (int i=2;i<=n;i++) { 9: steps[i] = steps[i-1] + steps[i-2]; 10: } 11: return steps[n]; 12: } 13: }

leetcode 考古題連結

個人覺得到目前這兩個網站的分類跟解題說明做得不錯,參考一下。 http://siddontang.gitbooks.io/leetcode-solution/content/array/find_minimum_in_rotated_sorted_array.html http://www.programcreek.com/2012/11/top-10-algorithms-for-coding-interview/

[leetcode] #215 Kth Largest Element in an Array

Image
下面的方法都太爛了,目標只有一個:如何 worst case = O(n)下實作 selection sort 。 其實就是透過 medians and order statistics 的概念。 Order Statistics 就是假設在一個 unsorted array 下要找到 i-th order 的值。要找到 maximum or minimum 一般可在 O(n) 下找到,即使是 i-th 也可以先作 O(nlogn) 的排序後找到。但是否有比 O(nlogn)更快的方法? => how can we modify quicksort to obtain expected-case $\theta(n)$  (hint)   pivot, partition, but recur only on one set of data. no join 複習一下 divide and conquer (這裡叫做 randomized_select) 1: def RANDOMIZED_SELECT(A, p, r, i): 2: if p == r: 3: return p 4: q = PARTITION(A, p, r) 5: k = q-p+1 6: if k == i: 7: return A[:i+1] 8: elif k < i: 9: return RANDOMIZED_SELECT(A, q+1, r, i-k) 10: else: 11: return RANDOMIZED_SELECT(A, p, q-1, i) 12: def PARTITION(A, p, r): 13: pivot = A[r] 14: i = p - 1 15: for j in range(p, r): 16: if A[j] <= pivot: 17: j+=1 18: swap(A, i,j) 19: swap(i+1, r) 20: return i+1  randomized_select 即便在一般時間是 O(n...

關於 java Integer 的 minimum 跟 maximum 的表示方式

要顯示 java  Integer type 的 minimum and maximum 的方式 Integer.MAX_VALUE (2147483647)  及 Integer.MIN_VALUE (-2147483648) 若不用內建涵式, 直覺會用: 1<<31 -1<<31 可結果卻都是 -2147483648 這是由於 1<<31 已發生 overflowed, 在java中下一個位數則是 -1<<31 要得到正確的 MAX_VALUE 可用 (1<<31)-1 其實這是我在作 leetcode (Reverse Integer) 的考題遇到的問題. 該題目回傳值跟輸入值是 int, 但側資的輸出有可能是 overflowed 的情形! 真是太狡猾了。 http://goo.gl/7el8Kf

R 語言:邏輯回歸 Logistic Regression using R language (三)

Image
文件上有另一個多個數值變數的回歸分析的例子,這裏簡單記錄一下分析流程與結果。 有三組自變數 { w, c, wc(w+c) }, 應變數為 seeen {0,1} STEP 1. 找出相關性 > str(gorilla) 'data.frame': 49 obs. of 4 variables: $ seen: int 0 0 0 0 0 0 0 0 0 0 ... $ W : int 126 118 61 69 57 78 114 81 73 93 ... $ C : int 86 76 66 48 59 64 61 85 57 50 ... $ CW : int 64 54 44 32 42 53 41 47 33 45 ... > cor(gorilla) seen W C CW seen 1.00000000 -0.03922667 0.05437115 0.06300865 W -0.03922667 1.00000000 0.43044418 0.35943580 C 0.05437115 0.43044418 1.00000000 0.64463361 CW 0.06300865 0.35943580 0.64463361 1.00000000 > 根據上面的結果發現其相關性與 seen 甚低。 > glm.out = glm(seen ~ W*C*CW, family=binomial(logit), data=gorilla) > summary(glm.out) Call: glm(formula = seen ~ W * C * CW, family = binomial(logit), data = gorilla) Deviance Residuals: Min 1Q Median 3Q Max -1.8073 -0.9897 -0.5740 1.2368 1.7362 Coefficients: Estimate Std. Error z ...

R 語言:邏輯回歸 Logistic Regression using R language (二)

Image
> library('MASS') > data(menarche) > str(menarche) 'data.frame': 25 obs. of 3 variables: $ Age : num 9.21 10.21 10.58 10.83 11.08 ... $ Total : num 376 200 93 120 90 88 105 111 100 93 ... $ Menarche: num 0 0 0 2 2 5 10 17 16 29 ... > summary(menarche) Age Total Menarche Min. : 9.21 Min. : 88.0 Min. : 0.00 1st Qu.:11.58 1st Qu.: 98.0 1st Qu.: 10.00 Median :13.08 Median : 105.0 Median : 51.00 Mean :13.10 Mean : 156.7 Mean : 92.32 3rd Qu.:14.58 3rd Qu.: 117.0 3rd Qu.: 92.00 Max. :17.58 Max. :1049.0 Max. :1049.00 上頭是 R 所提供的一個很好的 Logistic Regression with One numerical predictor 的例子。 簡單的說就是有一組三個自變數分別是 age, total 以及 menarche ,中文的大意是『我們收集了一共25組女性樣本,記錄每組的平均年紀,訪問次數以及受訪者是否發生初經』。 > plot(Menarch/Total ~ Age, data=menarche) 上圖很明顯的指出 age 與 menarch rate 呈指數關係,適用於羅輯回歸。 > glm.out = glm(cbind(Menarche, Total-Menarche) ~ Age, family = binomial(logit), data=m...