This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import time | |
import requests | |
issues_url = 'https://api.github.com/repos/alan-eu/Topics/issues' | |
comments_url = 'https://api.github.com/repos/alan-eu/Topics/issues/comments' | |
rate_limit_url = 'https://api.github.com/rate_limit' | |
headers = {'Authorization': 'token <your_token>', 'Accept': 'application/vnd.github.v3+json'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Get the number of orders for every customer signed in the last year: | |
WITH customers_with_orders AS MATERIALIZED ( -- [needs "MATERIALIZED" only for PG12+] | |
SELECT customer_id, signup_date, count(*) n_orders | |
FROM remote.customers c | |
JOIN remote.orders o ON c.id = o.customer_id | |
GROUP BY 1, 2 | |
) | |
SELECT * | |
FROM customers_with_orders | |
WHERE signup_date > current_date - 365 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Show the distribution of orders from senior customers per month: | |
WITH senior_customers AS ( -- [This would not be a pb if PG 12+] | |
SELECT * | |
FROM remote.customers | |
WHERE age > 60 | |
) | |
SELECT date_trunc(paid_date) AS order_month, count(*) AS n_orders | |
FROM remote.orders o -- brings back to the local server ALL the orders | |
JOIN senior_customers c ON c.id = o.customer_id -- do a JOIN without the indices from the remote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Show the number of paid and delivered orders per country: | |
WITH orders_from_france AS ( | |
SELECT paid_date, delivered_date | |
FROM orders | |
WHERE geo_country(lat, lon) = 'France' | |
) | |
, orders_by_paid_date AS ( | |
SELECT paid_date AS date_, count(*) AS n_paid_orders | |
FROM orders_from_france | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Show the distribution of customers per number of orders in 2020: | |
WITH n_orders_by_customer AS ( | |
SELECT customer_id, count(*) AS n_orders | |
FROM orders | |
WHERE paid_date > '2020-01-01' | |
GROUP BY 1 | |
) | |
SELECT n_orders, count(*) AS n_customers | |
FROM n_orders_by_customer | |
GROUP BY 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gmail.com | |
yahoo.com | |
hotmail.com | |
aol.com | |
hotmail.co.uk | |
hotmail.fr | |
msn.com | |
yahoo.fr | |
wanadoo.fr | |
orange.fr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from werkzeug.routing import Rule as BaseRule | |
class Rule(BaseRule): | |
except_hosts = [] | |
def match(self, path): | |
""" Monkey patched version of the default Werkzeug behavior to achieve host matching with catchall. | |
By default, if host matching is enabled, the match is only done if the host is always provided, which is |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import io | |
import tarfile | |
import urllib.request | |
import re | |
ARCHIVE_URL = 'http://d.pr/f/YqS5+' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Fuction that computes the devaluation factor depending on the | |
# time interval, based on the target yearly ratio. | |
decrease <- function(days, yrRatio = 0.5) { | |
exp(days/365.25 * log(yrRatio)) | |
} | |
# Test & plot | |
x <- 0:800; | |
plot(x, decrease(x), type = "l", yaxp = c(0.25, 1, 3), #xaxp = c(0, 365.25*2, 6), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## claim_queries.R | |
# Quick R-script to test the claim API built by | |
# Andrew. | |
# Setup ------------------------------------------------------------------- | |
# Library | |
library(httr) | |
# Constants |
NewerOlder