Skip to content

Instantly share code, notes, and snippets.

View david-wm-sanders's full-sized avatar
🖋️
up late

David Sanders david-wm-sanders

🖋️
up late
View GitHub Profile
import subprocess
def active_window_name():
window_id_cmd = ["/usr/bin/xprop", "-root", "_NET_ACTIVE_WINDOW"]
window_id = subprocess.check_output(window_id_cmd).decode("utf-8").strip().split()[-1]
window_name_cmd = ["/usr/bin/xprop", "-id", window_id, "_NET_WM_NAME"]
window_name = subprocess.check_output(window_name_cmd).decode("utf-8").strip()[29:-1]
return window_name
print(active_window_name())
@david-wm-sanders
david-wm-sanders / draft.py
Created February 20, 2016 02:08
Single draft from the list in heroes.txt
#!/usr/bin/env python3
import random
with open("heroes.txt", "r") as f:
heroes = f.read().splitlines()
draft = random.sample(heroes, 3)
print(*draft, sep=", ")
@david-wm-sanders
david-wm-sanders / recounter.py
Created February 21, 2016 16:02
Renames DSC_x.JPG to DSC_x+999.JPG to reorder pictures when a new folder has been created after DSC_0999.JPG and the pictures in the new folder start from DSC_0001.JPG again.
#!/usr/bin/env python3
import os
import sys
from shutil import copy2
from pathlib import Path
if len(sys.argv) != 2:
raise Exception("Invalid number of arguments. One directory path must be provided.")
p = Path(sys.argv[1])
@david-wm-sanders
david-wm-sanders / pep8.sh
Created March 4, 2016 03:28
Run pep8 on current directory, excluding the venv (virtual environment) sub-directory.
#!/usr/bin/env bash
pep8 --exclude=venv .
@david-wm-sanders
david-wm-sanders / factorio_take_screenshot.lua
Last active January 30, 2017 04:41
Factorio Console Script: Save a 2500x2500 screenshot at zoom=0.290 to "screenshot_{seed}_{tick}.png"
game.take_screenshot{resolution={2500,2500}, zoom=0.290, path="screenshot_"..game.local_player.surface.map_gen_settings.seed.."_"..game.tick..".png", show_gui=false, show_entity_info=true}
@david-wm-sanders
david-wm-sanders / factorio_fill_lakes.lua
Last active October 20, 2018 16:30
Factorio Console Script: Fill in lake(s).
game.player.print("Getting player position...")
local player_position = game.player.position
game.player.print(string.format("Player is at x=%.3f, y=%.3f", player_position.x, player_position.y))
game.player.print("Checking for neighbouring water tiles...")
local neighbouring_water_tiles = {}
for x=player_position.x-1,player_position.x+1 do
for y=player_position.y-1,player_position.y+1 do
local t = game.player.surface.get_tile(x,y)
if t.name == "water" or t.name == "deepwater" then
@david-wm-sanders
david-wm-sanders / matplotlib_colours.py
Created April 18, 2016 23:36
Pretty colours for pie charts using matplotlib
colours = ["#5DA5DA", "#FAA43A", "#60BD68", "#B276B2", "#DECF3F", "#F15854"]
c:\Windows\System32\certutil.exe -hashfile c:\full\path\to\file [HASH_ALGORITHM]
Supported HASH_ALGORITHMs are: MD2, MD4, MD5, SHA1, SHA256, SHA384, SHA512
import random
import statistics
import sys
def d(x):
return random.randint(1, x)
def droplow_4d6():
dice = [d(6), d(6), d(6), d(6)]
dice.sort()
import collections
import itertools
import random
from csv import DictReader
from pathlib import Path
gems_csv= Path("./gems.csv")
Gem = collections.namedtuple("Gem", "name value")
GemCategory = collections.namedtuple("GemCategory", "weight diev dievmult avgv gems")