Skip to content

Instantly share code, notes, and snippets.

View saiqulhaq's full-sized avatar
🏠
Working from home

Saiqul Haq saiqulhaq

🏠
Working from home
View GitHub Profile
@saiqulhaq
saiqulhaq / slow_query_tracker_worker.rb
Created August 28, 2025 10:28
Rails slow query tracker (config/initializers/9999_track_slow_queries.rb)
class SlowQueryTrackerWorker < ApplicationWorker
def perform(payload_sql, payload_name, duration, backtrace)
# Use Rails cache to deduplicate within 5 minutes
sql_hash = Digest::MD5.hexdigest(payload_sql)
cache_key = "slow_query_tracker:#{sql_hash}"
# Skip if we've already processed this query recently
Rails.cache.fetch(cache_key, expires_in: 5.minutes) do
analyze_slow_query(payload_sql, payload_name, duration, backtrace)
true # Store something in cache to mark as processed
@saiqulhaq
saiqulhaq / note claude
Created August 3, 2025 18:10
fix require SSL in Keycloak in start-dev (development mode)
⏺ Bash(docker exec keycloak_app /opt/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin --password 123)
⎿  Logging into http://localhost:8080 as user admin of realm master
⏺ Bash(docker exec keycloak_app /opt/keycloak/bin/kcadm.sh update realms/master -s sslRequired=NONE)
⎿  (No content)
@saiqulhaq
saiqulhaq / Llama 3.1 70B Instruct
Created November 30, 2024 17:04
opencommit commit messages
feat(conversations): improve prompt formatting by introducing a `pretty_print_prompt` helper method to display messages in a table format
@saiqulhaq
saiqulhaq / percona.sh
Created January 31, 2024 05:00
run percona monitoring and management
#!/usr/bin/env bash
#
# ###############################
# Script to run PMM 2.
# If docker is not installed, this script will try to install it as root user.
#
# Usage example:
# curl -fsSL https://raw.githubusercontent.com/percona/pmm/main/get-pmm.sh -o get-pmm2.sh; chmod +x get-pmm2.sh; ./get-pmm2.sh
#
#################################
@saiqulhaq
saiqulhaq / simplecov_rails_engine_minitest.rb
Last active January 6, 2024 07:19
Simplecov for Rails Engine with Minitest
# add this to your main library file
# lib/<engine_name>.rb
if ENV['RAILS_ENV'] == 'test'
require 'simplecov'
SimpleCov.start do
load_profile "test_frameworks"
add_filter %r{^/config/}
add_filter %r{^/db/}
@saiqulhaq
saiqulhaq / application_helper.rb
Created September 30, 2023 00:11
Rails active_link_to helper
module ApplicationHelper
def active_class(link_path)
current_path = request.path
# Special case for root path
return 'active' if current_path == '/' && link_path == '^/$'
return '' if current_path != '/' && link_path == '^/$'
# Use Regex to match the route or any conditions you need
current_path.match(Regexp.new(link_path)) ? 'active' : ''
@saiqulhaq
saiqulhaq / init.vim
Last active February 7, 2023 02:37
My Vim config
"set termguicolors
call plug#begin('~/.local/share/nvim/plugged')
Plug 'wakatime/vim-wakatime'
Plug 'hashivim/vim-terraform'
" Colorscheme
Plug('flazz/vim-colorschemes')
Plug('arcticicestudio/nord-vim')
@saiqulhaq
saiqulhaq / application_controller.rb
Created December 12, 2021 00:42
Ruby on Rails: include view files from gem/plugins
class ApplicationController < ActionController::Base
before_action :prepend_view_paths
def prepend_view_paths
prepend_view_path "#{Bundler.locked_gems.dependencies['your_gem_name'].source.path}/app/views/"
end
end
@saiqulhaq
saiqulhaq / compare.py
Created November 25, 2021 01:59 — forked from sanzoghenzo/compare.py
Compare Excel sheets with Pandas
"""
Compare two Excel sheets
Inspired by https://pbpython.com/excel-diff-pandas-update.html
For the documentation, download this file and type:
python compare.py --help
"""
import argparse
import pandas as pd
@saiqulhaq
saiqulhaq / toLocaleDateString.js
Created January 31, 2021 17:56
Date.toLocaleDateString.js
//Date.toLocaleDateString.js
(function(global) {
"use strict";
var dateFormatOverride = function(locale) {
var formatUS =
this.getMonth() + 1 + "/" + this.getDate() + "/" + this.getFullYear();
var formatTH =
this.getDate() +
"/" +