Skip to content

Instantly share code, notes, and snippets.

View petergi's full-sized avatar
💭
Just Busy Living On The Side Of A Square

Peter Giannopoulos petergi

💭
Just Busy Living On The Side Of A Square
View GitHub Profile
@petergi
petergi / Check for Superset in Javascript.js
Last active December 27, 2023 22:28
Checks if the first iterable is a superset of the second one, excluding duplicate values.
/**
* Checks if one set is a super set of another set.
*
* @param {Array} a - The first set.
* @param {Array} b - The second set.
* @return {boolean} Returns true if the first set is a super set of the second set, otherwise returns false.
*/
function superSet(a, b) {
const sA = new Set(a)
const sB = new Set(b)
@petergi
petergi / Remove Accents - SQL.sql
Created December 27, 2023 20:09
Only ever tested in MS SQLServer.
CREATE FUNCTION replaceAccentChar (@source as varchar(255))
RETURNS varchar(255) AS
BEGIN
declare @charList as varchar(20)
declare @temp as varchar(255)
declare @t asint
set @temp = @source
set @charList = 'aeioucn'
@petergi
petergi / Swift 5 Cheatsheet.md
Created December 27, 2023 20:03
Learn you some Swift. Hmm would that make you a "Swiftie" ?
@petergi
petergi / Swift Basics Cheatsheet.md
Created December 27, 2023 20:00
Strict Minimum to get started with

Examples

Classes

class MyClass : OptionalSuperClass, OptionalProtocol {
    var myProperty: String
@petergi
petergi / Asciimojis Cheatsheet.md
Created December 27, 2023 16:02
Flip a table or shrug, in ASCII !
ʘ‿ʘ (`·ω·´) ( ͡° ͜ʖ ͡°)
Innocent face feel perky 4chan emoticon
ಠ_ಠ (╬ ಠ益ಠ) ಥ_ಥ
Reddit disapproval face angry face crying face
(╯°□°)╯︵ ┻━┻ ☜(⌒▽⌒)☞ ᕙ(⇀‸↼‶)ᕗ
Table Flip / Flipping Table excited flexing
@petergi
petergi / Standard deviation in JavaScript.js
Last active January 29, 2024 23:22
Calculates the standard deviation of an array of numbers
/**
* Calculates the standard deviation of an array of numbers.
*
* @param {Array} arr - The array of numbers.
* @param {Boolean} usePopulation - Optional. If true, the function uses the population standard deviation formula. Default is false, which uses the sample standard deviation formula.
* @return {Number} - The standard deviation of the array.
*/
const standardDeviation = (arr, usePopulation = false) => {
const n = arr.length
let sum = 0
@petergi
petergi / Starts with substring in Javascript.js
Last active December 27, 2023 22:37
Checks if a given string starts with a substring of another string
// Changed the loop to start from the end of the word string and iterate backwards.
// This allows us to avoid unnecessary slicing operations.
//Used substring instead of slice since we only need to get the substring starting from i to the end.
/**
* Finds the longest substring of the word that is a prefix of the text.
*
* @param {string} text - The text to search for the substring.
* @param {string} word - The word to find the substring from.
* @return {string|undefined} The longest substring that is a prefix of the text, or undefined if no such substring exists.
@petergi
petergi / String to Words in Javascript.js
Last active December 27, 2023 22:31
Converts a given string into an array of words
// Replaced the split method with the match method, which uses a regular expression to split the string into an array of words.
// Also removed the filter(Boolean) call since the match method already returns an array with only the matched words.
/**
* Returns an array of all words in a given string that match a given pattern.
*
* @param {string} str - The input string to search for words.
* @param {RegExp} pattern - The pattern to match words against. Defaults to /[a-zA-Z-]+/g.
* @return {Array} - An array of words that match the given pattern.
*/
@petergi
petergi / Convert digits to roman numeral in Javascript.js
Last active December 27, 2023 22:19
Converts an integer to its roman numeral representation
/**
* Converts a given number to a Roman numeral representation.
*
* @param {number} num - The number to be converted.
* @return {string} The Roman numeral representation of the given number.
*/
function toRomanNumeral(num) {
const lookup = new Map([
[1000, "M"],
[900, "CM"],
@petergi
petergi / Vector Distance in Javascript.js
Last active December 27, 2023 22:12
Calculates the distance between two vectors
/**
* Calculates the distance between two vectors.
*
* @param {Array} x - The first vector.
* @param {Array} y - The second vector.
* @return {number} The distance between the two vectors.
*/
function vectorDistance(x, y) {
return Math.sqrt(x.reduce((acc, val, i) => acc + (val - y[i]) ** 2, 0))
}