Skip to content

Instantly share code, notes, and snippets.

View Hebilicious's full-sized avatar
🖤

Heb Hebilicious

🖤
View GitHub Profile
@Hebilicious
Hebilicious / .profile
Created September 10, 2023 15:34
Fast recursive delete node modules directories
#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 {} +
}
@Hebilicious
Hebilicious / cloudflare-pages-bun.env
Last active April 10, 2024 01:01
Cloudflare Pages and Bun
# 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
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++]
---
version: "2"
services:
emby:
image: linuxserver/emby
container_name: emby
environment:
- PUID=998
- PGID=100
- TZ=America/Denver
@Hebilicious
Hebilicious / smoke.md
Last active February 17, 2021 04:05
Smoke Finance
/**
* 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}) => {
@Hebilicious
Hebilicious / reduce.js
Created November 20, 2019 14:16
await for...of =>reduce
[1,2,3,4,5,6].reduce(async(previousPromise, thing) => {
await previousPromise
return asyncOperation(thing)
}, Promise.resolve())
@Hebilicious
Hebilicious / proxy.js
Last active July 27, 2021 02:06
Proxy useful use case
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 }
@Hebilicious
Hebilicious / demo.js
Created January 22, 2018 00:51
ES Class constructor spread operator arguments
//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
@Hebilicious
Hebilicious / node.webpack.config.js
Created January 19, 2018 01:14
Webpack & Node 2018 Starter Config
/**
* 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');