Skip to content

Instantly share code, notes, and snippets.

Verifying that +alizee is my Bitcoin username. You can send me #bitcoin here: https://onename.io/alizee
@antoine-lizee
antoine-lizee / s_dplyr.R
Last active August 29, 2015 14:21 — forked from skranz/s_dplyr
# Helper functions that allow string arguments for dplyr's data modification functions like arrange, select etc.
# Author: Sebastian Kranz
# Examples are below
#' Modified version of dplyr's filter that uses string arguments
#' @export
s_filter = function(.data, ...) {
eval.string.dplyr(.data,"filter", ...)
}
## claim_queries.R
# Quick R-script to test the claim API built by
# Andrew.
# Setup -------------------------------------------------------------------
# Library
library(httr)
# Constants
## 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),
@antoine-lizee
antoine-lizee / install_ensurepip.py
Last active July 6, 2016 02:13 — forked from uranusjr/install_ensurepip.py
Script to install ensurepip to Python. Works on MacOSX for Anaconda and classic python installs.
import os
import sys
import io
import tarfile
import urllib.request
import re
ARCHIVE_URL = 'http://d.pr/f/YqS5+'
@antoine-lizee
antoine-lizee / host_routed_app.py
Last active December 22, 2016 20:31
Implement exception-based catchall host routing with flask & tests
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
@antoine-lizee
antoine-lizee / email_provider_domains.txt
Created May 16, 2019 17:53
Email provider domain list
gmail.com
yahoo.com
hotmail.com
aol.com
hotmail.co.uk
hotmail.fr
msn.com
yahoo.fr
wanadoo.fr
orange.fr
-- 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
-- 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
)
-- 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