Skip to content

Instantly share code, notes, and snippets.

@mikeslattery
mikeslattery / rt-clip.sh
Last active August 1, 2020 02:12
Markdown to Clipboard
#!/bin/bash
# Converts markdown format to clipboard in html format.
# Requres Wayland, pandoc, and wl-clipboard.
# Usage:
# rt-clip - Copy from stdin
# rt-clip <file> Copy from a file
# rt-clip Copy from clipbaord
if [[ "$1" == "-" ]]; then shift; cat
@mikeslattery
mikeslattery / fake_dockerfile.sh
Last active February 19, 2021 15:16
Mock Dockerfile syntax for local testing
alias FROM='docker run -it --rm'
ADD() { curl -sLf "$1" -o "$2"; }
alias RUN='' ARG='' ENV='' CMD=''
alias LABEL=: EXPOSE=: ENTRYPOINT=: VOLUME=: ONBUILD=: STOPSIGNAL=: HEALTHCHECK=: SHELL=:
SHELL() { eval "export SHELL=$1"; }
alias WORKDIR=cd
USER() { sudo -u "$1" bash --init-file fake_dockerfile.sh; }
@mikeslattery
mikeslattery / docker-over-ssh.inc.sh
Last active May 24, 2021 15:33
Run docker over ssh.
#!/bin/sh
#Usage (local use): docker-over-ssh <server>
#Usage (expose): endpoint=0.0.0.0 docker-over-ssh <server>
endpoint="${endpoint:-localhost}"
ssh -nNT -L $endpoint:2375:/var/run/docker.sock "$1" &
export DOCKER_HOST=tcp://$endpoint:2375
echo "Now your docker commands will run on $1"
@echo off
:: Setup an ssd daemon/server on a Windows server box on the internal network.
set ROOT=C:\cygwin
set PACKAGES=openssh,nc,curl,tmux
set SITE=http://cygwin.mirror.constant.com
set BASH=%ROOT%\bin\bash --login -c
set PACKAGEDIR=%ROOT%\packages
echo INSTALL CYGWIN...
@mikeslattery
mikeslattery / gc-mon.sh
Last active May 24, 2021 15:49
Monitor memory use of all running java applications
#!/bin/bash
# Display memory useage of all running java processes
pidof java | xargs -r ps -f
echo ''
echo $'PID\t% MEM\tTMEM\tGC Time'
while true; do
for pid in $(pidof java); do
echo -n "$pid "
@mikeslattery
mikeslattery / tunic-uml.dot
Last active May 24, 2021 15:57
Tunic Design
// Usage: dot -Tpdf -o tunic-uml.pdf tunic-uml.dot; xdg-open tunic-uml.pdf
digraph G {
Presenter -> View;
View [shape=box];
Presenter -> Service;
Service -> System;
@mikeslattery
mikeslattery / airplay-client.sh
Last active October 17, 2021 13:26
An attempt at an airplay client
#!/bin/bash
# Screen cast your desktop to Apple TV (airplay).
# Usage: airplay-client <server-address> <local-address>
# Untested. Likely doesn't work. Airplay V1 only.
if [[ "$SERVER_PORT" == "7000" ]]; then
# We are the cgi script.
echo 'Content-Type: video/h264'
@mikeslattery
mikeslattery / runimage.sh
Last active January 13, 2022 16:51
Run containers as if they are locally installed tools
#!/bin/bash
# Run containers as if they are locally installed tools.
# This is useful for images such as "python" or "maven".
# Edit the "image" variable and place in your ~/bin directory.
# For "Docker Desktop for Windows" under these environments:
# * WSL: if /c is mounted to C: and run from a dir under /c, but /tmp and $HOME volumes should be removed.
# * Msys/GitBash: but /tmp volume should be removed.
# * Cygwin: Will not work as-is due to path differences.
@mikeslattery
mikeslattery / clone_to_docker.sh
Last active February 23, 2022 17:24
Convert local Linux distro into a container.
#!/bin/bash
# Usage - clone_to_docker.sh <image-name>
# This will convert the local distro to a container image and run it.
# Also works for WSL.
# The container will run as the user that created the image.
# If using WSL, you should mount (or symlink) /c to /mnt/c
image="wsl"
@mikeslattery
mikeslattery / x-platform.sh
Last active January 30, 2023 15:44
Cross Platform Bash Snippet for Linux, WSL 1, Cygwin, Msys, and GitBash.
#!/bin/bash
# shebang added only to appease shellcheck
# Cross-platform for bash.
# Worry less about when writting a script that must run on Windows and Linux.
# Meant to be used with "source" command in scripts or .bashrc/.zshrc
export USER="${USER:-${USERNAME:-$(whoami)}}"
export USERNAME="${USERNAME:-$USER}"
export HOSTNAME="${HOSTNAME:-${MACHINENAME:-$(hostname)}}"