Skip to content

Instantly share code, notes, and snippets.

View scmmishra's full-sized avatar
🎯
Focusing

Shivam Mishra scmmishra

🎯
Focusing
View GitHub Profile
@scmmishra
scmmishra / smtp-test.sh
Created July 29, 2025 09:15
Test SMTP connection from a VPS
#!/bin/bash
# Chatwoot SMTP Diagnostics Script (Clean Version)
SMTP_HOST="smtp.gmail.com"
PORTS=(465 587)
echo "=== Chatwoot SMTP Diagnostics ==="
echo
@scmmishra
scmmishra / fix-reply-time.rb
Last active July 22, 2025 13:23
Fix reply time
# Script to fix reply_time events that occur after conversation_resolved events
# Usage in Rails console:
# load 'fix_reply_time_after_resolved.rb'
# find_conversations_to_fix(account_id: 1) # returns array of conversation IDs
# fix_reply_times(account_id: 1) # dry run by default
# fix_reply_times(account_id: 1, dry_run: false) # actual fix
def verify_conversation(conversation)
events = conversation.reporting_events.order(created_at: :asc).to_a
/**
* Browser Bot Script
* -----------------
*
* This script uses Puppeteer to simulate real browser behavior by:
* - Using random viewport sizes and user agents
* - Simulating human-like scrolling (50% chance)
* - Clicking FAQ links (30% chance)
*
* Usage:
@scmmishra
scmmishra / fix-emits.js
Created October 3, 2024 08:03
Add emits to vue files
const fs = require('fs');
const path = require('path');
const glob = require('glob');
// Directory containing your Vue components
const componentsDir = path.resolve(__dirname, 'app/javascript');
// Use glob.sync() for synchronous file matching
const files = glob.sync(`${componentsDir}/**/*.vue`);

Simplest solution, ain't it a beauty

This is the simplest solution I could come up with. It ain't robust, but it's the easiest to understand.

function onlyEvens(arr) {
  return arr.filter(num => num % 2 === 0).sort((a, b) => a - b);
}
const darkColors = {
primary: {
25: '#0B101F',
50: '#101729',
75: '#142251',
100: '#182B6D',
200: '#1F3581',
300: '#284092',
400: '#304CA8',
500: '#3959C4',
@scmmishra
scmmishra / db-schema-health.md
Created March 5, 2024 06:53
Queries I run to check for DB health

Cache Efficiency Ratio

SELECT relname, heap_blks_read, heap_blks_hit, 
       (heap_blks_hit / NULLIF(heap_blks_hit + heap_blks_read, 0)) AS hit_ratio 
FROM pg_statio_user_tables 
ORDER BY hit_ratio ASC, heap_blks_read DESC 
LIMIT 10;

-- hit_ratio: Represents the proportion of times data requested from a table was 
@scmmishra
scmmishra / parse.py
Created December 11, 2023 11:20
Count MutexApplicationJob::LockAcquisitionError in a list of logs
import json
from collections import defaultdict
LEADING = """MutexApplicationJob::LockAcquisitionError: Failed to acquire lock for key: FB_MESSAGE_CREATE_LOCK::"""
def get_logs():
f = open('logs.json')
return json.load(f)
module ColorHelper
def hex_to_rgb(hex_color)
# Remove the '#' character if it's there
hex_color = hex_color.tr('#', '')
# Split the hex color string into the RGB components
r = hex_color[0..1].to_i(16)
g = hex_color[2..3].to_i(16)
b = hex_color[4..5].to_i(16)
@scmmishra
scmmishra / color_helper.rb
Last active November 8, 2023 14:44
Contrast colors with Ruby
module ColorHelper
def hex_to_rgb(hex_color)
# Remove the '#' character if it's there
hex_color = hex_color.tr('#', '')
# Split the hex color string into the RGB components
r = hex_color[0..1].to_i(16)
g = hex_color[2..3].to_i(16)
b = hex_color[4..5].to_i(16)