Skip to content

Instantly share code, notes, and snippets.

View MaherSaif's full-sized avatar

Maher Saif MaherSaif

View GitHub Profile
@MaherSaif
MaherSaif / comments_channel.rb
Created May 15, 2025 18:25 — forked from dhh/comments_channel.rb
On-boarding a specialized broadcast method in the channel itself
# Channel
class CommentsChannel < ApplicationCable::Channel
def self.broadcast_comment(comment)
broadcast_to comment.message, comment: CommentsController.render(
partial: 'comments/comment', locals: { comment: comment }
)
end
def follow(data)
stop_all_streams
@MaherSaif
MaherSaif / pandas_ta_technical_indicators.md
Created May 15, 2025 09:37 — forked from textarcana/pandas_ta_technical_indicators.md
pandas_ta full list of technical indicators as of 2024
@MaherSaif
MaherSaif / 1-dsl.rb
Created April 26, 2025 01:46 — forked from VinceGuidry/1-dsl.rb
Ruby DSL
require 'tempfile'
# The DSL class. The render method simply takes a block, then executes the block in the scope of the DSL class. You can see
# a use of it in the next file.
module Keyd
class DSL
def self.render(&block)
d = new
d.instance_exec(&block)
@MaherSaif
MaherSaif / pg_stat_statements.sql
Created March 28, 2025 02:40 — forked from benoittgt/pg_stat_statements.sql
Quickly look at pg_stat_statements
-- based on https://www.crunchydata.com/blog/understanding-postgres-iops
SELECT
interval '1 millisecond' * total_exec_time AS "Total Exec. Time",
to_char (
(total_exec_time / sum(total_exec_time) OVER ()) * 100,
'FM90D0'
) || '%' AS "Proportional Exec. Time",
to_char (calls, 'FM999G999G999G990') AS "Calls",
interval '1 millisecond' * (blk_read_time + blk_write_time) AS "Time Spent on IO",
@MaherSaif
MaherSaif / excited_dev.md
Created March 28, 2025 02:38 — forked from benoittgt/excited_dev.md
As Rails developers, why we are excited about PostgreSQL 17

At the time of writing this article, PostgreSQL 17 is nearly out. On September 5th, the first release candidate was published. The final release is expected on September 26th, but we can already explain why we’ve been eagerly awaiting this release since 1 year.

At Lifen, we’ve loved Rails from the beginning. We have several Rails applications, each with different scopes and teams, all using PostgreSQL as the main database. Some of these applications handle a significant amount of traffic, and their databases need to be properly monitored. This is done by the infrastructure team and the developers themselves using PgAnalyze, Grafana and sometimes AWS console with "Performance Insight".

More than a year ago, we started monitoring the 95th and 99th percentile response times (p95, p99) on an endpoint that was experiencing timeouts. These p99 times were important because they involved a client with significantly mo

-- Carefull setup script is slow
-- SETUP SCRIPT :: START --
DROP TABLE IF EXISTS docs;
CREATE TABLE docs (
id SERIAL PRIMARY KEY,
type varchar(40) DEFAULT 'pdf' NOT NULL,
status varchar(40) NOT NULL,
sender_reference varchar(40) NOT NULL,
sent_at TIMESTAMPTZ,
@MaherSaif
MaherSaif / keymap.json
Created March 27, 2025 23:43 — forked from joeldrapper/keymap.json
My Zed Config
[
{
"context": "Editor",
"bindings": {
"alt-up": "editor::SelectLargerSyntaxNode",
"alt-down": "editor::SelectSmallerSyntaxNode",
"ctrl-cmd-up": "editor::MoveLineUp",
"ctrl-cmd-down": "editor::MoveLineDown"
}
}
@MaherSaif
MaherSaif / fuzzy_index.rb
Created March 27, 2025 23:42 — forked from joeldrapper/fuzzy_index.rb
Simple fuzzy index with left weight
class FuzzyIndex
def initialize
@index = Hash.new { |h, k| h[k] = Set.new }
end
def []=(key, value)
trigrams(key).each { @index[it] << [key, value] }
end
def [](query)
@MaherSaif
MaherSaif / list_of_p2p_file_sharing.md
Created March 12, 2025 19:58 — forked from SMUsamaShah/list_of_p2p_file_sharing.md
List of P2P file sharing tools

Browser Based

  1. Web Wormhole https://webwormhole.io/ https://github.com/saljam/webwormhole
  2. ToffeeShare https://toffeeshare.com/
  3. FilePizza https://file.pizza/
  4. ShareDrop sharedrop.io https://github.com/szimek/sharedrop (SOLD, not recommended, use one of the forks)
    1. A clone SnapDrop snapdrop.net https://github.com/RobinLinus/snapdrop (SOLD, not recommended, use one of the forks)
      1. A fork PairDrop https://pairdrop.net/ https://github.com/schlagmichdoch/pairdrop
  5. Instant.io https://instant.io/
  6. FileTC https://file.tc/
@MaherSaif
MaherSaif / CONVENTIONS.md
Created February 20, 2025 18:22 — forked from peterc/CONVENTIONS.md
CONVENTIONS.md file for AI Rails 8 development
  • You MUST NOT try and generate a Rails app from scratch on your own by generating each file. For a NEW app you MUST use rails new first to generate all of the boilerplate files necessary.
  • Create an app in the current directory with rails new .
  • Use Tailwind CSS for styling. Use --css tailwind as an option on the rails new call to do this automatically.
  • Use Ruby 3.2+ and Rails 8.0+ practices.
  • Use the default Minitest approach for testing, do not use RSpec.
  • Default to using SQLite in development. rails new will do this automatically but take care if you write any custom SQL that it is SQLite compatible.
  • An app can be built with a devcontainer such as rails new myapp --devcontainer but only do this if requested directly.
  • Rails apps have a lot of directories to consider, such as app, config, db, etc.
  • Adhere to MVC conventions: singular model names (e.g., Product) map to plural tables (products); controllers are plural.
  • Guard against incapable browsers accessing controllers with `allo