Skip to content

Instantly share code, notes, and snippets.

@studiotomi
studiotomi / string_to_bucket.js
Created January 11, 2023 16:38
String to bucket in javascript
const putS3StringObject = async (bucket, key, str) => {
try {
const s3 = new aws_sdk_1.S3();
const buf = Buffer.from(str);
await s3.putObject({
Key: key,
Bucket: bucket,
Body: buf,
ContentEncoding: 'base64'
}).promise();
@studiotomi
studiotomi / images.js
Last active April 24, 2020 13:17 — forked from eric-sproles-volusion/images.js
Write 404 images
const axios = require('axios');
const fs = require('fs');
const headers = { 'x-vol-tenant': '5c49cda1ddca5800122fad4e' };
const materialApi = 'https://api.material.com/images';
const getImages = async (url, headers) => {
if (!fs.existsSync('404s.txt')) {
fs.writeFileSync('404s.txt', '');
}
const params = {
@studiotomi
studiotomi / python_profile.sh
Created October 7, 2019 14:23
profile a python process
python3 -m cProfile -s cumulative script.py > profile.txt
@studiotomi
studiotomi / truncate.sql
Created August 19, 2019 17:22
truncate all tables in a postgres schema
DO $func$
BEGIN
EXECUTE (
SELECT
'TRUNCATE TABLE ' || string_agg(oid::regclass::text, ', ') || ' CASCADE'
FROM
pg_class
WHERE
relkind = 'r'
AND relnamespace = 'schema_name'::regnamespace);
find the difference between the arc lengths of the inner and outer radius you want and divide by the kerf width, that'll give you the number of cuts, then space them evenly
@studiotomi
studiotomi / containerCommand.sh
Created June 12, 2019 14:59
Given a string, find id of matching docker container, and return id and name or execute arbitrary command.
#!/bin/bash
function containerCommand() {
# Given a string, search for the matching running docker containers.
# If more than one argument is passed, attempt to run remaning arguments
# on that docker container.
container=`docker ps --format '{{.ID}} {{.Names}}'1`;
shift;
if [[ ! -z "$@" ]]
then
@studiotomi
studiotomi / ps-snapshot.sh
Created February 7, 2017 16:33
Back up postgres db to google cloud storage
#!/bin/bash
# Requirements:
# - gcloud/gsutil is installed on the box
# - gcloud is logged in as a user with write access to Google Cloud Storage
# - The file has execution rights so that it can be run in cron
# - The Google Cloud Storage bucket already exits
# Exit on any error
set -e
@studiotomi
studiotomi / kccontexts.sh
Last active August 3, 2021 18:11
Set kubernets current-context from one of the contexts in the config file
kccontexts() {
# Works with kubectl v1.4.0 and the config file generated by gcloud containers clusters get-credentials
# If you pass in an arg, then we will filter the contexts for that string
# The following block creates a list of the contexts and filters if an argument
# is passed in.
if [[ $1 ]]
then
options=(`kubectl config get-contexts -o name | sort | grep $1`)
else
@studiotomi
studiotomi / kubctl-cheat-sheet.sh
Created June 24, 2016 19:30
Kubernetes cheat sheat
# To determine which node a container is on:
kubectl get pods -o wide
# To view current resource usuage and limits of a cluser
kubectl describe nodes <cluster name>
# To view what is happening on a container
kubectl attach <container-name>
# To start an interactive shell on a container
@studiotomi
studiotomi / gist:18cf6c91e80da680d5a3
Created July 14, 2015 22:33
Find what base class an attributes is coming from in Python
def find_attribute_class(model, attribute):
"""
If the attribute is found, it returns an array of places the attribute is defined.
The array is ordered by priority, the first element being the one that is called.
If not found, returns an empty array.
"""
return [m for m in model.mro() if attribute in m.__dict__]