Skip to content

Instantly share code, notes, and snippets.

View luan0ap's full-sized avatar
👁️‍🗨️
Looking for a job

Luan AP luan0ap

👁️‍🗨️
Looking for a job
View GitHub Profile
@luan0ap
luan0ap / addDay.js
Created March 10, 2024 23:36
Add days to Date
const addDay = (days = 1) => {
const date = new Date()
date.setDate(date.getDate() + days)
return date
}
@luan0ap
luan0ap / waitForElement.ts
Created March 14, 2023 20:53
Wait for an element be on DOM
function waitForElm <T extends Element> (selector: string): Promise<T | null> {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector) as T | null);
}
const observer = new MutationObserver(() => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector) as T | null);
This file has been truncated, but you can view the full file.
{"words":[{"word":"a","id":1},{"word":"a-","id":2},{"word":"a2 level","id":3},{"word":"a3","id":4},{"word":"a4","id":5},{"word":"a5","id":6},{"word":"aaa","id":7},{"word":"aaas","id":8},{"word":"aad","id":9},{"word":"aadhaar","id":10},{"word":"aam","id":11},{"word":"a — and a half","id":12},{"word":"aapa","id":13},{"word":"aardwolf","id":14},{"word":"aargh","id":15},{"word":"aaronic","id":16},{"word":"aaron's beard","id":17},{"word":"aaron's rod","id":18},{"word":"aarp","id":19},{"word":"a'asia","id":20},{"word":"aasvoel","id":21},{"word":"aau","id":22},{"word":"aaup","id":23},{"word":"ab","id":24},{"word":"ab-","id":25},{"word":"aba","id":26},{"word":"a bad apple","id":27},{"word":"a bad lot","id":28},{"word":"a bad penny always turns up","id":29},{"word":"a bad taste in someone's mouth","id":30},{"word":"a bad workman always blames his tools","id":31},{"word":"a bag of bones","id":32},{"word":"a bag of tricks","id":33},{"word":"abaht","id":34},{"word":"abandon","id":35},{"word":"abandoned","id":36},{"word":
@luan0ap
luan0ap / png2jpg.js
Created September 14, 2022 19:06
Image converter PNG to JPG
const createElement = (HTMLElementName, { ...HTMLAttributes } = {}) => {
const $el = document.createElement(HTMLElementName)
for (const key in HTMLAttributes) {
$el.setAttribute(key, HTMLAttributes[key])
}
return $el
}
@luan0ap
luan0ap / ObservePattern.js
Last active August 11, 2022 22:17
My Observe Pattern implementation using classes
class Observer {
#id
#container
constructor() {
this.#id = 0
this.#container = {}
}
subscribe(topic, f) {
@luan0ap
luan0ap / Observable.js
Created July 19, 2022 22:27
Observable classes practical examples -- case of study
class Observable {
constructor(observer){
this._observer = observer;
}
subscribe(observer) {
return this._observer(observer)
}
}
@luan0ap
luan0ap / rps.js
Created July 7, 2022 10:45
Rock, paper and scissors. Memoizer solution
const memoizer = (fn, initialState = null) => {
const _cache = initialState || {}
return (...params) => {
const _stringified = JSON.stringify(params)
if (_cache[_stringified] === undefined) {
const result = fn(...params)
_cache[_stringified] = result
@luan0ap
luan0ap / sortVersions.js
Last active June 21, 2022 21:28
Sort version numbers
function sortVersions (versions = []) {
const sortByVersionNumber = (vA, vB) => {
const versionsA = vA.split('.')
const versionsB = vB.split('.')
const compareVersionNumbers = (index = 0, lastResult = 0) => {
const versionNumberA = Number(versionsA[index]) || 0
const versionNumberB = Number(versionsB[index]) || 0
if (lastResult === 0) {
@luan0ap
luan0ap / promiseAll.js
Last active October 18, 2022 11:37
My polyfill implementation of Promise.all
function promiseAll (promises = []) {
return new Promise((resolve, reject) => {
let result = []
let resolvedPromisesCount = 0
const handle = (index, data) => {
if (data instanceof Error) {
return reject(data)
}
@luan0ap
luan0ap / filledEmptyArray.js
Last active May 31, 2022 18:51
Create a new array filled with zeros
/**
* Fill an array with zeros
* @param n - expected array length
* @returns Array
*/
const filledEmptyArray = (n) => {
const zerosArray = new Array(n)
for (let i=0; i<n; ++i) {
zerosArray[i] = 0