Skip to content

Instantly share code, notes, and snippets.

View arikfr's full-sized avatar

Arik Fraimovich arikfr

View GitHub Profile
@arikfr
arikfr / refresh.py
Last active May 3, 2024 10:33
Redash Refresh API usage example with parameters Raw
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']))
@arikfr
arikfr / README.md
Last active April 26, 2024 10:07
Setting up HTTPS with LetsEncrypt for Redash Docker Deployment
  1. Make sure the domain you picked points at the IP of your Redash server.
  2. Switch to the root user (sudo su).
  3. Create a folder named nginx in /opt/redash.
  4. Create in the nginx folder two additional folders: certs and certs-data.
  5. Create the file /opt/redash/nginx/nginx.conf and place the following in it: (replace example.redashapp.com with your domain name)
    upstream redash {
        server redash:5000;
    }
    
@arikfr
arikfr / README.md
Last active April 16, 2024 07:53
Redash Query Export Tool

Setup

$ pip install click requests

Usage

$ python query_export.py --redash-url "https://app.redash.io/" --api-key ""
@arikfr
arikfr / get-query-result.js
Created August 18, 2019 11:14
Query Redash's API for fresh results from Javascript
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function getQueryResult(slug, queryId, apiKey, options = {}) {
const instance = axios.create({
baseURL: `https://app.redash.io/${slug}`,
headers: {
Authorization: `Key ${apiKey}`
}
@arikfr
arikfr / refresh_example.py
Created July 22, 2016 11:40
Example code of how to use Redash refresh API
REDASH_HOST = os.environ.get('REDASH_HOST', 'https://app.redash.io/name')
def poll_job(s, job):
# TODO: timeout
while job['status'] not in (3,4):
response = s.get('{}/api/jobs/{}'.format(REDASH_HOST, job['id']))
job = response.json()['job']
time.sleep(1)
return job['status'] == 3
@arikfr
arikfr / saas_metrics.sql
Last active February 20, 2022 14:57
SaaS Metrics Query
/*
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'
@arikfr
arikfr / fabfile.py
Last active February 19, 2021 10:03
re:dash fabfile
#!/usr/bin/env python
# vim: ts=4:sw=4:expandtab:autoindent:
import os
import sys
import requests
import filecmp
from fabric.context_managers import hide, settings, prefix
from fabric.api import sudo, task, run, cd, env
from fabric.contrib.console import confirm
from fabric.colors import green
@arikfr
arikfr / export_lists.py
Created August 19, 2014 04:57
Simple script to export Twitter lists to CSV
import twitter # python-twitter
import csv
import cStringIO
import codecs
from requests_oauthlib import OAuth1Session
REQUEST_TOKEN_URL = 'https://api.twitter.com/oauth/request_token'
ACCESS_TOKEN_URL = 'https://api.twitter.com/oauth/access_token'
AUTHORIZATION_URL = 'https://api.twitter.com/oauth/authorize'
SIGNIN_URL = 'https://api.twitter.com/oauth/authenticate'
@arikfr
arikfr / index.js
Created March 10, 2020 18:56
Changelog generator
const Octokit = require("@octokit/rest");
const createCsvWriter = require("csv-writer").createObjectCsvWriter;
const octokit = new Octokit({
auth: "token " + process.env.GITHUB_TOKEN
});
async function getCommits(since) {
const options = octokit.repos.listCommits.endpoint.merge({
owner: "getredash",
repo: "redash",
@arikfr
arikfr / trigger_refresh.py
Last active December 20, 2019 16:49
Trigger refresh of Redash queries based on query tag
from urllib.parse import urljoin
import requests
import click
import json
class Redash:
def __init__(self, host, api_key):
self.host = host
self.api_key = api_key