Skip to content

Instantly share code, notes, and snippets.

View whitehorse0's full-sized avatar
🤓
trying to make the world better with software

eka-putra whitehorse0

🤓
trying to make the world better with software
  • @bibit.id
  • Jakarta, Indonesia
View GitHub Profile
@ahmadjoya
ahmadjoya / pmt.js
Last active May 5, 2024 13:10
Excel PMT function to JavaScript
const PMT = (rate, nper, pv, fv, type) => {
/*
* rate - interest rate per month
* nper - number of periods (months)
* pv - present value
* fv - future value
* type - when the payments are due:
* 0: end of the period, e.g. end of month (default)
* 1: beginning of period
*/
@azagniotov
azagniotov / beautiful.rest.api.docs.in.markdown.md
Last active July 12, 2024 02:11
Example to create beautiful REST API docs in Markdown, inspired by Swagger API docs.
@sohamkamani
sohamkamani / rsa.js
Last active July 4, 2024 13:04
An example of RSA Encryption implemented in Node.js
const crypto = require("crypto")
// The `generateKeyPairSync` method accepts two arguments:
// 1. The type ok keys we want, which in this case is "rsa"
// 2. An object with the properties of the key
const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", {
// The standard secure default length for RSA keys is 2048 bits
modulusLength: 2048,
})
@daleyjem
daleyjem / deep-imports.md
Last active August 7, 2023 07:07
Explanation of a "deep import"

Deep Imports

Description

A "deep import" is simply an ESM import that goes deeper than the package root:

import thingA from 'my-package-name/src/components/thingA'
import thingB from '@my-namespace/my-package-name/src/components/thingA'
@qoomon
qoomon / conventional-commits-cheatsheet.md
Last active July 22, 2024 14:40
Conventional Commits Cheatsheet

Conventional Commit Messages

See how a minor change to your commit message style can make a difference.

Tip

Have a look at git-conventional-commits , a CLI util to ensure these conventions, determine version and generate changelogs

Commit Message Formats

Default

@loilo
loilo / magic-methods.js
Last active June 15, 2024 07:36
PHP Magic Methods in JavaScript
function magicMethods (clazz) {
// A toggle switch for the __isset method
// Needed to control "prop in instance" inside of getters
let issetEnabled = true
const classHandler = Object.create(null)
// Trap for class instantiation
classHandler.construct = (target, args, receiver) => {
// Wrapped class instance
@SylarRuby
SylarRuby / userAvatar.js
Last active June 21, 2024 14:48
NodeJs AWS S3 Upload
/**
* This gist was inspired from https://gist.github.com/homam/8646090 which I wanted to work when uploading an image from
* a base64 string.
* Updated to use Promise (bluebird)
* Web: https://mayneweb.com
*
* @param {string} base64 Data
* @return {string} Image url
*/
const imageUpload = async (base64) => {
@NigelEarle
NigelEarle / Knex-Migrations-Seeding.md
Last active June 19, 2024 14:20
Migration and seeding instructions using Knex.js!

Migrations & Seeding

What are migrations??

Migrations are a way to make database changes or updates, like creating or dropping tables, as well as updating a table with new columns with constraints via generated scripts. We can build these scripts via the command line using knex command line tool.

To learn more about migrations, check out this article on the different types of database migrations!

Creating/Dropping Tables

@acabreragnz
acabreragnz / select_distance_knex.js
Last active September 30, 2020 16:37
This module extends the knex query builder with selectDistance method, the method adds a virtual column to the current query (qb) with the alias as, in which resides the calculated distance from the geoPoint to the entity.location column. It also accepts some options parameters like the unit (km | mi) and the decimalPrecision of the result. Deps…
var knex;
/**
* This module extends the knex query builder with selectDistance method,
* The method adds a virtual column to the current query (qb) with the alias as, in which
* resides the calculated distance from the geoPoint to the entity.location column.
* It also accepts some options parameters like the unit (km | mi) and the decimalPrecision of the result.
* Deps: Postgis
* @example
'use strict';
const co = require('co');
const EventEmitter = require('events');
const Promise = require('bluebird');
const AWS = require('aws-sdk');
const ssm = Promise.promisifyAll(new AWS.SSM());
const DEFAULT_EXPIRY = 3 * 60 * 1000; // default expiry is 3 mins