View .profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#paste this in your .bashrc/.zshrc file | |
purgenodemodules() { | |
perl -e 'use File::Find; find(sub { unlink $File::Find::name if (-f && $File::Find::dir =~ /node_modules/) }, ".")' && find . -name 'node_modules' -type d -exec rm -rf {} + | |
} |
View cloudflare-pages-bun.env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bun is now officially supported and these environments variables are no longer needed. Keeping this gist for legacy purposes. | |
# SKIP_DEPENDENCY_INSTALL=true | |
# UNSTABLE_PRE_BUILD=asdf install bun latest && asdf global bun latest && bun i |
View concurrent-n-promises.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function processItems ( | |
items: unknown[], | |
operation: () => Promise, | |
concurrency = 25 | |
) { | |
const errors = [] | |
let id = 0 | |
const exec = async () => { | |
if (id === items.length) return | |
const item = items[id++] |
View gist:82689144288418f480477addeb4ceaed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
version: "2" | |
services: | |
emby: | |
image: linuxserver/emby | |
container_name: emby | |
environment: | |
- PUID=998 | |
- PGID=100 | |
- TZ=America/Denver |
View retry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Retries the given function until it succeeds given a number of retries and an interval between them. They are set | |
* by default to retry 5 times with 1sec in between. There's also a flag to make the cooldown time exponential | |
* @param {Function} fn - Returns a promise | |
* @param {Number} retriesLeft - Number of retries. If -1 will keep retrying | |
* @param {Number} interval - Millis between retries. If exponential set to true will be doubled each retry | |
* @param {Boolean} exponential - Flag for exponential back-off mode | |
* @return {Promise<*>} | |
*/ | |
const retryPromise = ({fn, retriesLeft = 5, interval = 1000, exponential = false}) => { |
View reduce.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1,2,3,4,5,6].reduce(async(previousPromise, thing) => { | |
await previousPromise | |
return asyncOperation(thing) | |
}, Promise.resolve()) |
View proxy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from "fs" | |
import path from "path" | |
import { inspect } from "util" | |
const { Console } = console | |
const makeFile = (name = "result") => fs.createWriteStream(path.join(__dirname, `../${name}.log`)) | |
const inspectOptions = { maxArrayLength: null, depth: null } |
View demo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Let's create some arguments as functions | |
let message = () => "hello" | |
let content = () => "world" | |
let text = () => "lorem" | |
//Let's change the function internal name value... | |
Object.defineProperty(text, "name", {writable:true}); | |
text.name = "book" | |
//Now we create a class |
View node.webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Inspired by https://jlongster.com/Backend-Apps-with-Webpack--Part-I | |
*/ | |
const webpack = require('webpack'); | |
const path = require('path'); | |
const fs = require('fs'); | |
//Use nodemon to livereload when using webpack --watch. | |
const NodemonPlugin = require('nodemon-webpack-plugin'); | |
//Ignore node externals when bundling | |
const nodeExternals = require('webpack-node-externals'); |