Skip to content

Instantly share code, notes, and snippets.

Avatar
🎸
hard as a rock

Christian Castelli chrisvoo

🎸
hard as a rock
View GitHub Profile
@chrisvoo
chrisvoo / solution.md
Last active Jul 5, 2021 — forked from lgg/solution.md
JetBrains intellij idea + NVM + nodejs + WebStorm
View solution.md

NVM + WebStorm

If you get error:

run npm command gives error "/usr/bin/env: node: No such file or directory

Modify the Desktop icon ~/.local/share/applications/jetbrains-webstorm.desktop with:

@chrisvoo
chrisvoo / lastfm_search_discography.ts
Created May 10, 2021
Retrieving artist's top albums
View lastfm_search_discography.ts
/* 57034 results for 1141 pages! */
import dotenv from 'dotenv';
import LastFM from 'last-fm';
import { envSchema } from './utils';
import { showResult } from './utils/terminal';
const result = dotenv.config();
if (result.error) {
console.error(result.error.message);
@chrisvoo
chrisvoo / discogs_search_example.ts
Created May 10, 2021
An example on how to retrieve an artist's discography with Discogs
View discogs_search_example.ts
/* The API returns way too much results: the example below is the best approximation
* to get a discography. Anyway, there are some errors:
* - another group is present
* - Cheshire cat's album is missing
*/
import { Client } from 'disconnect';
import dotenv from 'dotenv';
import { envSchema } from './utils';
import { showResult } from './utils/terminal';
@chrisvoo
chrisvoo / pre-commit
Created May 5, 2021
Avoit to commit tests with `only`
View pre-commit
# Redirect output to stderr.
exec 1>&2
# prevent it.only or describe.only commited
if [ "$allowonlytests" != "true" ] &&
test $(git diff --cached | grep -E "\b(it|describe).only\(" | wc -l) != 0
then
cat <<\EOF
Error: Attempt to add it.only or describe.only - which may disable all other tests
@chrisvoo
chrisvoo / removeDuplicatesFromArray.js
Created Jun 8, 2020
Removes duplicates from an array, regardless of its depth or content
View removeDuplicatesFromArray.js
const removeDuplicatesFromArray = arr =>
[...new Set(arr.map(el => JSON.stringify(el)))].map(e => JSON.parse(e))
@chrisvoo
chrisvoo / IntelIJTrialReset.bat
Created Feb 17, 2020
How to Reset InteIIiJ IDEA Evaluation Key in Windows
View IntelIJTrialReset.bat
cd "C:%HOMEPATH%\.IntelliJIdea*\config"
rmdir "eval" /s /q
del "options\other.xml"
reg delete "HKEY_CURRENT_USER\Software\JavaSoft\Prefs\jetbrains\idea" /f
:: This will work for idea 2018.3 and later
::
:: It is Highly Advised to Purchase the JetBrain Softwares
:: This is only for the case You just want to Extend the
:: Trial Period and Evaluate the IDE for some more Time
@chrisvoo
chrisvoo / VirginRadioReducer.user.js
Last active Sep 19, 2019
Removes unnecessary parts from virginradio.it
View VirginRadioReducer.user.js
// ==UserScript==
// @name VirginRadio Reducer
// @namespace http://tampermonkey.net/
// @version 0.6
// @description Removes unnecessary parts from virginradio.it
// @author Christian Castelli <voodoo81people@gmail.com>
// @match https://www.virginradio.it/*
// @grant none
// ==/UserScript==
@chrisvoo
chrisvoo / redis.js
Created Mar 19, 2019
Node.js and Redis: async GET/SET
View redis.js
const redis = require("redis")
const { promisify } = require("util")
const {
redis: { clientOptions, expire },
} = require("../config/get-config")
let client
/**
* Asynchronous version of `client.get`
@chrisvoo
chrisvoo / isLocalhost.js
Created Feb 21, 2019
Tests if the scripts is running in local (taken from registerServiceWorker.js - CRA apps)
View isLocalhost.js
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,
),
);
@chrisvoo
chrisvoo / getFileHash.js
Created Feb 19, 2019
Node.js: function to create an hash from a file (path or Buffer)
View getFileHash.js
const crypto = require('crypto');
const fs = require('fs');
/**
* It calculates the hash of a file
* @param {string} hashName type of hash (md5, sha1, etc)
* @param {string|Stream} file a file's path or a readable stream
* if it's been already opened somewhere else
*/
function getFileHash(hashName, file) {