Skip to content

Instantly share code, notes, and snippets.

@Fraasi
Fraasi / npm-update-all
Last active Nov 28, 2021
small bash script to print out command to update all (dev)dependencies from package.json to @latest
View npm-update-all
#!/bin/bash
USAGE="Usage:
npm-update-all
-> prints all dependencies
-d
-> prints all devDependencies
from current dirs package.json
@Fraasi
Fraasi / wttr.sh
Last active Sep 2, 2021
simple wrapper function around http://wttr.io to get sensible defaults
View wttr.sh
#!/usr/bin/env bash
# simple wrapper function around http://wttr.io to get sensible defaults
# easily modified by changing the defaults and/or last parameters in the url
function wttr() {
USAGE="
Usage: wttr [OPTIONS]
Options:
-c <city> city name, double words with +, eg. new+york
@Fraasi
Fraasi / cowsay-random-quote.sh
Created Oct 26, 2019
Curl random quote and pass it to cowsay
View cowsay-random-quote.sh
#!/bin/bash
declare -a MODES
MODES=("b" "d" "g" "p" "s" "t" "w" "y")
declare -a COWS
COWS=("tableflip" "aperture-blank" "beavis.zen" "bees" "biohazard" "box" "broken-heart" "cat" "cat2" "clippy" "cowfee" "cube" "default" "dragon" "hedgehog" "kilroy" "kosh" "nyan" "owl" "psychiatrichelp" "psychiatrichelp2" "shrug" "squirrel" "tux")
MODES_LENGTH=${#MODES[@]}
MODES_INDEX=$(($RANDOM % $MODES_LENGTH))
@Fraasi
Fraasi / checkChallenges.js
Created May 12, 2019
Little node script to check what coding train challenges have been ported to P5/Processing.
View checkChallenges.js
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 / github-repo-created-at-bookmarklet.js
Created Feb 18, 2019
Bookmarklet to get github repository creation time.
View github-repo-created-at-bookmarklet.js
(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 / resize-window.js
Created Jan 26, 2019
Resize browser/electron/extension window based on content
View resize-window.js
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 / get-iframe-links.js
Last active Apr 26, 2019
Devtools snippet to easily get video links in certain video sites to copy paste to youtube-dl.
View get-iframe-links.js
@Fraasi
Fraasi / myMap.js
Created Oct 9, 2018
Rewriting map function
View myMap.js
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 Apr 30, 2018
reOrganizeQuotes from { quote: author} to { author: [quote] }
View reOrganizeQuotes.js
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 Feb 22, 2018
Tampermonkey script to change youtube playlist title link to playlist page instead of first item in playlist & prevent autoplays
View changePlaylistLinks.js