Skip to content

Instantly share code, notes, and snippets.

@Richienb
Richienb / README.md
Created October 27, 2019 23:28
Interop exports

Exports for CJS and ES

@Richienb
Richienb / README.md
Created October 25, 2019 10:25
Finding the operation completion times per unit from given data

Assuming an operation was completed n times in t units of time, how many operations on average were completed every p units of time?

If 2 operations were completed in 15 seconds then in 60 seconds (1 minute)...

2:15
8:60 <- ratio 4x more

The final formula is:

@Richienb
Richienb / index.d.ts
Last active October 1, 2019 12:11
DevBed scoreboard typings
interface ObjectivePlayer {
[player: string]: number
}
interface Objective {
id: string,
name?: string,
display?: "list" | "sidebar" | "belowName",
players?: ObjectivePlayer
}
@Richienb
Richienb / listAll.ps1
Created July 26, 2019 11:59
List everything in a directory in powershell
Get-ChildItem . -filter "*" -Recurse | % {$_.fullname}
@Richienb
Richienb / cores.ts
Created June 23, 2019 01:01
Get core count
export var cores = (() => {
if (typeof process !== 'undefined' && process.release.name === 'node') {
return require('os').cpus().length;
} else if (typeof navigator !== 'undefined' && navigator.hardwareConcurrency !== 'undefined') {
return navigator.hardwareConcurrency
} else if (typeof window !== 'undefined') {
console.log("Please use https://github.com/oftn-oswg/core-estimator")
}
})()
@Richienb
Richienb / README.md
Created June 23, 2019 00:21
Light JQuery Alternative

Example usage

Instead of

document.querySelector("body").innerHTML

do

$("body").innerHTML
@Richienb
Richienb / lib.js
Created June 11, 2019 07:08
Auto SASS Compile
(() => {
const sass = new Sass();
const handleFiles = () => {
Array.from(document.querySelectorAll(`style[type="text/sass"], style[type="text/scss"]`)).map(val => {
sass.compile(val.innerHTML, {
indentedSyntax: val.getAttribute("type") === "text/sass"
}, ({
text
}) => val.innerHTML = text);
@Richienb
Richienb / bot.js
Last active August 24, 2019 05:19
Live Mathletics Bot
/* eslint-disable require-jsdoc */
(() => {
function injectScript(src) {
return new Promise((resolve, reject) => {
const script = document.createElement("script")
script.async = true
script.src = src
script.addEventListener("load", resolve)
script.addEventListener("error", () => reject(new Error("Error loading script.")))
script.addEventListener("abort", () => reject(new Error("Script loading aborted.")))
@Richienb
Richienb / lib.js
Created May 16, 2019 14:07
document.designMode shortcut activator
const designMode = val => document.designMode = val === true ? "on" : "off"
@Richienb
Richienb / api.js
Last active July 28, 2019 06:58
Google Translate API
const sourceLang = "en"
const targetLang = "id"
const sourceText = "Hello"
const translate = (sourceLang, targetLang, sourceText) => new Promise((resolve, reject) => {
$.getJSON(`https://translate.googleapis.com/translate_a/single`, {
client: "gtx",
sl: sourceLang,
tl: targetLang,
dt: "t",