Skip to content

Instantly share code, notes, and snippets.

View MaherSaif's full-sized avatar

Maher Saif MaherSaif

View GitHub Profile
@MaherSaif
MaherSaif / pg.txt
Created July 1, 2025 10:28 — forked from peterc/pg.txt
Ruby pg (Postgres) library notes
# gem 'pg'
# https://github.com/ged/ruby-pg
# http://deveiate.org/code/pg
#
# I always find it a nightmare to look up how it works because
# it's not intuitive at all. So here are some notes.
# CONNECTION
# ==========
# No connection URL support, so..
#!/bin/bash
#
# Backs up my entire website, in case Tumblr or CloudApp goes down someday.
# Last time I ran this, it took 18 minutes.
#
wget \
--mirror `# turns on recursion and timestamping, basically says we want to "mirror" the whole site` \
--convert-links `# after download, convert all links to point to localhost` \
@MaherSaif
MaherSaif / Caddyfile
Created July 1, 2025 10:22 — forked from peterc/Caddyfile
Caddyfile for running Mastodon – November 2022 edition
put.your.domain.here {
@local {
file
not path /
}
log {
output file /var/log/caddy/mastodon.log
}
@MaherSaif
MaherSaif / Gemfile
Created July 1, 2025 10:09 — forked from peterc/Gemfile
Example of releasing a tiny gem entire on Gist
source "https://rubygems.org"
gemspec
@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,