Skip to content

Instantly share code, notes, and snippets.

View lukestanley's full-sized avatar

Luke Stanley lukestanley

View GitHub Profile
@lukestanley
lukestanley / vm_launcher.py
Last active April 22, 2022 11:41
PySide2 VirtualBox VM launcher script for Linux
"""
A PySide2 script to open selected VirtualBox VMs.
It shows a list of VirtualBox VM's and that is filtered on every key press (without pressing enter).
When enter is pressed, we launch or switch to the first matching VirtualBox machine.
Later the filter query is cleared ready for the next interaction.
VirtualBox's own GUI doesn't clear it's search box after using it.
This annoyed me so I wrote this for my Linux box.
It depends on PySide2, wmctrl, and VBoxManage.
"""
from PySide2.QtWidgets import (
@lukestanley
lukestanley / pingy_meter_now.py
Last active October 6, 2021 13:06
pingy_meter_now.py is a Python script that shows how reliable your Internet connection is. It graphs how long it takes 8.8.8.8 to respond to ping requests. It depends on plotille. It runs on all Unix systems that support Python 3. Unacceptable ping attempts are marked in red, passes are green, response time is shown in milliseconds.
"""
pingy_meter_now.py is a Python script that shows how reliable your Internet connection is.
It graphs how long it takes 8.8.8.8 to respond to ping requests.
It depends on plotille.
It runs on all Unix systems that support Python 3.
Unacceptable ping attempts are marked in red, passes are green, response time is shown in milliseconds.
"""
try:
import plotille
@lukestanley
lukestanley / save_open_x_window_icons.py
Last active September 14, 2021 16:13
Saves icons for open X windows to a folder
"""Saves icons for open X windows to a folder.
Pypanel inspired me, by showing that Python can get icons with Xlib.
This does that in a more simple and uses PIL to save them too :)
"""
from PIL import Image
from Xlib import X, display, error, Xatom
DIRECTORY = "/home/user/icons/"
@lukestanley
lukestanley / auto_apply_screen_layout.py
Created June 25, 2020 18:03
Detects external monitor by polling xrandr and sets up my custom layout saved from arandr because XFCE didn't do it for me.
from time import sleep
from subprocess import check_output
from os import system as run
def shell(command):
return check_output(command, shell=True)
def display_count():
return str(shell("xrandr -q")).count(' connected')
@lukestanley
lukestanley / compress_pdf.sh
Last active May 4, 2020 14:47
Compress PDF as JPG
# Adjust these variables as desired:
quality=80
density=200
convert -density $density "$1" -background white -alpha remove -alpha off -compress none BMP3:_temp_conv_file%02d.bmp
for f in _temp_conv_file*.bmp;
do
cjpeg -quality $quality -outfile "$f.jpg" "$f";
done;
@lukestanley
lukestanley / hotspot.sh
Created February 19, 2020 10:48
Setting up hotspot corners on Ubuntu Desktop 18.04
# Something like this:
mkdir -p $HOME/.local/share/gnome-shell/extensions/customcorner@eccheng.gitlab.com
cd ~/Downloads/
wget https://extensions.gnome.org/extension-data/customcorner%40eccheng.gitlab.com.v3.shell-extension.zip
restart
unzip customcorner@eccheng.gitlab.com.v3.shell-extension.zip -d $HOME/.local/share/gnome-shell/extensions/customcorner@eccheng.gitlab.com
# restart your window manager sesson, for the Wayland window manager this may require logging out, sorry!
gnome-tweaks
# enable the extension and set the hot spot regions as desired
# if you want to lock the computer, this command can help:
@lukestanley
lukestanley / termux-sshd-wormhole.sh
Last active March 27, 2023 20:29
Access Android's files remotely with SSH server on Termux, and magic-wormhole for key exchange
# With Termux installed, something like this should work
# to type less, you might be able to copy and paste this,
# or use Curl / wget
# First enable file access permission:
termux-setup-storage # accept file access as prompted
pkg install clang cmake python openssh libsodium
SODIUM_INSTALL=system pip install pynacl # skip building bundled version
pip install magic-wormhole
sshd
wormhole ssh invite # follow directions
@lukestanley
lukestanley / reconnect_wifi_on_portal_wifi.py
Last active October 30, 2017 12:48
A simple script I use for reconnecting my wifi device on a network that has a portal. Used on Ubuntu 16.04.3 LTS.
from os import system as run
from random import random
import requests
from time import sleep
def reconnect_wifi():
run("nmcli d connect wlp3s0")
run("firefox http://bbc.co.uk/?"+str(random()))
def are_we_connected():
@lukestanley
lukestanley / setting_react_text_box_value_via_dom.js
Created July 26, 2017 15:41
Updating text box values on DOM elements in React using dispatchEvent - login example
function simulate_input_event(element) {
var event = new Event('input', { bubbles: true });
element.dispatchEvent(event);
}
document.forms[0][0].value='username';
simulate_input_event(document.forms[0][0]);
document.forms[0][1].value='password';
simulate_input_event(document.forms[0][1]);
@lukestanley
lukestanley / tree.py
Created June 5, 2017 10:56
Use Python's built in tk to view Python dict as a tree, with collapsing and such
# Credit to https://stackoverflow.com/a/22722889/122364
import uuid
import tkinter as tk
from tkinter import ttk
def json_tree(tree, parent, dictionary):
for key in dictionary:
uid = uuid.uuid4()
if isinstance(dictionary[key], dict):