Skip to content

Instantly share code, notes, and snippets.

View DRBragg's full-sized avatar

Drew Bragg DRBragg

View GitHub Profile
@jbranchaud
jbranchaud / gdoc-download.sh
Created March 11, 2025 03:35
A script to download a public Google Doc from its link, prompts for format with fzf
#!/bin/bash
# Check if fzf is installed
if ! command -v fzf &> /dev/null; then
echo "Error: fzf is not installed. Please install it first."
echo "You can install it with:"
echo " - On macOS: brew install fzf"
echo " - On Ubuntu/Debian: sudo apt install fzf"
echo " - On other systems: see https://github.com/junegunn/fzf#installation"
exit 1

Ruby: The future of frozen string literals

What is a literal?

In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.

Some examples:

7 # integer literal
@julianrubisch
julianrubisch / convert_to_webp.rb
Last active October 4, 2024 19:46
Ruby Oneliners to convert images to webp and generate thumbnails
require 'fileutils'
# Loop through all .jpg and .png files in the current directory
Dir.glob("{*.jpg,*.png}").each do |img|
# Construct the output filename with .webp extension
output_filename = "#{File.basename(img, File.extname(img))}.webp"
# Execute ffmpeg command to convert the image
system("ffmpeg -i '#{img}' '#{output_filename}'")
end
@andrewmcodes
andrewmcodes / good_job.sh
Created November 22, 2023 14:01
Add comment to random Ruby file
#! /usr/bin/env zsh
file=$(fd -e rb -H -1 | shuf -n 1)
line=$(shuf -i 1-$(($(wc -l < "$file") + 1)) -n 1)
awk -v line="$line" 'NR==line{$0="# GOOD_JOB: YOU PROBABLY FORGOT TO REMOVE THIS COMMENT DIDNT YOU\n"$0}1' "$file" > temp && mv temp "$file"
@andrewmcodes
andrewmcodes / dragon.txt
Created May 5, 2023 20:36
ASCII of a Dragon from Podia's codebase, originally added by @ideasasylum
. _///_,
. / ` ' '>
) o' __/_'>
( / _/ )_\'>
' "__/ /_/\_>
____/_/_/_/
/,---, _/ /
"" /_/_/_/
/_(_(_(_ \
( \_\_\\_ )\
@dcyoung-dev
dcyoung-dev / active_link_to.rb
Last active April 10, 2023 16:54
An `active_link_to` helper that adds the `.active` class and sets `aria-current="page"`
# This should be triggered through a cron job at 6:15 PM on week days.
# Example cron: 15 18 * * 1,2,3,4,5 cd ~/code/jury_duty && ~/.rbenv/shims/ruby call.rb >> ~/code/jury_duty/call-log.txt 2>&1
# It uses Twilio to make a call based on TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, and TWILIO_PHONE.
# It calls the JURY_PHONE, transcribes it, looks for JURER_NUMBER and texts the result to PERSONAL_PHONE.
require "rubygems"
require "bundler/setup"
Bundler.require(:default)
Dotenv.load
@kddnewton
kddnewton / latexify.rb
Last active November 7, 2022 14:45
LaTeXify Ruby methods
#!/usr/bin/env ruby
# frozen_string_literal: true
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "syntax_tree"
end
@kaspth
kaspth / scope_with_class_methods.rb
Created July 1, 2022 11:22
`scope` extension to allow marking a class method as a scope.
# In Active Record, class method scopes have to remember to return `all` otherwise they're break the call chain.
#
# def self.some_scope = nil # Assume more complex conditions that would result in a branch that accidentally didn't return `all`.
#
# User.some_scope.first # => raises NoMethodError `first' for NilClass
#
# Note: Active Record ensures a `scope :some_scope, -> { nil }` returns `all` via `|| all` here:
# https://github.com/rails/rails/blob/c704da66de59262f4e88824589ae4eddefb6ed4a/activerecord/lib/active_record/scoping/named.rb#L181
#
# Now, this extension allows you to mark a class method as a scope, so you don't have to remember and the code is more clearly demarcated too.
@camertron
camertron / gifify.sh
Created June 17, 2022 22:29
Easily create a gif
#!/bin/bash
# Usage: gifify.sh <input file> <output file>
ffmpeg -i $1 -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" $2