Skip to content

Instantly share code, notes, and snippets.

View rigwild's full-sized avatar

rigwild

View GitHub Profile
@rigwild
rigwild / README.md
Last active March 29, 2024 20:08
Cache a function locally and automatically - With a lockable cache version if using multi threading

Using withCache

const myFriends: CacheMap<{ name: string; age: number }> = {}

async function fetchMyFriendsFromCity(fromCity: string) {
  // This is to preserve the name of the function in the stack trace
  const fetchMyFriendsFromCity = async () => {
    console.log('Fetching my friends from the database...')
    return (await db.query('SELECT * FROM friends WHERE city = ?', [fromCity])).rows
@rigwild
rigwild / README.md
Created February 17, 2024 21:38
Super simple helper class to use OpenPGP.js without getting an headache
@rigwild
rigwild / coolcats_download.sh
Created January 13, 2024 16:50
Download all Cool Cats NFT metadata and images
#!/bin/bash
set -e
set -x
# Directory to save the JSON files and images
mkdir -p coolcats
cd coolcats
# Loop from 1 to 9999
@rigwild
rigwild / 0_README.md
Last active December 3, 2023 01:18
VM Setup for dockerized apps and Portainer, including exposed NGINX with TLS configuration

Introduction

The goal of this this tutorial is to fully deploy a VM with multiple apps.

All the apps data will be stored in Docker volumes mounted to the host at /var/www/my-deploys for easy edit and backup. The benefit of this is you can create a GitHub repository and store all your configuration files in one place.

To deploy the docker-compose.yml of the apps below into Portainer, go to Stacks > Add stack.

Pre-requisites

@rigwild
rigwild / README.md
Last active November 26, 2023 18:29
Install https://github.com/dgtlmoon/changedetection.io behind a NGINX proxy
cd /var/www
git clone git@github.com:dgtlmoon/changedetection.io.git
cd changedetection.io

Edit the configuation

nano docker-compose.yml
@rigwild
rigwild / README.md
Last active September 27, 2023 23:31
Install Prometheus, Prometheus Pushgateway and Grafana and add them to systemd startup

Install and use metrics with Prometheus and Grafana

Install metrics agents

Install Prometheus, Prometheus Pushgateway and Grafana. Put them behind NGINX reverse proxy, get a TLS certificate, and run the service on startup with systemd.

Do a replace all of prometheus-pushgateway.example.com and grafana.example.com with your own domains.

chmod u+x ./install_metrics_agents.sh
@rigwild
rigwild / evmTokens.js
Last active January 7, 2023 00:31
List of EVM (Ethereum-based) networks including its explorer and top most used smart contracts tokens addresses (ERC20) - On 2023-01-07
/*
Networks:
* ethereum
* binanceSmartChain
* polygon
* fantom
* optimism
* arbitrum
* avalanche
/**
* Convert any string to kebab-case.
* Removes accents, multiples whitespaces and symbols to one "-" and converts to lower case.
* Removes any leading and leading "-".
*
* @param {string} str string to convert
* @returns {string} string in kebab-case
* @author rigwild <me@rigwild.dev>
* @see https://gist.github.com/rigwild/3e4d30bd269535b7508926c8beaeef90
*/
@rigwild
rigwild / script.js
Last active September 4, 2022 14:33
Userscript to improve the wegobuy.com agent website
// ==UserScript==
// @name Photo fixed + EUR price + Keyboard arrows
// @namespace Violentmonkey Scripts
// @match https://www.wegobuy.com/en/page/buy
// @grant none
// @version 1.0
// @author -
// @description 8/28/2022, 1:40:18 AM
// ==/UserScript==
@rigwild
rigwild / crypt_aes-256-gcm.js
Last active December 20, 2022 18:45
`aes-256-gcm` encryption with native crypto module
const crypto = require('crypto')
/**
* Encrypts text by given key
* @param {string} text to encrypt
* @param {Buffer | string} masterkey
* @returns {string} encrypted text, base64 encoded
*/
function encrypt(text, masterkey) {
// random initialization vector