Skip to content

Instantly share code, notes, and snippets.

View isaacharrisholt's full-sized avatar
👨‍💻
Programming, probably

Isaac Harris-Holt isaacharrisholt

👨‍💻
Programming, probably
View GitHub Profile
@isaacharrisholt
isaacharrisholt / result.ts
Created July 21, 2023 15:45
A TypeScript port of the Rust `Result` type
/**
* A TypeScript port of the Result type from Rust.
*/
class Result<T, E = Error> {
private constructor(private readonly value: T, private readonly error?: E) {}
/**
* Create a new Result with a value.
* @param value
* @returns Result
@isaacharrisholt
isaacharrisholt / fib.py
Created May 29, 2023 18:51
Fibonacci - Python vs Rust benchmark
import sys
from timeit import timeit
import fibbers
RUNS = 100
def fibonacci(n: int) -> int:
if n <= 1:
@isaacharrisholt
isaacharrisholt / lib.rs
Created May 29, 2023 18:46
Fibonacci - Rust implementation
use pyo3::prelude::*;
/// Calculate the nth Fibonacci number.
#[pyfunction]
fn fib(n: u32) -> u32 {
if n <= 1 {
return n;
}
fib(n - 1) + fib(n - 2)
}
@isaacharrisholt
isaacharrisholt / lib.rs
Created May 29, 2023 18:43
Default Maturin `lib.rs`
use pyo3::prelude::*;
/// Formats the sum of two numbers as string.
#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Ok((a + b).to_string())
}
/// A Python module implemented in Rust.
#[pymodule]
@isaacharrisholt
isaacharrisholt / fib.py
Created May 29, 2023 18:33
Fibonacci - Python implementation
import sys
from timeit import timeit
RUNS = 100
def fibonacci(n: int) -> int:
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
@isaacharrisholt
isaacharrisholt / main.go
Created March 16, 2023 16:08
Supabase DB Seeder
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"sort"
@isaacharrisholt
isaacharrisholt / why_learn_sql.py
Created October 8, 2022 13:40
Full benchmark code
import timeit
import faker
import matplotlib.pyplot as plt
import pandas as pd
from cycler import cycler
from sqlalchemy import (
Boolean,
Column,
ForeignKey,
@isaacharrisholt
isaacharrisholt / why_learn_sql.sql
Created October 8, 2022 13:22
The SQL implementation for finding users with failed orders
/* Naive Python implementation */
SELECT *
FROM orders
WHERE NOT payment_status
-- Loop over the results from previous query
-- and run this select each time
SELECT *
FROM users
WHERE id = '{{ user_id }}'
@isaacharrisholt
isaacharrisholt / why_learn_sql.py
Created October 8, 2022 13:15
The Python functions for finding users with failed orders
from sqlalchemy.orm import Session
...
class User(Base):
...
class Order(Base):
...
@isaacharrisholt
isaacharrisholt / docker-compose.yml
Created October 8, 2022 13:04
A simple docker-compose file for a MySQL database
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: default
MYSQL_USER: user
MYSQL_PASSWORD: password
ports:
- "3306:3306"