Skip to content

Instantly share code, notes, and snippets.

@eynopv
eynopv / recurrent_add_function.md
Created October 12, 2022 12:51
My embarrassing moment
function add(number) {
  return function(nextNumber) {
    if (nextNumber === undefined) {
      return number;
    }
    
    return add(number + nextNumber);
  }
}
@eynopv
eynopv / js-function-promise-and-callback.md
Created September 22, 2022 07:49
Make javascript function which supports promise and callback
// Define function
function wait(timeMS, callback) {
  const f = new Promise((resolve) => {
    setTimeout(() => {
      resolve();
    }, timeMS);
  });
  
 if (!callback) return f;

SSH key

Generate

To generate ssh key with ed25519 use:

$ ssh-keygen -t ed25519 -C "<email>"

How to add new user to AWS ec2 instance?

  1. Login as a ec2-user to the instance
$ ssh -i ~/.ssh/<key> ec2-user@<ip-address>
  1. Create user
@eynopv
eynopv / libphonenumber_regioncode_from_international_number.md
Created May 20, 2022 11:32
Get region code from international phone number using javascript google-libphonenumber
const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
const PNF = require('google-libphonenumber').PhoneNumberFormat;

const phoneNumber = '0461234567';
const regionCode = 'fi';
const parsed = phoneUtil.parse(phoneNumber, regionCode);
const internationalNumber = phoneUtil.format(parsed, PNF.INTERNATIONAL);
const internationalParsed = phoneUtil.parse(internationalNumber);
const regionCodeFromInternationalNumber = phoneUtil.getRegionCodeForNumber(internationalParsed);
@eynopv
eynopv / conventional_commits.md
Created March 31, 2022 09:46
Conventional Commits

Conventional Commits

Be better programmer through better commits.

Structure

<type>(<optional scope>): <summary in present tence>