Skip to content

Instantly share code, notes, and snippets.

@jakeemerson
jakeemerson / gist:2f0070c4736e8e1bcd97
Created March 11, 2015 18:12
nginx log status counter
cat access.log.1 | cut -d '"' -f3 | cut -d ' ' -f2 | sort | uniq -c | sort -r
@jakeemerson
jakeemerson / gist:dd8b91e752fe70206793
Created March 30, 2015 20:50
elasticsearch common search query example
curl -X GET "http://elastic-04:9200/content/_search/?size=10" -d'
{
"query" : {
"common": {
"post_content": {
"query": "waterfront concert series",
"cutoff_frequency": 0.001,
"low_freq_operator" : "and"
}
}
@jakeemerson
jakeemerson / handy_es_queries
Last active June 23, 2022 14:25
helpful elastic search queries
## get all the pageviews on the boundary-vpc host in the last hour, sort by timestamp
curl -X GET "http://elastic-04:9200/logstash-2015.03.31/_search/?pretty" -d'
{
"query": {
"filtered": {
"query": {
"match": {"host" : "boundary-vpc"}
},
"filter": {
@jakeemerson
jakeemerson / gist:f7f2fe3e61b7eaba611f
Created April 7, 2015 18:44
keywords, tokenized (for free) and aggregated
curl -X GET "http://elastic-04:9200/logstash-2015.04.07/_search/?pretty" -d'
{
"size" : 0,
"query": {
"filtered": {
"query": {
"match": {"query_string.userId[muid]" : "46bce8bec4abf177"}
},
"filter": {
"range": {
@jakeemerson
jakeemerson / tokenizer_with_char_filter
Created April 9, 2015 18:40
tokenizer with char filter
{
"settings": {
"number_of_shards": 5,
"analysis": {
"analyzer": {
"happy_tokens": {
"type": "pattern",
"tokenizer": "split_on_comma",
"char_filter": ["kill_pluses"]
}
@jakeemerson
jakeemerson / tree.md
Last active August 29, 2015 14:26 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

<meta name="keywords" content="Maine, news, elections, election results, politics, sports, Bangor, Portland, Augusta, weather, obituaries, Waterville, Aroostook, Penobscot, Piscataquis, Somerset, Hancock, Washington, bdn, health, next, nation, regions, we all want to die with dignity, but not yet, is_article, unbylined" />
@jakeemerson
jakeemerson / ranked_choice_simulation.py
Last active January 11, 2017 21:22
A (hopefully) complete listing of the functions required to run a ranked choice voting simulation
import scipy.stats as ss
from scipy.stats import norm, beta, zscore, gamma
import numpy as np
from math import sqrt
from itertools import chain, permutations
# the functions below aim to replicate the R function here:
# http://stat.ethz.ch/R-manual/R-patched/library/stats/html/power.prop.test.html
@jakeemerson
jakeemerson / geocode.py
Created July 6, 2017 15:29
Using the google geocode api
import pandas as pd
import re
import urllib2
import pprint
import json
def geocode(place):
add = urllib2.quote(place)
geocode_url = "http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false&region=us" % add
@jakeemerson
jakeemerson / alter_postgis_topology_schema.sql
Created July 13, 2017 17:51
Update AWS RDS to give the rds_superuser role ownership of the topology schema
DO
$BODY$
DECLARE
_sql text;
BEGIN
EXECUTE 'SET search_path = topology,public;';
EXECUTE 'ALTER SCHEMA topology OWNER TO rds_superuser;';