Skip to content

Instantly share code, notes, and snippets.

View StackTrac3's full-sized avatar
📈

Justin StackTrac3

📈
View GitHub Profile
@StackTrac3
StackTrac3 / startpage.com-minimalistic.userscript.js
Last active May 13, 2021 16:40
(ES5 Compat) Greasemonkey Startpage Minimalistic/ Styling with config example
// ==UserScript==
// @name Startpage Options
// @grant GM_style.add
// @match *://startpage.com/*
// @match *://www.startpage.com/*
// @run-at document-begin
// ==/UserScript==
// Updated for May 2021 startpage element selector changes
@StackTrac3
StackTrac3 / sunglasses.js
Last active May 25, 2022 20:13
Greasemonkey script for darkening your web browser
// ==UserScript==
// @name Webkit's filter may globally dim
// @description web pages in a pleasing manner
// @grant GM_addStyle
// @run-at document-end
// @exclude *://*.github.com/*
// @exclude *://github.com/*
// ==/UserScript==
function addStyle(css) {
@StackTrac3
StackTrac3 / hard-dependency.js
Created January 29, 2021 10:26 — forked from ryyppy/hard-dependency.js
Jest: Module Mocking vs. Simple Dependency Injection
// ###############################
// runPackager.js
// ###############################
// In this example, the IO function is tightly coupled with the implementation
import { execFileSync } from 'child_process';
type RunPackagerOptions = {
projectRoot: string, // CWD the react-native binary is being run from
targetDir: string, // Target directory absolute or relative to projectRoot (e.g. 'rna/')
@StackTrac3
StackTrac3 / config.py
Last active January 29, 2021 10:16
qutebrowser configuration files
# Bindings
config.bind("gi", "hint inputs")
config.bind("<f12>", "inspector")
#config.unbind("+")
#config.unbind("-")
#config.unbind("=")
#config.bind("z+", "zoom-in")
#config.bind("z-", "zoom-out")
@StackTrac3
StackTrac3 / tiny-profiler.js
Created January 22, 2021 12:04
Super simple JavaScript execution timing
const microtime = (() => {
const currentNano = () => {
const [a, b] = process.hrtime()
return a * 1000000000 + b
}
const nanoToMilli = (ns) => (ns / 1000000).toFixed(3)
const markers = {
'-1': currentNano()
}
return {
@StackTrac3
StackTrac3 / lookup-map-lean.js
Last active January 7, 2021 23:28
Keep a lookup map concise - more in comments
const logMessage = (message) => console.log(Date.now(), message)
const responses = [
{
input: "test-one",
answer: "One"
},
{
input: "test-two",
helper: (input, callback) => callback("Two helper")
@StackTrac3
StackTrac3 / recursion-simple.js
Created January 7, 2021 02:36
Recursion: An important intermediate level concept for nested processing
// Recursion: a function may call itself and work with the return value.
// It can do this multiple times before returning the original execution
const getDeepTotal = function deepTotal(inputArray) {
let total = 0
inputArray.forEach((el)=>{
total += Array.isArray(el) ? deepTotal(el) : el
})
return total
}
@StackTrac3
StackTrac3 / lookup-map-example.js
Created January 5, 2021 22:09
This pattern is a dynamic and extensible alternative to multiple if-else blocks, or a switch statement
const logMessage = (message) => console.log(Date.now(), message)
const responses = [
{
input: "test-one",
answer: "One",
},
{
input: "test-two",
helper: (input, callback) => {