Skip to content

Instantly share code, notes, and snippets.

This is an example how to perform multi-select faceting in ElasticSearch.
Selecting multiple values from the same facet will result in an OR filter between each of the values:
(facet1.value1 OR facet1.value2)
Faceting on more than one facet will result in an AND filter between each facet:
(facet1.value1 OR facet1.value2) AND (facet2.value1)
I have chosen to update the counts for each facet the selected value DOES NOT belong to since we are performing an AND between each facet. I have included an example that shows how to keep the counts if you don't want to do this (filter0.sh).
@jayzeng
jayzeng / app.js
Created April 28, 2014 22:39 — forked from egaumer/app.js
/*jshint globalstrict:true */
/*global angular:true */
'use strict';
angular.module('demo', [
'demo.controllers',
'demo.directives',
'elasticjs.service'
]);
@jayzeng
jayzeng / rds_logs.py
Created April 23, 2015 19:59
get & download rds logs
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 18:05
boto sqs hello world
import boto
import json
from boto.sqs.message import Message
sqs = boto.connect_sqs()
queue = sqs.get_queue('queue')
mess = {
"test":"hello world"
}
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 / manage.py
Created December 2, 2015 21:41
Enable flask profiling
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()

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 / clone.md
Last active December 28, 2016 23:35
clone table w/ primary key
create table mytable_clone (like mytable including defaults including constraints including indexes);
@jayzeng
jayzeng / recover_source_code.md
Created March 12, 2017 08:04 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory

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 / pedantically_commented_playbook.yml
Created April 5, 2017 23:32 — forked from marktheunissen/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
---
# ^^^ 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.