Skip to content

Instantly share code, notes, and snippets.

View thangtv611's full-sized avatar

Thang Tran Viet thangtv611

  • Ho Chi Minh
  • 06:47 (UTC +07:00)
View GitHub Profile
@thangtv611
thangtv611 / amqplib-delayed-message.js
Created August 10, 2019 03:54 — forked from materkel/amqplib-delayed-message.js
Scheduling messages with RabbitMQ, using the rabbitmq_delayed_message_exchange plugin and amqplib in NodeJS
/**
* Install and enable the rabbitmq_delayed_message_exchange plugin as described by Alvaro Videla in this blogpost:
* https://www.rabbitmq.com/blog/2015/04/16/scheduling-messages-with-rabbitmq/
*/
const amqp = require('amqplib');
const exchange = 'yourExchangeName';
const queue = 'yourQueueName';
const queueBinding = 'yourQueueBindingName';
// Message consumer
@thangtv611
thangtv611 / challange.md
Created June 5, 2021 15:30
MySQL employees sample database challange

Problem 1

-- Find the number of Male (M) and Female (F) employees in the database and order the counts in descending order.

SELECT 
    gender, COUNT(*) AS totalGender
FROM
    employees
GROUP BY gender
ORDER BY totalGender DESC;
@thangtv611
thangtv611 / rsa.js
Created July 5, 2021 04:39 — forked from sohamkamani/rsa.js
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,
})

MYSQL

use native password

SET GLOBAL validate_password.LENGTH = 4;
SET GLOBAL validate_password.policy = 0;
SET GLOBAL validate_password.mixed_case_count = 0;
SET GLOBAL validate_password.number_count = 0;
SET GLOBAL validate_password.special_char_count = 0;
SET GLOBAL validate_password.check_user_name = 0;
ALTER USER 'user'@'localhost' IDENTIFIED BY 'pass';
@thangtv611
thangtv611 / clean_code.md
Created October 14, 2021 06:47 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@thangtv611
thangtv611 / git_tricks.md
Last active November 26, 2021 02:20
Some tricks about git

Move to new remote

git clone --mirror <old-repo-url>
cd <repo-name>
git remote add new-origin <new-repo-url>
git push new-origin --mirror

Convert subfolder to a git repo:

@thangtv611
thangtv611 / grafana_telegram_bot.md
Created February 22, 2022 04:50 — forked from ilap/grafana_telegram_bot.md
Grafana Telegram Alert

Config Telegrambot for grafana's alerts.

1. Create bot

Open Telegram and search for @BotFather user and message them the following:

You
/newbot 

BotFather
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
source ~/.nvm/nvm.sh
nvm install --lts
@thangtv611
thangtv611 / vagrant-cheat-sheet.md
Created October 17, 2022 07:00 — forked from wpscholar/vagrant-cheat-sheet.md
Vagrant Cheat Sheet

Typing vagrant from the command line will display a list of all available commands.

Be sure that you are in the same directory as the Vagrantfile when running these commands!

Creating a VM

  • vagrant init -- Initialize Vagrant with a Vagrantfile and ./.vagrant directory, using no specified base image. Before you can do vagrant up, you'll need to specify a base image in the Vagrantfile.
  • vagrant init <boxpath> -- Initialize Vagrant with a specific box. To find a box, go to the public Vagrant box catalog. When you find one you like, just replace it's name with boxpath. For example, vagrant init ubuntu/trusty64.

Starting a VM

  • vagrant up -- starts vagrant environment (also provisions only on the FIRST vagrant up)
sudo apt-get install stress-ng
stress-ng --cpu 4 --vm 2 --fork 8 --switch 4 --timeout 1m
##stress-ng: info: [32254] dispatching hogs: 4 cpu, 8 fork, 4 switch, 2 vm
##stress-ng: info: [32254] cache allocate: default cache size: 8192K