Skip to content

Instantly share code, notes, and snippets.

View mitchellvitez's full-sized avatar

Mitchell Vitez mitchellvitez

View GitHub Profile
@mitchellvitez
mitchellvitez / dijkstra_roadmap.py
Created July 18, 2023 15:30
Road map route finder using Dijkstra's algorithm and Blender
import bpy
import random
import math
import collections
import json
import queue
westernmost_longitude = -130
def distance(a, b):
@mitchellvitez
mitchellvitez / violin.py
Last active February 9, 2022 23:16
Violin animation made out of many tiny notes. Frames rendered in parallel.
from PIL import Image
import random
import multiprocessing
background = Image.new('RGBA', (2048, 2048), (255, 255, 255, 255))
image = Image.open(r"violin.jpg").convert('RGBA').load()
note = Image.open(r"note.png").convert('RGBA')
def gen_frame(frame):
for x in range(2048):
@mitchellvitez
mitchellvitez / Cardinality.hs
Last active August 8, 2021 16:49
Type-level functions to find the cardinality of various types
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoStarIsType #-}
{-# LANGUAGE DeriveGeneric #-}
module Cardinality where
import Data.Void
@mitchellvitez
mitchellvitez / Email.hs
Last active July 15, 2021 13:55
quasiquoter for compile-time checks without TH splices
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskellQuotes #-}
{-# LANGUAGE DeriveLift #-}
module Email where
import Language.Haskell.TH.Quote (QuasiQuoter(..))
import Language.Haskell.TH.Syntax (Lift, lift, Q, Exp)
-- don't expose this constructor
@mitchellvitez
mitchellvitez / png_add_border.py
Created May 22, 2021 18:44
Adds a solid-colored border to images of a known width/height
# you will need a folder called `images` with pngs you want to add a border to,
# and a folder called `altered` where they'll be written to
from PIL import Image
import glob
WIDTH = 200
HEIGHT = 500
MARGIN = 10
COLOR = (255, 255, 255, 255) # RGBA white
@mitchellvitez
mitchellvitez / spotify_links_to_playlist.py
Created January 26, 2020 19:30
download all spotify links from a website into a playlist
// https://www.realtimerendering.com/raytracing/Ray%20Tracing%20in%20a%20Weekend.pdf
use cgmath::Vector3;
use rand::prelude::*;
type Point = Vector3<f64>;
fn point(x: f64, y: f64, z: f64) -> Point {
return Vector3::new(x, y, z);
}
@mitchellvitez
mitchellvitez / magic_square.rs
Created November 6, 2019 04:09
magic square generator, using backtracking
const SIZE: usize = 3;
const SUM: u32 = magic_constant(SIZE as u32);
const fn magic_constant(n: u32) -> u32 {
return n * (n * n + 1) / 2;
}
const fn initial() -> [[u32; SIZE]; SIZE] {
return [[0; SIZE]; SIZE];
}
@mitchellvitez
mitchellvitez / curate.py
Last active August 5, 2019 04:00
Simple genetic-ish algorithm
import random
POPULATION_SIZE = 1000
HEIGHT = 5
WIDTH = 20
MUTATION_CHANCE = 1 / (WIDTH * HEIGHT)
def randChar():
"""Get a random gene.
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilyDependencies #-}
module Nat where
-- Our own little prelude with just Bool and not
import Prelude((++), Show(..), error)