Skip to content

Instantly share code, notes, and snippets.

@andrewmatte
andrewmatte / policy.txt
Created May 29, 2022 16:49
privacy policy
This app was not programmed to send any data off-device. We will not collect nor share anything about you.
# conversation from twitter: https://twitter.com/driscollis/status/1475571532898385927
# This function's worst case performance is n*log(n)
def find_most_common_number_in_list(number_list):
# O(n*log(n)))
counts = {}
for number in number_list:
try:
counts[number] += 1
except:
@andrewmatte
andrewmatte / xicor.py
Last active December 29, 2021 21:44
Modified Xi correlation, implementation of Chatterjee's new coefficient for nonlinear relationships (including sinusoidal)
# https://arxiv.org/pdf/1909.10140.pdf
from random import shuffle
from math import sin
def xicor_integrated(X, Y):
# sort Y based on X
new_vars = []
def one_way_distance(string_a, string_b)
score = 0
against = 0
(0..string_a.size-1).each do |idx|
(idx..string_a.size-1).each do |len|
if !string_b.index(string_a[idx, len-idx+1], 0).nil?
score += (len-idx+1)*2
else
against += 1
end
@andrewmatte
andrewmatte / CachedFile.py
Last active November 2, 2023 02:07
Better than accessing the hard drive every time
"""This class provides a way to access to most up-to-date version of a file without reading the whole file from the harddrive.
It does this by first reading when the file was last updated from the filesystem and only reads the whole file if the
file has been updated since. This is more useful for large files and works because RAM has faster access than the harddrive."""
from datetime import datetime
import os
class CachedFile:
@andrewmatte
andrewmatte / json2sql.py
Created May 23, 2021 18:31
Got an API that you want to scrape into a SQL database? Check out this utility that accepts JSON and its type/name, prompts to you tell it which is the ID key, and creates types also for array-valued keys in a similar way. It could be extended to create table-creation statements in SQL.
import json
def add_table(name, json, exclude=None):
non_array_columns = [key for key in json if not isinstance(
json[key], list) and key != exclude]
id_column = prompt_for_selection(non_array_columns, name)
non_array_columns = [x for x in non_array_columns if x != id_column]
array_values = [key for key in json if isinstance(
json[key], list) and key != id_column and key != exclude]
@andrewmatte
andrewmatte / primes.rs
Created August 23, 2020 18:09
toy program to calculate and cache prime numbers, limited by sqlite3 integer types
//[dependencies]
//rusqlite = "0.24.0"
use std::env;
use rusqlite::{params, Connection};
use std::process;
struct Prime {
id: i64,
}
@andrewmatte
andrewmatte / fuzzy.rs
Created September 22, 2019 23:58
same old fuzzy string algo, shiny to rust implementation
use std::env;
//"./fuzzy andrew andy" should yield 0.91588783
fn main() {
let args: Vec<String> = env::args().collect();
let arg1 = &args[1];
let arg2 = &args[2];
println!("{}", fuzzy(arg1.to_string(), arg2.to_string()));
}
#include <stdio.h>
#include <string.h>
void substring(const char [], char[], int, int);
float fuzzy_string(const char* a, const char* b) {
int reward = 0;
int penalty = 0;
int len_a = 0;
while (a[len_a] != '\0') len_a++;
@andrewmatte
andrewmatte / release.sh
Created March 15, 2019 21:04 — forked from rodydavis/release.sh
Flutter Release Script with Fastlane
#!/bin/bash
echo "App Release Automator by @rodydavis"
action="$1"
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
if [ ${action} = "build" ]; then