Skip to content

Instantly share code, notes, and snippets.

View aseroff's full-sized avatar

Andrew Seroff aseroff

View GitHub Profile
@michelson
michelson / async_method_job.rb
Created April 23, 2024 01:50
Asynchronously Concern
class AsyncMethodJob < ApplicationJob
queue_as :default
def perform(target:, method_name:, args:, queue_name: :default)
self.class.queue_as(queue_name)
# `target` could be either an instance or a class
target = target.constantize if target.is_a?(String) # Convert class name to class object if needed
target.send(method_name, *args)
end
end
@julianrubisch
julianrubisch / convert_to_webp.rb
Last active April 26, 2024 08:27
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
@varyform
varyform / multiple_importmaps.rb
Last active April 3, 2024 21:58
Multiple importmaps
# config/initializers/public_importmap.rb
Rails.application.config.public_importmap = Importmap::Map.new
Rails.application.config.public_importmap.draw(Rails.root.join("config/public_importmap.rb"))
# app/helpers/application_helper.rb
# copied from importmaps replacing javascript_inline_importmap_tag
#
# !!! No longer needed after this change https://github.com/rails/importmap-rails/pull/187
#
# def javascript_public_importmap_tags(entry_point = "application", shim: true)
// create a bookmark and use this code as the URL, you can now toggle the css on/off
// thanks+credit: https://dev.to/gajus/my-favorite-css-hack-32g3
javascript: (function() {
var elements = document.body.getElementsByTagName('*');
var items = [];
for (var i = 0; i < elements.length; i++) {
if (elements[i].innerHTML.indexOf('* { background:#000!important;color:#0f0!important;outline:solid #f00 1px!important; background-color: rgba(255,0,0,.2) !important; }') != -1) {
items.push(elements[i]);
}
}
@mrmartineau
mrmartineau / stimulus.md
Last active May 12, 2024 04:35
Stimulus cheatsheet
@phansch
phansch / yardoc_cheatsheet.md
Last active June 26, 2024 12:23 — forked from chetan/yardoc_cheatsheet.md
Improved YARD cheatsheet
@venantius
venantius / gist:ba11dc49cc7a770a3420
Created December 9, 2015 05:09
Rubocop summary stats generator
#!/usr/bin/env python3
"""
A little script to quickly identify the worst offenders. Easily extensible to
find and sort by other issues. Expects you to have results available in an
easily consumable JSON file, which you can generate by running:
rubocop --format progress --format json --out rubocop.json
"""
@raecoo
raecoo / awk-example.sh
Last active September 21, 2023 07:12
awk/grep commands for Rails log analysis
# Access number
cat production.log | grep "^Processing" | wc | awk '{print $1}'
# Each IP access number
cat production.log | grep “^Processing” | awk ‘{print $4}’ | uniq -c
# Independent IP number
cat production.log | grep "^Processing" | awk '{print $4}' | uniq | wc | awk '{print $1}'
cat production.log | grep “^Processing” | awk ‘{print $4}’ | uniq | wc -l
@kyledrake
kyledrake / ferengi-plan.txt
Last active April 6, 2024 00:30
How to throttle the FCC to dial up modem speeds on your website using Nginx
# The blog post that started it all: https://neocities.org/blog/the-fcc-is-now-rate-limited
#
# Current known FCC address ranges:
# https://news.ycombinator.com/item?id=7716915
#
# Confirm/locate FCC IP ranges with this: http://whois.arin.net/rest/net/NET-165-135-0-0-1/pft
#
# In your nginx.conf:
location / {
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end