Skip to content

Instantly share code, notes, and snippets.

View Mathspy's full-sized avatar
💭
Working on few big surprises! 🌸

Mathspy

💭
Working on few big surprises! 🌸
View GitHub Profile
@Mathspy
Mathspy / all_primes_iter.rs
Last active August 21, 2019 21:48
All the prime numbers your heart desires in Rust!
// Use this if you want [2, 3, 5.....]
use std::collections::HashMap;
/// This is a prime number generator based on [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)
/// that can be _trivially_ improved by switching to [Sieve of Atkin](https://en.wikipedia.org/wiki/Sieve_of_Atkin) for extra speed
struct PrimeIterator {
current: u64,
composite_to_primes: HashMap<u64, Vec<u64>>,
}
@Mathspy
Mathspy / discord-workaround-puppeteer-fail.js
Created June 8, 2019 15:01
A Discord login workaround that failed but contains many valuable knowledge I guess
const puppeteer = require("puppeteer");
// This works around Discord's security measurements
// to set values on localStorage before we go to discord.com/login
const setDomainLocalStorage = async (browser, url, values) => {
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on("request", r => {
r.respond({
status: 200,
@Mathspy
Mathspy / spotify-playlist-saver.js
Created June 24, 2018 22:08
Turns a Spotify playlist into an array for copying
Array.from(document.querySelectorAll(".track-name-wrapper")).map(node => {
let temp = {}
temp.name = node.firstElementChild.textContent
let artistAlbum = node.lastElementChild.querySelectorAll("a")
temp.artist = {name: artistAlbum[0].textContent, link: artistAlbum[0].href}
temp.album = {name: artistAlbum[1].textContent, link: artistAlbum[1].href}
return temp
})
@Mathspy
Mathspy / partial-youtube-playlist-time-calc.js
Last active June 29, 2018 21:27
Calculates the time remaining until one finishes a playlist if they have been watching videos linearly in it
Array.from(document.querySelectorAll("ytd-playlist-video-renderer"))
.slice(121) //Changes this number to the number of the last video you watched
.map(x => x.querySelector(".ytd-thumbnail-overlay-time-status-renderer").textContent.trim())
.reduce((acc, video) => {
let [h, m, s] = video.split(":").map(x => parseInt(x));
if (!s) {s = m; m = h; h = 0;}
acc[0] += h;
acc[1] += m;
acc[2] += s;
return acc;