Skip to content

Instantly share code, notes, and snippets.

@andyneff
andyneff / git-submodule-diff.sh
Created March 27, 2018 16:06
Show commit diff between expected and current submodule
#!/usr/bin/env bash
#****f* git/submodule_diff
# NAME
# git_submodule_diff - show commit diff between expected and current submodule
# DESCRIPTION
# When changing version of a superproject, submodules will often show up as
# being different. Often the right answer is to run "git submodule update".
# However, sometimes this is not the right answer. It is tedious to switch to
# a submodule, look through the logs for the SHAs in question, and understand
@andyneff
andyneff / install_pipenv.sh
Last active December 11, 2018 21:56
Cleanly add pipenv to OS
#!/usr/bin/env bash
set -eu
TMP_DIR="$(mktemp -d)"
python3 <(curl -L https://bootstrap.pypa.io/get-pip.py) --no-cache-dir -I --root "${TMP_DIR}" virtualenv
sudo env PYTHONPATH="$(cd "${TMP_DIR}"/usr/local/lib/python*/*-packages/; pwd)" "${TMP_DIR}/usr/local/bin/virtualenv" "/usr/local/pipenv/"
sudo /usr/local/pipenv/bin/pip install --no-cache-dir pipenv
sudo ln -s /usr/local/pipenv/bin/pipenv /usr/local/bin
@andyneff
andyneff / socat.py
Last active May 8, 2019 20:20
Python script to emulate socat behavior, but uses a single executable instead of one per connection
#!/usr/bin/env python
import os
import sys
from subprocess import Popen, PIPE
from socket import *
import atexit
from select import select
from logging import getLogger, basicConfig
@andyneff
andyneff / bash.md
Last active November 11, 2019 23:14
Tricks on how to do bash variable indirection

Indirection

Setting a variable

  1. A "local" variable, that will be local to the function
var=foo
value="b a  r"
declare "${var}=${value}"
@andyneff
andyneff / shim.cpp
Last active December 18, 2019 16:32
Executable shims (for when you need the setuid/setgid/sticky bit)
#include <unistd.h>
#include <stdio.h>
#include <time.h>
// This should be easy to edit in a hex editor
char exe[256]="/bin/ls\0HEXEDIT STRING HERE";
int main(int argc, char* argv[])
{
FILE *fid = fopen("/tmp/rnuril_log.txt", "a");

Git Mirror with submodules

While creating a git mirror is as simple as git clone --mirror, unfortunately this git command does not support git submodules (difficult) or lfs (easier). These scripts help in creating a mirror of a project with submodule and/or git lfs.

General user case:

  1. You have a git repo with submodule on a git server
  2. git_mirror https://github.com/visionsystemsinc/vsi_common.git master, recursively create mirrors of all submodule currently in the master branch.
  3. Transfer vsi_common_prep/transfer_{date}.tgz to your destination
@andyneff
andyneff / relocate.py
Created March 10, 2020 23:51
Relocate a virtualenv on windows.
# Usage:
# Move your virtualenv, then
# {virtual env dir}\Scripts\python.exe relocate.py
# TODO: Merge with Linux script
# TODO: Detect and hangle GUI exes
import sys
import os
import glob
import re
@andyneff
andyneff / cygwin xserver.md
Last active January 17, 2023 21:15
Modified Cygwin startxwin script that syncs X11 with WSL

Using cygwin X in WSL1 and MingW (and others)

Cygwin comes with an X Server that can be useful with tools other than Cygwin itself. With a few modifications, we can add cygwin's X Server support to other shell implementations including cygwin, mingw64 (such as git for windows), msys2, WSL1, WSL2, and others.

With a few minor modifications, we can save the DISPLAY variable to files accessible by any shell. Once the DISPLAY value is accessible, an rc file can load it and it will automatically be used.

Optionally, we can even add a "one click" link to the start menu to start the xserver

TL;DR

@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}
  1. Install readline: e.g. apk add --no-cache readline
  2. Reload readline: Ctrl+x, Ctrl+r
  3. There is no step 3