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
#include <iostream>
#include <array>
#include <utility>
#include <vector>
using ll = long long;
using pll = std::pair<ll, ll>;
const int maxN = 3005;
struct Line {
@CodeByAidan
CodeByAidan / main.cpp
Created May 28, 2024 20:03
example of a C++ class with a predecessor (base class), a main function, and usage of the numeric library’s std::accumulate function to sum an array of numbers (highly optimized, sorry)
#include <iostream>
#include <numeric>
#include <vector>
class Predecessor {
protected:
int value;
public:
inline Predecessor(int val) : value{val} {}
@CodeByAidan
CodeByAidan / Powershell-Version-Finder.ps1
Created May 28, 2024 14:22
Finds the version of PowerShell in a simple one-liner.
$PSVersionTable.PSVersion.ToString() # "5.1"
# You can also just use $PSVersionTable.PSVersion or simply $PSVersionTable
@CodeByAidan
CodeByAidan / Public-IP-Address-Finder.ps1
Created May 27, 2024 22:33
One-Liner Find Public IP Address via Powershell!
Invoke-RestMethod -Uri 'http://ipinfo.io/ip'
@CodeByAidan
CodeByAidan / demo1.ec
Last active May 24, 2024 15:07
`CLOSE` demo using Informix ESQL/C
#include <stdio.h>
EXEC SQL define FNAME_LEN 15;
EXEC SQL define LNAME_LEN 15;
int main() {
EXEC SQL BEGIN DECLARE SECTION;
char fname[FNAME_LEN + 1];
char lname[LNAME_LEN + 1];
EXEC SQL END DECLARE SECTION;
@CodeByAidan
CodeByAidan / Fast-Range.py
Last active May 24, 2024 00:14
My personal take on the classic range() (or xrange()) function in Python3
class Range:
def __init__(self, start, stop=None, step=1, /):
if stop is None:
start, stop = 0, start
self.start, self.stop, self.step = start, stop, step
if step < 0:
lo, hi, step = stop, start, -step
else:
lo, hi = start, stop
self.length = 0 if lo > hi else ((hi - lo - 1) // step) + 1
@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,