Skip to content

Instantly share code, notes, and snippets.

@andyneff
andyneff / jupyter-git-filter.md
Last active September 7, 2022 18:55
Jupyter notebook filter

Putting Jupyter notebooks in source control is always a good idea. However, the size of notebooks can grow to be quite large due to the output of the cells being large or images. On top of that, re-running a notebook to generate different results would create a large diff for very little to no change in the code, further increasing the repo size. Eventually the repo will be large enough to be unwieldy or even hit maximum repo limits like 2GB most git servers enforce.

The solution is to strip the output of the notebooks automatically, to prevent accidentally commmiting the output. Git provides two different mechanisms to do this:

  • Pre-commit hooks: Pre-commit hooks must be setup after a clone, but can wipe the output of your notebooks right before commit. However this would essentially wipe the output in your working copy, which is less than desired.
  • Clean/smudge filters: Custom filters must be setup after a clone, but the better solution is to create a "clean filter" that wipes the output in the staged c
@andyneff
andyneff / clip.py
Created June 16, 2022 16:18
Windows Clipboard Viewer
# Needs virtualenv with win32clipboard installed
import argparse
import hashlib
import ctypes
from ctypes import wintypes
from collections import OrderedDict
import win32clipboard
import pywintypes
@andyneff
andyneff / AD_in_docker.md
Created January 25, 2022 15:26
Docker using host's sssd connection to AD

Based on this article, I created a simple docker that uses the host's sssd and can authenticate

docker build -t {someimage} .
docker run -it --rm -v=/var/lib/sss/pipes/:/var/lib/sss/pipes/:rw {someimage}

Tests to show it's working

@andyneff
andyneff / docker_to_wsl.bsh
Created July 13, 2021 22:09
Convert a docker image to WSL script
#!/usr/bin/env bash
set -eu
# Should be run in MinGW
if [ "$#" -lt "2" ]; then
echo "Usage: $0 {docker_image_name} {WSL name}" >&2
exit 1
fi
@andyneff
andyneff / sed.md
Last active September 20, 2021 20:02
Some sed-ism

Some less than simple sed statements

Remove every instance of pattern2 comming directly after pattern 1

stuff | sed -n '/pattern1.*/b remove
                b next
                :remove
                # Load a second long
 N
@andyneff
andyneff / nightly_shutdown.py
Last active January 18, 2021 15:24
A script to forceable put your computer to sleep
# Basic windows GUI that will persistently try and put your computer to sleep.
# WARNING: This ignores Alt+F4 and commands to kill the app. This is on purpose.
# The only way to kill is with a force kill, which defeats the purpose of the
# script
import signal
import time
import os
import threading
@andyneff
andyneff / eco.py
Last active December 30, 2020 08:30
import os
from glob import glob
import re
import numpy as np
from itertools import combinations
from fractions import Fraction
from math import gcd
class FoodFile:
def __init__(self, name):
@andyneff
andyneff / print_env.go
Last active October 27, 2020 17:43
Simple program to print the environment variable names in order (apparently there is an order)
package main
// docker run -it --rm -v `pwd`:/src -w /src golang go build print_env.go
import (
"fmt"
"os"
"strings"
)
  1. Install readline: e.g. apk add --no-cache readline
  2. Reload readline: Ctrl+x, Ctrl+r
  3. There is no step 3
@andyneff
andyneff / gotty.sh
Last active March 22, 2023 21:45
Script to start a secure gotty session in "one line"
#!/usr/bin/env bash
# Usage: bash <(curl -L https://git.io/Jfr1J)
# or: bash <(wget -O - https://git.io/Jfr1J)
# or: bash <(perl -MLWP::Simple -e "getprint 'https://git.io/Jfr1J'")
# or: bash <(python -c $'try:\n import urllib2 as u\nexcept:\n import urllib.request as u\nimport os; os.write(1,u.urlopen("https://git.io/Jfr1J").read())')
function gotty_main()
{
: ${VERSION=2.0.0-alpha.3}