Skip to content

Instantly share code, notes, and snippets.

View pseudosavant's full-sized avatar

Paul Ellis pseudosavant

View GitHub Profile
@pseudosavant
pseudosavant / alternate-for.js
Created October 21, 2022 18:02
Simple JavaScript for loops
// Alternate for loop that is more of a functional style
// `fr` accepts two arguments.
// The first argument expects an Array (to get the length of it) or a number. Passing in an array is similar to `myArray.forEach()`.
// The second argument is a function with the signature `(currentIteration, totalIterations)`
const fr = (iterationsOrArray, fn) => {
if (typeof iterationsOrArray !== 'number'&& !Array.isArray(iterationsOrArray)) {
throw new TypeError('Invalid argument: expected an `Array` or `number` for the first argument');
}
let iterations = (Array.isArray(iterationsOrArray) ? iterationsOrArray.length : iterationsOrArray);

Roku devices can be easily controlled via an HTTP API. It is accessed by issuing a POST request to http://{device_ip}:8060/keypress/{command}.

[NOTE: it must be accessed by IP address only and not hostname due to how Roku handled addressing a DNS Rebinding vulenerability.][1]

Request URL Examples:

Available Commands:

@pseudosavant
pseudosavant / wifi-backup.bat
Created April 30, 2020 21:59
Batch files for backing up and restoring Windows wifi networks
@ECHO OFF
REM This will export all wifi profiles to the current folder. Each profile has its own XML file.
netsh wlan export profile key=clear
@pseudosavant
pseudosavant / special-chars.txt
Created April 3, 2020 15:48
Characters I regularly use but can't remember the keyboard shortcut for
_
±
;
:
@pseudosavant
pseudosavant / ChromiumEdge Protocol Handler Bypass.reg
Created March 25, 2020 18:51
Windows registry file for enabling the "always open these links in XYZ application" checkbox
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Edge]
"ExternalProtocolDialogShowAlwaysOpenCheckbox"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome]
"ExternalProtocolDialogShowAlwaysOpenCheckbox"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Chromium]
"ExternalProtocolDialogShowAlwaysOpenCheckbox"=dword:00000001
@pseudosavant
pseudosavant / chromiumSearchProviders.md
Last active March 18, 2024 18:06
Extra Search Providers for Chrome/Edge (Chromium)

This is a list of OpenSearch providers that can be used with most Chromium-based browsers. Go to Chrome/Edge Settings (chrome://settings/searchEngines) to add them so you can quick search from the URL bar.

@pseudosavant
pseudosavant / canvasToDataUrl.js
Last active April 19, 2021 22:28
async method for creating a data URL from a canvas
function canvasToDataURL(canvas, type='image/webp', option=0.1) {
const promise = new Promise((resolve) => {
requestAnimationFrame(() => resolve(canvas.toDataURL(type, option)));
});
return promise;
}
/*
Examples:
@pseudosavant
pseudosavant / canvasToObjectUrl.js
Last active November 19, 2023 17:14
async method for creating an object URL from a canvas
const canvasToBlobUrl = (() => {
const canvasToBlobURL = (canvas, type='image/webp', option=0.1) => {
const promise = new Promise(async (resolve) => {
await rAF();
const blob = await canvasToBlob(canvas);
resolve(URL.createObjectURL(blob, type, option));
});
return promise;
}
@pseudosavant
pseudosavant / camelize.js
Created October 17, 2019 18:02
Convert strings or object keys from underscore_naming to camelCaseNaming. Example here: https://glitch.com/edit/#!/camelize
function camelize(s) {
return s.replace(/(?:-|_)([a-z])/g, (c) => c[1].toUpperCase());
}
function camelizeObjectKeys(o) {
const entries = Object.entries(o);
const output = {};
entries.forEach(([key, value]) => output[camelize(key)] = value);
@pseudosavant
pseudosavant / throttle.js
Created October 8, 2019 18:40
Really basic throttling function that returns a throttled function wrapped around the provided function
function throttle(fn, duration) {
var t;
return function(...args) {
clearTimeout(t);
t = setTimeout(fn.bind(null, ...args), duration);
}
};