Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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",
@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 / resize-window.js
Created January 26, 2019 22:27
Resize browser/electron/extension window based on content
function resizeWindow() {
const padding = 20 // title bar height without menu in electron
const heightDiff = (document.body.clientHeight - document.documentElement.clientHeight) + padding
window.resizeBy(0, heightDiff)
}
@Fraasi
Fraasi / github-repo-created-at-bookmarklet.js
Created February 18, 2019 11:21
Bookmarklet to get github repository creation time.
(function () {
if (window.location.host !== 'github.com') {
alert('Not a GitHub page.');
return;
}
if (window.location.pathname.split('/').length < 3) {
alert('Not in a repository page.');
return;
}
function formatBytes(a, b) { if (0 == a) return "0 Bytes"; var c = 1024, d = b || 2, e = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], f = Math.floor(Math.log(a) / Math.log(c)); return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f] }
@Fraasi
Fraasi / get-iframe-links.js
Last active April 26, 2019 14:02
Devtools snippet to easily get video links in certain video sites to copy paste to youtube-dl.
@Fraasi
Fraasi / checkChallenges.js
Created May 12, 2019 18:37
Little node script to check what coding train challenges have been ported to P5/Processing.
const path = require('path')
const fs = require('fs')
let folderCount = 0
let stdoutWidth = process.stdout.columns - 9
let startTime
const results = {}
function checkChallenges(startDir) {
startTime = new Date()
@Fraasi
Fraasi / npm-update-all
Last active November 28, 2021 12:33
small bash script to print out command to update all (dev)dependencies from package.json to @latest
#!/bin/bash
USAGE="Usage:
npm-update-all
-> prints all dependencies
-d
-> prints all devDependencies
from current dirs package.json
@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