Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
## Uses GCP's Text-to-Speech API to convert text to MP3
## example: ./text-to-speech.sh -li sheet1 # loop through file sheet1.csv, store files in folder called sheet1/
## ./text-to-speech.sh -i sample.txt -o sample.mp3 # do single text block
## ./text-to-speech.sh -i "hello world!" -o sample.mp3 # do inline text
## prerequisite CLI tools: csvtool, jq, curl, gcloud
## Needs service account and features enabled in GCloud:
## - APIs
'''Merge complex dictionaries'''
def is_element(obj):
if isinstance(obj, dict) or isinstance(obj, list):
return False
return True
def is_dict(obj):
return isinstance(obj, dict)
@OblateSpheroid
OblateSpheroid / inst_config.json
Last active August 7, 2020 19:57
Oracle OCI instance configuration example
# remove these first 3 lines before use. CLI command example:
# oci compute-management instance-configuration create -c $COMPARTMENT_OCID --instance-details file://$PWD/inst_config.json --display-name $INST_CONFIG_NAME
# oci compute-management instance-configuration launch-compute-instance --instance-configuration-id $INST_CONFIG_OCID --launch-details '{"display-name": "inst-config-test"}'
{ "block-volumes": null,
"instance-type": "compute",
"launch-details": {
"agent-config": {
"is-management-disabled": false,
"is-monitoring-disabled": false
},
import sys
import json
import logging
from logging.handlers import TimedRotatingFileHandler
from pythonjsonlogger import jsonlogger
STREAM_FORMATTER = logging.Formatter(
"%(asctime)s — %(name)s — %(levelname)s: %(message)s"
)
FORMAT_DICT = {
Cmd Note
Activating Modes
i activate insert mode
I move cursor to beginning of line and activate insert mode
a move cursor forward one and activate insert mode
A append - move to end of line and activate insert mode
r replace single character
R activate replace mode
v activate highlight (visual) mode
'''
Render a single Jinja2 template. Example usage:
python render_single_template.py -v vars.yml > nginx.conf
Sample vars.yml file:
template: nginx.conf.j2
search-path: "./"
name: localhost
locations:
- root
# download data from https://ourworldindata.org/coronavirus#confirmed-covid-19-cases-by-country
# filter to US only
# date starts with March 1, 2020
# Setup dataframe
df <- read.csv('data-covid-19.csv', header=F, sep="\t")
df$V1 <- as.Date(df$V1, format="%m/%d/%Y")
names(df) <- c("date", "count")
r.num <- nrow(df)

parse variable

awk '{split($2,a,"."); print a[1]"."a[2]}' <<< $(python --version)
awk -F[.' '] '{ print $2"."$3 }' <<< $(python --version)

parse from file

PYTHON_VERSION=$(awk '/python_version/{ print $3 }' Pipfile)
PYTHON_VERSION=$(awk -F' = ' '/python_version/{ print $2 }' Pipfile)
#!/usr/bin/env python
'''RobinHood gives account info as string. This converts string into DataFrame'''
import pandas as pd
pd.set_option('display.max_columns',10)
pd.set_option('display.max_rows',200)
pd.set_option('display.expand_frame_repr',False)
## int to bytes
from math import ceil
def int2byte(i):
bytes = ceil(i.bit_length()/8)
return i.to_bytes(bytes, 'big')
x = 5
type(x)