Skip to content

Instantly share code, notes, and snippets.

View thomasnield's full-sized avatar

Thomas Nield thomasnield

  • Frisco, Texas (United States)
View GitHub Profile
import matplotlib.pyplot as plt
# Parameters
p = 0.7 # probability of success (recovery)
x = [0, 1] # possible outcomes
probabilities = [1-p, p] # probabilities of failure and success
# Create the plot
plt.figure(figsize=(10, 6))
bars = plt.bar(x, probabilities,
@thomasnield
thomasnield / monty_hall_monte_carlo.py
Created February 6, 2025 19:20
monty_hall_monte_carlo.py
from random import randint, choice
def random_door():
return randint(1, 3)
trial_count = 10_000
stay_wins = 0
switch_wins = 0
@thomasnield
thomasnield / rust_mp4_length_sum.rs
Created January 29, 2025 18:14
Rust - Calculate Total Length of MP4s in Folder
use std::process::Command;
use walkdir::WalkDir;
use regex::Regex;
/*
[package]
name = "rust_playground"
version = "0.1.0"
edition = "2021"
cd ~/git/my_project_with_large_files
git lfs install
git lfs migrate import --include="*.pptx, *.pdf" --everything
git lfs ls-files
git push --all --force
# https://josh-ops.com/posts/migrate-to-git-lfs/
@thomasnield
thomasnield / manim_circle_trace.py
Last active August 26, 2023 00:49
Manim - Circle Trace
from manim import *
import os
class CircleTraceTest(Scene):
def construct(self):
circle = Circle(radius=2)
self.add(circle)
vt = ValueTracker(0.0)
point: Dot = always_redraw(lambda: Dot(point=circle.point_from_proportion(vt.get_value())))
@thomasnield
thomasnield / iterate_rename_files.py
Created June 13, 2023 16:03
Python - Iterate and Rename Files
# import required module
import os
from pathlib import Path
import re
# assign directory
directory = Path('/Users') / 'thomasnield' / 'git' / 'oreilly_essential_math_for_data_science_book'
def two_digit_correct(filename: str):
return re.sub(r"(?<=[0-9])_(?=[0-9][A-z])", "_0", filename)
@thomasnield
thomasnield / chatgpt_manim_example1.py
Created April 28, 2023 17:25
ChatGPT Manim Example 1
%%manim -qk Histogram
"""
PROMPT: Create sample Python code using manim to plot data into a histogram. Use that same data to create a numberline with points beneath it. Then draw a distribution function over the histogram.
"""
from manim import *
import numpy as np
class Histogram(Scene):
def construct(self):
@thomasnield
thomasnield / json_tabuler.json
Created January 2, 2023 16:47
JSON Tabular Example
[
{
"ID" : 1,
"NAME": "Alpha Medical",
"ADDRESS" : "18745 Train Dr",
"CITY" : "Dallas",
"STATE": "TX",
"ZIP" : 75021,
"CATEGORY" : "INDUSTRIAL"
},
@thomasnield
thomasnield / linear_regression_manim.py
Created October 4, 2022 19:55
linear_regression_manim.py
import pandas as pd
from math import sqrt
from manim import *
def create_model() -> tuple:
data = list(pd.read_csv("https://bit.ly/2KF29Bd").itertuples())
m = ValueTracker(1.93939)
b = ValueTracker(4.73333)
ax = Axes(
@thomasnield
thomasnield / bit_shifting.c
Created July 18, 2022 01:36
Bit Shifting and Byte Display
// C program to demonstrate the
// showbits() function
#include <stdio.h>
#define BV(bit) (1 << bit)
#define setBit(byte, bit) (byte |= BV(bit))
#define clearBit(byte, bit) (byte &= ~BV(bit))
#define toggleBit(byte, bit) (byte ^= BV(bit))
#define getBit(byte, bit) (byte >> bit) & BV(0)