Skip to content

Instantly share code, notes, and snippets.

git reflog
git reflog show <your-feature-branch>
git reset --hard <commit>
@justnoise
justnoise / gist:e94f542e782cc084c7caec12cdf4c4fd
Created March 23, 2025 20:21
PG concurrent index commands
-- check on creation status
SELECT * FROM pg_stat_progress_create_index;
-- look for broken indexes
SELECT * FROM pg_class, pg_index WHERE pg_index.indisvalid = false AND pg_index.indexrelid = pg_class.oid;
-- fix
REINDEX INDEX CONCURRENTLY idx_users_email_2019;
-- find unused indexes
func NetworkSize(cidr string) int {
_, ipnet, err := net.ParseCIDR(cidr)
if err != nil {
return 0
}
ones, bits := ipnet.Mask.Size()
exp := uint(bits - ones)
size := 1 << exp
return size
}
@justnoise
justnoise / .emacs.el
Last active March 10, 2021 05:55
Minimal Emacs Config
(setq make-backup-files nil) ; stop creating backup~ files
(setq auto-save-default nil) ; stop creating #autosave# files
(global-set-key "\C-w" 'backward-kill-word)
(global-set-key "\C-x\C-k" 'kill-region)
(global-set-key "\C-x\C-m" 'execute-extended-command)
(require 'ido)
(ido-mode t)
(ido-everywhere t)
(defun ido-settings ()
@justnoise
justnoise / streaming_mysql_client.py
Created July 8, 2016 06:33
Simple demonstration of streaming queries from mysql
import MySQLdb
import logging
log = logging.getLogger(__name__)
class StreamingMysqlClient(object):
def __init__(self, host, user, password, dbname):
self.conn = MySQLdb.connect(host, user, password, dbname)
def stream_query(self, query):
@justnoise
justnoise / .commonrc
Last active August 16, 2017 23:45
Quick list of aliases
# -*- mode: shell-script -*-
export EDITOR='emacs'
export PATH=$HOME/bin:$PATH
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
alias ggs='git status'
alias ggbl='git branch --list'
alias ee='emacs -nw'
alias eew='emacs'
@justnoise
justnoise / generate_flocker_certs.sh
Created March 9, 2016 01:55
Flocker CA using openssl
#!/bin/bash
# README:
# the first time you run this, you'll need to setup your
# certificate store (feel free to create these directories
# whereever you feel is appropriate):
#
# mkdir $HOME/ssl
# cd $HOME/ssl
# mkdir csr newcerts
@justnoise
justnoise / Grab Log Subset
Created November 14, 2013 19:21
Sometimes repeatedly grepping through huge logs is time consuming. If you're targeting a specific period in time, just grab that period and dump it to a pruned log file.
filename=access_log.log
output_filename=${filename}_pruned
start_pattern='2013:13:'
end_pattern='2013:16:30:'
start=`grep -n -m1 "$start_pattern" $filename | cut -f1 -d:`
end=`grep -n -m1 "$end_pattern" $filename | cut -f1 -d:`
sed -n "$start,${end}p" $filename > $output_filename
@justnoise
justnoise / wait_for_true
Created November 12, 2013 22:19
decorator that calls f until f returns true or takes longer than timeout
def wait_for_true(timeout=60, sleep=1.0):
def _wait_for_true(f):
def __wait_for_true(*args, **kwargs):
start_time = time.time()
ret_val = False
while (not ret_val and
timeout is not None and
time.time() - start_time < timeout):
ret_val = f(*args, **kwargs)
time.sleep(sleep)
@justnoise
justnoise / SimpleDb.py
Last active December 22, 2015 23:09
Quick wrapper around MySQLdb for Python 2.4 and up
import MySQLdb
class SimpleDB(object):
def __init__(self, h, u, p, fetchsize=10000):
self.db = MySQLdb.connect(host=h, user=u, passwd=p)
self.cursor = self.db.cursor()
self.cursor.arraysize = fetchsize
def query(self, q, params = None):
'''note: if you're using more recent pythons, you can change