Skip to content

Instantly share code, notes, and snippets.

View mehdi-farsi's full-sized avatar

Mehdi FARSI mehdi-farsi

View GitHub Profile
@mehdi-farsi
mehdi-farsi / rails_project_loc.rb
Last active February 9, 2024 07:13
Count the lines of code of a rails project - in pure Ruby
# Workflow:
#
# 1- if the path points to a directory
# 1.1- if the directory isn't in the exclusion list then: count LOC
# 1.2- else: prune directory
# 2- else
# 1.1- if the file extension is whitelisted then: count LOC
# 1.2- else: next
require 'find'
@mehdi-farsi
mehdi-farsi / twitter.md
Last active September 20, 2023 17:27
Script to mass-unfollow OR delete all tweets on Twitter

Mass-unfollow

Step 1

Go to the console tab in your browser: right-click -> "inspect" -> "Console" tab

STEP 2

Paste the following script and press Enter:

trap("SIGINT") { exit! }
total_width = `stty size`.scan(/\d+/)[1].to_i # terminal width
snowflakes = {}
puts "\033[2J"; # clearing output
loop do
snowflakes[rand(total_width)] = 0
@mehdi-farsi
mehdi-farsi / habtm_hmt.md
Last active February 5, 2023 10:32
Replace HABTM by HMT with Join Table as Model

Has And Belongs To Many (use case)

how it works ?

Let's take the simple example of a blog with:

  • A post habtm tags
  • A tag habtm posts
@mehdi-farsi
mehdi-farsi / my_fir.rb
Last active December 23, 2022 08:07
Display a Fir Tree On Terminal
def usage
abort 'Wrong number of argument: ruby my_fir.rb FIR_SIZE'
end
def display_trunk(width)
trunk_width = trunk_height = ((width / 2) - 2).round
(1..trunk_height).each { puts ("|" * trunk_width).center(width) }
end
def display_level(width, line_length)
en:
errors:
messages:
http_unauthorized: 'Authentication required'
http_not_found: 'Not found'
http_bad_request: 'Incorrect or incomplete input'
http_service_unavailable: 'Service unavailable'
http_forbidden: 'Forbidden'
http_unprocessable_entity: 'Unprocessable Entity'
resource_not_found: 'Resource not found'
module TemporaryPatch
refine Hash do
def to_s
''
end
end
end
my_ebook = {
ebook: 'Ruby Object Model',
Regexp.new(".*").class # => Regexp
/.*/.class # => Regexp
%r{.*}.class # => Regexp
if projects = /(?<domain>rubycademy)/.match('https://www.rubycademy.com')
p projects['domain'] # => "rubycademy"
end
if /(?<domain>rubycademy)/ =~ 'https://www.rubycademy.com'
p domain # => "rubycademy"
end