Skip to content

Instantly share code, notes, and snippets.

View lukestanley's full-sized avatar

Luke Stanley lukestanley

View GitHub Profile
@lukestanley
lukestanley / double_click_here_to_start_remote_support.command
Created July 4, 2011 19:02
Mac OS X bash script TEMPLATE to download a VNC server and run it with a reverse connection to a server
curl -O http://example.com/vine.dmg
hdiutil attach vine.dmg
cd "/Volumes/Vine Server/Vine Server.app"
./OSXvnc-server -connectHost example.com
@lukestanley
lukestanley / hide_firefox_titlebar_on_ubuntu_linux.py
Last active April 22, 2022 11:47 — forked from unhammer/window-toggle-decorations.py
A quick script to hide the window decoration for Firefox, for on Ubuntu systems like Xubunu, where Firefox can look ugly compared to Chrome/Chromium, taking up unneeded space with it's title bar.
#! /usr/bin/python
"""
To install, you may paste this at your terminal command prompt:
mkdir ~/bin
wget https://gist.github.com/lukestanley/5922793/raw/hide_firefox_titlebar_on_ubuntu_linux.py
mv hide_firefox_titlebar_on_ubuntu_linux.py fixfox; chmod +x fixfox
Then, you may simple enter fixfox, to run it.
"""
@lukestanley
lukestanley / render-identicon-from-string
Created March 12, 2014 03:55
Renders an identicon from a string. It's not very good at the moment. It builds upon Caligatio's jsSHA and donpark's identicon - both MIT/BSD, I beleive.
<canvas title="identicon -2044886870" width="48" height="48"></canvas>
<script type="text/javascript" src="https://raw.github.com/donpark/identicon/master/identicon-canvas/identicon_canvas.js"></script>
<script type="text/javascript" src="https://raw.github.com/Caligatio/jsSHA/master/src/sha1.js"></script>
<script>//override existing render func, to not check for prefix
function render_identicon_canvases(prefix) {
var canvases = document.getElementsByTagName("canvas");
var n = canvases.length;
for (var i = 0; i < n; i++) {
var node = canvases[i];
### Keybase proof
I hereby claim:
* I am lukestanley on github.
* I am lukestanley (https://keybase.io/lukestanley) on keybase.
* I have a public key whose fingerprint is BD4D EABC 6129 F49E 0701 4384 FEF5 563D F6A6 AD31
To claim this, I am signing this object:
@lukestanley
lukestanley / battery_alarm.py
Last active August 29, 2015 14:24
Battery Alarm - run red alert sound if power is unplugged
#download mp3 from http://soundbible.com/81-Red-Alert.html
from time import sleep #load a delay function
from os import system #load the "system" call function
import subprocess #load subprocess module
maybeRunningAlertSound = False #store if we are playing sounds, we are not yet
#Because "True" is always true, this is a good way to run the program forever:
while True is True:
@lukestanley
lukestanley / compress_middleware.py
Created February 17, 2017 13:55
How to use compression with Sanic responses and requests using gzip
def compress_requests_and_responses(app):
import gzip
@app.middleware('response')
async def compress_response(request, response):
uncompressed_body_length = len(response.body)
wants_gzip = 'gzip' in request.headers['Accept-Encoding']
if (uncompressed_body_length > 0) and wants_gzip:
compressed_body = gzip.compress(response.body)
compressed_body_length = len(compressed_body)
@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):
@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 / 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 / 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