Skip to content

Instantly share code, notes, and snippets.

View archiewood's full-sized avatar

Archie Sarre Wood archiewood

View GitHub Profile
@archiewood
archiewood / monaco-editor-docs.md
Last active March 27, 2025 19:08
The Missing Docs for the Monaco Editor, focussing on Svelte (AI Generated)
@archiewood
archiewood / send-email.js
Created January 30, 2025 19:09
Send an email with an attached pdf
import nodemailer from 'nodemailer';
import * as dotenv from 'dotenv';
import fs from 'fs';
// Load environment variables
dotenv.config();
const sendEmail = async () => {
try {
// Read recipients and email content from .env
@archiewood
archiewood / generate-pdf.js
Created January 30, 2025 19:07
Login and generate a PDF from an Evidence app
import puppeteer from 'puppeteer';
import * as dotenv from 'dotenv';
// Load environment variables
dotenv.config();
const generatePDF = async () => {
try {
// Load URL, username, and password from environment variables
const url = process.env.PDF_URL || 'https://example.com';
@archiewood
archiewood / AgGrid.svelte
Last active January 14, 2025 09:28
AgGrid Evidence component
<script>
import { onMount } from 'svelte';
import { AllCommunityModule, ModuleRegistry, createGrid } from 'ag-grid-community';
export let data = [];
ModuleRegistry.registerModules([AllCommunityModule]);
function calculateColumnWidth(data) {
return Object.keys(data).map(field => {
@archiewood
archiewood / presidential_odds.sql
Last active July 24, 2024 14:31
Win Probability for the US election in SQL
PIVOT(
select
date,
contractname as candidate,
substring(closeshareprice,2,10)::double as implied_probability
from read_csv('https://www.predictit.org/Resource/DownloadMarketChartData?marketid=7456&timespan=30d')
--where candidate in ('Trump', 'Harris', 'Biden')
order by date desc, implied_probability desc
)
ON candidate using sum(implied_probability)
@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`
*/