Skip to content

Instantly share code, notes, and snippets.

View amicojeko's full-sized avatar

Stefano Guglielmetti amicojeko

View GitHub Profile
@amicojeko
amicojeko / unused_methods.sh
Last active January 10, 2024 18:29
Finds defined and unused methods in a Ruby project
#!/bin/bash
cd /path/to/my/app # Go to the app path
echo "Searching for Ruby method definitions..."
method_names=$(git grep -h -o -E '^ *def +([a-zA-Z_][a-zA-Z0-9_]*)' -- '*.rb' | sed -E 's/^ *def +//' | sort -u)
if [ -z "$method_names" ]; then
echo "No Ruby method found, or no .rb files found."
@amicojeko
amicojeko / contributors_deleted_lines.sh
Last active January 10, 2024 14:29
Git deleted lines report per contributor
#!/bin/bash
# Verify is this is a git repo
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo "Questo non è un repository Git."
exit 1
fi
IFS=$'\n' # Change the line separator to avoid breaking lines on spaces
@amicojeko
amicojeko / secret_santa.rb
Last active November 15, 2022 14:15
Secret Santa's Helper Bot
# frozen_string_literal: true
# To obtain a google mail's password, you need to:
# 1. Go to gmail
# 2. in the top right corner click on the menu icon and select 'Account'
# 3. Click on 'Sign in & Security'
# 4. Scroll down the 'Security' and find a section called 'Signing in to Google'.
# 5. Click on "App passwords"
# 6. You should see a dropdown labelled 'Select App'. Select Mail.
# 7. For the 'on my device' dropdown select 'Other' and type in commandline or whatever you want to call the app.
@amicojeko
amicojeko / yaml.rake
Last active August 30, 2022 10:23
YAML Sorter
# Code by PZac
require 'yaml_sorter'
namespace :yaml do
task :fix_all do
Dir.glob('config/locales/**/*.yml').each do |f|
YamlSorter.new(f).fix!
end
end

Introduction

Ruby on Rails is the framework of choice for web apps at Shopify. It is an opinionated stack for quick and easy development of apps that need standard persistence with relational databases, an HTTP server, and HTML views.

By design, Rails does not define conventions for structuring business logic and domain-specific code, leaving developers to define their own architecture and best practices for a sustainable codebase.

@amicojeko
amicojeko / wait_for_turbo.rb
Last active February 3, 2022 13:22
waits for the turbo progress bar to show and disappear
def wait_for_turbo
has_css?('.turbo-progress-bar', visible: true)
has_no_css?('.turbo-progress-bar')
end
@amicojeko
amicojeko / clipboard.rb
Last active February 2, 2021 08:57
Copy to clipboard with Ruby
# Windows and WSL
def clip_copy(input)
str = input.to_s
IO.popen('clip.exe', 'w') { |f| f << str }
str
end
# Mac
@amicojeko
amicojeko / rgbLed.ino
Created November 28, 2020 18:07
RGB Led effects experiment
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
int buttonPin = 2;
int buttonState = 0;
int lastButtonState = 0;
char cmdBuffer[2];
int counter = 0;
@amicojeko
amicojeko / nested_form_controller.js
Last active January 5, 2024 04:35
Stimulus nested form (cocoon alternative)
// Visit The Stimulus Handbook for more details
// https://stimulusjs.org/handbook/introduction
//
// This example controller works with specially annotated HTML like:
//
// <h4>Tasks</h4>
// <div data-controller="nested-form">
// <template data-target="nested-form.template">
// <%= form.fields_for :tasks, Task.new, child_index: 'NEW_RECORD' do |task| %>
// <%= render "task_fields", form: task %>
@amicojeko
amicojeko / jekobot.js
Last active March 22, 2016 15:57
JekoBot typewriter edition
// easy win @ http://10fastfingers.com/typing-test
setInterval( function(){
$('#inputfield').val($(".highlight").html());
$('#inputfield').trigger(
jQuery.Event('keyup', {which: 32})
);
}, 100);