Skip to content

Instantly share code, notes, and snippets.

View scmmishra's full-sized avatar
🎯
Focusing

Shivam Mishra scmmishra

🎯
Focusing
View GitHub Profile
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)
time_zone = '<YourTimezone>'
account_id = '<YourAccountID>'
start_date = Time.zone.now - 12.days
end_date = Time.zone.now
a = Account.find(account_id)
outlier_events = a.reporting_events.where(created_at: start_date..end_date, name: 'conversation_resolved').order(value: :desc).limit(30)

Downloading HAR file

Instructions for Chrome:

  • Open Google Chrome and navigate to the website that you want to capture the HAR file for.
  • Open the Developer Tools panel by pressing F12 or right-clicking anywhere on the page and selecting "Inspect".
  • Click on the "Network" tab in the Developer Tools panel.
  • Make sure the "Preserve log" option is selected. This will ensure that all network requests are captured in the HAR file.
  • Refresh the page to start capturing the network traffic.
  • Once the page has finished loading, right-click anywhere in the Network tab and select "Save as HAR with Content".
## Class to generate sample data for a chatwoot test @Account.
############################################################
### Usage #####
#
# # Seed an account with all data types in this class
# Seeders::AccountSeeder.new(account: Account.find(1)).perform!
#
#
############################################################
@scmmishra
scmmishra / meta_extract.py
Created September 27, 2022 16:06
Script to extract meta tags from a page
from bs4 import BeautifulSoup
from pprint import pprint
import requests
import csv
const sitemap_url = ''
def get_pages_to_crawl():
pages = []
@scmmishra
scmmishra / razorpay_check_members.py
Last active October 17, 2021 06:41
Validate Razorpay e-mandate tokens
import razorpay
import os
import csv
from collections import OrderedDict
fieldnames = ("sr", "name", "member_name", "razorpay_token", "customer_id")
members = []
with open("member.csv", "r") as csvfile: