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
@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 / 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 / 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 / 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 / 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/
env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography
curl -i -H "Origin: http://[web app domain]" -H "Access-Control-Request-Method: GET" -X OPTIONS [target web resource]
@jonascheng
jonascheng / gist:e6530fa4249e78e5174550f853642987
Created February 5, 2017 01:06
android tool hierarchyviewer is not working
The standalone version of hieararchyviewer is deprecated.
Please use Android Device Monitor (tools/monitor) instead.
08:57:39 E/ViewServerDevice: Unable to debug device: samsung-sm_n9208-05157df5db5a2417
08:57:39 E/hierarchyviewer: Missing forwarded port for 05157df5db5a2417
08:57:39 E/hierarchyviewer: Unable to get the focused window from device 05157df5db5a2417
For anyone working with Android 4.1 or later:
you can get Hierarchy Viewer working by setting the environment variable ANDROID_HVPROTO to ddm.
Mac OSX/Android Studio users, remember to start hierarchy viewer from command line so it will pick up the environment variable.
@jonascheng
jonascheng / handler.js
Created January 24, 2017 12:25
AWS Lambda blueprint cloudwatch-alarm-to-slack
'use strict';
/**
* Follow these steps to configure the webhook in Slack:
*
* 1. Navigate to https://<your-team-domain>.slack.com/services/new
*
* 2. Search for and select "Incoming WebHooks".
*
* 3. Choose the default channel where messages will be sent and click "Add Incoming WebHooks Integration".
@jonascheng
jonascheng / gist:9c0ec4f03af4d6a56203d802dfff29c0
Created November 27, 2016 06:50
Install python 3.3.x with pyenv in OSX
CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 3.3.0