Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

techsin techsin

🏠
Working from home
  • New York, NY
View GitHub Profile
@techsin
techsin / solution.js
Created May 16, 2021
create-target-array-in-the-given-order
View solution.js
/**
* @param {number[]} nums
* @param {number[]} index
* @return {number[]}
* https://leetcode.com/problems/create-target-array-in-the-given-order/submissions/
*/
function Node(val) {
this.val = val;
this.next = null;
@techsin
techsin / width.js
Created Apr 30, 2021
Dimensions in JavaScript
View width.js
console.log($0.offsetWidth)
console.log($0.clientWidth)
console.log($0.scrollWidth)
console.log($0.getBoundingClientRect().width)
console.log(getComputedStyle($0).width)
console.log($0.clientLeft)
console.log($0.offsetLeft)
console.log($0.scrollLeft)
console.log(innerWidth)
console.log(outerWidth)
View font.js
{
'color': css.color,
'font-family': css.fontFamily,
'font-size': css.fontSize,
'font-style': css.fontStyle,
'font-variant': css.fontVariant,
'font-weight': css.fontWeight,
'letter-spacing': css.letterSpacing,
'line-height': css.lineHeight,
'text-align':css.textAlign ,
@techsin
techsin / scopeclosure.js
Last active Feb 27, 2021
scope closure
View scopeclosure.js
a = ['a','b', 'c']
for (let i = 0; i < 3; i++) {
var c = a[i];
setTimeout(()=> console.log(c)); // c c c
}
//is same as, var is function scoped
var c;
a = ['a','b', 'c']
for (let i = 0; i < 3; i++) {
@techsin
techsin / cookie.js
Created Jan 29, 2021
cookie parser
View cookie.js
@techsin
techsin / sortEle.js
Created Oct 23, 2020
Sort Html Elements
View sortEle.js
// $container - css selector for nodes that need to be sorted
// $number - css selector for node with number
function sortElements($container, $number) {
const hash = new Map();
const list = Array.from(document.querySelectorAll($container));
for (let i = 0; i < list.length; i++) {
for (let j = i; j < list.length; j++) {
const element = list[i];
@techsin
techsin / worker.js
Last active Oct 18, 2020
Testing performance of service workers vs promises
View worker.js
function wrk() {
var blobURL = URL.createObjectURL(new Blob(['(',
function () {
for (let i = 0; i < 5000000000; i++) { } console.log(1000);
}.toString(),
')()'], { type: 'application/javascript' }));
const worker = new Worker(blobURL);
@techsin
techsin / cookie.js
Created Sep 10, 2020
Read and set cookie as a 3rd party
View cookie.js
@techsin
techsin / download_audio.js
Created Aug 13, 2020
download audio recording in sms google voice
View download_audio.js
document.querySelectorAll('audio').forEach((au) => {
const url = au.currentSrc;
fetch(url).then(r => r.blob()).then(obj => downloadAudio(obj));
})
function downloadAudio(blob) {
const ele = document.createElement('a');
let counter = 0;
downloadAudio = function (blob) {
@techsin
techsin / islands.js
Created Jun 12, 2020
find islands leetcode
View islands.js
var numIslands = function(grid) {
let islands = 0;
for (let i = 0; i < grid.length; i++) {
for (let j = 0; j < grid[i].length; j++) {
if (grid[i][j] == 1) {
markRecur(i, j, grid);
islands++;
}
}
}