Instantly share code, notes, and snippets.

View get_changes.py
#!/bin/env python
import sys
import re
import subprocess
def get_change_log(previous_sha):
args = ['git', '--no-pager', 'log', '--merges', '--grep', 'Merge pull request', '--pretty=format:"%h|%s|%b|%p"', 'master...{}'.format(previous_sha)]
log = subprocess.check_output(args)
changes = []
View saas_metrics.sql
/*
Explanation of what's going on in this query can be found in this blog post: https://blog.redash.io/sql-query-to-calculate-saas-metrics-dd25d72a0521.
*/
WITH v_charges AS (
SELECT org_id,
date_trunc('month', start_date) AS month,
coalesce((extra::json->>'amount')::float, (extra::json->>'charged_amount')::integer/100) as total
FROM charges
WHERE extra::json->>'months' = '1'
View example.py
import requests
class Redash(object):
def __init__(self, redash_url, api_key):
self.redash_url = redash_url
if not self.redash_url.endswith('/'):
self.redash_url = '{}/'.format(self.redash_url)
self.auth_headers = {'Authorization': 'Key {}'.format(api_key)}
View dynamodb_readonly.json
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"dynamodb:BatchGetItem",
"dynamodb:DescribeTable",
"dynamodb:GetItem",
"dynamodb:ListTables",
"dynamodb:Query",
View refresh.py
import os
import requests
import time
from pprint import pprint
def poll_job(s, redash_url, job):
# TODO: add timeout
while job['status'] not in (3,4):
response = s.get('{}/api/jobs/{}'.format(redash_url, job['id']))
View countries.json
{"rows": [{"code": "BD", "continent": "AS", "name": "Bangladesh"}, {"code": "BE", "continent": "EU", "name": "Belgium"}, {"code": "BF", "continent": "AF", "name": "Burkina Faso"}, {"code": "BG", "continent": "EU", "name": "Bulgaria"}, {"code": "BA", "continent": "EU", "name": "Bosnia and Herzegovina"}, {"code": "BB", "continent": "NA", "name": "Barbados"}, {"code": "WF", "continent": "OC", "name": "Wallis and Futuna"}, {"code": "BL", "continent": "NA", "name": "Saint Barthelemy"}, {"code": "BM", "continent": "NA", "name": "Bermuda"}, {"code": "BN", "continent": "AS", "name": "Brunei"}, {"code": "BO", "continent": "SA", "name": "Bolivia"}, {"code": "BH", "continent": "AS", "name": "Bahrain"}, {"code": "BI", "continent": "AF", "name": "Burundi"}, {"code": "BJ", "continent": "AF", "name": "Benin"}, {"code": "BT", "continent": "AS", "name": "Bhutan"}, {"code": "JM", "continent": "NA", "name": "Jamaica"}, {"code": "BV", "continent": "AN", "name": "Bouvet Island"}, {"code": "BW", "continent": "AF", "name": "Botswan
View cohort.sql
with
time_frame as (
select current_date - 14
),
population as (
select created_at::date as cohort_date, id as unique_id
from organizations
where created_at > (select * from time_frame)
View keybase.md

Keybase proof

I hereby claim:

  • I am arikfr on github.
  • I am arikfr (https://keybase.io/arikfr) on keybase.
  • I have a public key ASBNUSKY0adYMAYhkO4QmrqOdjIuV4DtSAtiPsuyb6ZjIgo

To claim this, I am signing this object:

View dashboard_editor.py
import os
import sys
import requests
import json
import time
REDASH_HOST = os.environ.get('REDASH_HOST', 'https://app.redash.io/account')
API_KEY = '...'
View poll.py
import os
import requests
import time
from pprint import pprint
REDASH_HOST = os.environ.get('REDASH_HOST', 'https://demo.redash.io')
def poll_job(s, job):
# TODO: add timeout
while job['status'] not in (3,4):