Skip to content

Instantly share code, notes, and snippets.

@zelaznik
zelaznik / normal_approximation_ab_testing.md
Created November 12, 2024 21:12
normal_approximation_ab_testing

Attempt #2, Using Normal Distribution

Find the combined click-through rate:

$$\widehat{\mu} = \frac{k_a + k_b}{n_a + n_b} = \frac{10 + 13}{100 + 100} = \frac{23}{200} = 0.115 $$

Find the variance of the click through rate:

You can look up the mean and variance of a distribution on Wikipedia. This is the distribution of a single visitor and whether this visitor signs up (1) or not (0).

@zelaznik
zelaznik / binomial.js
Last active November 4, 2024 20:04
Javascript Chicago Lightning Talk Outline (WIP)
// A pure Javscript implementation of binomial distribution
// This is for educational purposes. These numbers can become unreliable
// when the numerators and denominators get too big. This is because
// of floating point arithmetic.
//
// Use a more robust statistical library for mission critical calculations
function factorial(n) {
let total = 1;
for(let i=n; i>1; i--) {
@zelaznik
zelaznik / my_avg.sql
Created August 14, 2024 15:12
Custom Agg Functions
CREATE TYPE avg_state AS (
total numeric,
count integer
);
CREATE OR REPLACE FUNCTION my_avg_state(state avg_state, value numeric)
RETURNS avg_state AS $$
BEGIN
IF value IS NOT NULL THEN
state.total := state.total + value;
@zelaznik
zelaznik / my_count.sql
Created August 14, 2024 15:00
Custom Agg Functions Notes
CREATE OR REPLACE FUNCTION my_count_state(state integer, value anyelement)
RETURNS integer AS $$
BEGIN
IF value IS NOT NULL THEN
RETURN state + 1;
ELSE
RETURN state;
END IF;
END;
$$ LANGUAGE plpgsql;
@zelaznik
zelaznik / comparing_tdd_and_stats.md
Last active July 18, 2024 03:01
Just Enough Probability and Stats For Software Engineers

Comparing Statistics To Test Driven Development:

I’m assuming a lot of people in the audience haven’t studied statistics, but because this is Rubyconf, plenty of you know the principles of test-driven-development (TDD). If you haven’t studied statistics before, it follows the same principle as TDD.

In TDD, you demonstrate that your code is correct in two steps. First, assume your code is wrong. Second, try to disprove that assumption. The first step is when you write the test so that it fails. The second step is to change your application code so that the test passes.

In statistics we do the same thing. We first assume the opposite of what we want to prove. If we want to show that a drug treats a disease, we first assume that this drug has no effect. That’s what the placebo group is for. The placebo group is the “red” portion of “red-green refactoring.” The group that’s treated with the drug is (hopefully) the “green” portion of “red-green” factoring.

A statistical test will never PROVE that t

@zelaznik
zelaznik / csv_import_with_typescript.js
Created November 11, 2023 00:42
Webpack Plugin, From CSV To Typescript
var file_path = "/Users/stevezelaznik/src/gnar/aarp-foundation-pta/app/javascript/src/tools/mn-2023/tables/renters_refund_table.csv"
var fs = require("fs");
var Papa = require("papaparse");
var sourceText = fs.readFileSync(file_path).toString();
function hydrateType(types, cell, column_index) {
const type = typeof cell
switch(type) {
case 'string':
@zelaznik
zelaznik / NestedHeader.tsx
Created October 28, 2023 15:44
Nested header tags in React
import React, { useContext, createContext } from "react";
const NestedHeaderContext = createContext<number>(2);
type HxCallback = (component: typeof Hx) => React.ReactNode;
type HxProps = {
children: React.ReactNode;
[x: string]: any;
};
@zelaznik
zelaznik / auto_adjust_table_column_widths.js
Created May 16, 2023 19:05
Javascript Code To Make Sure Table Column Widths Are Consistent
function equalize_widths(table) {
var col_count = [...table.querySelectorAll('thead > tr > th')].length;
var total_table_width = 0;
for (let i=0; i<col_count; i++) {
let elements = [...table.querySelectorAll(`thead > tr > th:nth-child(${i+1}), tbody > tr > td:nth-child(${i+1})`)];
let max_column_width = elements.reduce(function(acc, el) {
let computedStyle = window.getComputedStyle(el);
require 'rspec/expectations'
=begin
# Example use case in a test suite:
# Make sure to have defined a factory in factory-bot for "job_application"
describe JobApplication, type: :model do
it { is_expected.to enforce_uniqueness_of(:uuid) }
end
=end
require 'openssl'
# THIS IS A WORK IN PROGRESS
# NOT READY FOR PRODUCTION
# YOU'VE BEEN WARNED
class PostgresEncryptionSerializer
VALID_DATA_PATTERN = /\\x([0-9a-fA-F]{4})+/
def self.load(binary_encrypted_data)
if binary_encrypted_data.nil?