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 / 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
@yzhong52
yzhong52 / Api.Swift
Created Feb 16, 2020
Building a Client App From Scratch
View Api.Swift
import Foundation
class Article: Decodable {
let title: String
let description: String?
let url: URL
let urlToImage: String?
let content: String?
}
@yzhong52
yzhong52 / ViewController.swift
Last active Feb 16, 2020
Building a Client App From Scratch (ViewController with Client and TableView)
View ViewController.swift
import UIKit
import RxSwift
import SafariServices
class ViewController: UIViewController {
private let disposeBag = DisposeBag()
private let client = NewsClient()
private var articles: [Article] = []
@yzhong52
yzhong52 / ViewController.swift
Last active Feb 16, 2020
Building a Client App From Scratch (ViewController with UITableViewDelegate)
View ViewController.swift
extension ViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let article = articles[indexPath.row]
present(SFSafariViewController(url: article.url), animated: true, completion: nil)
}
}
@yzhong52
yzhong52 / ViewController.swift
Last active Feb 16, 2020
Building a Client App From Scratch (UITableViewDataSource)
View ViewController.swift
extension ViewController: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return articles.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
@yzhong52
yzhong52 / render_teapot.py
Created Feb 16, 2020
Beyond data scientist: 3d plots in Python with examples
View render_teapot.py
vertices, triangles = read_obj("teapot.obj")
x = vertices[:,0]
y = vertices[:,1]
z = vertices[:,2]
ax = plt.axes(projection='3d')
ax.set_xlim([-3, 3])
ax.set_ylim([-3, 3])
ax.set_zlim([0, 3])
ax.plot_trisurf(x, z, triangles, y, shade=True, color='white')
@yzhong52
yzhong52 / read_obj.py
Last active Feb 16, 2020
Beyond data
View read_obj.py
import numpy as np
def read_obj(filename):
triangles = []
vertices = []
with open(filename) as file:
for line in file:
components = line.strip(' \n').split(' ')
if components[0] == "f": # face data
# e.g. "f 1/1/1/ 2/2/2 3/3/3 4/4/4 ..."
indices = list(map(lambda c: int(c.split('/')[0]) - 1, components[1:]))
@yzhong52
yzhong52 / NewsClient.swift
Last active Feb 16, 2020
Building a Client App From Scratch (NewsClient)
View NewsClient.swift
// TODO: update the API key
private let apiKey: String = "c8707b3709a34bbe90837f63c71537ed"
private let path: String = "https://newsapi.org/v2/top-headlines?apiKey=\(apiKey)&country=us"
enum ClientError: Error {
case missingResponseData
}
class NewsClient {
func headlines() -> Single<ArticlesResponse> {
@yzhong52
yzhong52 / readme.md
Created Sep 2, 2019
Differences between Numpy array and regular python array
View readme.md

In regular python array, a slice view of an array is actually a copy. Modifiying elements through the slice won't affect the original array.

>>> arr = [0, 1, 2]
>>> arr[0:][0] = 100
>>> arr
[0, 1, 2]
@yzhong52
yzhong52 / gist:270dbcc7fb1c80303c8111109446ae96
Created Aug 13, 2019
sudo systemctl status -l -n 20 prometheus.service
View gist:270dbcc7fb1c80303c8111109446ae96
[CA2 yzhong@ca2-p1v01-mon4-0001 ~]$ sudo systemctl status -l -n 20 prometheus.service
● prometheus.service - Prometheus
Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2019-08-09 17:04:21 UTC; 4 days ago
Process: 16654 ExecReload=/bin/kill -s HUP $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 15929 (prometheus)
CGroup: /system.slice/prometheus.service
└─15929 /opt/prometheus/prometheus/prometheus --config.file /opt/prometheus/prometheus/prometheus.yml --storage.tsdb.path=/srv/prometheus/prometheus --storage.tsdb.retention=120d --web.listen-address=0.0.0.0:9090
Aug 13 21:19:42 ca2-p1v01-mon4-0001.ca2.internal.zone prometheus[15929]: level=warn ts=2019-08-13T21:19:42.797Z caller=manager.go:513 component="rule manager" group=HoustonDashboard msg="Evaluating rule failed" rule="alert: HoustonDashboardBackendErrorRate\nexpr: ((sum by(instance) (rate(haproxy_backend_http_responses_total{backend=~\"houston-dashboa
You can’t perform that action at this time.