Skip to content

Instantly share code, notes, and snippets.

View alejandrohagan's full-sized avatar
🙃
Working from home

Alejandro Hagan alejandrohagan

🙃
Working from home
  • Exxon Mobil Corporation
  • Spring, Texas
View GitHub Profile
fairness_ratio <- function(coins, flips, trials = 10^6) {
all_heads <- rbinom(trials, flips, 1/2) == flips
is_unfair <- rbinom(trials, 1, 1 / coins)
ratio <- sum(all_heads & !is_unfair) / sum(is_unfair)
return(ratio)
}
# the problem as Daniel stated it
fairness_ratio(coins = 10000, flips = 10)
@adityawarmanfw
adityawarmanfw / duckdb__dim_date.sql
Last active December 15, 2024 21:28
Generate Date Dimension table in DuckDB
WITH generate_date AS (
SELECT CAST(RANGE AS DATE) AS date_key
FROM RANGE(DATE '2009-01-01', DATE '2013-12-31', INTERVAL 1 DAY)
)
SELECT date_key AS date_key,
DAYOFYEAR(date_key) AS day_of_year,
YEARWEEK(date_key) AS week_key,
WEEKOFYEAR(date_key) AS week_of_year,
DAYOFWEEK(date_key) AS day_of_week,
ISODOW(date_key) AS iso_day_of_week,