Skip to content

Instantly share code, notes, and snippets.

View ozydingo's full-sized avatar

Andrew H Schwartz ozydingo

View GitHub Profile
@ozydingo
ozydingo / gitprompt
Last active June 8, 2023 19:42
Functions for git in bash / zsh prompt
# To use gitprompt to set your prompt to include a colored git branch label:
# bash:
# source gitprompt
# bash_colors
# PS1='[\[$(git_branch_color)\]$(parse_git_branch)\[${NORMAL}\]] '"$PS1"
# zsh:
# source gitprompt
# zsh_colors
# setopt PROMPT_SUBST
# export PROMPT='[%F{$(git_branch_color)}$(parse_git_branch)%f] %B%F{240}%~%f %# '
@ozydingo
ozydingo / .zlogin
Last active May 15, 2023 14:35
.zlogin
# enable colorized terminal output
export CLICOLOR=1
# Parse display and control chars in the less pager
export LESS=-R
# Set default editor for terminal tasks to emacs
export EDITOR=emacs
# Moved to .zshrc
eval $(/opt/homebrew/bin/brew shellenv)
@ozydingo
ozydingo / enum.rb
Last active April 13, 2022 20:24
Enum in Ruby
# Slightly odd to inherit from Module; this lets us define consts such as FOOBAR::FOO
class Enum < Module
include Enumerable
attr_reader :values
delegate :each, to: :values
def initialize(&blk)
super(&nil) # Don't pass the block to super
@ozydingo
ozydingo / clean_local_branches.sh
Created March 4, 2022 21:21
Delete local git branches that were deleted from remote
git fetch -p
git branch -vv | \
awk '$3 ~ /\[[[:punct:][:alnum:]]+:/ && $4 == "gone]" { print $1}' | \
while read branch; do echo git branch -D $branch; git branch -D $branch; done
@ozydingo
ozydingo / conftest.py
Last active February 21, 2022 14:42
Configure and use requests-mock for all tests without fussing with decorators or function params in your tests
import pytest
import requests_mock
# By autousing this yielding fixture, all tests with have requests_mock enabled with
# the registered stubbed responses as defined here
@pytest.fixture(autouse=True)
def stub_or_disable_requests():
with requests_mock.Mocker() as mocker:
mocker.get('//example.com/mock1', text='example.com mock 1')
@ozydingo
ozydingo / clean_old_remote_branches.sh
Created December 29, 2021 15:40
Delete old remote git branches
USAGE="clean_old_remote_branches.sh
Remove branches from remote older than a specified threshold.
Arguments:
-h : print this message
-n, --dry-run : print actions, do not take them.
-d, --days : threshold for \"old\", in days. Default: 200
@ozydingo
ozydingo / .gitbranch
Last active August 15, 2020 14:32
Display your git branch and status in your terminal
# To use gitbranch to set your prompt to include a colored git branch label:
# bash:
# source .gitbranch
# bash_colors
# PS1='[\[$(git_branch_color)\]$(parse_git_branch)\[${NORMAL}\]] '"$PS1"
# zsh:
# source .gitbranch
# zsh_colors
# setopt PROMPT_SUBST
# export PROMPT='[%F{$(git_branch_color)}$(parse_git_branch)%f] %B%F{240}%~%f %# '
@ozydingo
ozydingo / colors.sh
Created January 16, 2020 19:39
Git branch parsing and terminal prompt color setting
bash_colors() {
export BLACK=$(tput setaf 0)
export RED=$(tput setaf 1)
export GREEN=$(tput setaf 2)
export YELLOW=$(tput setaf 3)
export BLUE=$(tput setaf 4)
export MAGENTA=$(tput setaf 5)
export CYAN=$(tput setaf 6)
export WHITE=$(tput setaf 7)
export NORMAL=$(tput sgr0)
@ozydingo
ozydingo / inspections_controller.rb
Created March 27, 2019 18:09
Rails controller to see your request
class InpsectionsController < ApplicationController
def index
log
head :ok
end
def create
log
head :ok
end
@ozydingo
ozydingo / sagemaker_demo.py
Last active February 15, 2019 19:28
SageMaker getting started tutorial
#!/usr/bin/env python
# coding: utf-8
# In[1]:
# import libraries
import boto3, re, sys, math, json, os, sagemaker, urllib.request
from sagemaker import get_execution_role
import numpy as np