Skip to content

Instantly share code, notes, and snippets.

View peterc's full-sized avatar
🏠
Working from home

Peter Cooper peterc

🏠
Working from home
View GitHub Profile
@peterc
peterc / songs_to_spotify.py
Created March 8, 2023 23:20
Python app to take a list of songs and add them to a Spotify playlist
# finds songs by names listed in a text file
# and adds them to a spotify playlist
import pprint
import re
import spotipy
from spotipy.oauth2 import SpotifyOAuth
from iteration_utilities import grouper
playlist = ...
@peterc
peterc / gist:6fce570061cc179ff262791b0bc45adf
Last active February 16, 2023 00:24
ufw rules to block abusive IP ranges in 2023
ufw insert 1 deny from 2.59.50.0/24 to any
ufw insert 1 deny from 5.183.130.0/24 to any
ufw insert 1 deny from 31.40.203.0/24 to any
ufw insert 1 deny from 45.11.20.0/23 to any
ufw insert 1 deny from 45.11.20.0/24 to any
ufw insert 1 deny from 45.11.21.0/24 to any
ufw insert 1 deny from 45.15.72.0/23 to any
ufw insert 1 deny from 45.15.72.0/24 to any
ufw insert 1 deny from 45.15.73.0/24 to any
ufw insert 1 deny from 45.15.236.0/23 to any
@peterc
peterc / Caddyfile
Last active July 1, 2025 10:22
Caddyfile for running Mastodon – November 2022 edition
put.your.domain.here {
@local {
file
not path /
}
log {
output file /var/log/caddy/mastodon.log
}
@peterc
peterc / do_this.sh
Last active November 19, 2022 21:18
Commands to get AUTOMATIC1111 / stable-diffusion-webui running on vast.ai GPU instances
# install sd-webui on CUDA enabled linux distro
export URL_TO_MODEL=https://huggingface.co/....there_are_lots_of_options_here....ckpt
ln -fs /usr/share/zoneinfo/Etc/GMT /etc/localtime
dpkg-reconfigure --frontend noninteractive tzdata
adduser sd --disabled-password --gecos ""
apt update -y
apt install -y software-properties-common
add-apt-repository -y ppa:deadsnakes/ppa
apt update -y
@peterc
peterc / grab.rb
Created November 17, 2022 01:04
Grab all text visible on a Web page with Ruby and Ferrum
# notice the cheating technique of selecting all,
# copying to clipboard, then reading the
# clipboard back via JavaScript(!!)
# there's also some stuff to rip content out of
# shadow roots which can be useful if a page
# is doing dynamic rendering
#
# MIT licensed, (c) 2022 Peter Cooper
require 'ferrum'
@peterc
peterc / screencastocr.py
Created October 25, 2022 22:15
Scan screencast videos for (sensitive) text – ROUGH WORK IN PROGRESS
# Scan screencast videos for (sensitive) text
# MIT licensed – Copyright (c) 2022 Peter Cooper – @cooperx86
# Quite a bit of the code comes from
# https://github.com/RhetTbull/osxphotos/blob/master/osxphotos/text_detection.py
# which is itself MIT licensed and copyright (c) 2019-2021 Rhet Turnbull
import tempfile
import subprocess
@peterc
peterc / Gemfile
Last active August 17, 2025 14:32
Example of releasing a tiny gem entire on Gist
source "https://rubygems.org"
gemspec
@peterc
peterc / fingerd.rb
Created July 3, 2022 22:03
finger daemon
#!/usr/bin/env ruby
require 'eventmachine'
class FingerServer < EM::Connection
def receive_data(data)
data.strip!
if data =~ /\A\w+\z/ && data.length <= 100
puts "Got a request for user #{data}"
@peterc
peterc / mlr.txt
Created June 7, 2022 18:33
Using mlr to filter and sort a CSV of GitHub projects
mlr --csv filter 'strptime($pushed_at,"%Y-%m-%d %H:%M:%S %Z") > strptime("2021-09-01", "%Y-%m-%d") && $stargazers >= 2' then sort -nr stargazers list.csv > goodlist.csv
@peterc
peterc / 3b.rb
Last active December 7, 2021 20:08
advent of code day 3 part 2
lines = File.readlines("3.txt")
def dl(lines, m)
12.times do |pos|
rs = lines.map(&:chars).map { |s| s[pos] }.tally
.sort_by { |k, v| [v * m, k.ord * m] }
lines.select! { |l| l[pos] == rs[1][0] }
break lines.first.to_i(2) if lines.size == 1
end
end