Skip to content

Instantly share code, notes, and snippets.

View checkaayush's full-sized avatar

Aayush Sarva checkaayush

View GitHub Profile
@checkaayush
checkaayush / Search my gists.md
Created November 25, 2022 06:03 — forked from santisbon/Search my gists.md
How to search gists

Enter this in the search box along with your search terms:

Get all gists from the user santisbon.
user:santisbon

Find all gists with a .yml extension.
extension:yml

Find all gists with HTML files.
language:html

@checkaayush
checkaayush / kill-long-running-queries.sql
Last active November 30, 2022 09:27
Finding and killing long running PostgreSQL queries
-- List all long-running queries
SELECT
pid,
now() - pg_stat_activity.query_start AS duration,
query,
state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
@checkaayush
checkaayush / latency.txt
Created June 11, 2022 06:36 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@checkaayush
checkaayush / postgres_index_usage.sql
Created May 25, 2022 06:58
Get Index size/usage statistics
-- Source: https://wiki.postgresql.org/wiki/Index_Maintenance
SELECT
t.schemaname,
t.tablename,
c.reltuples::bigint AS num_rows,
pg_size_pretty(pg_relation_size(c.oid)) AS table_size,
psai.indexrelname AS index_name,
pg_size_pretty(pg_relation_size(i.indexrelid)) AS index_size,
CASE WHEN i.indisunique THEN 'Y' ELSE 'N' END AS "unique",
@checkaayush
checkaayush / postgres_unused_indexes.sql
Created March 21, 2022 14:53
Get unused indexes in PostgreSQL
-- Source: https://www.cybertec-postgresql.com/en/get-rid-of-your-unused-indexes
SELECT s.schemaname,
s.relname AS tablename,
s.indexrelname AS indexname,
pg_relation_size(s.indexrelid) AS index_size
FROM pg_catalog.pg_stat_user_indexes s
JOIN pg_catalog.pg_index i ON s.indexrelid = i.indexrelid
WHERE s.idx_scan = 0 -- has never been scanned
AND 0 <>ALL (i.indkey) -- no index column is an expression
@checkaayush
checkaayush / GitHub-Forking.md
Created February 21, 2020 16:54 — forked from Chaser324/GitHub-Forking.md
GitHub Standard Fork & Pull Request Workflow

Whether you're trying to give back to the open source community or collaborating on your own projects, knowing how to properly fork and generate pull requests is essential. Unfortunately, it's quite easy to make mistakes or not know what you should do when you're initially learning the process. I know that I certainly had considerable initial trouble with it, and I found a lot of the information on GitHub and around the internet to be rather piecemeal and incomplete - part of the process described here, another there, common hangups in a different place, and so on.

In an attempt to coallate this information for myself and others, this short tutorial is what I've found to be fairly standard procedure for creating a fork, doing your work, issuing a pull request, and merging that pull request back into the original project.

Creating a Fork

Just head over to the GitHub page and click the "Fork" button. It's just that simple. Once you've done that, you can use your favorite git client to clone your repo or j

@checkaayush
checkaayush / Machine_Setup.md
Last active September 27, 2023 06:55
New Machine Setup
  • Trackpad

    • Settings -> Trackpad -> Check "Tap to click"
    • Increase tracking speed by 2 pointers
  • Software

    • Chrome (sign in and turn on auto-sync to get extensions, etc.)
      • Might have to export bookmarks from old machine and import into new one if auto-sync is disabled.
    • Homebrew
      • /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Oh My Zsh

@checkaayush
checkaayush / python_decorator_guide.md
Created May 14, 2019 08:09 — forked from Zearin/python_decorator_guide.md
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].

@checkaayush
checkaayush / myip.go
Last active November 25, 2018 12:06
Get your public and private IP addresses with one command
// Utility to get your public and private IP addresses
// Usage:
// 1. Run: go build -o myip myip.go
// 2. Add the executable myip to your PATH
// 3. Run: myip
package main
import (
"fmt"
@checkaayush
checkaayush / server.go
Created October 24, 2018 07:58
Simple HTTP API in Golang
package main
import (
"fmt"
"log"
"net/http"
"os"
)
// main starts an HTTP server listening on $PORT which dispatches to request handlers.