Skip to content

Instantly share code, notes, and snippets.

# gem install icalendar
require 'icalendar'
# Open a file or pass a string to the parser
cal_file = File.open("/path/to/my_large_calendar.ics")
# Parser returns an array of calendars because a single file
# can have multiple calendars.
cals = Icalendar::Calendar.parse(cal_file)
cal = cals.first
@wteuber
wteuber / check_namespaces.rb
Last active May 30, 2025 14:53
Ruby namespace checker
#!/usr/bin/env ruby
# frozen_string_literal: true
# Example usage:
# ./check_namespaces.rb
# for dir in */; do (cd "$dir" && ../check_namespaces.rb); done
# ./check_namespaces.rb path/to/test/
# ls -d *components/**/test/* | xargs ./check_namespaces.rb
require "prism"
@wteuber
wteuber / ruby_value_omission.sh
Last active November 18, 2024 17:36
Apply Ruby's keyword argument and hash value omission in a git repo
# https://gist.github.com/wteuber/c435bafcd79beb91b65e354fc907efe8
# macOS/zsh
# Apply Ruby's keyword argument and hash value omission in a git repo
# First occurence only
git grep -lP '\b([A-Za-z0-9_]+): \1\b[,\)]' -- '*.rb' | head -1 | xargs -I {} sed -i -E 's/\b([A-Za-z0-9_]+): \1\b([,\)])/\1:\2/g' "{}"
# Apply for "<var>: <var>," and "<var>: <var>)"
git grep -lP '\b([A-Za-z0-9_]+): \1\b[,\)]' -- '*.rb' | xargs -I {} sed -i -E 's/\b([A-Za-z0-9_]+): \1\b([,\)])/\1:\2/g' "{}"
@wteuber
wteuber / generate_random_bitmaps.sh
Last active November 13, 2024 18:13
random bitmap generator
#!/bin/bash
# Usage: ./generate_random_bitmaps.sh <width> <height> <color> <entropy>
# Example ./generate_random_bitmaps.sh 100 100 red 0.8
# Default dimensions
WIDTH=${1:-100}
HEIGHT=${2:-100}
PIXELS=$((WIDTH * HEIGHT))
@wteuber
wteuber / number_of_words_in_git_repo.sh
Created August 14, 2024 18:24
number of words in git repo
git ls-files | xargs wc -w 2> /dev/null | ruby -e "puts ARGF.map{_1.scan(/^\s*(\d+)/)[0][0].to_i}.inject(&:+)"
@wteuber
wteuber / mp4_to_gif.sh
Created August 14, 2024 10:38
mp4 to gif
ffmpeg -i "My Movie.mp4" -vf "fps=10,scale=320:-1:flags=lanczos" -c:v pam -f image2pipe - | convert -delay 10 - -loop 0 -layers optimize output.gif
@wteuber
wteuber / list_unique_prs_for_search_term.sh
Created August 13, 2024 18:27
List unique PRs for search_term
export PAGER="cat"
git --no-pager log -S'search_term' --source --all --pretty=format:'%H' | xargs -I {} gh pr list --search "{}" --state merged --json url -q '.[].url' | sort -u
@wteuber
wteuber / mysql_table_stats.sql
Last active July 1, 2024 15:09
List MySQL tables, their respective row count and size.
SELECT
table_name AS `Table`,
table_rows AS `Row Count`,
ROUND(data_length + index_length) AS `Size (Bytes)`,
CASE
WHEN data_length + index_length < 1024 THEN CONCAT(ROUND((data_length + index_length), 2), ' B')
WHEN data_length + index_length < 1024 * 1024 THEN CONCAT(ROUND((data_length + index_length) / 1024, 2), ' KB')
WHEN data_length + index_length < 1024 * 1024 * 1024 THEN CONCAT(ROUND((data_length + index_length) / 1024 / 1024, 2), ' MB')
WHEN data_length + index_length < 1024 * 1024 * 1024 * 1024 THEN CONCAT(ROUND((data_length + index_length) / 1024 / 1024 / 1024, 2), ' GB')
ELSE CONCAT(ROUND((data_length + index_length) / 1024 / 1024 / 1024 / 1024, 2), ' TB')
@wteuber
wteuber / volume.md
Last active February 3, 2024 21:50
FFmpeg - Audio Volume Manipulation

Audio Volume Manipulation

ffmpeg -i input.mp4 -af "volume=<volume_level>" output.mp4
input.mp4: The input video file.
-af: Stands for audio filter. This option tells FFmpeg to apply an audio filter.
@wteuber
wteuber / reduce_pdf.sh
Created February 1, 2024 16:18 — forked from knugie/reduce_pdf.sh
reduce pdf size
#reduce PDF size
#-dPDFSETTINGS
# /screen
# /ebook
# /printer
# /prepress
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -sOutputFile=out.pdf in.pdf