Skip to content

Instantly share code, notes, and snippets.

View GalassoLuca's full-sized avatar
🦊

Luca GalassoLuca

🦊
View GitHub Profile
@GalassoLuca
GalassoLuca / logvar.code-snippets
Last active February 23, 2022 15:01
This is a VS Code snippet that let me log a variable to console in the following format console.log('variable', variable)
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
"Print a variable to console": {
"prefix": "logvar",
@GalassoLuca
GalassoLuca / .zshrc
Last active June 16, 2022 10:44
Bash/zsh aliases
alias p="pnpm"
alias i="p install"
alias u="p uninstall"
alias s="p dev"
alias t="p test"
alias tw="p run test:watch"
alias c="code ."
alias o="open ."
alias rmi="rm -rf node_modules; i"
alias rmit="rmi; t"
@GalassoLuca
GalassoLuca / read-file.js
Last active May 5, 2022 14:04
How to read a file in NodeJS from a relative path
const fs = require('fs')
const path = require('path')
const html1 = fs.readFileSync(path.join(__dirname, '../test/fixtures/page1.html'), 'utf-8')
// in one line
const html2 = require('fs').readFileSync(require('path').join(__dirname, '../test/fixtures/page2.html'), 'utf-8')
// with a function
const readFile = relativePath => require('fs').readFileSync(require('path').join(__dirname, relativePath), 'utf-8')
const html3 = readFile('../test/fixtures/page3.html')
@GalassoLuca
GalassoLuca / mongodb-query-with-objectid-from-date.js
Last active April 29, 2022 09:21
query MongoDB documents based on creation date present in ObjectId
const idFromDate = ObjectId.fromDate(ISODate("2021-02-08"))
db['collection'].count({ _id: { $gte: idFromDate } })
@GalassoLuca
GalassoLuca / upfind.sh
Last active December 16, 2021 10:19
Upwards find: find the first filename backward from the current folder to the root
# Upwards find
## Description: find the first filename backward from the current folder to the root
upfind() {
folder="$(pwd)"
while [ "$folder" != "/" ]; do
for arg in "$@"; do
if [ -e "${folder}/$arg" ]; then
echo $folder/$arg
@GalassoLuca
GalassoLuca / load-nvmrc.sh
Last active December 16, 2021 10:37
Load node version with fnm and automatically taking the node version contained in the first upwards .nvmrc (or .node-version) file
# Load .nvmrc file using fnm
## Description: load nvmrc by automatically taking the node version contained in the first upwards .nvmrc (or .node-version) file
## See GIST/upfind.sh https://gist.github.com/GalassoLuca/a502c3ba2489b6fae7270f5653bedfc0
local last_nvmrc_path=null
load-nvmrc() {
local nvmrc_path="$(upfind .nvmrc .node-version)"
@GalassoLuca
GalassoLuca / remove-git-branches.sh
Created April 29, 2022 09:20
Remove all local git branches but keep develop, stage and master
git branch | egrep -v " develop| stage| master" | xargs git branch -D