Skip to content

Instantly share code, notes, and snippets.

@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active July 31, 2026 07:52
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@miku
miku / client.py
Last active July 30, 2021 05:35
Kombu example
from __future__ import with_statement
from kombu.common import maybe_declare
from kombu.pools import producers
from queues import task_exchange
priority_to_routing_key = {'high': 'high',
'mid': 'mid',
'low': 'low'}
@caseywatts
caseywatts / bookmarkleting.md
Last active July 31, 2026 05:47
Making Bookmarklets

This is one chapter of my "Chrome Extension Workshops" tutorial, see the rest here: https://gist.github.com/caseywatts/8eec8ff974dee9f3b247

Unrelated update: my book is out! Debugging Your Brain is an applied psychology / self-help book

Making Bookmarklets

I'm feeling very clever. I've got this sweet line of javascript that replaces "cloud" with "butt". My mom would LOVE this, but she doesn't computer very well. I'm afraid to show her the Developer Console and have her type/paste this in. But she IS pretty good at bookmarks, she knows just how to click those!

A bookmark normally takes you to a new web page. A bookmarklet is a bookmark that runs javascript on the current page instead of taking you to a new page. To declare that it is a bookmarklet, the "location" it points to starts with javascript:.

@paragonie-scott
paragonie-scott / Industry.md
Created June 7, 2015 19:20
On the Industry

This is just a collection of thoughts and feelings about the technology industry and guidelines I feel should be upheld.

Public Speaking

Don't Present Original Research at Expensive Events

If a minimum wage employee cannot reasonably afford to attend an event (e.g. saving $300 for DEFCON is probably the upper limit), original research should NOT be presented at that event.

Presenting cutting-edge ideas to the wealthy only serves to insulate the fat cats from the disruptions of the poor. There are plenty of other researchers that hunger for career progression that will serve the whims and aims of the upper class that can afford to drop several thousand dollars on a technology conference.

@DmitrySoshnikov
DmitrySoshnikov / Recursive-descent-backtracking.js
Last active January 3, 2024 17:15
Recursive descent parser with simple backtracking
/**
* = Recursive descent parser =
*
* MIT Style License
* By Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*
* In this short lecture we'll cover the basic (non-predictive, backtracking)
* recursive descent parsing algorithm.
*
* Recursive descent is an LL parser: scan from left to right, doing
@paragonie-scott
paragonie-scott / crypto-wrong-answers.md
Last active April 22, 2026 21:43
An Open Letter to Developers Everywhere (About Cryptography)
@soulmachine
soulmachine / jwt-expiration.md
Last active May 3, 2026 13:29
How to deal with JWT expiration?

First of all, please note that token expiration and revoking are two different things.

  1. Expiration only happens for web apps, not for native mobile apps, because native apps never expire.
  2. Revoking only happens when (1) uses click the logout button on the website or native Apps;(2) users reset their passwords; (3) users revoke their tokens explicitly in the administration panel.

1. How to hadle JWT expiration

A JWT token that never expires is dangerous if the token is stolen then someone can always access the user's data.

Quoted from JWT RFC:

@shivamMg
shivamMg / min-heap.py
Last active March 1, 2026 15:14
Data Structures
class MinHeap:
"""A min-heap using an array"""
# storing tree in level-order
arr = []
@staticmethod
def parent(i): return (i - 1) // 2
@staticmethod
def children(i): return (2*i + 1, 2*i + 2)
def insert(self, a):
@shivamMg
shivamMg / counting-sort.py
Last active March 1, 2026 15:14
Sorting Algorithms
# Total possible values in array
# Array can only be sorted if it's in range [0, K)
K = 10
def counting_sort(arr):
counter = [0 for _ in range(K)]
for a in arr:
counter[a] += 1
@shivamMg
shivamMg / bellman-ford.py
Last active March 1, 2026 15:14
Graph Theory
class GraphBellmanFord(Graph):
def bellman_ford(self, src: str):
dist = {}
for _, u in self.V.items():
dist[u] = float('Inf')
src = self.V[src]
dist[src] = 0
edges = []
for e in self.E.values():