Skip to content

Instantly share code, notes, and snippets.

View CodeByAidan's full-sized avatar
💻
i love HPC/DL

aidan CodeByAidan

💻
i love HPC/DL
View GitHub Profile
@CodeByAidan
CodeByAidan / levenshteinDistance.js
Created May 23, 2024 16:27
A Levenshtein distance calculator function, using a 2D matrix.
const levenshteinDistance = (s, t) => {
if (s === t) {
return 0;
}
if (s.length === 0) {
return t.length;
}
if (t.length === 0) {
return s.length;
}
@CodeByAidan
CodeByAidan / FibSeq.cs
Last active May 22, 2024 19:54
Fibonacci Sequence using Matrix Manipulations in CSharp (Console Project w/.NET 8)! https://dotnetfiddle.net/UvXEgY
using System;
using System.Numerics;
class Program {
static void Main() {
Console.Write("Enter the position of the Fibonacci sequence: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(
$"The {n}th number in the Fibonacci sequence is {Fibonacci(n)}");
}
@CodeByAidan
CodeByAidan / email-address.js
Last active May 22, 2024 17:22
JavaScript regular expression that matches a valid email address. Full explanation here + tests: https://regex101.com/library/AcdLjE?orderBy=RELEVANCE&search=email+validator+javascript
let emailRegex = /^(([^<>()[\]\\.,;:@"]+(\.[^<>()[\]\\.,;:@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
console.log(emailRegex.test('test@example.com')); // true
console.log(emailRegex.test('test.example.com')); // false
console.log(emailRegex.test('test@example')); // false
console.log(emailRegex.test('test@.com')); // false
console.log(emailRegex.test('test@exa_mple.com')); // false
console.log(emailRegex.test('test@exa-mple.com')); // true
console.log(emailRegex.test('test@exa.mple.co')); // true
@CodeByAidan
CodeByAidan / index.js
Created May 22, 2024 14:09
My intro w/JTypes! See JSFiddle to use with ease ( https://jsfiddle.net/CodeByAidan/raw1s8de/10/ )
var Person = $$(function($fName, $lName, $age) {
this.firstName = $fName;
this.lastName = $lName;
this._age = $age;
}, {
'public readonly firstName': '',
'public readonly lastName': '',
'protected _age': 0,
@CodeByAidan
CodeByAidan / explanation.md
Last active May 22, 2024 13:44
RGB to Hex Color Code function using binary operators in JavaScript! (WITH EXPLANATION!)

RGB colors are represented by three values (red, green, blue), each ranging from 0 to 255. Each of these values can be represented by 8 bits, which can be converted to a hexadecimal representation:

  0 => 0b00000000 (binary) => 0x00 (hexadecimal)
255 => 0b11111111 (binary) => 0xff (hexadecimal)

The RGB color is represented by a 24-bit sequence, with 8 bits for each color component.

@CodeByAidan
CodeByAidan / Capture.PNG
Last active May 22, 2024 13:31
RGB to Hex Color Code- Simple HTML website optimized using bitwise operators!
Capture.PNG
@CodeByAidan
CodeByAidan / Capture.PNG
Last active May 22, 2024 13:25
Hex Color Code to RGB - Simple HTML website optimized using bitwise operators!
Capture.PNG
@CodeByAidan
CodeByAidan / nn.py
Last active May 22, 2024 13:25
A simple neural network - example of a simple perceptron using a logistic (sigmoid) activation function for binary classification - in 12 lines of Python3.11 code
from numpy import array, dot, exp, random
training_set_inputs = array([[0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 1]])
training_set_outputs = array([[0, 1, 1, 0]]).T
rng = random.default_rng(1)
synaptic_weights = 2 * rng.random((3, 1)) - 1
for _ in range(10000):
output = 1 / (1 + exp((dot(-training_set_inputs, synaptic_weights))))
synaptic_weights += dot(training_set_inputs.T, (training_set_outputs - output) * output * (1 - output))
@CodeByAidan
CodeByAidan / most-typescript-thing-ive-wrote.ts
Created April 29, 2024 15:26
most typescript thing i've wrote, will update when things get worse
type Category = {
title: string;
items: Array<{ name: string }>;
};
type Config = {
categories: Record<string, Category>;
};
function isCategory(obj: unknown): obj is Category {
@CodeByAidan
CodeByAidan / EnumMetaExample.py
Last active April 24, 2024 17:14
An example using EnumMeta, with EASE!
>>> from enum import EnumMeta, Enum
>>> Color3 = EnumMeta('Color3', (Enum,), (_ := EnumMeta.__prepare__(
... 'Color3', (Enum,),)) and any(map(_.__setitem__, *(zip(*{
... 'RED': 1,
... 'GREEN': 2,
... 'BLUE': 3,
... }.items())))) or _
... )
>>> print(Color3(1)) # or without print(): <Color3.RED: 1>
Color3.RED