Skip to content

Instantly share code, notes, and snippets.

@peterc
peterc / Caddyfile
Last active Dec 1, 2022
Caddyfile for running Mastodon – November 2022 edition
View Caddyfile
put.your.domain.here {
@local {
file
not path /
}
log {
output file /var/log/caddy/mastodon.log
}
@peterc
peterc / do_this.sh
Last active Nov 19, 2022
Commands to get AUTOMATIC1111 / stable-diffusion-webui running on vast.ai GPU instances
View do_this.sh
# 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 Nov 17, 2022
Grab all text visible on a Web page with Ruby and Ferrum
View grab.rb
# 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 Oct 25, 2022
Scan screencast videos for (sensitive) text – ROUGH WORK IN PROGRESS
View screencastocr.py
# 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 Oct 20, 2022
Example of releasing a tiny gem entire on Gist
View Gemfile
source "https://rubygems.org"
gemspec
View fingerd.rb
#!/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 Jun 7, 2022
Using mlr to filter and sort a CSV of GitHub projects
View mlr.txt
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 Dec 7, 2021
advent of code day 3 part 2
View 3b.rb
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
View backup.sh
#!/bin/bash
#
# Backs up my entire website, in case Tumblr or CloudApp goes down someday.
# Last time I ran this, it took 18 minutes.
#
wget \
--mirror `# turns on recursion and timestamping, basically says we want to "mirror" the whole site` \
--convert-links `# after download, convert all links to point to localhost` \
@peterc
peterc / movies.txt
Last active Jul 23, 2021
Movies Watched in 2021 So Far
View movies.txt
I'm trying to migrate from my own spreadsheet to Letterboxd without
much success so far.. so this is just a total mess of a list,
but broadly in order watched this year.
Favourites have been all the Gasper Noe ones (Enter The Void,
Irreversible, etc.)
Only Tenet, The Father and A Quiet Place 2 were at the cinema 🙁
Some are rewatches (e.g. 2001, 1408, Alien) due to getting them