Skip to content

Instantly share code, notes, and snippets.

View jonascheng's full-sized avatar
🏠
Working from home

Jonas Cheng jonascheng

🏠
Working from home
View GitHub Profile
curl -i -H "Origin: http://[web app domain]" -H "Access-Control-Request-Method: GET" -X OPTIONS [target web resource]
env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography
@jonascheng
jonascheng / wget-download-site.sh
Created July 17, 2017 15:09
Use wget to get a local copy of a site with all files and folders
wget -m -p -E -k -K -np http://site/path/
@jonascheng
jonascheng / term_colors.py
Created December 12, 2017 10:13 — forked from christian-oudard/term_colors.py
Terminal output colors in python
from __future__ import print_function
"""
Utilities for 256 color support in terminals.
Adapted from:
http://stackoverflow.com/questions/1403353/256-color-terminal-library-for-ruby
The color palette is indexed as follows:
0-15: System colors
@jonascheng
jonascheng / list_time_series.py
Created May 16, 2018 02:28
Sample code to list_time_series from GCP Pub/Sub
# export GOOGLE_APPLICATION_CREDENTIALS='credential file in JSON'
import arrow
from google.cloud import monitoring_v3
from google.cloud.monitoring_v3 import enums
from google.cloud.monitoring_v3.types import TimeInterval, Aggregation
from google.api_core import exceptions
client = monitoring_v3.MetricServiceClient()
@jonascheng
jonascheng / celery_beat_checker.py
Created July 2, 2018 07:39
Celery beat health check script, you may specify this inside Dockerfile
import sys
import arrow
import shelve
import os.path
from datetime import datetime, timedelta
# Name of the file used by PersistentScheduler to store the last run times of periodic tasks.
FN_CELERYBEAT = 'celerybeat-schedule'
@jonascheng
jonascheng / EmployeeClass.py
Last active June 9, 2019 15:27
SOLID-EmployeeClass
import datetime
class Employee:
def __init__(self, first_name: str , last_name: str, birth: datetime, hourly_rate: int, labor_hours: int):
self.first_name = first_name
self.last_name = last_name
self.birth = birth
self._hourly_rate = hourly_rate
self._labor_hours = labor_hours
@jonascheng
jonascheng / EmployeeClassWithPrintMethods.py
Created June 8, 2019 14:53
SOLID-EmployeeClassWithPrintMethods
import datetime
class Employee:
// ...
def printForHR(self):
print(u'{},{},{}'.format(self.first_name, self.last_name, self.wage))
def printForIT(self):
print(u'{},{},{}'.format(self.first_name, self.last_name, self.birth))
@jonascheng
jonascheng / EmployeePrintClass.py
Last active June 8, 2019 15:08
SOLID-EmployPrintClass
class EmployeePrinterForHR:
def printCSV(employee: Employee):
print(u'{},{},{}'.format(employee.first_name, employee.last_name, employee.wage))
class EmployeePrinterForIT:
def printCSV(employee: Employee):
print(u'{},{},{}'.format(employee.first_name, employee.last_name, employee.birth))
@jonascheng
jonascheng / SalesPersonClass.py
Created June 9, 2019 02:47
SOLID-SalesPersonClass
class SalesPerson(Employee):
@property
def bonus(self):
return self._bonus
@bonus.setter
def bonus(self, bonus):
self._bonus = bonus