Skip to content

Instantly share code, notes, and snippets.

Avatar

Arik Fraimovich arikfr

View GitHub Profile
@arikfr
arikfr / index.js
Created Mar 10, 2020
Changelog generator
View index.js
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 Dec 20, 2019
Trigger refresh of Redash queries based on query tag
View trigger_refresh.py
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
@arikfr
arikfr / get-query-result.js
Created Aug 18, 2019
Query Redash's API for fresh results from Javascript
View get-query-result.js
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}`
}
View redash.py
import requests
import os
class Redash(object):
def __init__(self, redash_url, api_key):
self.redash_url = redash_url
self.session = requests.Session()
self.session.headers.update({'Authorization': 'Key {}'.format(api_key)})
def test_credentials(self):
@arikfr
arikfr / example.rb
Last active Mar 15, 2019
Example of for using Redash API in Ruby to update the schedule
View example.rb
require 'httparty'
class Redash
include HTTParty
def initialize(slug, api_key)
@base_uri = "https://app.redash.io/#{slug}"
@headers = {
'Authorization': "Key #{api_key}"
}
@arikfr
arikfr / README.md
Last active Apr 15, 2021
Setting up HTTPS with LetsEncrypt for Redash Docker Deployment
View README.md
  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;
    }
    
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 = []
@arikfr
arikfr / saas_metrics.sql
Last active Apr 14, 2021
SaaS Metrics Query
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'
@arikfr
arikfr / example.py
Created Sep 11, 2017
Redash API usage example
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",