Skip to content

Instantly share code, notes, and snippets.

@andrewmatte
andrewmatte / introPython.py
Last active January 12, 2020 16:41
This is a 20-minute introduction to the Python programming language for a talk given at Lighthouse Labs in 2016.
#http://bit.ly/28VdHva
##########
#VARIABLES
##########
#numbers
a = 3 #float, int, and long
#strings
b = 'ha '
<html>
<head><title>No Framework JavaScript</title>
<style>
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
</style>
@andrewmatte
andrewmatte / fuzzySearch.html
Last active May 14, 2021 18:11
This is a stand alone HTML file with a nifty JavaScript algorithm for matching strings, implemented to search through a list of names. It was presented as a part of a workshop for TorontoJS on Monday the 12th of December 2016.
<html>
<head><title>Fuzzy Search</title>
<script id="algorithm">
//This algorithm is an original work by Andrew Matte in Toronto, [email protected]
//You are completely free to do whatever you want with this algorithm but,
//please credit me if the project is open source. Also there is no warranty that is it perfectly suited to your use case.
//Written originally in Visual Basic to replace VLOOKUP's fuzzy lookup in Microsoft Excel
//in 2014, implemented in MS-SQL, Python, and JS.
//Apologies for any similarities to an algorithm you personally might have written independently.
var proximity = (wordA, wordB) => {
@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
#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 / 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()));
}
@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 / 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 / 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:
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