Skip to content

Instantly share code, notes, and snippets.

View dkam's full-sized avatar

Dan Milne dkam

View GitHub Profile
@dkam
dkam / epubr.rb
Last active April 9, 2024 05:16
Read and write ePub metadata
#!/usr/bin/env ruby
require 'bundler/inline'
#gemfile do
# source 'https://rubygems.org'
# gem 'zip'
# gem 'nokogiri'
# gem 'tty-prompt'
# gem 'debug'
@dkam
dkam / blah.rb
Created February 20, 2024 05:40
Copy and paste snippet
def zzz
t = `pbpaste`
`echo "#{t.split.map {|t| t.tr(',', '') }.join(', ')}" | pbcopy`
end
@dkam
dkam / shrink.md
Created February 8, 2024 11:42
Shrink LXC container

Shink the volume of a Proxmox LXC container

From the Proxmox Forum

List the containers:

pct list

Stop the particular container you want to resize:

pct stop 999

Find out it's path on the node:

@dkam
dkam / Dockerfile
Last active February 22, 2024 05:31
Docker build stage for JXL
#...
WORKDIR /rails
#...
# https://github.com/libjxl/libjxl/blob/main/BUILDING.md
FROM base as buildjxl
ENV CC=clang
ENV CXX=clang++
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y git cmake pkg-config libbrotli-dev libgif-dev libjpeg-dev libopenexr-dev libpng-dev libwebp-dev clang make build-essential && \
@dkam
dkam / longest_wp_tag.rb
Created January 30, 2024 02:10
Find longest Wordpress Tag / Category
Feedjira.parse(URI.open("https://blog.booko.com.au/feed/").read).entries.max_by {|e| e.categories.max_by {|c| c.length }.then {|c| c.length } }
@dkam
dkam / gist:5725c01173a6fa71f7f80c0e08605f96
Last active January 22, 2024 05:54
Convert ISNI_persons.jsonld.gz into a JSONL file using command line tools sed and jq.
# https://isni.org/page/linked-data/
# https://isni.oclc.org:2443/isni/public_export/ISNI_persons.jsonld.gz
wget https://isni.oclc.org:2443/isni/public_export/ISNI_persons.jsonld.gz
# The file I downloaded was full of the 0x1E character, or ^^ in ASCII. This will strip that
sed 's/\x1E//g' ISNI_persons.jsonld > cleaned_ISNI_persons.jsonld
# Then use JQ to convert the file into the way more sane JSONL format. By default, it tries to read it all into
@dkam
dkam / random_isbn13.rb
Created December 28, 2023 04:07
Random ISBN13
def random_isbn13
isbn12 = rand(978_000_000_000..979_999_999_999).to_s
chksum = (10 - isbn12.each_char.with_index.sum { |digit, i| digit.to_i * (i.even? ? 1 : 3) } % 10 ) % 10
"#{isbn12}#{chksum}"
end
def risbn13 = rand(978_000_000_000..979_999_999_999).then {|isbn12| "#{isbn12}#{(10 - isbn12.to_s.each_char.with_index.sum { |digit, i| digit.to_i * (i.even? ? 1 : 3) } % 10 ) % 10}" }
@dkam
dkam / favicon.rb
Last active December 15, 2023 07:51
Get a site's favicon
class Favicon
def initialize(doc, url: nil)
@doc = doc
@url = if url
@url = URI(url.to_s)
elsif canonical
URI(canonical)
else
@dkam
dkam / gist:37d7a41d3c4ab00278580531832130bd
Last active November 27, 2023 02:07
Postgres table, index & toast size.
# This ( https://gist.github.com/hatarist/675dc3debf6cf5f825b5c15aed4cbac0 ) with TOAST size formatting
SELECT
table_name,
pg_size_pretty(table_bytes) AS table,
pg_size_pretty(index_bytes) AS index,
pg_size_pretty(toast_bytes) AS toast,
pg_size_pretty(total_bytes) AS total
FROM (
SELECT
@dkam
dkam / songlink.rb
Created October 31, 2023 02:41
Lookup albums on song.link for sharing