Skip to content

Instantly share code, notes, and snippets.

View thenlpstudent's full-sized avatar

thenlpstudent

View GitHub Profile
@thenlpstudent
thenlpstudent / entropy.py
Created April 5, 2023 16:42
A short code snippet to visualize information entropy
# Simulate and visualize entropy
# Entropy(X) = -1 * (sum p(X=x) log(P(X=x)))
# Author: Chirath Nissanka
import pygame
import random
import math
WINDOW_WIDTH = 1280
WINDOW_HEIGHT = 1000
@thenlpstudent
thenlpstudent / monad.py
Created May 4, 2023 15:12
A basic monad in python that logs information of pure functions
def main():
log = initLog(0)
log = logRunner(log, addTwo)
log = logRunner(log, square)
log = logRunner(log, divideBy5)
print(log)
def square(n):
@thenlpstudent
thenlpstudent / us_pop.json
Last active May 18, 2023 16:09
A dataset for the population of US from 1910 to 2020 (sourced from https://www.census.gov/data/tables/time-series/dec/popchange-data-text.html)
{
"cols": [
"Location",
"2020",
"2010",
"2000",
"1990",
"1980",
"1970",
"1960",
@thenlpstudent
thenlpstudent / print-monad.py
Created July 16, 2023 10:48
A python monad to print stuff
def printHelloWorld(args):
return "Hello world, " + args[0]
def printYoloWorld(args):
return "Yolo " + args[0]
def prettyPrint(state):
if state == None:
return;
for s in state:
@thenlpstudent
thenlpstudent / fhtml.py
Last active July 17, 2023 14:18
Functional HTML in Python
def get_key(params, key):
if key not in params:
return ""
return params[key]
def put_key(params, key, value):
if key == "":
return params
params[key] = value
return params
@thenlpstudent
thenlpstudent / scrabble.c
Created August 9, 2023 14:36
A point calculator for scrabble written via c and uses a simple rule checker to add/modify scrabble rules via a simple struct
#include <stdio.h>
#include <string.h>
#define RULE_SIZE 7
char toLower(char c)
{
if (c >= 'A' && c <= 'Z')
return (c + (('a' - 'A')));
return c;
@thenlpstudent
thenlpstudent / solVit.js
Created September 9, 2023 04:56
D3 Sol-Vit
width = 800
height = 600
const params = d3.select("body")
.append("div")
.attr("style", "width:100%;display:flex;height:10%;align-items:center;");
params.append("label")
.text("Size of Rectangles: ")