Skip to content

Instantly share code, notes, and snippets.

View OrderAndCh4oS's full-sized avatar
🕰️
Writing code

Sean Cooper OrderAndCh4oS

🕰️
Writing code
View GitHub Profile
@OrderAndCh4oS
OrderAndCh4oS / date-functions.ts
Created September 26, 2024 00:43
Date Functions
const randomInt = (max: number, min: number = 0): number => {
return Math.floor(Math.random() * (max - min)) + min;
};
export const getRandomTimeToday = () => {
const date = new Date();
date.setHours(randomInt(24));
date.setMinutes(randomInt(60));
date.setSeconds(randomInt(60));
date.setMilliseconds(randomInt(1000));
@OrderAndCh4oS
OrderAndCh4oS / count-occurrences.ts
Created September 26, 2024 00:27
Count Occurrences
const str = 'onè, twö, three and, ö four. *%#@ four and three!!! 😍 💕, 👍👌\nblah blah blah hyphenated-word thing–endash and an—emdash a/slash some!!thing 10:00am';
const countOccurrences = (str: string) =>
Object.entries<number>(
str
.replace(/[\n\r–—/]+/g, ' ')
.replace(/[^\p{L}\p{N}\p{M}\p{Zs}\p{So}\s-]+/ug, '')
.replace(/\s\s+/g, ' ')
.split(' ')
.reduce((obj: any, word: string) => (
@OrderAndCh4oS
OrderAndCh4oS / validation.ts
Created September 26, 2024 00:21
Validation
interface IValidationSchema {
[property: string]: (IValidateProperty | IValidateArray | IValidateObject)
}
interface IValidateArray {
required: boolean
type: 'array',
schema: IValidationSchema
}
@OrderAndCh4oS
OrderAndCh4oS / simple-query-parser.ts
Created September 25, 2024 23:57
simple query parser
const one = '{one}';
const two = '{two}';
const three = '{three}';
const oneAndTwoAndThree = '{one} + {two} + {three}';
const oneNotTwo = '{one} - {two}';
const oneAndTwoNotThree = '{one} + {two} - {three}';
const oneOrTwoOrThree = '{one} | {two} | {three}';
const quoteAnalysisParser = (query: string, values: string[]) => {
@OrderAndCh4oS
OrderAndCh4oS / word-boundaries.js
Created September 25, 2024 23:56
Word Boundaries
const text = `Þig, sem í fjarlægð fjöllin bak við dvelur
og fagrar vonir tengdir líf mitt við,
minn hugur þráir, hjartað ákaft saknar,
er horfnum—stundum ljúfum dvel ég hjá.
Heyrirðu ei hvern hjartað kallar á?
Heyrirðu ei storm er kveðju mína ber?
Þú fagra minning eftir skildir eina,
sem aldrei gleymist, meðan lífs ég er.`
const enDashEmDashOrForwardSlash = /[\u2013\u2014/]/g;
@OrderAndCh4oS
OrderAndCh4oS / slugify.ts
Created September 25, 2024 23:55
Slugify
const slugify = (str: string) => str
.normalize("NFD")
.replace(/[^\w\s]/g, '')
.trim()
.replace(/\s+/g, '-')
.toLowerCase()
;
console.log(slugify(' Blhä+ LFgha+áaf. asfaASF aFsfsf. '));
@OrderAndCh4oS
OrderAndCh4oS / is-object.ts
Created September 25, 2024 23:37
isObject
const isObject = (obj?: unknown): obj is object =>
Boolean(obj) && (obj?.constructor === Object);
console.log(isObject()); // false
console.log(isObject(null)); // false
console.log(isObject(true)); // false
console.log(isObject(1)); // false
console.log(isObject('str')); // false
console.log(isObject([])); // false
console.log(isObject(new Date)); // false
@OrderAndCh4oS
OrderAndCh4oS / fetch-audio-src
Created November 10, 2021 22:57
Fetch audio src
fetchSrc = async(url, mimeType) => {
const audioResponse = await fetch(url, {
method: 'get',
headers: {'Accept': mimeType},
});
const blob = await audioResponse.blob();
audio.mimeType = mimeType;
audio.preload = 'metadata';
audio.src = URL.createObjectURL(blob);
};
I am attesting that this GitHub handle OrderAndCh4oS is linked to the Tezos account tz1iM7PB4brTmkbTUccsrXYjepSQ6ext7KYu for tzprofiles
sig:edsigtdsPStL8c1MGmAVCPn3PnEypvFLww1V4GGxZjvAcGE9vrKgfpTKuDLSZqBqmf1oDsY7jvioNgxq7BXvrKR3bLSwnfnqcvn
@OrderAndCh4oS
OrderAndCh4oS / get-burns.js
Created August 9, 2021 16:20
get-burns.js
import fetch from 'node-fetch';
import ObjectsToCsv from 'objects-to-csv';
import path from 'path';
const getBurns = async(objktId) => {
const response = await fetch(
`https://api.tzkt.io/v1/operations/transactions?target=KT1RJ6PbjHpwc3M5rw5s2Nbmefwbuwbdxton&entrypoint=transfer&status=applied&limit=10000&parameter.[0].txs.[0].token_id=${objktId}&parameter.[0].txs.[0].to_=tz1burnburnburnburnburnburnburjAYjjX&select=id,hash,parameter`);
const data = await response.json();
let i = 1;
return data.reduce((arr, d) => {