Skip to content

Instantly share code, notes, and snippets.

View N8python's full-sized avatar
🫖
Exploring Computer Graphics

n8programs N8python

🫖
Exploring Computer Graphics
View GitHub Profile
@N8python
N8python / Fmait.js
Created June 23, 2019 11:01
An asynchronous, concurrent function for creating efficient, easy-to-understand promise pipelines.
async function fmait(callbacks, array) {
for (const callback of callbacks) {
array = await Promise.all(array.map(item => Promise.resolve(callback(item))));
}
return array;
}
@N8python
N8python / keybindr.js
Created August 1, 2019 20:21
Keybindr - A small and easy way to bind callbacks to keys.
window.keybindr = (() => {
// Declare set of keys that are pressed
const keys = new Set();
// Declare "associative array" of bindings to callback
const bindings = [];
function tokenizeKeys(keys){
// Get array of different keys from string
return keys.split("+");
}
window.addEventListener("keydown", ({key}) => {
@N8python
N8python / vecTo.js
Created March 13, 2020 01:04
The following code calculates a unit vector from coordinates (x, y) to the point (x1, y1).
const degrees = radians => radians * 180 / Math.PI;
const radians = degrees => degrees * Math.PI / 180;
function vecTo(x1, y1, x2, y2) {
const xDist = x2 - x1;
const yDist = y2 - y1;
let direction;
if (xDist > 0 && yDist > 0) {
direction = degrees(Math.atan(yDist / xDist));
} else if (xDist > 0 && yDist < 0) {
direction = 360 + degrees(Math.atan(yDist / xDist));
@N8python
N8python / seirs.R
Created July 7, 2020 15:29
SEIRS Model - A SEIRS Model with support for vital dynamics, mortality, and seasonal variance in r0.
library(deSolve)
library(reshape2)
library(ggplot2)
initial_state_values <- c(S = 0.999, E = 0, I = 0.001, R = 0, M = 0) # S = Susceptible, E = Exposed, I = Infected, R = Recovered, M = Dead
parameters <- c(
beta = 0.07142857142 * 3, # Contact Rate
theta = 0.2, # 1 / (Length of Latent Period)
gamma = 0.07142857142, # 1 / (Length of Infection)
ro = 0.00130718954, # 1 / (Length of Immunity)
nu = 0.00003281917, # Birth Rate
library(deSolve)
library(reshape2)
library(ggplot2)
initial_state_values <- c(I = 1000000, R = 0, M = 0)
parameters <- c(gamma = 0.1, mu = 0.2)
times <- seq(from = 0, to = 28, by = 1)
cohort_model <- function(time, state, parameters) {
with (as.list(c(state, parameters)), {
dI <- -gamma * I - mu * I
dR <- gamma * I
runs <- 1
for(run in 1:runs) {
beta <- 0.65
gamma <- 0.15
N <- 1000
S <- c(999)
I <- c(1)
R <- c(0)
for(i in 1:(7*8)){
l <- rbinom(1, round(I[length(I)]), beta)
library(deSolve)
library(reshape2)
library(ggplot2)
N <- 1000
initial_state_values <- c(
S = 0.999,
E = 0,
IMI = 0.001,
IM = 0,
A = 0,
@N8python
N8python / terrainAutomata.js
Created September 3, 2020 14:54
Terrain generation using p5js and cellular automata.
const SQUARE_SIZE = 5;
let storage = [];
function setup() {
createCanvas(600, 600);
for (let x = 0; x < width / SQUARE_SIZE; x++) {
storage[x] = [];
for (let y = 0; y < height / SQUARE_SIZE; y++) {
storage[x].push((Math.random() > 0.5) ? "red" : "blue")
}
const fs = require("fs");
const R = require("ramda");
const tf = require("@tensorflow/tfjs-node");
const fsExtra = require('fs-extra')
const text = fs.readFileSync("input.txt").toString();
const chars = Array.from(new Set(text.split("")));
const encoding = Object.fromEntries(chars.map((x, i) => [x, i]));
const decoding = Object.fromEntries(chars.map((x, i) => [i, x]));
const sampleLength = 20; // when I change this to 100, my lstm's loss goes to NaN
const epochSize = 5000;
async function main() {
const fs = require("fs");
const R = require("ramda");
const tf = require("@tensorflow/tfjs-node");
const fsExtra = require('fs-extra');
const text = fs.readFileSync("input.txt").toString();
const chars = Array.from(new Set(text.split("")));
const encoding = Object.fromEntries(chars.map((x, i) => [x, i]));
const decoding = Object.fromEntries(chars.map((x, i) => [i, x]));
const sampleLength = 50;