Skip to content

Instantly share code, notes, and snippets.

View codergautam's full-sized avatar

Coder Gautam codergautam

View GitHub Profile
@codergautam
codergautam / streetViewExists.js
Created June 6, 2024 16:47
Check if a Google street view exists at a specific latitude and longitude - NodeJS No api key
async function hasStreetViewImage(lat, long, radius) {
const url = `https://maps.googleapis.com/maps/api/js/GeoPhotoService.SingleImageSearch?pb=!1m5!1sapiv3!5sUS!11m2!1m1!1b0!2m4!1m2!3d${lat}!4d${long}!2d${radius}!3m18!2m2!1sen!2sUS!9m1!1e2!11m12!1m3!1e2!2b1!3e2!1m3!1e3!2b1!3e2!1m3!1e10!2b1!3e2!4m6!1e1!1e2!1e3!1e4!1e8!1e6&callback=_xdc_._2kz7bz`;
const response = await fetch(url, {
headers: {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/59.0.3071.109 Chrome/59.0.3071.109 Safari/537.36'
}
});
const text = await response.text();
@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));