Skip to content

Instantly share code, notes, and snippets.

View MaherSaif's full-sized avatar

Maher Saif MaherSaif

View GitHub Profile
@MaherSaif
MaherSaif / README.md
Created March 29, 2024 18:06 — forked from hopsoft/README.md
ActiveRecord ETL

ActiveRecord ETL

I created this to help me run benchmarks/comparisons against Universal ID, but it could serve as the foundation for a robust ETL data pipeline... and it's less than 70 LOC right now! 🤯 🚀

It handles the extract and transform parts of an ETL process and supports the following options:

  • only - specify which attributes to include
@MaherSaif
MaherSaif / README.md
Created March 29, 2024 18:03 — forked from hopsoft/README.md
stdin → fzf with preview

stdin → fzf with preview

Setup

  1. Add the script below to your PATH
  2. Pipe anything from stdin to infzf
  3. Enjoy!

Usage

@MaherSaif
MaherSaif / analyzer.rb
Created March 22, 2024 09:44 — forked from fffx/analyzer.rb
blurhash rails-7 with libvips
class BlurhashAnalyzer < ActiveStorage::Analyzer::ImageAnalyzer::Vips
def metadata
read_image do |image|
if rotated_image?(image)
{ width: image.height, height: image.width }
else
{ width: image.width, height: image.height }
end.merge blurhash(image)
end
end
@MaherSaif
MaherSaif / trim.py
Created March 17, 2024 13:26 — forked from kitze/trim.py
trim blank space around images in a folder
from PIL import Image
import os
input_folder = "./public/old"
output_folder = "./public"
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for filename in os.listdir(input_folder):
@MaherSaif
MaherSaif / build_insert_query.rb
Created March 15, 2024 20:32 — forked from hopsoft/build_insert_query.rb
Get the SQL for an insert statement from ActiveRecord
# Builds an SQL insert query for a given record
#
# @param record [ActiveRecord::Base] Record used to build the SQL insert query
# @return [String] SQL insert query
def build_insert_query(record)
columns = record.class.columns.reject { |col| col.name == record.class.primary_key }
values = columns.map { |col| record[col.name] }
insert_manager = Arel::InsertManager.new
insert_manager.into(record.class.arel_table)
insert_manager.insert(columns.zip(values)).to_sql
@MaherSaif
MaherSaif / inspect_queries.rb
Created January 22, 2024 20:05 — forked from fatkodima/inspect_queries.rb
Inspect db queries
# Make sure to have prepared statements enabled.
# config/database.yml
# test:
# database: ...
# prepared_statements: true
# Add this to the top scope of test/test_helper.rb or spec/rails_helper.rb and
# run tests as usual.
queries = Hash.new(0)
@MaherSaif
MaherSaif / Dockerfile
Created September 24, 2023 07:58 — forked from robzolkos/Dockerfile
Kamal / SQLite3 issue
# syntax = docker/dockerfile:1
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.2
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
# Rails app lives here
WORKDIR /rails
# Set production environment
@MaherSaif
MaherSaif / render_flash_now_for_xhr.rb
Created May 18, 2023 19:16 — forked from goulvench/render_flash_now_for_xhr.rb
Force Rails to render flash messages for XHR responses
# To display flash messages inside XHR responses,
# place this file in app/controllers/concerns/
# then include it in ApplicationController
module RenderFlashNowForXhr
extend ActiveSupport::Concern
private
# Flash messages are not directly available for XHR requests
@MaherSaif
MaherSaif / active_link_to.rb
Created March 26, 2023 08:13 — forked from dcyoung-dev/active_link_to.rb
An `active_link_to` helper that adds the `.active` class and sets `aria-current="page"`
@MaherSaif
MaherSaif / test.rb
Created February 24, 2023 12:56 — forked from skatkov/test.rb
speed up testsuit by using unlogged tables in PG
# config/environments/test.rb
ActiveSupport.on_load(:active_record_postgresqladapter) do
# For this optimization to work, you need to recreate your test database
self.create_unlogged_tables = true
end