Skip to content

Instantly share code, notes, and snippets.

@asowder3943
Last active July 18, 2023 03:06
Show Gist options
  • Save asowder3943/b2504fac1e618a2ecfc8d7b71404b146 to your computer and use it in GitHub Desktop.
Save asowder3943/b2504fac1e618a2ecfc8d7b71404b146 to your computer and use it in GitHub Desktop.
Useful One Liners and Small Scripts

Useful One Liners and Small Scripts

Windows

Remote Administration

Install Windows Native OpenSSH Client

Credit: Ravi Nandval - Superuser

  1. install:
 DISM.exe /Online /Add-Capability /CapabilityName:OpenSSH.Client~~~~0.0.1.0
  1. Ensure service is enabled and set to run automatically image

  2. git clone using specific identity file Credit: Jan Toth - devopsinuse

git clone git@github.com:autocloudmaniacs/red-queen-appl.git --config core.sshCommand="ssh -i ~/.ssh/erste"

Configure Windows Headless Server for Remote Teamviewer Connection From 2020 M1 Macbook Air

macos-headless-display.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\SIMULATED_1002_6939_00000001_00000000_100^90637A258A32A466A3662FA204717CB2\00]
"PrimSurfSize.cx"=dword:00000a00
"PrimSurfSize.cy"=dword:00000640
"Stride"=dword:00002800

Enterprise Apps Hell

Delete broken Skype sip archives (Tested on Windows 10 1808 - Windows 10 20hr2)

Used to fix global address syncing issues credit: Peter Schmidt MS Digest

get-childitem -path "c:\users\" -filter "sip*" -recurse -force -errorAction SilentlyContinue | remove-item -confirm

USB Tools

Creating Bootable Windows 10 USB on MacOS

Credit: Alex Lubbock

  1. Get List of Disks Make Note of identifier of your removable media
diskutil list
  1. Format the removable Media
diskutil eraseDisk MS-DOS "WINDOWS10" MBR <Your Disk Identifier>
  1. Mount Windows 10 ISO in Finder
  2. Make Note of Volume Name
ls /Volumes
  1. Copy all files except .wim to removable USB
rsync -avh --progress --exclude=sources/install.wim /Volumes/<Your Volume Name>/ /Volumes/WINDOWS10
  1. install wimlab requires brew
brew install wimlib
  1. Use WimLib to copy over the .wim files to the removable media
wimlib-imagex split /Volumes/<Your Volume Name>/sources/install.wim /Volumes/WINDOWS10/sources/install.swm 3800

Docker

Setting and Unsetting Environment variables in a .env file

credit: Silas Paul and others stackoverflow

# set all variables defined in the .env file
export $(grep -v '^#' .env | xargs)

# up your composition expecting the defined environment variables
docker-compose up -d

# Unset the variables when done
unset $(grep -v '^#' .env | sed -E 's/(.*)=.*/\1/' | xargs)

Running Docker via Rosetta (For Compatability)

credit: superpoussin22 github

export DOCKER_DEFAULT_PLATFORM=linux/amd64

Quickly Cleaning Local Docker environment

Credit: John Kuriakose

docker-clean.sh

#!/bin/bash
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -a -q)
docker volume prune -f
docker network prune -f

Keep Container open for Debugging

Credit: devopscube

ENTRYPOINT ["tail", "-f", "/dev/null"]

Create Local Postgres DB For Testing (mirror/expose db port at localhost)

docker run --name [name] -e POSTGRES_PASSWORD=[pass] -e POSTGRES_USER=[user] -e POSTGRES_DB=[dbname] -d -p 5432:5432 postgres

Linux

Quickly Create Cron Job for Script

apt-get update && apt-get install -y cron && echo "* * * * * <USER> sh /path/to/script.sh" >> /etc/crontab && service cron restart

Django

Initialize Superuser using environment variables

echo "from django.contrib.auth.models import User" > createadmin.py
echo "User.objects.create_superuser('$SUPERUSER', '$SUPERUSER_EMAIL', '$SUPERUSER_PASS')" >> createadmin.py
python manage.py shell < createadmin.py
rm -f createadmin.py

Generate new Django Secret Key

credit Serhat Teker

python manage.py shell -c 'from django.core.management import utils; print(utils.get_random_secret_key())'

Macos

manage python versions using brew and pyenv

  1. install pyenv
brew install pyenv
  1. install specific python version
pyenv install 3.11.1
  1. configure zsh ~/.zshrc
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init --path)"
  eval "$(pyenv init -)"
fi
  1. set pyenv global environment
pyenv global 3.11.1

QA Playwright / Chrome Dev

Inspect Elements that Disappear

setTimeout(() => {
  debugger;
}, 5000);

Ubuntu

Remote Management

Remove Excessive Alerts on Wifi Scanning Remote Machines

credit Griffon stackexchange

/etc/polkit-1/localauthority/50-local-d

[Allow Wifi Scan]
Identity=unix-user:*
Action=org.freedesktop.NetworkManager.wifi.scan;org.freedesktop.NetworkManager.enable-disable-wifi;org.freedesktop.NetworkManager.settings.modify.own;org.freedesktop.NetworkManager.settings.modify.system;org.freedesktop.NetworkManager.network-control
ResultAny=yes
ResultInactive=yes
ResultActive=yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment