Skip to content

Instantly share code, notes, and snippets.

View almokhtarbr's full-sized avatar
👋

almokhtar almokhtarbr

👋
  • 22:33 (UTC -04:00)
View GitHub Profile
require 'net/dns/resolver'
# Custom Domain
#
# Require net-dns gem
#
# A Rack middleware to to resolve the custom domain to original subdomain
# for your multi telent application.
#
# It's all transperant to your application, it performs cname lookup and
@almokhtarbr
almokhtarbr / customdomain.rb
Created January 4, 2023 19:57 — forked from johnthethird/customdomain.rb
rack middleware to resolve a custom domain to an original subdomain in a multi-tenant application
require 'net/dns/resolver'
# Custom Domain
#
# Require net-dns gem
#
# A Rack middleware to to resolve the custom domain to original subdomain
# for your multi telent application.
#
# It's all transperant to your application, it performs cname lookup and
# 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
@almokhtarbr
almokhtarbr / gist:c959a0c1e90ab8983938a596cc9afbe2
Created November 27, 2022 17:27 — forked from brianstorti/gist:3839690
Practical Object Oriented Design in Ruby

#Practical Object Oriented Design in Ruby

Design that anticipate specific future requirements almost always end badly.
Practical design does not anticipate what will happen to your application, it merely accepts that something
will and that, in the present, you cannot know what. It does not guess the future; it preserves your options for accommodating the future.
It doesn't choose; it leaves you room to move.
The purpose of design it to allow you to do it later and its primary goal is to reduce the cost of change.

Design is more the art of preserving changeability than it is the act of achieving perfection.

@almokhtarbr
almokhtarbr / poodr.md
Created November 27, 2022 17:27 — forked from jonnyjava/poodr.md
Practical Object-Oriented Design in Ruby

Practical Object-Oriented Design in Ruby

1 Introduction

  • OO is about managing dependencies. Objects interact between them exchanging messages
  • Code must follow S.O.L.I.D. principles
    • Single responsibility
    • Open/Closed
    • Liskow substitution
  • Interface segregation
@almokhtarbr
almokhtarbr / poodir-notes.md
Created November 27, 2022 11:22 — forked from speric/poodir-notes.md
Notes From "Practical Object-Oriented Design In Ruby" by Sandi Metz

Chapter 1 - Object Oriented Design

The purpose of design is to allow you to do design later, and it's primary goal is to reduce the cost of change.

SOLID Design:

  • Single Responsibility Principle: a class should have only a single responsibility
  • Open-Closed Principle: Software entities should be open for extension, but closed for modification (inherit instead of modifying existing classes).
  • Liskov Substitution: Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.
  • Interface Segregation: Many client-specific interfaces are better than one general-purpose interface.
@almokhtarbr
almokhtarbr / System Design.md
Created September 14, 2022 11:39 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@almokhtarbr
almokhtarbr / gem-bisect
Created August 17, 2022 06:36 — forked from andynu/gem-bisect
Find the last version that passes the tests by doing a binary search through a range of versions
#!/usr/bin/env ruby
#
# Find the last version that passes the tests by doing
# a binary search through a range of versions
#
# Usage: gem-bisect <gem_name> [<from_version> [<to_version>]]
#
# Example
# ❯ gem-bisect rack-attack 6.3 6.6.1
# Checking versions 6.6.1, 6.5.0, 6.4.0, 6.3.1

Commit Message Guidelines

Short (72 chars or less) summary

More detailed explanatory text. Wrap it to 72 characters. The blank
line separating the summary from the body is critical (unless you omit
the body entirely).

Write your commit message in the imperative: "Fix bug" and not "Fixed
bug" or "Fixes bug." This convention matches up with commit messages
@almokhtarbr
almokhtarbr / flac2mp3.rb
Created March 8, 2022 21:12 — forked from lpar/flac2mp3.rb
Ruby script I use to convert FLAC files to MP3, and then copy the metadata across.
#!/usr/bin/env ruby
# encoding: UTF-8
# Convert FLAC files to mp3 files, keeping metadata from the FLAC files.
#
# Requires that FLAC (including metaflac) and LAME tools be installed
# and on the path.
#
# Takes any number of .flac files on the command line.