Skip to content

Instantly share code, notes, and snippets.

View tkt028's full-sized avatar

Khon tkt028

  • home
  • Vietnam
View GitHub Profile
@tkt028
tkt028 / reconnect.js
Created May 9, 2021 07:36 — forked from carlhoerberg/reconnect.js
How to build reconnect logic for amqplib
var amqp = require('amqplib/callback_api');
// if the connection is closed or fails to be established at all, we will reconnect
var amqpConn = null;
function start() {
amqp.connect(process.env.CLOUDAMQP_URL + "?heartbeat=60", function(err, conn) {
if (err) {
console.error("[AMQP]", err.message);
return setTimeout(start, 1000);
}
@tkt028
tkt028 / introrx.md
Created February 27, 2021 04:47 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@tkt028
tkt028 / mac-rabbitmq-setup.md
Created September 28, 2020 17:00 — forked from tomysmile/mac-rabbitmq-setup.md
Install RabbitMQ using Brew

Update Homebrew’s package database.

brew update

To install the MongoDB binaries, issue the following command in a system shell:

brew install rabbitmq
@tkt028
tkt028 / apache-airflow.md
Created April 27, 2020 05:18 — forked from shravan-kuchkula/apache-airflow.md
Install apache-airflow locally on mac

Using Docker and docker-compose to manage Apache Airflow on mac

Using our beloved docker and docker-compose, we can very quickly bring up an Apache Airflow instance on our mac.

Contents of docker-compose.yml

About the only thing you need to customize in this docker-compose.yml file is the volumes section. This will tell docker to map the given directory containing your Airflow DAGs/plugins to container file system.

version: '3'
services:
@tkt028
tkt028 / monit
Created March 29, 2020 16:09 — forked from roman01la/monit
Node.js + Nginx + Varnish + Upstart + Monit
check host localhost with address 127.0.0.1
start "/sbin/start myapp"
stop "/sbin/stop myapp"
if failed port 3000 protocol HTTP
request /
with timeout 5 seconds
then restart
@tkt028
tkt028 / brute-force-protection-by-ip.js
Created March 24, 2020 12:40 — forked from animir/brute-force-protection-by-ip.js
Node.js rate-limiter-flexible. Brute-force protection - Block source of requests by IP.
const http = require('http');
const express = require('express');
const redis = require('redis');
const { RateLimiterRedis } = require('rate-limiter-flexible');
const redisClient = redis.createClient({
enable_offline_queue: false,
});
const maxWrongAttemptsByIPperMinute = 5;
const maxWrongAttemptsByIPperDay = 100;
@tkt028
tkt028 / nginx-tuning.md
Created March 20, 2020 17:23 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@tkt028
tkt028 / postgres-cheatsheet.md
Created January 17, 2019 06:19 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@tkt028
tkt028 / compile_emacs.sh
Created September 20, 2016 04:26 — forked from marcwebbie/compile_emacs.sh
Compile emacs 24 on Red Hat 6 workstations
# install needed libraries
sudo yum install texinfo libXpm-devel giflib-devel libtiff-devel libotf-devel
# compile autoconf
cd /tmp
wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.bz2
tar xjvf autoconf-2.68.tar.bz2
cd autoconf-2.68/
./configure && make && sudo make install
@tkt028
tkt028 / storeImgInMongoWithMongoose.js
Created March 4, 2016 02:12 — forked from aheckmann/storeImgInMongoWithMongoose.js
store/display an image in mongodb using mongoose/express
/**
* Module dependencies
*/
var express = require('express');
var fs = require('fs');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// img path