Skip to content

Instantly share code, notes, and snippets.

@neatshell
neatshell / ifElse.js
Created February 1, 2025 16:04
ifElse() HOF
const execIfFunc = x => (typeof x === 'function' ? x() : x);
/**
* This is a higher order function that accepts a boolean condition and will
* return a function allowing you to provide if/else values that should be
* resolved based on the boolean condition.
*
* @param {Boolean|() => Boolean} condition:
* The condition to test against. This can be a function for lazy resolution.
*
level=${1-critical}
# Generate an audit report of Level or Critical advisories
yarn audit --json --level "${level}" > audit.lines
# Transform from JSON-lines to JSON format
jq -s '.' audit.lines > audit.json
# Extract advisories
jq -r '.[] |
select(.type == "auditAdvisory") |
@neatshell
neatshell / useStateWithCallback.ts
Created July 6, 2023 14:27
useStateWithCallback like old setState callback behaviour
// https://betterprogramming.pub/synchronous-state-in-react-using-hooks-dc77f43d8521
import { useState } from 'react';
export function useStateWithCallback<T>(initialValue: T) {
const [value, setValue] = useState(initialValue);
const setValueAndCallback = (newValue: T, callback: (prevValue: T, newValue: T) => void) => {
setValue((prevValue) => {
if (callback) {
callback(prevValue, newValue);
@neatshell
neatshell / brew-dnsmasq.md
Created February 20, 2023 10:25 — forked from davebarnwell/brew-dnsmasq.md
install dnsmasq with brew

Install dnsmasq and configure for *.dev.local domains

$ brew install dnsmasq
$ vim /usr/local/etc/dnsmasq.conf

Reload configuration and clear cache

# Copy the daemon configuration file into place.
$ sudo cp $(brew list dnsmasq | grep /homebrew.mxcl.dnsmasq.plist$) /Library/LaunchDaemons/

$ sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

@neatshell
neatshell / yo_non_root
Last active January 2, 2021 18:18 — forked from Jay991/solution.text
Solution for Yoeman Error: EACCES, permission denied '/root/.config/configstore/insight-yo.json' You don't have access to this file.
You need to create a new user and give it sudo privleges:
$adduser username
Set password prompts:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for username
Enter the new value, or press ENTER for the default
Full Name []:
(function(org, notificationType) {
// org:
// the organizazione name
// notificationType:
// 'included' = participating and @mentions,
// 'subscribed' = all activity,
// 'ignore' = ignore
let qx = $x;
let unwatch = function(org, notificationType) {
@neatshell
neatshell / ngx_brotli_osx.md
Last active April 26, 2020 14:48
Add dynamic nginx-brotli-module to nginx

Pre-requisites:

nginx installed with homebrew from the core tap

git installed and all the software needed to build something from source

Getting sources:

First of all, you need to get your currently installed nginx version simply by executing:

import path from 'path';
import fs from 'fs';
const testAgainstRegex = (patterns, string) => {
if (typeof patterns === 'string') {
return new RegExp(patterns).test(string);
} else if (patterns instanceof Array) {
return new RegExp(patterns.join('|')).test(string);
} else {
return patterns;
# Retrieve the arguments passed to an npm/yarn script
ARGV=$(echo "console.log(JSON.parse(process.argv[2]).original.splice(1, Infinity).join(' '))" | node - ${npm_config_argv})
@neatshell
neatshell / document.querySelectorCheatsheet
Last active March 4, 2020 20:23
document.querySelector* cheatsheet
// Get the canonical url of a page
document.querySelector("link[rel='canonical']").href;
document.querySelector("link[rel='canonical']").getAttribute("href");