Skip to content

Instantly share code, notes, and snippets.

@mritzco
mritzco / How to create Node cli executable from npm.md
Last active April 28, 2024 06:30
Create Node Package (cli) executable from npm scripts

Creating an executable NPM package and using it

This short guide explains how to create an NPM package that can be called as a script from another project. For clarity: The package to execute will be called: Module The place where you use it: Application

1. Build your module

Create a standard module ignore command line parsing

@mritzco
mritzco / cachedFetch.js
Last active December 18, 2023 09:14
Javascript caching fetch data
// From https://www.sitepoint.com/cache-fetched-ajax-requests/
// All credits to: Peter Bengtsson
// Added Content-type to headers so it can go to traditional validation like fetch does
// Add some debugging messages: activate with { verbose: true }
// Add a request to be able to add headers instead of just calling URL
const CachedFetch = (url, options) => {
let expiry = options.seconds || 5 * 60 // 5 min default
let logger = (options.verbose) ? console.log : function(){};
@mritzco
mritzco / plopfile.js
Created March 8, 2018 08:09
Custom action for plop. Appends data to JSON files
const fs = require('fs-extra');
const methods = {}, priv = {};
// Private methods to do string replacement. Not optimized and cummulative trying to keep it simple.
// far better options here: https://stackoverflow.com/questions/5069464/replace-multiple-strings-at-once
priv.replaceObj = function(value, vars) {
let obj = value;
Object.keys(obj).forEach(function(item) {
obj[item] = priv.replaceStr(obj[item], vars);
});
return obj;
@mritzco
mritzco / install.md
Last active September 2, 2022 00:11
Running AR.js sample locally
@mritzco
mritzco / git_undo.sh
Created April 2, 2022 16:04
Undo the last local commit, fix and re-commit
git commit -m "Something terribly misguided" # (0: Your Accident)
git reset HEAD~ # (1)
#[ edit files as necessary ] # (2)
git add . # (3)
git commit -c ORIG_HEAD # (4)
#Ref: https://stackoverflow.com/questions/927358/how-do-i-undo-the-most-recent-local-commits-in-git
@mritzco
mritzco / miraclecast.sh
Created April 17, 2019 16:47
Installing miraclecast and dependencies on Linux Mint
# not really an sh file but the sequence I used to install, might work as .sh but haven't tried
# If running as .sh with sudo it might not need the sudo's
# 1. Clone the repo and create the directories
git clone https://github.com/albfan/miraclecast.git
cd miraclecast/
mkdir build
cd build/
# 2. There's lots of dependencies not listed
sudo apt-get install autoconf automake libtool libudev-dev libsystemd-dev libglib2.0-dev libreadline-dev
# 3. Continue the building process
@mritzco
mritzco / .tmux.conf
Created September 15, 2021 09:20
tmux and VI custom config
#Tweak timing between key sequence
set -s escape-time 0
## active window title colors
set-window-option -g window-status-current-attr bright
# Set prefix to Ctrl-Space instead of Ctrl-b
unbind C-b
set -g prefix C-Space
bind Space send-prefix
@mritzco
mritzco / resize.sh
Created August 10, 2021 10:05
Lineman image resizing
#!/bin/bash
filetype=png
for i in *.$filetype; do
name=$(echo $i | sed 's/\.[^.]*$//')
echo "Processing: $i"
mkdir -p $name
convert $i -resize 700x700\> $name/700;
convert $i -resize 460x460\> $name/460;
@mritzco
mritzco / CacheCollection.js
Created June 14, 2018 10:07
localStorage class
// src/utils/CacheCollection.js
/**
* Creates a collection of unique values in local storage
* Works with arrays only
* Singleton method to allow sharing between classes without adding extra stuff
*/
class CacheCollection {
constructor (key, expire=1200) {
this.key = key;
this.expire = expire;
@mritzco
mritzco / ip.sh
Created January 4, 2021 11:51
Find your true IP
# Find out true IP for DB access.
# Ref: https://www.digitalocean.com/community/questions/trusted-sources-not-allowing-connections-from-my-ip?comment=94488#
curl ifconfig.io