Skip to content

Instantly share code, notes, and snippets.

View tchen's full-sized avatar
:shipit:

Tom Chen tchen

:shipit:
  • Dallas, TX
View GitHub Profile
@tchen
tchen / sample.go
Last active July 22, 2022 08:30
aws-sdk-go-v2 credentials
// How to set up a AWS SDK client using credentials coming from other than the regular AWS_ACCESS_KEY_ID
// e.g. if you have multiple sets of credentials for doing cross-account stuff
import (
"os"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
@tchen
tchen / sample.py
Last active April 8, 2024 01:38
openpyxl: dealing with merged cells
# When exporting excel spreadsheets with merged cells, only the first cell of the merged cell has a value
# This snippet allow you to take the value from the first cell for all the other cells within the merged range
# Tested with openpyxl 3.0.7 as of 2021-06-17
#
# References:
# https://stackoverflow.com/questions/39574991/how-to-detect-merged-cells-in-excel-with-openpyxl
# https://openpyxl.readthedocs.io/en/stable/api/openpyxl.worksheet.merge.html
import openpyxl
def parent_of_merged_cell(cell):
@tchen
tchen / observe.py
Created November 27, 2020 06:34
Observe Bluetooth advertisements for Govee H5075 and H5177 thermo-gygrometer and print out temperature, humidity, battery level
import datetime
from time import sleep
from bleson import get_provider, Observer
def c2f(val):
return round(32 + 9*val/5, 2)
last = {}
def temp_hum(values, battery, address):
@tchen
tchen / README.md
Last active February 27, 2020 06:01
NTILE(), percentile_disc(), percentile_cont()

To use this, place the docker-compose.yaml file in a new directory. Then run:

docker-compose up

Once up, you can access http://localhost:8080 to administrate the db. Login with: postgres/example

Or run this from another terminal for command line access:

docker-compose exec db bash
@tchen
tchen / main.py
Created May 31, 2017 04:59
Tornado JSON request body
# An example tornado request handler that handles both JSON POST request
# bodies and x-www-form-urlencoded POST bodies.
#
# The benefit of JSON request bodies are more complicated and potentially
# nested dict and list data types.
#
# One drawback to JSON request bodies is that arguments can come in
# different types, so handlers will need to perform additional checks.
# With x-www-form-urlencoded fields, all argument values are strings, if
# they exist.
@tchen
tchen / gist:970ac457ab03f274a68dd22703f0f2dc
Created December 2, 2016 15:26
Py3 Virtual Environment bootstrap
# https://docs.python.org/3/library/venv.html
# Under Ubuntu Xenial64, install the following package before getting started
sudo apt-get install python3-venv
# Usage: python3 -m venv [directory]
python3 -m venv ~/env/web
. ~/env/web/bin/activate
@tchen
tchen / new_gist_file_0
Created November 14, 2016 21:58
unix timestamp to human readable format
import datetime
datetime.datetime.fromtimestamp(
int("1284101485")
).isoformat()
@tchen
tchen / 0_reuse_code.js
Created November 14, 2016 21:53
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@tchen
tchen / gist:a844c589f3fab497ff930c116aa267e7
Last active January 8, 2024 07:30
Extract Images From Zillow Home Views
/**
* Note: First, browser through all the images for the home. Then paste the following snippet into the console.
* Images will be saved to the download directory.
*/
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
@tchen
tchen / gist:a1c7f681a4f06f788390
Created September 1, 2015 15:03
Good tips to follow on OSS code maintenance and patching
Tips for getting your patches accepted:
Don't needlessly break compatibility with older versions of PyCrypto. Patches that break compatibility with older version of PyCrypto, especially PyCrypto 2.0.1, will need an explanation about why it's worth breaking compatibility. Exception: Removing buggy code that nobody uses is fine.
Don't needlessly break compatibility with older versions of Python. Run the test suite using Python 2.1 and the latest version of Python 2.x.
Don't needlessly add complexity. The more complex the code is, the harder it is to maintain, and the more likely it is to have bugs.
Don't needlessly add features. Seriously. X.509 doesn't belong in PyCrypto. Or anywhere, really.
Don't create copyright headaches. It took me the better part of a year to sort out the licensing ambiguities in PyCrypto 2.0.1. If you're adding new files, include the standard PyCrypto public domain dedication at the top.
Whatever you do in _fastmath.c, also do in _slowmath.py. PyCrypto has two math libraries: one that