Skip to content

Instantly share code, notes, and snippets.

Avatar

Alan Berezin aberezin

View GitHub Profile
@aberezin
aberezin / argparse.bash
Last active Aug 18, 2020
sql-server-odbc-connect
View argparse.bash
#!/usr/bin/env bash
# Use python's argparse module in shell scripts
#
# The function `argparse` parses its arguments using
# argparse.ArgumentParser; the parser is defined in the function's
# stdin.
#
# Executing ``argparse.bash`` (as opposed to sourcing it) prints a
# script template.
View python-setup-macos.md

Installing python on MacOS The Right Way

To completely avoid the MacOS python, start with brew or macport. If you start with macports, you will not be using that python version for much (ideally). But we need some, somewhat isolated python to start with.

sudo port install python38
sudo port install py38-pip
@aberezin
aberezin / python-crazy.md
Last active Jul 16, 2020
certified crazy -- Where all the certs are hidden
View python-crazy.md

Certificates in Python

You can see what path openssl lib uses for certs openssl version -a

Python packages often use the default cafile $ python -c "import ssl; print(ssl.get_default_verify_paths())" But note that there are other places packages could look even just based on the above. SSL_CERT_DIR SSL_CERT_FILE

View git-global-pre-commit
# from https://medium.com/@ripoche.b/using-global-pre-commit-hook-to-prevent-committing-unwanted-code-edbbf957ad12
#
# To prevent debug code from being accidentally committed, simply add a comment near your
# debug code containing the keyword NO_GITCOMMIT (with underscore gone) and this script will abort the commit.
#
# I also made this available here
# https://gist.github.com/aberezin/7078ec087c7e4f8a078dd518d30a75bf
#
if git commit -av --dry-run | grep $(echo NO_GITCOMMIT | tr -d _) >/dev/null 2>&1
@aberezin
aberezin / Dockerfile
Created Mar 24, 2020
Alpine linux with rcinit and ssh
View Dockerfile
FROM alpine:edge
# use the CDN mirror from gilderlabs since its much faster
RUN mkdir -p /etc/apk && echo "http://alpine.gliderlabs.com/alpine/edge/main" > /etc/apk/repositories &&\
# Install openrc
apk update && apk add openrc &&\
# Tell openrc its running inside a container, till now that has meant LXC
sed -i 's/#rc_sys=""/rc_sys="lxc"/g' /etc/rc.conf &&\
# Tell openrc loopback and net are already there, since docker handles the networking
echo 'rc_provide="loopback net"' >> /etc/rc.conf &&\
@aberezin
aberezin / ini2json.py
Created Jan 1, 2020 — forked from Natim/ini2json.py
Convert an ini configuration file into a json file
View ini2json.py
# -*- coding: utf-8 -*-
import json
import sys
from ConfigParser import (ConfigParser, MissingSectionHeaderError,
ParsingError, DEFAULTSECT)
class StrictConfigParser(ConfigParser):
def _read(self, fp, fpname):
@aberezin
aberezin / recursive-cat.sh
Created May 24, 2019
One-liner to force dropbox to synch every file
View recursive-cat.sh
find . -type f -exec sh -c 'cat "$1" > /dev/null; printf "$1"' -- '{}' \;
View psjson
#! /usr/bin/env bash
# Use at own risk. License CC0 see https://creativecommons.org/publicdomain/mark/1.0/
# alanberezin.com
OPTIND=1 # Reset in case getopts has been used previously in the shell.
opt_stripclasspath=false
while getopts ":hc" opt; do
case "$1" in
-h | --help )
cat <<-EOF
@aberezin
aberezin / iterm
Created Jun 22, 2018 — forked from vyder/iterm
iterm.bash - Launch iTerm from command line
View iterm
#!/usr/bin/env bash
#
# Open new iTerm window from the command line using v3 syntax for applescript as needed in iTerm2 Version 3+
# This script blocks until the cmd is executed in the new iTerm2 window. It then leaves the window open.
# TODO Add option to close iTerm2 after cmd execs
# See also https://www.iterm2.com/documentation-scripting.html
#
# Usage:
View gist:0ee9c5e6354996849d3b0bcb50c6e29c
" Canonical is at https://gist.github.com/aberezin/0ee9c5e6354996849d3b0bcb50c6e29c"
" This didnt work for me so lets just manually synch with the gist above
" let configpath = '/Users/aberezin/.cvimrc'
" set localconfig
" ccim_server in ~/bin needs to be run mannually for now. Maybe make a
" service
set noautofocus
set autoupdategist