Skip to content

Instantly share code, notes, and snippets.

View Georgy5's full-sized avatar
😶

Karl Keller Georgy5

😶
View GitHub Profile
@Georgy5
Georgy5 / webserver.rb
Created September 7, 2024 16:29
Simple Ruby+Puma "hello world" web app
require 'rack/handler/puma'
class PumaRackApp
def call(env
['200', {'Content-Type => 'text/html'}, ['Hello, World!']]
end
end
Rack::Handler::Puma.run(PumaRackApp.new, Post: 5000)
@Georgy5
Georgy5 / gist:72a97ca62e30e8accfc2eb20396d0a1a
Created July 29, 2024 13:37
Resolving full path to a shell script
# Full path to this script
# two different ways to get the same full path
SCRIPT_DIR=$(dirname $(readlink -f $0))
REALPATH=$(dirname $(realpath $0))
echo "This script is located in: $SCRIPT_DIR"
echo "This script realpath is located in: $REALPATH"
# example use case:
@Georgy5
Georgy5 / normalize.rb
Created April 2, 2024 07:25
"Latinize" string normalization
def latinize(string)
string.unicode_normalize(:nfd).chars.select do |char|
char.match(/\p{Latin}|\s/)
end.join
@Georgy5
Georgy5 / find_unused_routes.rb
Last active March 7, 2024 11:10
Find unused Rails routes
require_relative "config/environment"
# Note: As of Rails 7.1+ we can just use:
# `rails routes --unused`
Rails.application.routes.routes.map(&:requirements).each do |route|
next if route.blank?
next if route[:internal]
controller_name = "#{route[:controller].camelcase}Controller"
next if controller_name.constantize.new.respond_to?(route[:action])
@Georgy5
Georgy5 / gist:7d5f5acc021ab5df842cc96ad08554c2
Created January 17, 2024 15:18
How to fix a corrupt zsh history file
How to fix a corrupt zsh history file
Occasionally you may find you have a corrupt zsh history file preventing you from using the `fc` command or searching the history. Here's how to fix it.
Estimated reading time: 1 minutes
Table of contents
Corrupt ZSH history file
How to fix it
Making it a script
Corrupt ZSH history file
If you use zsh for your shell very occasionally you may find the following message appearing indicating a corrupt history file. This is normally after a reboot.
@Georgy5
Georgy5 / SEO_friendly_URLs
Created March 12, 2023 10:02
Rails SEO friendly URLs
# It's super easy to create SEO friendly URLs (I love that it just works!)
def to_param
"#{id}-#{title.parameterize}"
end
## Alternative implementation of the #to_param method from the book
## Learn Rails 6 by Adam Notodikromo
## Change the default :id parameter
@Georgy5
Georgy5 / update_.ruby-version
Last active July 30, 2023 13:06
Update .ruby-version in several subfolders
# Change the last 6 in the found -ruby-version files to a 7
# You can change to regular expression to be less specific, this was my use case
find ./ -name ".ruby-version" -exec sed -i "s/6$/7/" {} +
# Same thing but only go down one level of subfolders
find ./ -mindepth 2 -name ".ruby-version" -exec sed -i "s/6$/7/" {} +
@Georgy5
Georgy5 / git-clearHistory
Created October 24, 2022 21:45
Steps to clear out the history of a git/github repository
-- Remove the Git history
rm -rf .git
-- reinitialise Git
git init
git add .
git commit -m "Initial commit"
-- create repo through Github CLI
gh repo create --public --source=.
@Georgy5
Georgy5 / RAILS_CHEATSHEET.md
Created January 6, 2021 01:26 — forked from mdang/RAILS_CHEATSHEET.md
Ruby on Rails Cheatsheet

Ruby on Rails Cheatsheet

Architecture

Create a new application

Install the Rails gem if you haven't done so before

c9 WebsiteOne 17.10.2018
be rake cucumber
Failing Scenarios:
cucumber features/hangouts/hangout.feature:131 # Scenario: Infinite scroll on hangouts scroll down until no more hangouts
cucumber features/premium/sponsor_other_member.feature:19 # Scenario: User upgrades another user from free tier to premium via card
cucumber features/premium/subscribe_self_to_nonprofit_basic.feature:12 # Scenario: Sign up for nonprofitbasic support
cucumber features/premium/subscribe_self_to_premium.feature:14 # Scenario: Pay by card
cucumber features/premium/subscribe_self_to_premium.feature:23 # Scenario: Logged in user has sponsor set to self
cucumber features/premium/subscribe_self_to_premium.feature:54 # Scenario: Pay by card, but encounter error