This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import puppeteer, { Browser, ElementHandle, Page } from "puppeteer"; | |
export async function getPageHandler(url, openPage, delayMillis, headless = false) { | |
const openBrowser = await puppeteer.launch({ | |
headless, | |
}); | |
let page; | |
if(!openPage){ | |
page = await openBrowser.newPage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Node(value, parent = null){ | |
this.value = value | |
this.left = null | |
this.right = null | |
this.parent = parent | |
} | |
// create tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Node(value, parent = null){ | |
this.value = value | |
this.left = null | |
this.right = null | |
this.parent = parent | |
} | |
// create tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Node(value, parent = null){ | |
this.value = value | |
this.left = null | |
this.right = null | |
this.parent = parent | |
} | |
// create tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FenwickTree{ | |
constructor(array){ | |
this.source = [...array] | |
this.length = this.source.length; | |
this.fenwick = new Array(array.length+1).fill(0) | |
this.build(); | |
} | |
build(){ | |
for(let i = 0; i < this.length; i++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function animate({ timing, duration, draw }){ | |
return new Promise((resolve, reject) => { | |
const start = performance.now(); | |
function animation(time){ | |
const progress = Math.min((time-start)/duration, 1); | |
const visualProgress = timing ? timing(progress): progress; | |
draw(visualProgress); | |
if(progress < 1) requestAnimationFrame(animation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Calendar { | |
constructor(selector){ | |
this.MONTHS= ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] | |
this.root = document.querySelector(selector); | |
this.activeDateTime = new Date(); | |
this.render(); | |
this.attachEvents(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compress(arr): | |
arr.sort(); | |
compress_map = {} | |
val = 1 | |
for el in arr: | |
if el not in compress_map: | |
compress_map[el] = val | |
val += 1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for singly-linked list. | |
# class ListNode: | |
# def __init__(self, val=0, next=None): | |
# self.val = val | |
# self.next = next | |
class Solution: | |
def findMiddle(self, head): | |
slow, fast = head, head | |
while fast and fast.next and fast.next.next: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def minSwaps(arr, N): | |
newArr = [ (arr[i], i) for i in range(len(arr)) ] | |
newArr.sort() | |
ans = 0 | |
for i in range(len(newArr)): | |
j = newArr[i][1] | |
while newArr[i][1] != newArr[j][1]: |
NewerOlder