In ~/.zshrc
, put the following:
pidportfunction() {
lsof -n -i4TCP:$1 | grep LISTEN
}
alias pidport=pidportfunction
import UIKit | |
import Alamofire | |
class ImageManager { | |
private let session = Alamofire.Session() | |
static let shared = ImageManager() | |
func load(url: URLConvertible, completionHandler: @escaping (UIImage) -> Void) -> Void { |
extension ViewController: UITableViewDataSource { | |
... | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let tableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! NewsTableViewCell | |
let article = articles[indexPath.row] | |
tableViewCell.titleLabel.text = article.title | |
tableViewCell.contentLabel.text = article.content |
import Foundation | |
enum LoadState<T> { | |
case loading | |
case updating | |
case loaded(response: T) | |
case failed(error: Error) | |
} |
import Foundation | |
import RxSwift | |
import RxCocoa | |
class NewsManager { | |
typealias NewsLoadState = LoadState<ArticlesResponse> | |
enum LoadError: Error { | |
case unknownError | |
} |
class ViewController: UIViewController { | |
private let manager = NewsManager() | |
private let disposeBag = DisposeBag() | |
private var articles: [Article] = [] | |
private let titleLabel: UILabel = { | |
let label = UILabel() | |
label.text = NSLocalizedString("News", comment: "") |
// This snippet is a lazy, temporary, inappropriate, not secure fix for error: | |
// | |
// "No 'Access-Control-Allow-Origin' header is present on the requested resource". | |
// | |
// It works as a proxy and add 'Access-Control-Allow-Origin: *' to the response header. | |
// | |
// 1) Init proejct and add dependencies: | |
// | |
// ``` | |
// npm init |
Put this helper funciton in your ~/.zshrc
or ~/.bash_profile
:
release_port() {
pid=$(lsof -ti:$1)
if [ -z $pid ]; then
echo "Nothing is running on port $1"
else
kill $pid
echo "Killed process on port $1 with pid $pid"