Skip to content

Instantly share code, notes, and snippets.

@npretto
npretto / automatic-node-pacakge-manager.sh
Created January 12, 2026 10:41
automatically detect yarn/bun/npm
# find package manager by looking for lockfiles in current and parent directories
function find-pkg-manager() {
local dir="$PWD"
while [ "$dir" != "/" ]; do
if [ -f "$dir/bun.lockb" ]; then
echo "bun|$dir/bun.lockb"
return 0
elif [ -f "$dir/pnpm-lock.yaml" ]; then
echo "pnpm|$dir/pnpm-lock.yaml"
return 0
@npretto
npretto / metabase-dev.user.js
Last active June 11, 2025 13:26
handy userscript for working on metabase
/* eslint-disable no-color-literals */
// ==UserScript==
// @name Metabase dev stuff
// @namespace Violentmonkey Scripts
// @version 1.3
// @description Fills forms and do things
// @author Your Name
// @match *://*/*
// @grant GM_registerMenuCommand
// @grant GM_setValue
@npretto
npretto / universal-link-copy.user.js
Last active February 10, 2025 17:50
user script to copy link to the page as md
@npretto
npretto / consolelogwithtypeof.code-snippets
Created June 16, 2020 12:00
console log with typeof
{
"console log with typeof": {
"prefix": ["clt"],
"body": ["console.log(\"$0\", typeof $0, $0)"],
"description": "console log with typeof"
}
}
@npretto
npretto / calibre-dark.css
Created May 31, 2020 12:14
calibre epub/ebook reader dark theme
body,
body * {
background-color: #1e1e1e !important;
color: #e1e1e1 !important;
}
h1,h2,h3,h4,h5,h6,h7 {
color: #9d5c63 !important;
}
@npretto
npretto / figmastyles.js
Created April 9, 2020 12:44
get colors from figma and print them as ts code
// v this will probably change every figma deploy
const styles = [...document.querySelectorAll('.style_icon--styleIcon--3-PzQ')]
const colors = styles.map(style =>{
try {
const name = style.attributes['data-tooltip-style-name'].value.split(" ")[2]
const rgb = style.children[0].children[0].style.backgroundColor
@npretto
npretto / testID.code-snippets
Created February 20, 2020 15:52
vscode snippets for testID props
{
"testID interface props interface": {
"prefix": ["tii"], // [t]est [i]d [i]nterface
"body": ["testID?: string;"],
"description": "testID ts interface"
},
"testID prop forwarding": {
"prefix": ["tip"], // [t]est [i]d [p]rop
"body": ["testID={this.props.testID}"],
@npretto
npretto / start-haxe.js
Last active February 13, 2020 21:15
overcomplicated watch for "multi folder" haxe projects
const chokidar = require("chokidar");
const { spawn } = require("child_process");
const compilerPort = 6066;
// TODO:
// [ ] start compilation server
// [ ] use compilation server
// [ ] parse paths in stdout and add cwd so they can be clicked
// [ ] proper support for openfl / assets (run openfl build only when assets change)
@npretto
npretto / parseQueryString.js
Last active November 6, 2019 09:16
query string to object
queryString.split("&").map(string => string.split("=")).reduce((params,[key,value]) => ({...params, [key]:value}),{})
@npretto
npretto / parse-logs.js
Created November 14, 2017 13:24
node parse-logs.js file-di-log.txt > parsed.csv
var path = process.argv[2];
console.log(`reading file ${path}`)
console.log(`Date, Memory`)
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream(path)
});
var regexp = /(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*Memory : (\d*)MB/g;