Skip to content

Instantly share code, notes, and snippets.

View codergautam's full-sized avatar

Coder Gautam codergautam

View GitHub Profile
@codergautam
codergautam / fetcher.js
Created January 8, 2023 19:15
One-line Fetch API
const fetcher = (...args) => fetch(...args).then((res) => res.json())
@codergautam
codergautam / msToTime.js
Created May 16, 2022 19:58
Millisecond to Human Readable time converter
function msToTime(duration) {
const portions = [];
const msInDay = 1000 * 60 * 60 * 24;
const days = Math.trunc(duration / msInDay);
if (days > 0) {
portions.push(days + 'd');
duration = duration - (days * msInDay);
}
const msInHour = 1000 * 60 * 60;
@codergautam
codergautam / wordlesolver.js
Last active February 22, 2022 22:28
A simple wordle solver
//go into wordle (https://www.powerlanguage.co.uk/wordle/)
//open js console (right click -> inspect -> console in top bar)
//paste the below code
//watch your wordle get solved! (100% GUARANTEED TO SOLVE, AT MOST 6 TRIES)
var guesses = eval(/var Ma=(\[.*"zymic"\])/.exec(await fetch(`main.${window.wordle.hash}.js`).then(r => r.text()))[1]); var answers = eval(/var Ma=(\[.*"shave"\])/.exec(await fetch(`main.${window.wordle.hash}.js`).then(r => r.text()))[1]);var all=[...guesses,...answers];const alphabet="abcdefghijklmnopqrstuvwxyz".split(""),matchesFilters=(t,e)=>t.filter((t=>{let r=!0;for(let o=0;o<e.length;o+=1){const{colour:s,position:n,letter:l}=e[o];if("black"===s&&t.includes(l)){r=!1;break}if("green"===s&&t[n]!==l){r=!1;break}if("yellow"===s&&(!t.includes(l)||t[n]===l)){r=!1;break}}return r})),colours=["green","yellow","black"],calculateLetterColor=(t,e,r,o)=>{const s=matchesFilters(t,[{colour:o,position:r,letter:e}]);return{p:1*s.length/t.length,list:s}},createObject=(t,e,r)=>{if(r>4)return e;{colours
@codergautam
codergautam / transpose.js
Created January 14, 2022 16:05
Transpose an array!
const transpose = (m)=>m[0].map((_, i) => m.map(r => r[i]));
@codergautam
codergautam / unsub.js
Created December 20, 2021 14:55
Unsubscribe from everyone on YouTube!
// STEPS TO USE:
// 1. Go to https://www.youtube.com/feed/channels
// 2. Right click > Inspect Element > Console
// 3. Paste script
// 4. Press enter
var count = document.querySelectorAll("ytd-channel-renderer:not(.ytd-item-section-renderer)").length;
tick();
function tick() {
@codergautam
codergautam / clamp.js
Created October 24, 2021 16:40
A simple js clamp function
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
@codergautam
codergautam / conversion.js
Created October 24, 2021 15:36
Easily convert between to types of numbers!
/*
num = val
newNum = ?
convert(2, 10, 4) //20
convert(5, 10, 50) //100
*/
const convert = (num, val, newNum) => (newNum * val) / num
@codergautam
codergautam / betterAngleLerp.js
Last active October 19, 2022 02:37 — forked from shaunlebron/angleLerp.js
The best way to interpolate 2D angles
//note: degrees only
const lerp = (start,end,amt) => start+(end-start)*amt
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
const repeat = (t, m) => clamp(t - Math.floor(t / m) * m, 0, m);
function lerpTheta(a, b, t) {
const dt = repeat(b - a, 360);
return lerp(a, a + (dt > 180 ? dt - 360 : dt), t);
}
@codergautam
codergautam / getRandomInteger.js
Last active October 24, 2021 15:38
A simple function to get a random integer from a range in JavaScript.
const getRandomInt = (min, max) => min + Math.floor(Math.random() * (max - min + 1));
@codergautam
codergautam / viewportDimensions.js
Created October 8, 2021 21:55
Get the width and height of the viewport
function viewport()
{
var e = window
, a = 'inner';
if ( !( 'innerWidth' in window ) )
{
a = 'client';
e = document.documentElement || document.body;
}
return { width : e[ a+'Width' ] , height : e[ a+'Height' ] }