Skip to content

Instantly share code, notes, and snippets.

View dkam's full-sized avatar

Dan Milne dkam

View GitHub Profile
@dkam
dkam / puma_dev_ssl.md
Last active June 7, 2024 02:23
Make PumaDev work with Ruby HTTP Libraries

From GitHub

#You must specify where to find CA certs for ruby to use them.

create /tmp/cert.pem containing puma-dev CA and all default CAs

cat $(ruby -e "require 'net/http'; puts OpenSSL::X509::DEFAULT_CERT_FILE") "${HOME}/Library/Application Support/io.puma.dev/cert.pem" > /tmp/cert.pem

configure Net::HTTP to use the CA bundle including puma-dev's CA

require 'open-uri'
require 'net/http'
@dkam
dkam / set readonly policy on bucket.txt
Last active June 5, 2024 07:00
Set my minio bucket to be public ( anonymous ) readable
mc anonymous set download myalias/mybucket
@dkam
dkam / kv.md
Last active June 4, 2024 08:55
List of key value stores
@dkam
dkam / mp3tom4b.rb
Last active May 17, 2024 00:50
Convert a bunch of mp3 files into an m4b file
#!/usr/bin/env ruby
require 'open3'
require 'tempfile'
##
# Create a single m4b file from multiple mp3 files.
# Finds all *.mp3 files, merges them, in lexigraphical order, creates chapters based on the mp3 files, adds cover.jpg as a cover
## Todo
@dkam
dkam / as_audit.rb
Last active May 15, 2024 23:34
Ensure all objects in s3 bucket are referenced in ActiveStorage::Blob
## Checking files in your bucket are referenced by ActiveStorage
require 'aws-sdk-s3'
s3_client = Aws::S3::Client.new(
region: "us-east-1",
access_key_id: Rails.application.credentials.dig(Rails.env, :s3, :access_key_id),
secret_access_key: Rails.application.credentials.dig(Rails.env, :s3, :secret_access_key),
endpoint: "https://myendpoint.com",
force_path_style: true
@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 / 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 && \