Skip to content

Instantly share code, notes, and snippets.

View FFKL's full-sized avatar
🦔
This is The Hedgehog!

Dmitrii Korostelev FFKL

🦔
This is The Hedgehog!
View GitHub Profile
@wiedymi
wiedymi / ftp-dump.js
Last active June 27, 2022 20:21
Dump ftp folder (Node.js)
require('dotenv').config()
const ftp = require('ftp')
const fs = require('fs')
const { promisify } = require('util')
const env = {
host: process.env.FTP_HOST,
user: process.env.FTP_USER,
password: process.env.FTP_PASS,
folder: process.env.FTP_FOLDER || '/'
@sindresorhus
sindresorhus / esm-package.md
Last active July 1, 2024 12:16
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
// Reference - https://mongoosejs.com/docs/transactions.html
// "mongoose": "^5.11.2"
const assert = require("assert")
const mongoose = require("mongoose")
const case1 = () => {
// Expect Output:
// >>> case 1 catch error error.message
// >>> case1 finally
@pmkay
pmkay / installing-postman.md
Created April 27, 2020 02:49 — forked from ba11b0y/installing-postman.md
Installing Postman on Ubuntu/Gnome

Since Chrome apps are now being deprecated. Download postman from https://dl.pstmn.io/download/latest/linux

Although I highly recommend using a snap

sudo snap install postman

Installing Postman

tar -xzf Postman-linux-x64-5.3.2.tar.gz
@eduardo-matos
eduardo-matos / rabbit-graceful-shutdown.js
Last active April 29, 2024 09:13
RabbitMQ graceful shutdown in NodeJS
const amqp = require('amqplib');
const uuid = require('uuid')
const CONSUMER_TAG = uuid.v4();
const QUEUE_NAME = 'my_queue'
async function main() {
const conn = await amqp.connect('amqp://guest:guest@localhost:5672/%2F');
const channel = await conn.createChannel();
await channel.assertQueue(QUEUE_NAME);
@iffa
iffa / better-scroll-restoration-logic-angular.ts
Last active May 16, 2024 20:48
Custom scroll position restoration logic for Angular 2+, that doesn't consider query parameter changes in route as forward navigation, thus preventing certain scenarios where you don't want query parameter changes to scroll-to-top as they would with 'scrollPositionRestoration: enabled'.
export class AppModule {
constructor(private router: Router, private viewportScroller: ViewportScroller) {
// Disable automatic scroll restoration to avoid race conditions
this.viewportScroller.setHistoryScrollRestoration('manual');
this.handleScrollOnNavigation();
}
/**
* When route is changed, Angular interprets a simple query params change as "forward navigation" too.
  • Based on https://gist.github.com/mdziekon/221bdb597cf32b46c50ffab96dbec08a
  • Installation date: 16-08-2019
  • Additional notes based on my own experience
  • EFI boot
  • Ubuntu 19.04 -> 21.04
  • This should work on any computer. Only the RAID > AHCI change described below and the device name for the nvme ssd drive are specific to this laptop.
  • The process describes a completely fresh installation with complete repartitioning, however it should work fine when Windows is already installed (eg. brand new machine with Windows preinstalled) as long as Windows already boots with EFI.
  • The process was conducted on Dell's XPS 15 9560 (2017) with specs:
  • CPU: i7-7700HQ
@harveyconnor
harveyconnor / a-mongodb-replica-set-docker-compose-readme.md
Last active June 24, 2024 15:07
MongoDB Replica Set / docker-compose / mongoose transaction with persistent volume

This will guide you through setting up a replica set in a docker environment using.

  • Docker Compose
  • MongoDB Replica Sets
  • Mongoose
  • Mongoose Transactions

Thanks to https://gist.github.com/asoorm for helping with their docker-compose file!

@dvaJi
dvaJi / mock-active-router.ts
Created May 16, 2019 23:35
Mock ActivatedRoute (with snapshot, queryParams and params), tested in Angular 7+
import { Params } from '@angular/router';
import { BehaviorSubject } from 'rxjs';
export class MockActivatedRoute {
private innerTestParams?: any;
private subject?: BehaviorSubject<any> = new BehaviorSubject(this.testParams);
params = this.subject.asObservable();
queryParams = this.subject.asObservable();
@icebob
icebob / saga-sample.js
Last active October 2, 2023 10:47
Saga middleware PoC for Moleculer
"use strict";
const _ = require("lodash");
const chalk = require("chalk");
const Promise = require("bluebird");
const ServiceBroker = require("../src/service-broker");
const { MoleculerError } = require("../src/errors");
// --- SAGA MIDDLEWARE ---
const SagaMiddleware = function() {