Skip to content

Instantly share code, notes, and snippets.

Jay Zeng jayzeng

Block or report user

Report or block jayzeng

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View postgres_queries_and_commands.sql
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), 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(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@jayzeng
jayzeng / http_streaming.md
Created Apr 29, 2017 — forked from CMCDragonkai/http_streaming.md
HTTP Streaming (or Chunked vs Store & Forward)
View http_streaming.md

HTTP Streaming (or Chunked vs Store & Forward)

The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.

However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on

@jayzeng
jayzeng / pedantically_commented_playbook.yml
Created Apr 5, 2017 — forked from marktheunissen/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
View pedantically_commented_playbook.yml
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.
@jayzeng
jayzeng / recover_source_code.md
Created Mar 12, 2017 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory
View recover_source_code.md

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@jayzeng
jayzeng / clone.md
Last active Dec 28, 2016
clone table w/ primary key
View clone.md
create table mytable_clone (like mytable including defaults including constraints including indexes);
View queries.md

Slow queries:

SELECT (SELECT datname FROM pg_database WHERE dbid = oid), query, calls,  (total_time / 1000 / 60) as total_minutes, (total_time/calls) as average_time FROM pg_stat_statements ORDER BY total_time DESC limit 5;

Missing indexes

SELECT relname, seq_scan, seq_tup_read, idx_scan, seq_tup_read / seq_scan as ratio from pg_stat_user_tables where seq_scan > 0 order by seq_tup_read desc limit 10;
@jayzeng
jayzeng / manage.py
Created Dec 2, 2015
Enable flask profiling
View manage.py
from app import app
from werkzeug.contrib.profiler import ProfilerMiddleware
if __name__ == '__main__':
app.config['PROFILE'] = True
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])
app.run()
View rds_logs.py
import subprocess
import json
import os, errno
import argparse
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
@jayzeng
jayzeng / sqs.py
Created May 22, 2015
boto sqs hello world
View sqs.py
import boto
import json
from boto.sqs.message import Message
sqs = boto.connect_sqs()
queue = sqs.get_queue('queue')
mess = {
"test":"hello world"
}
@jayzeng
jayzeng / rds_logs.py
Created Apr 23, 2015
get & download rds logs
View rds_logs.py
import subprocess
import json
import os, errno
import argparse
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
You can’t perform that action at this time.