Skip to content

Instantly share code, notes, and snippets.

View N8python's full-sized avatar

n8programs N8python

View GitHub Profile
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;
@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 / 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 / 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;
}
@patriciogonzalezvivo
patriciogonzalezvivo / GLSL-Noise.md
Last active May 2, 2025 08:14
GLSL Noise Algorithms

Please consider using http://lygia.xyz instead of copy/pasting this functions. It expand suport for voronoi, voronoise, fbm, noise, worley, noise, derivatives and much more, through simple file dependencies. Take a look to https://github.com/patriciogonzalezvivo/lygia/tree/main/generative

Generic 1,2,3 Noise

float rand(float n){return fract(sin(n) * 43758.5453123);}

float noise(float p){
	float fl = floor(p);
  float fc = fract(p);