Skip to content

Instantly share code, notes, and snippets.

View darkmavis1980's full-sized avatar
🎯
Focusing

Alessio Michelini darkmavis1980

🎯
Focusing
View GitHub Profile
@darkmavis1980
darkmavis1980 / rand.md
Created February 5, 2024 16:41
Generate random hex string with OpenSSL
openssl rand -hex 32
@darkmavis1980
darkmavis1980 / testspeed.md
Created November 22, 2023 21:13
Check MicroSD Speed on Raspberry PI
sudo hdparm -tT /dev/mmcblk0
const asyncFn = () => Promise.reject(new Error("async fn error", {
cause: {
type: 'FirstErrorCause'
}
}));
const asyncManipulateResponse = (response) => Promise.resolve("manipulated response");
const tryCatchFn = async () => {
try {
const response = await asyncFn();
const functionA = async () => {
try {
// request something that resolves in a promise
} catch (error) {
throw new Error("Function A failed");
}
}
const functionB = async () => {
try {
@darkmavis1980
darkmavis1980 / fix-docker.sh
Created March 10, 2023 23:47
Fix Docker Permission Denied WSL 2
sudo addgroup --system docker
sudo adduser $USER docker
newgrp docker
# And something needs to be done so $USER always runs in group `docker` on the `Ubuntu` WSL
sudo chown root:docker /var/run/docker.sock
sudo chmod g+w /var/run/docker.sock
@darkmavis1980
darkmavis1980 / hs-regex.js
Last active December 22, 2022 14:04
Matches either hubspot domain or hs-sites (sandboxes)
// url => https://regex101.com/r/jhw0wy/1
const regex = /https:\/\/([a-z\.]{4})?([0-9]+.hs-sites|hubspot).com[\/]?/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('https:\/\/([a-z\.]{4})?([0-9]+.hs-sites|hubspot).com[\/]?', 'gm')
const str = `https://hubspot.com/
https://123456.hs-sites.com/
https://google.com`;
@darkmavis1980
darkmavis1980 / replace.js
Last active September 10, 2022 20:47
Replace require with ESM import in VS Code find/replace
/**
* search for:
* const x = require('x');
* const { a } = require('a');
*/
const ([\w\s\n,{}:]+) = require\('([.\/@\w-]+)'\)
/**
* replace with:
@darkmavis1980
darkmavis1980 / FixLoop.md
Created March 25, 2020 21:29
Fix ubuntu login loop

If you get stuck with the login loop, press ctrl + alt + F3 to access to the shell. Login with your account, then run these commands:

sudo apt purge gdm3
sudo apt install gdm3

Restart and you should be able to login now.

@darkmavis1980
darkmavis1980 / kebabToCamel.js
Created March 20, 2020 09:25
Kebab case to camel case string conversion
/**
* @description Transform a kebab case string into a Camel Case
* @param {string} string Source string
*
* @example
* // returns thisIsMyString
* kebabToCamelCase('this-is-my-string');
* @returns {string}
*/
export function kebabToCamelCase(string) {
@darkmavis1980
darkmavis1980 / format.js
Created March 3, 2020 16:46
Format a string with variables passed as an object
function format(string, keyValues) {
const regex = /{{([a-zA-Z]+)}}/g;
return string.replace(regex, (match, key) => {
return keyValues[key];
});
}
console.log(format('Hello {{name}}', {name: 'Alessio'})); // Hello Alessio
console.log(format('The price is {{currency}} {{price}}', {price: '10.5', currency: 'EUR'})); // The price is EUR 10.5
console.log(format('Il prezzo è {{price}}{{currency}}', {price: '10.5', currency: 'EUR'})); // Il prezzo è 10.5EUR