Skip to content

Instantly share code, notes, and snippets.

View aberezin's full-sized avatar

Alan Berezin aberezin

View GitHub Profile
@aberezin
aberezin / gist:692657ff3d5711349f2abce0ab9ccb30
Last active March 27, 2023 19:13 — forked from rolandcrosby/gist:c26571bf4e263f695d2f
Convert rich text on the clipboard to Markdown
We couldn’t find that file to show.
@aberezin
aberezin / fant2add
Created June 25, 2022 15:59
fantastical command line
#!/usr/bin/env bash
if [[ "${1/--help/-h}" == '-h' ]]; then
echo 'fan2add [-h | --help]'
echo 'fan2add [-i | --immediately] statement...'
echo
echo '##### Statement Examples ########'
cheat fantastical-statements
exit
fi
if [[ "${1/--immediately/-i}" == '-i' ]]; then
@aberezin
aberezin / defauts.duti
Created April 5, 2022 17:38 — forked from apfelchips/defaults.duti
set file-associations on macOS: ~ 🥖.config 🥖duti 🥖defauts.duti
# duti settings file
# src: https://gist.github.com/apfelchips/0073cb3e8d186115f590d318998c1025
# mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/duti/" && curl -L "https://git.io/JRtzH" -o "${XDG_CONFIG_HOME:-$HOME/.config}/duti/default.duti"
# duti-apply wrapper: alias duti-apply='duti -v "${XDG_CONFIG_HOME:-$HOME/.config}/duti"'
## duti documentation https://web.archive.org/web/20180901095433/http://duti.org/documentation.html
## see also: https://github.com/Lord-Kamina/SwiftDefaultApps#readme
# List of MIME Types:
@aberezin
aberezin / diff-pptx
Created February 1, 2022 00:40
Create difference images that represent a visual diff of two pptx files
#!/usr/bin/env bash
alias soffice=/Applications/LibreOffice.app/Contents/MacOS/soffice
shopt -s expand_aliases
soffice --headless --convert-to pdf arch1.pptx
soffice --headless --convert-to pdf arch2.pptx
convert -density 150 arch1.pdf -quality 80 'output1.jpg'
convert -density 150 arch2.pdf -quality 80 'output2.jpg'
i=0
for files in output1-*; do
@aberezin
aberezin / argparse.bash
Last active August 18, 2020 01:17
sql-server-odbc-connect
#!/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.

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 July 16, 2020 00:53
certified crazy -- Where all the certs are hidden

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

# 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 March 24, 2020 01:26
Alpine linux with rcinit and ssh
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 January 1, 2020 18:03 — forked from Natim/ini2json.py
Convert an ini configuration file into a json file
# -*- coding: utf-8 -*-
import json
import sys
from ConfigParser import (ConfigParser, MissingSectionHeaderError,
ParsingError, DEFAULTSECT)
class StrictConfigParser(ConfigParser):
def _read(self, fp, fpname):