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 / 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 / matplotlib_colours.py
Created April 18, 2016 23:36
Pretty colours for pie charts using matplotlib
colours = ["#5DA5DA", "#FAA43A", "#60BD68", "#B276B2", "#DECF3F", "#F15854"]
@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 / 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}
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")
@david-wm-sanders
david-wm-sanders / ffmpeg_chopvid_command
Last active March 24, 2017 04:11
ffmpeg: chop a video into image frames (10/s)
ffmpeg -i input -r 10 image-%03d.jpg
@david-wm-sanders
david-wm-sanders / ffmpeg_merge_command
Created March 24, 2017 04:16
ffmpeg: merge the first(0) video stream from first(0) input and the first(0) audio stream from the second(1) input to create the output
ffmpeg -i videoin -i audioin -map 0:v:0 -map 1:a:0 output
# Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams.
ffmpeg -i videoin -i audioin -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 output
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()