Skip to content

Instantly share code, notes, and snippets.

View wcarhart's full-sized avatar
🦉
Hoot hoot

Will Carhart wcarhart

🦉
Hoot hoot
View GitHub Profile
@wcarhart
wcarhart / bash_tidbits.md
Last active May 19, 2024 11:18
Helpful Bash design patterns

Helpful Bash tidbits

@wcarhart
wcarhart / links.txt
Last active January 24, 2024 23:07
Interesting software links
@wcarhart
wcarhart / 🐍 PyTricks.py
Last active February 26, 2023 13:46
List of Python tricks from Dan Bader's (realpython.com) newsletter
# List of Python tricks from Dan Bader's (realpython.com) newsletter
# ===================================== #
# How to merge two dictionaries (3.5+)
x = {'a': 1, 'b': 2}
y = {'b': 3, 'c': 4}
z = {**x, **y}
print(z)
# {'c': 4, 'a': 1, 'b': 3}
@wcarhart
wcarhart / ansi_cheats.py
Last active June 21, 2021 14:49
Python ANSI codes cheat sheet
# CURSOR
"\033[<N>A" # Move cursor up N lines (defaults to 1)
"\033[<N>B" # Move cursor down N lines (defaults to 1)
"\033[<N>C" # Move cursor right N lines (defaults to 1)
"\033[<N>D" # Move cursor left N lines (defaults to 1)
"\033[K" # Clear contents of line
# COLORS
"\033[90m" # light grey
"\033[91m" # red
@wcarhart
wcarhart / knock.sh
Last active January 13, 2021 19:06
Setup and use port knocking
#!/bin/bash
# test port knocking using nmap
for port in 7151 10888 8899 ; do nmap -Pn --host_timeout 201 --max-retries 0 -p $port ipaddress ; done && ssh root@ipaddress
# test port knocking using knock
sudo apt-get update
sudo apt-get install knockd
knock ipaddress 7151 10888 8899 && ssh root@ipaddress
@wcarhart
wcarhart / send_gmail.py
Last active September 23, 2020 19:09
Send an email via the Gmail API (you'll need to supply your token.pickle with your credentials). Code sample from blog post: https://www.willcarh.art/blog/automating-emails-in-python/
import os
import sys
import pickle
import base64
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from email.mime.text import MIMEText
def get_gmail_api_instance():
@wcarhart
wcarhart / bash_metaprogramming.sh
Created April 21, 2020 03:20
Bash metaprogramming
#!/bin/bash
# list all custom BASH functions
lsf() {
if [[ ! -d ~/.bash_functions ]] ; then
if [[ ! -f ~/.bashrc ]] ; then
echo "lsf: err: no such directory ~/.bash_functions, no such file ~/.bashrc"
return 1
fi
@wcarhart
wcarhart / remove_file.sh
Last active February 9, 2020 00:42
Completely remove a file from Git history
# Completely remove a file from git history
# Remove file from all commits
# $path_to_file supports wildcards: path/to/directory/*
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $path_to_file" HEAD
# Prune branch
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# Rewrite history in remote
@wcarhart
wcarhart / Dockerfile
Created February 6, 2020 23:58
Run a Matlab script in a Docker container without rebuilding the image when the script updates (could be extended to any script)
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y octave
WORKDIR /
ENV SCRIPT=""
COPY octave_runner /
RUN chmod +x /octave_runner
@wcarhart
wcarhart / initiate_git_lfs.sh
Last active February 6, 2020 23:52
Initialize Git LFS and start tracking files with it
# Initialize Git LFS and start tracking files with it
## Install Git LFS (MacOS)
brew install git-lfs
## Change to repository
cd $PROJECT_REPO
## If you've already added or committed the file(s) you'd like to track with LFS,
## you'll need to edit them out of the Git history. See: