Skip to content

Instantly share code, notes, and snippets.

View toloco's full-sized avatar
🎯
Focusing

Tolo Palmer toloco

🎯
Focusing
View GitHub Profile
'''
Borg kind of singleton
Supraclass for add monostate (all objects share state) properties a class
'''
class BorgObj(object):
_shared_state = {}
def __new__(cls, *a, **k):
def results(a_list, columns):
for row in a_list:
yield {k: v for k, v in izip(row, columns)}
my_generator = results(result, columns)
@toloco
toloco / gist:937481eb0fc1ecc0424339950fff55af
Created May 3, 2017 12:48
Fix docker for Max weird errors
* Screen into the Docker VM
$ screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
$ umount /var/lib/docker/overlay2
* Remove /var/lib/docker
$ rm -rf /var/lib/docker
* Restart Docker via the widget
@toloco
toloco / list_files_small_to_big.sh
Last active December 27, 2021 15:37
List GIT files and sort by size
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| sort --numeric-sort --key=2 \
| cut -c 1-12,41- \
| numfmt --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
@toloco
toloco / shello.sh
Created November 2, 2021 13:42
Load .env file in shellscript
function load_env(){
if [ -f $1 ]
then
export $(cat $1 | sed 's/#.*//g' | xargs)
else
echo "Can't find file"
fi
}
@toloco
toloco / .gitconfig
Last active June 17, 2022 07:46
ZSH and git
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
type = cat-file -t
dump = cat-file -p
publish = "!git push --set-upstream origin \"$(git rev-parse --abbrev-ref HEAD)\""
refresh = "!git pull origin \"$(git rev-parse --abbrev-ref HEAD)\""
#!/usr/bin/env python3
import csv
import argparse
TRANSLATION = {
"First Name": "First Name",
"Last Name": "Last Name",
"Company": "Current Company",
@toloco
toloco / shell.sh
Created June 17, 2022 07:54
Python code operations
clean: ## Remove all pyc and caches
@find . -name '*.py[co]' -exec rm -f {} +
@find . -name '\.pytest_cache' -exec rm -fr {} +
@find . -name '\.mypy_cache' -exec rm -fr {} +
@find . -name '__pycache__' -exec rm -fr {} +
@docker ps -aq | xargs -r docker rm -f
@docker volume ls -q | xargs -r docker volume rm -f
@docker images | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi -f
@docker builder prune -f
@toloco
toloco / argparse.py
Created July 6, 2022 15:37
Argparser python
import argparse
def parse_args():
log_levels = {
"info": logging.INFO,
"debug": logging.DEBUG,
"warning": logging.WARNING,
}
parser = argparse.ArgumentParser()
@toloco
toloco / envs.jssonet
Last active February 13, 2023 10:05
Jsonnet example
local v1 = import "v1.libsonnet";
local env = import "env.libsonnet";
local params = v1.params;
local sentry_params = v1.valuesForEnv(
"prod", {creds: "874c6f6d8b51422b9bfc2f6524a7b5b0", uri: "/11"})
.defaults({creds: "f980cfda63194d869e7ca5e0c9bb48cb", uri: "/14"}
);
local processes = v1.valuesForEnv("prod", "8").defaults("2");