Skip to content

Instantly share code, notes, and snippets.

Avatar
💯
Product Designer Interactive Storyteller

Scott C. Krause neodigm

💯
Product Designer Interactive Storyteller
View GitHub Profile
View overload_xhr.js
var RealXMLHttpRequest = window.XMLHttpRequest;
window.XMLHttpRequest = function(){
var ajax = new RealXMLHttpRequest();
var realOpen = ajax.open;
// steal the OPEN method | Has to be open to send header
ajax.open = function(method, url){
realOpen.apply(ajax, arguments);
@neodigm
neodigm / music-ad-blocker.js
Last active Apr 15, 2021
Automatically mute the Music player when Ads are playing and unmute when they are done (in Chrome).
View music-ad-blocker.js
let spotADify = ( (_d, _q, _t) => {
let eS = _d.querySelector( _q ), bS = true;
if( eS ){ // 🏖️ Play your Jams! 🎶
bS = ( eS.getAttribute("aria-label") == "Mute" );
setInterval( () => {spotADify.tick();}, _t);
return {
"tick": () => {
if((_d.title.indexOf("Adve") != -1) || (_d.title.indexOf("Spoti") != -1)){
if( bS ){ eS.click(); bS=!true; }
}else{
View kilo_format.js
export const kFormat = (num) =>
Math.abs(num) > 999
? Math.sign(num) * (Math.abs(num) / 1000).toFixed(1) + 'k'
: Math.sign(num) * Math.abs(num)
View getReadableTS.js
getReadableTS(){. //. Human readable timestamp for automatic file naming
const date = new Date();
const year = date.getFullYear();
const month = `${date.getMonth() + 1}`.padStart(2, '0');
const day =`${date.getDate()}`.padStart(2, '0');
const hour = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
return `${year}${month}${day}_${hour}${minutes}${seconds}`
}
@neodigm
neodigm / snackbar_toast.js
Last active Mar 25, 2021
World famous Snackbar Toast Component, now with automagic debounce!
View snackbar_toast.js
let snck = ( (_d, eID) => {// Material Design
const _nTimeout = 5400; // Toast 🍞 Snackbar
let _eSb = _d.getElementById(eID), // Toast Element
_eSbText = _eSb.querySelectorAll("P")[0],
_aQ = [];
const _fClose = function () {
_aQ.shift();
_eSb.classList.remove("snackbar__cont--show");
_eSb.classList.add("snackbar__cont--hide");
if (_aQ.length != 0) {
View generate_csv_and_download.js
// Desc: Produce CSV with client-side JS. Contruct Blob and Download as CSV file
let nativeCSV = ( ( _d )=>{
let oCnt, jnCSV, sCSV, blCSV, elCSV; // config, json, array, blob, and element
let retObj = {
"init": ( _oCnt )=>{
oCnt = _oCnt;
if( oCnt.fileName.indexOf("####") !== -1) {
oCnt.fileName = oCnt.fileName.replace("####", Date.now() );}
jnCSV = sCSV = blCSV = elCSV = "";
return retObj;
@neodigm
neodigm / cryptorange.js
Created Mar 17, 2021
unbiased dice roll in browser
View cryptorange.js
function getCryptoRange(min, max) {
const range = max - min + 1
const mBits = Math.ceil(Math.log2(range))
const mBytes = Math.ceil(mBits / 8)
const nAllowed = Math.floor((256 ** mBytes) / range) * range
const arBytes = new Uint8Array(mBytes)
let value
do {
crypto.getRandomValues(arBytes)
value = arBytes.reduce((acc, x, n) => acc + x * 256 ** n, 0)
View web_crypto_api_aes_base64.js
var winEcrypt = ( ( _w )=>{
let oKey = {};
return {
"base64ToArrayBuffer": function(base64) {
var binary_string = _w.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
@neodigm
neodigm / isPalimdrome.js
Last active Mar 6, 2021
Palindrome test 🐱
View isPalimdrome.js
// Is TACOCAT spelled backward still TACOCAT?
// People have been asking this question for thousands of years until...
// I wrote a function in JavaScript to prove it and end the debate. Palindrome in JavaScript
let isPalindrome = ( sIn = "tacocat" ) => ( sIn.split("").reverse().join("") === sIn );
/*
_._ _,-'""`-._
(,-.`._,'( |\`-/|
`-.-' \ )-`( , o o)
`- \`_`"'- My name is Omelette! ^_^
View recursive_object_squash.js
function squash(object) { // Deep JavaScript Object Squash
return Object
.entries(object)
.map(([key, value]) => Object.assign({ key }, value && typeof value === "object"
? { value: '', children: squash(value) }
: { value, children: [] }
));
}