Skip to content

Instantly share code, notes, and snippets.

@Fraasi
Fraasi / myMap.js
Created October 9, 2018 09:06
Rewriting map function
Array.prototype.myMap = function (callback, thisArg) {
if (!thisArg) thisArg = this
if (!Array.isArray(thisArg)) throw new Error('Not an Array')
if (typeof callback !== 'function') throw new Error('Callback must be a function')
const newArray = []
for (let i = 0; i < thisArg.length; i++) {
newArray.push(callback(thisArg[i], i, thisArg))
}
return newArray
}
@Fraasi
Fraasi / reOrganizeQuotes.js
Created April 30, 2018 19:37
reOrganizeQuotes from { quote: author} to { author: [quote] }
function reOrganizeQuotes(quotes) {
// from { quote: author}
// to { author: [quote] }
const newObj = {}
Object.entries(quotes).forEach(([key, value]) => {
newObj[value] === undefined ?
newObj[value] = [key] :
newObj[value].push(key)
@Fraasi
Fraasi / changePlaylistLinks.js
Last active March 9, 2022 20:58
Tampermonkey script to change youtube playlist title link to playlist page instead of first item in playlist & prevent autoplays
@Fraasi
Fraasi / bottimer.js
Created September 29, 2017 15:20
Simple timer to run my bot once everyday
function msToTime(duration) {
// from https://stackoverflow.com/questions/19700283/how-to-convert-time-milliseconds-to-hours-min-sec-format-in-javascript
var milliseconds = parseInt((duration%1000)/100)
, seconds = parseInt((duration/1000)%60)
, minutes = parseInt((duration/(1000*60))%60)
, hours = parseInt((duration/(1000*60*60))%24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
@Fraasi
Fraasi / codepen_download.js
Last active April 30, 2018 19:47
Node script to download all your codepen pens as zip file
// couldn't get scraper to get the data so I just used console
// easy to tweak for your own codepen page
// get data from console in 'https://codepen.io/Fraasi/pens/public/?grid_type=list';
// var aNodes = document.querySelectorAll('tr > td.title a')
// var pens = {};
// aNodes.forEach( a => { pens[a.innerText] = a.href; })
// copy(pens)
var pens = {
"D3 zoomable-draggable datapoint map":"https://codepen.io/Fraasi/pen/zwgdyV",