Skip to content

Instantly share code, notes, and snippets.

View formularin's full-sized avatar

Arin Khare formularin

View GitHub Profile
@formularin
formularin / bayesian_network.py
Created June 24, 2020 21:08
A Bayesian Network that uses the example in the 3Blue1Brown video "Bayes theorem"
from pygraph.classes.digraph import digraph as DirectedGraph
class BayesianNetwork(DirectedGraph):
"""A Bayesian Network.
Initialization takes no parameters.
Example usage:
@formularin
formularin / feature_selection.ipynb
Created July 21, 2020 17:19
A jupyter notebook that shows the steps in selecting features from a training data set.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@formularin
formularin / graph.py
Created August 1, 2020 15:54
The adjacency list of a graph in python.
graph = {255: [259, 246, 248, 256, 264, 243, 263], 259: [255, 265, 246, 263, 258], 265: [259, 263, 271, 258, 269], 242: [231, 246, 249, 236], 231: [242, 246, 238, 218, 210, 224], 246: [231, 242, 255, 259, 248, 249], 248: [246, 255, 243, 238], 280: [283, 279, 275], 283: [280, 278, 284], 279: [280, 274, 275, 282], 257: [256, 261, 268, 247, 250], 256: [255, 257, 264, 268, 243, 250], 264: [255, 256, 270, 274, 268, 263], 270: [264, 274, 263, 276, 271], 274: [264, 270, 279, 268, 275, 282, 276], 261: [257, 268, 260, 266, 267, 247], 268: [256, 257, 261, 264, 274, 275, 272, 267], 275: [268, 274, 280, 279, 278, 272], 278: [275, 283, 284, 272, 273], 284: [278, 283, 273], 272: [268, 278, 275, 273, 267], 273: [272, 278, 284, 260, 266, 267], 260: [273, 261, 266, 247], 266: [260, 261, 273, 267], 267: [261, 266, 273, 272, 268], 88: [62, 130, 116, 86, 82], 62: [88, 48, 35, 56], 130: [88, 114, 116, 86, 140, 155, 161, 148], 114: [130, 86, 108, 138, 140], 116: [88, 130, 148], 8: [5, 35, 52, 14], 5: [8, 48, 35], 48: [5, 62, 35, 4
@formularin
formularin / setup.py
Created October 4, 2020 18:20
setup.py for Cython package.
from setuptools import find_packages, setup
import numpy as np
from Cython.Build import cythonize
with open("README.md", 'r') as f:
long_description = f.read()
@formularin
formularin / Sorting.java
Created October 17, 2020 22:20
Sorting algorithm implementations.
/*
Implementations of sorting algorithms.
Takes input array from STDIN, integers separated by newlines with a
sentinel of ";". Prints the sorted integers to STDOUT, also separated
by newlines. Also prints time taken for the algorithm to run.
Usage:
$ java Sorting <algorithm_switch>
@formularin
formularin / Searching.java
Created October 17, 2020 22:21
Searching algorithm implementations.
/*
Implementation of binary and sequential search algorithms.
Takes input array from STDIN, integers separated by newlines with a
sentinel of ";". The final integer before the sentinel is searched
for in the previous integers. Its index is written to STDOUT. If not
in the array of integers, "Not in array." is written to STDOUT. Also
prints the time taken for the algorithm to run.
Usage:
@formularin
formularin / indus.ipynb
Last active August 3, 2022 19:58
Unbiasing water density distributions
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@formularin
formularin / zipf.py
Last active May 28, 2023 18:28
Uses Symbl.ai speech-to-text AI to generate a word frequency distribution from microphone audio.
"""Transcribes audio from microphone and produces real-time plot of word frequency by rank."""
from collections import Counter
from multiprocessing import Process, Queue
import json
import string
import matplotlib.animation as ani
import matplotlib.pyplot as plt
import numpy as np
@formularin
formularin / caliban.py
Last active January 21, 2025 02:32
Solution to Caliban's Will, as it appeared in "The Impossible Man" by Patchen Barss
"""Solution to Caliban's Will by brute force iteration.
"""
NUM_VARS = 8
STR_ORDERINGS = {"LYC", "LCY", "YLC", "YCL", "CLY", "CYL"}
class Ordering:
"""An ordering of Low, YY, and Critic for choosing from Caliban's books.
"""
@formularin
formularin / goto.sh
Last active February 3, 2025 19:25
Changes into shallowest directory in projects folder with the specified name
#!/bin/bash
# Depends on https://github.com/sharkdp/fd
# To make this script work as intended, it should be run using the "." or "source" command.
# Therefore, it may be convenient to add an `alias goto='. goto'`.
projects=~/Projects # CHANGE THIS TO DIRECTORY WHERE YOU KEEP PROJECTS
entries="$(fd . ${projects} --type d)"
declare -a hits=()
for full_path in $entries
do