Skip to content

Instantly share code, notes, and snippets.

View WizardOfArc's full-sized avatar

Azi Crawford WizardOfArc

View GitHub Profile
@WizardOfArc
WizardOfArc / azi_html.py
Created June 9, 2021 22:32
My Html Helper - to prevent me from messing up the html, let the program handle opening and closing tags
"""
To Use:
Build your dom structure out of these elements and then call render.()
on the document object to get the dom rendered as a string - either print that out
or write it to a file
"""
class Document:
def __init__(self, dom_elements):
@WizardOfArc
WizardOfArc / pretty_csv.cpp
Created April 2, 2021 23:44
C++ program to print a csv in pretty ascii
#include <algorithm>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
string make_border(const vector<int> &padding_vector, char border_char){
@WizardOfArc
WizardOfArc / ranked_choice_voting.py
Created July 21, 2020 20:51
Python script for finding winner of Ranked Choice election
import os
import sys
"""Ranked choice voting processes ranked votes as tuples and calculates the winner"""
# a ranked vote is a tuple of the voter preference first to last (can be shorter than candidate list if voter doesn't
# want any votes to go to any specific candidates
# votes is
@WizardOfArc
WizardOfArc / melody_manipulator.py
Last active February 2, 2020 19:26
A little "library" to help with melody manipulation.
from enum import Enum
import pygame.midi
import re
import time
instruments = [
'0: Acoustic Grand Piano',
'1: Bright Acoustic Piano',
'2: Electric Grand Piano',
'3: Honky-tonk Piano',
@WizardOfArc
WizardOfArc / sudokuChecker.js
Last active September 11, 2019 15:28
function to test a 9 x 9 array of integers to see if it's a winning Sudoku board
const checkSudoku = (board) => {
let rowCheck = new Array(9).fill(1);
let colCheck = new Array(9).fill(1);
let boxCheck = new Array(9).fill(1);
for(let row = 0; row < 9; row++){
for(let col = 0; col < 9; col++){
if( rowCheck[row] &= (1 << board[row][col]) != 0){
return false;
}
rowCheck[row] |= (1 << board[row][col]);
function tester(func, input, expected){
let actual = func(...input);
if ( compare(actual, expected) ){
console.log( "PASS" );
} else {
console.log( "FAIL: actual [" + actual + "] did not equal expected [" + expected + "]");
}
}
function batchTester(func, testCases){
@WizardOfArc
WizardOfArc / swap_transformation.js
Last active August 30, 2019 14:44
JavaScript function to quickly swap letters in one word to get to a target anagram.
const placeMarker = (index) => {
let pad = Array(index); pad.fill(" ");pad.push("|");
return pad.join("");
}
const areAnagrams = (word1, word2) => {
if(word1.length != word2.length){
return false;
}
@WizardOfArc
WizardOfArc / wordCount.scala
Last active July 1, 2019 14:33
Scala implementation of Source Code Word counter inspired by Fluent C++ ( https://www.fluentcpp.com/2018/10/12/word-counting-cpp-simple-word-counter/ )
import scala.io.Source
import scala.annotation.tailrec
import scala.collection.mutable.{Map -> MMap}
object WordCounter extends App {
if(args.length != 1){
println("Give me a file to investigate")
} else {
val wordList = Source.fromFile(args(0)).getLines
.flatMap(_.split("[()<>''+-=!|/ .,:{}\"]"))
#include <iostream>
#include <functional>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cctype>
#include <numeric>
@WizardOfArc
WizardOfArc / ChordFinderChartBuilder.scala
Created October 26, 2018 15:33
This builds an HTML table for a chart to find what chords contain a given note you are looking to play.
import java.io.FileWriter
object NumberHelper {
def safeMod(num: Int): Int = {
val modded = num % 12
if (modded < 0){
modded + 12
} else {
modded