Skip to content

Instantly share code, notes, and snippets.

View ei-grad's full-sized avatar

Andrew Grigorev ei-grad

View GitHub Profile
@ei-grad
ei-grad / mp.py
Last active April 6, 2016 09:57
Mixpanel API client with python2/python3 support and data export API support
#! /usr/bin/env python
#
# Mixpanel, Inc. -- http://mixpanel.com/
#
# Python API client library to consume mixpanel.com analytics data.
#
# Copyright 2010-2013 Mixpanel, Inc
# Copyright 2016 Edadeal, LCC
#
# Licensed under the Apache License, Version 2.0 (the "License");
#!/bin/sh
git grep -h import | sed -e 's/ *from \([^ ]\+\) import.*/\1/g' -e 's/ *import \([^ ]\+\).*$/\1/' | sort -u
@ei-grad
ei-grad / circle.yml
Created January 25, 2016 14:18
CircleCI YML with proper docker build && deployment
machine:
services:
- docker
environment:
DOCKER_REGISTRY: example.com
DOCKER_REPO: myproject
DOCKER_USER: circleci
DOCKER_EMAIL: [email protected]
dependencies:
@ei-grad
ei-grad / esplot.py
Created December 17, 2015 02:02
Automatically generate Beaker Notebook plots for Elasticsearch responses by extracting metrics from documents and aggregations, see https://pub.beakernotebook.com/#/publications/566c36fb-a7c0-4061-b1ca-0b2f38528ea8
from collections import defaultdict
from itertools import cycle
import re
import dateutil
from matplotlib import cm
from random import random
{
"beaker": "2",
"cells": [
{
"evaluator": "Python3",
"evaluatorReader": true,
"id": "codebd1MLI",
"input": {
"body": [
"from elasticsearch_dsl import Search",
#! /usr/bin/env python
#
# Mixpanel, Inc. -- http://mixpanel.com/
#
# Python API client library to consume mixpanel.com analytics data.
#
# Copyright 2010-2013 Mixpanel, Inc
# Copyright 2015, Andrew Grigorev <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
{
"template": "mixpanel-*",
"settings": {"index.refresh_interval": "1m"},
"mappings": {
"_default_": {
"_all": {"enabled": false},
"date_detection": false,
"dynamic_templates": [
{"string_fields": {
"match": "*",
import subprocess
from datetime import datetime
from time import sleep, time
import locale
import psutil
locale.setlocale(locale.LC_ALL, locale.getdefaultlocale())
@ei-grad
ei-grad / apache_combined.py
Last active November 18, 2015 19:40
Regular expression to parse apache combined log in python
import re
apache_combined = re.compile(
'(?P<clientip>[\d\.]+) (?P<ident>\S+) (?P<auth>\S+) '
'\[(?P<timestamp>.*?)\] '
'"(?P<verb>\S+) (.*) HTTP/(?P<httpversion>\d\.\d)" '
'(?P<response>\d+|-) (?P<bytes>\d+|-)'
'( "(?P<referrer>.*?)")?'
'( "(?P<agent>.*)")?'
)
@ei-grad
ei-grad / logstash-apache.conf
Last active November 24, 2017 04:37
Logstash example config to parse apache combined log
input { stdin { type => "access" } }
filter {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
remove_field => [ "message" ]
}
date {
match => [ "timestamp", "dd/MMM/yyyy:HH:mm:ss Z" ]
remove_field => [ "timestamp" ]