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 / 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
@aamiaa
aamiaa / CompleteDiscordQuest.md
Last active June 2, 2024 19:11
Complete Recent Discord Quest

Complete Recent Discord Quest

Note

This no longer works in browser!

This no longer works if you're alone in vc! Somebody else has to join you!

Warning

There are now two quest types ("stream" and "play")! Pay attention to the instructions!

@CodeByAidan
CodeByAidan / wordwrap.py
Last active April 15, 2024 20:19
Wordwrap text to a specified line length. Takes a string or file-like object as input and returns the wrapped text.
"""
Wordwrap text to a specified line length.
Takes a string or file-like object as input and returns the wrapped text.
"""
import re
from typing import IO, Union
def wordwrap(text_or_file: Union[str, IO], max_line_length: int = 80) -> str: