Skip to content

Instantly share code, notes, and snippets.

Avatar
⌨️
consider multiple solutions, commit on one, and iterate

Yuchen yzhong52

⌨️
consider multiple solutions, commit on one, and iterate
View GitHub Profile
@yzhong52
yzhong52 / readme.md
Last active Sep 11, 2020
在Ubuntu操作系统下运行shiny服务器
View readme.md

在Ubuntu操作系统下运行shiny服务器

Basic Command

ls - show the current diretory pwd - show the current folder cd - go to folder nano - edit file cat - show the content of a file mv - move a folder to another location

@yzhong52
yzhong52 / gist:4f86787f1a0cdd54ba038e177107bdec
Last active Aug 12, 2020
Check the service using port (mac)
View gist:4f86787f1a0cdd54ba038e177107bdec

Check The Process Using Port

In ~/.zshrc, put the following:

pidportfunction() {
    lsof -n -i4TCP:$1 | grep LISTEN
}
alias pidport=pidportfunction
View index.ts
// 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
@yzhong52
yzhong52 / ViewController.swift
Created Feb 16, 2020
Building a Client App From Scratch - ViewController NewsManager
View ViewController.swift
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: "")
@yzhong52
yzhong52 / NewsManager.swift
Created Feb 16, 2020
Building a Client App From Scratch - NewsManager
View NewsManager.swift
import Foundation
import RxSwift
import RxCocoa
class NewsManager {
typealias NewsLoadState = LoadState<ArticlesResponse>
enum LoadError: Error {
case unknownError
}
@yzhong52
yzhong52 / LoadState.swift
Created Feb 16, 2020
Building a Client App From Scratch - LoadState
View LoadState.swift
import Foundation
enum LoadState<T> {
case loading
case updating
case loaded(response: T)
case failed(error: Error)
}
@yzhong52
yzhong52 / gist:3f1497d7c58c7b1b0d97236b1e0d39ba
Created Feb 16, 2020
Building a Client App From Scratch (UITableViewDataSource v2)
View gist:3f1497d7c58c7b1b0d97236b1e0d39ba
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
@yzhong52
yzhong52 / ImagesManager.swift
Created Feb 16, 2020
Building a Client App From Scratch - Image download extension
View ImagesManager.swift
import UIKit
import Alamofire
class ImageManager {
private let session = Alamofire.Session()
static let shared = ImageManager()
func load(url: URLConvertible, completionHandler: @escaping (UIImage) -> Void) -> Void {
@yzhong52
yzhong52 / NewsTableViewCell.swift
Last active Feb 16, 2020
Building a Client App From Scratch (NewsTableViewCell)
View NewsTableViewCell.swift
import UIKit
class NewsTableViewCell: UITableViewCell {
let titleLabel: UILabel = {
let lable = UILabel()
lable.translatesAutoresizingMaskIntoConstraints = false
lable.numberOfLines = 3
lable.font = UIFont.systemFont(ofSize: 14)
return lable
@yzhong52
yzhong52 / ViewController.swift
Last active Feb 17, 2020
Building a Client App From Scratch (ViewController with Client)
View ViewController.swift
import UIKit
import RxSwift
class ViewController: UIViewController {
private let disposeBag = DisposeBag()
private let client = NewsClient()
override func viewDidLoad() {
super.viewDidLoad()
client.headlines().subscribe(onSuccess: { (response) in
You can’t perform that action at this time.