Skip to content

Instantly share code, notes, and snippets.

View oney's full-sized avatar

Wan-Huang Yang oney

View GitHub Profile
@oney
oney / Main.storyboard
Last active August 29, 2015 14:26
UITableViewDataSource
In ViewController
Add a UITableView to view of ViewController
connect UITableView to tableView property of ViewController
connect dataSource of UITableView to ViewController
@oney
oney / highest_profit.rb
Created July 28, 2015 10:11
Get highest profit
def highest_profit(stock_prices)
lowest = buy = sell = stock_prices.shift
stock_prices.each do |price|
current_profit = sell - buy
if (price - lowest) > current_profit
buy = lowest
sell = price
end
if price < lowest
lowest = price
@oney
oney / coleman_liau_readability_score.rb
Last active August 29, 2015 14:26
Compute Coleman–Liau index
def coleman_liau_readability_score(content)
def count_sentence_number(content)
content += " "
counter = 0
'.?!'.split('').each {|c| counter += content.scan("#{c} ").length }
counter
end
sentence_number = count_sentence_number(content)
word_number = content.split.size
@oney
oney / PhoneFormat.swift
Created August 11, 2015 23:59
Phone number formatting
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
var length = getLength(textField.text)
if length == 10 {
if range.length == 0 {
return false
}
}
if length == 3 {
var num = formatNumber(textField.text)
textField.text = "(\(num))"
@oney
oney / ruby_setup.md
Created November 27, 2015 21:03 — forked from julionc/ruby_setup.md
Deploy Ruby On Rails on Ubuntu 14.04

Deploy Ruby On Rails on Ubuntu 14.04

Server: Nginx with Phusion Passenger

Ruby Version: 2.1.3

User System: deploy

User System

@oney
oney / Copy property on Objective-C.md
Last active February 20, 2016 08:11
Copy property on Objective-C

Testing Copy property on Objective-C

Copy property on Objective-C

<!--
* Copyright (c) Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
-->
<!DOCTYPE html>
<html>
<head>

Keybase proof

I hereby claim:

  • I am oney on github.
  • I am oney (https://keybase.io/oney) on keybase.
  • I have a public key ASD9HJnfSSQnKFiLSYpq5AajEFmRGYBaBbktikdePTH2cQo

To claim this, I am signing this object:

extension UIView {
public class func fromNib(nibName: String? = nil, owner: Any? = nil) -> Self {
return fromNib(nibName: nibName, type: self, owner: owner)
}
public class func fromNib<T: UIView>(nibName: String? = nil, type: T.Type, owner: Any? = nil) -> T {
return fromNib(nibName: nibName, type: T.self, owner: owner)!
}
public class func fromNib<T: UIView>(nibName: String? = nil, type: T.Type, owner: Any? = nil) -> T? {