Skip to content

Instantly share code, notes, and snippets.

View classAndrew's full-sized avatar
🍉
1, 2, 4, 8, 16, 32, 64, 128, 256

Andrew Lin classAndrew

🍉
1, 2, 4, 8, 16, 32, 64, 128, 256
View GitHub Profile
@classAndrew
classAndrew / andmalloc.c
Created September 15, 2024 04:59
an explicit-free-list memory allocator
/**
* andmalloc is an explicit-free-list memory allocator.
* fprintf uses glibc malloc which uses the same program breakpoint
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
@classAndrew
classAndrew / raytrace_torch.py
Last active July 3, 2024 16:21
Ray tracing using Torch tensors
import time
import time
import numpy as np
import torch
torch.set_default_device('cuda')
device="cuda"
n = 320
@classAndrew
classAndrew / discord_ansicolor.py
Last active December 2, 2022 01:13
Discord ansi text block generator
# Andrew's Discord color utils https://gist.github.com/classAndrew/2f151a12c49a9e4a105fd1dfa338daba
# See https://gist.github.com/kkrypt0nn/a02506f3712ff2d1c8ca7c9e0aed7c06 for details
'''
example:
from discord_ansicolor import green bold, bg_light_gray
colored = green(bold(bg_light_gray("hello!")))
'''
from typing import Union, Callable
import os
import logging
import time
import requests
import json
__version__ = "1.0.0"
__author__ = "Andrew Lin"
logging.basicConfig(level=logging.INFO, format="[%(name)s] %(levelname)s %(asctime)s :: %(message)s")
@classAndrew
classAndrew / sphluids.cpp
Created May 15, 2022 18:17
SPH Solver Using Gaussian Smoothing Kernel
#define BOOST_LOG_DYN_LINK 1
#include <iostream>
#include <boost/log/trivial.hpp>
#include <SDL2/SDL.h>
#include <sys/time.h>
#include <cmath>
using namespace std;
"""
@classAndrew
Nonlinear regression with a single layer perceptron.
Forgot when this was written
"""
import numpy as np
import statistics
import matplotlib.pyplot as plt
/**
* @classAndrew
* Shunting-Yard logical expression truth table generator
* 9 September 2021
*/
interface BoolRefJSON {
[name: string]: boolean;
};
from collections import Counter
# for K, M-length dictionary words, and an N-tile hand, you can expect a complexity of
# O(KM * lg M) Assuming letter counting and comparing is done in O(n) time (it isn't but
# it can be with the cost of lots of memory) There's a pretty large coefficient of 2^26 since
# there's 26 characters.
# tiles our hand!
hand = "buncheesefoodragon"
# you can realize right away that there's "bun", "cheese", "food", "dragon", "on"