Skip to content

Instantly share code, notes, and snippets.

@mmguero
mmguero / namedtuple_etc.py
Created March 28, 2019 20:20
Different ways to do namedtuple-ish stuff with python
##########################################################
import collections
from collections import namedtuple
Robot = namedtuple('Robot', 'base, hinge1, arm_len, hinge2, wrist, hand')
Robot.base = 260
Robot.hinge1 = 20
Robot.arm_len = 120
Robot.hinge2 = 150
Robot.wrist = 90
@mmguero
mmguero / firefox-install.sh
Last active October 20, 2022 21:37
install latest linux64 Firefox
#!/bin/bash
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
curl -o /tmp/firefox.tar.bz2 -L "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64&lang=en-US"
if [[ $(file -b --mime-type /tmp/firefox.tar.bz2) = 'application/x-bzip2' ]]; then
sudo mkdir -p /opt
sudo rm -rvf /opt/firefox
sudo tar -xvf /tmp/firefox.tar.bz2 -C /opt/
@mmguero
mmguero / vagrant-install.sh
Last active October 20, 2022 21:38
install latest Vagrant .deb from releases.hashicorp.com
curl -o /tmp/vagrant.deb "$(curl -fsL "https://releases.hashicorp.com$(curl -fsL "https://releases.hashicorp.com/vagrant" | grep 'href="/vagrant/' | head -n 1 | grep -o '".*"' | tr -d '"' )" | grep "amd64\.deb" | head -n 1 | grep -o 'href=".*"' | sed 's/href=//' | tr -d '"')"
sudo dpkg -i /tmp/vagrant.deb
rm -f /tmp/vagrant.deb
@mmguero
mmguero / scriptpath.sh
Created September 4, 2020 13:31
determine script path in a bash script
#!/usr/bin/env bash
[[ "$(uname -s)" = 'Darwin' ]] && REALPATH=grealpath || REALPATH=realpath
[[ "$(uname -s)" = 'Darwin' ]] && DIRNAME=gdirname || DIRNAME=dirname
if ! (type "$REALPATH" && type "$DIRNAME") > /dev/null; then
echo "$(basename "${BASH_SOURCE[0]}") requires $REALPATH and $DIRNAME"
exit 1
fi
SCRIPT_PATH="$($DIRNAME $($REALPATH -e "${BASH_SOURCE[0]}"))"
@mmguero
mmguero / wwg.sh
Last active August 3, 2023 03:28
a wrapper script for wg/wg-quick/systemctl wireguard operations; supports encrypting/decrypting/using openssl-encrypted wireguard config files with wg-quick up and down
#!/usr/bin/env bash
# wwg.sh
# a wrapper script for wg/wg-quick/systemctl wireguard operations
# https://gist.github.com/mmguero/53f4c9c04ac49c330800e463e4620808/edit
# The idea is you create your wireguard config file (eg, `wg0.conf`),
# then run `wwg.sh enc wg0.conf` to encrypt it. Then, you can use `wwg.sh up wg0.conf`
# which will temporarily decrypt the file, run `wg-quick up` for that interface with
@mmguero
mmguero / systemctl user processes.txt
Last active December 9, 2020 15:35
systemctl user process howto
mkdir -p ~/.config/systemd/user/
sudo loginctl enable-linger $USER
---------------------------------------
~/.config/systemd/user/foobar.service
---------------------------------------
[Unit]
AssertPathExists=/home/johndoe/foo
[Service]
@mmguero
mmguero / Vagrantfile
Last active June 11, 2022 16:01
Vagrantfile for Debian 11 with rootless docker
unless Vagrant.has_plugin?("vagrant-sshfs")
raise 'vagrant-sshfs plugin is not installed!'
end
unless Vagrant.has_plugin?("vagrant-reload")
raise 'vagrant-reload plugin is not installed!'
end
# hack: https://github.com/hashicorp/vagrant/issues/8878#issuecomment-345112810
class VagrantPlugins::ProviderVirtualBox::Action::Network
@mmguero
mmguero / Vagrantfile
Last active March 31, 2021 18:01
Vagrantfile: Windows 10 (StefanScherer/windows_10) with WSL Debian and Chocolatey
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.define "vagrant-windows-10-preview"
config.vm.box = "StefanScherer/windows_10"
config.vm.communicator = "winrm"
# Admin username and password (see also WSL username/password setup in WSL_Debian_Setup.ps1)
@mmguero
mmguero / Vagrantfile
Created December 9, 2020 16:32
Vagrantfile for macOS High Sierra
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "macos/highsierra"
config.vm.guest = :freebsd
config.vm.communicator = "ssh"
# nfs doesn't currently work either
@mmguero
mmguero / Vagrantfile
Created May 12, 2021 22:00
Vagrantfile for Ubuntu 21.04 with Docker already set up (and a second user with a 1001 UID)
# hack: https://github.com/hashicorp/vagrant/issues/8878#issuecomment-345112810
class VagrantPlugins::ProviderVirtualBox::Action::Network
def dhcp_server_matches_config?(dhcp_server, config)
true
end
end
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-21.04"