Skip to content

Instantly share code, notes, and snippets.

View pauldevos's full-sized avatar
👋

Paul DeVos pauldevos

👋
View GitHub Profile
@pauldevos
pauldevos / nbstripout
Created February 27, 2016 17:05 — forked from minrk/nbstripout
git pre-commit hook for stripping output from IPython notebooks
#!/usr/bin/env python
"""strip outputs from an IPython Notebook
Opens a notebook, strips its output, and writes the outputless version to the original file.
Useful mainly as a git filter or pre-commit hook for users who don't want to track output in VCS.
This does mostly the same thing as the `Clear All Output` command in the notebook UI.
LICENSE: Public Domain
@pauldevos
pauldevos / 0_urllib2.py
Created March 14, 2016 03:05 — forked from kennethreitz/0_urllib2.py
urllib2 vs requests
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pauldevos
pauldevos / mongodb.md
Created June 1, 2016 03:17 — forked from artieziff/mongodb.md
MongoDb & Python Essentials

##MONGODB & PYTHON

###Ubuntu Install

sudo apt-get install mongodb
pip install pymongo

Table - Collection
Column - Property
Row - Document

with table_stats as (
select psut.relname,
psut.n_live_tup,
1.0 * psut.idx_scan / greatest(1, psut.seq_scan + psut.idx_scan) as index_use_ratio
from pg_stat_user_tables psut
order by psut.n_live_tup desc
),
table_io as (
select psiut.relname,
sum(psiut.heap_blks_read) as table_page_read,
@pauldevos
pauldevos / statistics.sql
Created October 31, 2018 04:20 — forked from ruckus/statistics.sql
Postgres statistics queries
** Find commmonly accessed tables and their use of indexes:
SELECT relname,seq_tup_read,idx_tup_fetch,cast(idx_tup_fetch AS numeric) / (idx_tup_fetch + seq_tup_read) AS idx_tup_pct FROM pg_stat_user_tables WHERE (idx_tup_fetch + seq_tup_read)>0 ORDER BY idx_tup_pct;
Returns output like:
relname | seq_tup_read | idx_tup_fetch | idx_tup_pct
----------------------+--------------+---------------+------------------------
schema_migrations | 817 | 0 | 0.00000000000000000000
user_device_photos | 349 | 0 | 0.00000000000000000000
@pauldevos
pauldevos / postgres_queries_and_commands.sql
Created October 31, 2018 04:21 — forked from virusdave/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- CHECK TIMINGS ON ACTIVE AND EXPENSIVE QUERIES
SELECT activity.*
FROM (
SELECT
pid,
CASE WHEN state = 'active' THEN AGE(clock_timestamp(), query_start)
ELSE AGE(state_change, query_start)
END as query_duration, -- This is how long the most recent query was running (or is running so far, if still active)
AGE(clock_timestamp(), xact_start) as xact_duration, -- Same, but for the currently active transaction
CASE WHEN state = 'active' THEN INTERVAL '0'