Skip to content

Instantly share code, notes, and snippets.

View archiewood's full-sized avatar

Archie Sarre Wood archiewood

View GitHub Profile
@archiewood
archiewood / win_odds.sql
Created July 23, 2024 01:36
Win Probability for the US election in SQL
select
date,
contractname as candidate,
substring(closeshareprice,2,10)::double as implied_probability
from read_csv('https://www.predictit.org/Resource/DownloadMarketChartData?marketid=7456')
order by date desc, implied_probability desc
limit 8
@archiewood
archiewood / word_frequency.sql
Created July 11, 2024 18:45
Word frequency analysis in SQL
with cleaned_docs as (
select
tweet_id,
regexp_replace(regexp_replace(text, '\\n', ' ', 'g'), 'https[^\\s]+', '', 'g') as cleaned_text
from tweets
where text is not null
),
tokenized_docs as (
select
@archiewood
archiewood / timestamps.sql
Created June 8, 2024 08:40
Duckdb Timestamps
INSTALL 'icu';
LOAD 'icu';
SET TimeZone = 'Europe/Berlin';
create or replace table metrics as SELECT TIMESTAMP '2024-06-07 00:00:00' AS mytimestamp, TIMESTAMP WITH TIME ZONE '2024-06-07 00:00:00+02' AS mytimestamptz, 1000 AS sales, 50 AS orders, 20 AS customers;
-- Check the stored timestamps to ensure they match Berlin time
SELECT
@archiewood
archiewood / linear_regression.sql
Last active June 7, 2024 02:23
Linear Regression in SQL
SELECT
regr_slope(num_orders, sales) AS slope,
regr_intercept(num_orders, sales) AS intercept,
regr_r2(num_orders, sales) AS r_squared
FROM orders_by_state
@archiewood
archiewood / createLocalDuckDB.js
Created June 4, 2024 15:03
Create a local copy of the Evidence WASM DuckDB database
/**
* Reads the manifest file and creates a schema and table for each parquet file in the manifest.
* It will create a DB called `local.duckdb` in the root of the project.
*
* Usage:
* 1. Copy this file to the root of your project Evidence project.
* 2. `npm run sources`
* 3. `node createLocalDuckDB.js`
*/