Skip to content

Instantly share code, notes, and snippets.

View Sonictherocketman's full-sized avatar

Brian Schrader Sonictherocketman

View GitHub Profile
@Sonictherocketman
Sonictherocketman / cleanup-git-branches.sh
Created October 10, 2017 22:50
Interactively remove branches in a given git repository.
#! /bin/bash
# Interactively clean up branches in a given repository.
#
# author: Brian Schrader
# Usage: cd /path/to/repo && ./cleanup-git-branches
BRANCHES="$(git branch | sed 's/[ \*]//g')"
for BRANCH in $BRANCHES; do
CONFIRM_MSG=">>> Delete $BRANCH? [y/n, default: n]: "
read -en 1 -p "$CONFIRM_MSG";
@Sonictherocketman
Sonictherocketman / pre-commit
Created July 11, 2018 20:27
A pre-commit hook that performs checks based on what is being committed.
#! /bin/bash
# Before we allow a commit, let's first enable preflight.
# To disable this check, set NO_PREFLIGHT=1
# The commit will fail if the preflight checks do.
set -e;
should_check() {
APP=$1
FOUND="-1"
@Sonictherocketman
Sonictherocketman / step-count-analysis.r
Created August 29, 2022 22:24
A script to process and chart step count data exported from Pedometer++ for iOS.
#! /usr/bin/env Rscript
library(zoo)
raw_data = read.csv('Export.csv')
raw_data$Date <- as.Date(raw_data$Date, "%m/%d/%y")
readings = data.frame(
dates=raw_data$Date,
steps=raw_data$Steps
)
@Sonictherocketman
Sonictherocketman / mp.parallel.py
Created August 28, 2022 23:23
Multiplicative Persistence Calculations in Python
#! /usr/bin/env pypy3
# Find a number with a multiplicative persistance larger than 11.
from collections import Counter
from functools import reduce
from multiprocessing import Pool
import json
import requests
import time
URL = 'https://api.pushover.net/1/messages.json'
@Sonictherocketman
Sonictherocketman / bmp.py
Created August 16, 2022 22:45
Continual Pressure/Temperature Monitoring (run on a cronjob)
# I didn't write this code. I just found it online.
# make sure to install python-smbus using below command
# sudo apt-get install python-smbus
import smbus
import time
from ctypes import c_short
DEVICE = 0x77 # Default device I2C address
@Sonictherocketman
Sonictherocketman / abs.py
Created August 23, 2021 22:46
A terrible way to calculate the absolute value of a number in Python.
# A terrible way to calculate the absolute value of any integer with no reliance on complex computer math!
# Do not do this.
# Usage:
# >>> abs(10)
# 10
# >>> abs(-10)
# 10
# >>> abs(10.2)
# 10.2
#! /bin/bash
# A basic CentOS Setup Script
echo "[$(date)] Starting Base Installs"
sudo yum -y update
sudo yum install -y tmux git epel-release htop
echo "[$(date)] Installing Docker"
sudo yum -y install docker docker-registry
sudo systemctl enable docker.service
@Sonictherocketman
Sonictherocketman / docker-bootstrap.sh
Created September 11, 2020 22:15
A sample set of configurations for running Django/Gunicorn apps in Docker. This config even supports zero-downtime deploys! Some implementation required.
#! /bin/bash
set -e;
MODE="api"
log() {
echo "[$(date)] $@"
}
load_secrets() {
@Sonictherocketman
Sonictherocketman / xmpp_oauth_authentication.py
Created October 24, 2017 22:05
Use OAuth tokens as XMPP passwords given an OAuth Provider.
#! /usr/bin/python
# https://docs.ejabberd.im/developer/guide/#toc_8
import sys, os
from struct import *
from requests import get
BASE_URL = os.environ['BASE_URL']
DJANGO_AUTH = os.environ['DJANGO_AUTH']
DJANGO_IS_USER = os.environ['DJANGO_IS_USER']
@Sonictherocketman
Sonictherocketman / json_query.py
Created May 9, 2018 21:06
Get values from nested structures in Python.
def query(q, data, default=None, should_raise=False):
""" This method allows for a simple recursive queries on JSON fields,
including Python's native dictionary.
Sample query:
data = {
'user' {
'aliases': [
{