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 / Makefile
Last active June 25, 2017 15:12 — forked from wenchy/Makefile
Compile all .cpp files into one target under the current directory.
CC := g++
CFLAGS := -Wall -g
TARGET := example
# $(wildcard *.cpp /xxx/xxx/*.cpp): get all .cpp files from the current directory and dir "/xxx/xxx/"
SRCS := $(wildcard *.cpp)
# $(patsubst %.cpp,%.o,$(SRCS)): substitute all ".cpp" file name strings to ".o" file name strings
OBJS := $(patsubst %.cpp,%.o,$(SRCS))
all: $(TARGET)
@yzhong52
yzhong52 / readme.md
Last active August 19, 2017 03:29
Sublime Text Settings: Auto Intent, Tap to Spaces, Rulers

Preferences > Key Bindings:

[
    { "keys": ["alt+command+l"], "command": "reindent" , "args": {"single_line": false}}
]

Preferences > Settings:

@yzhong52
yzhong52 / replace_or_fail.sh
Created August 29, 2017 21:32
Replace Or Fail
#!/usr/bin/env bash
replace_or_fail() {
FROM_VALUE=$1
TO_VALUE=$2
FILENAME=$3
echo "Replace from '$FROM_VALUE' to '$TO_VALUE' in '$FILENAME'... "
grep -q ${FROM_VALUE} ${FILENAME} && sed -i.old 's/'${FROM_VALUE}'/'${TO_VALUE}'/' ${FILENAME} || ( (>&2 echo "\033[0;31mError: '$FROM_VALUE' not found") && exit 1 )
echo "Done. "
}
@yzhong52
yzhong52 / Readme.md
Last active February 20, 2018 19:26
alias_gen.py

alias generation

Genereate alias for each of the git folder in ~/Documents.

  1. Run the script python3 alia_gen.py
  2. Add the following to .bash_profile
# Added by Yuchen: using alias!
if [ -f ~/.alias_gen ]; then 
@yzhong52
yzhong52 / gist:aaea17f43a5578473d26d0fdba9973bf
Created August 13, 2019 21:51
sudo systemctl status -l -n 20 prometheus.service
[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
@yzhong52
yzhong52 / gist:270dbcc7fb1c80303c8111109446ae96
Created August 13, 2019 21:51
sudo systemctl status -l -n 20 prometheus.service
[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
@yzhong52
yzhong52 / readme.md
Created September 2, 2019 12:55
Differences between Numpy array and regular python array

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 / read_obj.py
Last active February 16, 2020 05:01
Beyond data
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 / render_teapot.py
Created February 16, 2020 05:02
Beyond data scientist: 3d plots in Python with examples
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 / Api.Swift
Created February 16, 2020 15:47
Building a Client App From Scratch
import Foundation
class Article: Decodable {
let title: String
let description: String?
let url: URL
let urlToImage: String?
let content: String?
}