Skip to content

Instantly share code, notes, and snippets.

View yzhong52's full-sized 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 February 17, 2020 00:04
Building a Client App From Scratch (ViewController with Client)
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 / index.ts
Created May 24, 2020 20:15
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 / gist:4f86787f1a0cdd54ba038e177107bdec
Last active August 12, 2020 15:13
Check the service using port (mac)

Check The Process Using Port

In ~/.zshrc, put the following:

pidportfunction() {
    lsof -n -i4TCP:$1 | grep LISTEN
}
alias pidport=pidportfunction
@yzhong52
yzhong52 / readme.md
Last active September 11, 2020 03:07
在Ubuntu操作系统下运行shiny服务器

在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 / readme.md
Created October 30, 2020 20:33
To Kill a Process Using a Port (Mac)

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"
@yzhong52
yzhong52 / PurchaseRequest-formatted.log
Last active September 6, 2021 13:49
Sublime Text Plugin - PurchaseRequest Formatted
PurchaseRequest(
itemId: 375,
name: "Spook",
price: Amount(
value: 100,
currency: 'USD'
),
insurancePolicies=[
20931,
12035
@yzhong52
yzhong52 / ExampleCommand.py
Created September 6, 2021 13:51
Sublime Text Plugin - ExampleCommand.py
import sublime
import sublime_plugin
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, 0, "Hello, World!")
@yzhong52
yzhong52 / BracketFormatterCommand (part 1).py
Created September 6, 2021 14:01
Sublime Text Plugin - format
import sublime
import sublime_plugin
def format(input):
output = ""
counter = 0
SPACE = ' '
for char in input:
if char in "([{":
counter += 1
@yzhong52
yzhong52 / ExampleCommand.py
Created September 6, 2021 14:01
Sublime Text Plugin - ExampleCommand.py
def format(input):
...
class BracketFormatterCommand(sublime_plugin.TextCommand):
def run(self, edit):
whole_region = sublime.Region(0, self.view.size())
text = self.view.substr(sublime.Region(0, self.view.size()))
formatted_text = format(text)
self.view.replace(edit, whole_region, formatted_text)
@yzhong52
yzhong52 / working_with_json.py
Created September 8, 2021 12:17
Serialize and Deserialize complex JSON in Python
from typing import List
import json
class Student(object):
def __init__(self, first_name: str, last_name: str):
self.first_name = first_name
self.last_name = last_name
@classmethod
def from_json(cls, data):