Skip to content

Instantly share code, notes, and snippets.

View dkam's full-sized avatar

Dan Milne dkam

View GitHub Profile
@dkam
dkam / gist:78695d2272ed3f835f984148b0e7cff4
Created April 26, 2024 06:31
Create iOS ringtone from mp3
ffmpeg -i input.mp3 -c:a aac -b:a 192k -vn output.m4a && mv output.m4a output.m4r
# -i input.mp4: Specifies the input video file (replace with your input file path).
# -vn: Tells FFmpeg to ignore the video stream.
# -c:a aac: Sets the audio codec to AAC.
# -b:a 192k: Sets the audio bitrate to 192 kbps (adjust as needed).
# output.m4a: Specifies the output M4A file.
@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 / 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 / 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 / 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 / compile-ffmpeg.sh
Created August 18, 2020 12:38 — forked from wildrun0/compile-ffmpeg.sh
Compiling ffmpeg for Raspberry Pi 4
#!/bin/bash
# Note that there's no libdrm because this lib cause errors
sudo apt update -y && sudo apt upgrade -y
sudo apt-get -y install \
autoconf \
automake \
build-essential \
@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