Skip to content

Instantly share code, notes, and snippets.

View hanut's full-sized avatar
🌐
Building stuff

Hanut Singh Gusain hanut

🌐
Building stuff
View GitHub Profile
@hanut
hanut / gist:8f13e42d090a4a85fdf95972bd95c260
Created February 7, 2025 15:30
Get the max allocated size of memory for a nodejs process

This is a one line command for the cli that will spit out the amout of RAM allocated (approximately) to your nodejs process.

$ node -e "console.log(Math.round(require('v8').getHeapStatistics().heap_size_limit / (1024*1024)))"

The output value is in the megabytes.

@hanut
hanut / ANSI.md
Created February 19, 2023 02:53 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@hanut
hanut / PEM file from crt+key.md
Last active May 2, 2021 10:11
Generate a .pem file from crt and key

Especially useful if you are using HAProxy for SSL termination ahead of your microservices.

Just use this command

sudo cat domain.tld.crt domain.tld.key | sudo tee domain.tld.pem
@hanut
hanut / Move AWS Key across regions.md
Last active May 2, 2021 10:11
Move a key around aws regions easily

Move an AWS key across regions

Given below is a step by step process to copying keys around AWS incase you dont wish to follow the proper AWS way using the cli tool.

  1. Make sure you have your privatekey.pem file.
  2. In the AWS console, select the EC2 service.
  3. Select the Key Pairs tab in the Network and Security.
  4. Click the Actions button and select Import key pair from the options.
  5. Give the key the same name as in the other region.
  6. On your machine, navigate to the privatekey.pem and run the following
@hanut
hanut / install_node_exporter_1.0.1.md
Last active September 10, 2020 19:05
Setup Node Exporter for Prometheus

Download

cd /tmp
curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
tar -xvf node_exporter-1.0.1.linux-amd64.tar.gz
rm node_exporter-1.0.1.linux-amd64.tar.gz
sudo mv node_exporter-1.0.1.linux-amd64/node_exporter /usr/local/bin/

Setup user for Node Exporter

@hanut
hanut / manually-clone-repo.md
Last active August 29, 2020 13:27
Manually clone a git repo from X to Y

Use the following command on the cli to move a repository from one git host to another.

git clone --bare <path to original repo> <folder name> && \
cd <folder name> && \
git remote rm origin && \
git remote add origin <path to new repo> && \
git push -u origin --all && \
git push --force --tags origin &amp;&amp; \
@hanut
hanut / Clear *nix Socket Descriptors Faster
Last active March 18, 2019 11:41
Vertical Superscale
In Linux, TCP keepalive parameters are:
tcp_keepalive_intvl
tcp_keepalive_probes
tcp_keepalive_time
Their default values are:
tcp_keepalive_time = 7200 (seconds)
tcp_keepalive_intvl = 75 (seconds)
@hanut
hanut / Generate MD5
Created February 7, 2019 08:02
Cute Nodejs Snippets
const crypto = require('crypto');
let message = "Some data you want to encrypt";
let hash = crypto.createHash('md5').update(data).digest("hex");
@hanut
hanut / SSH Management in *NIX
Last active March 28, 2019 07:41 — forked from grenade/01-generate-ed25519-ssh-key.sh
Commands for ssh key management under *nix
I Will write a readme here later
@hanut
hanut / pgpurge.sh
Created September 3, 2018 10:16
Postgresql uninstall script
#!/bin/bash
sudo systemctl stop postgres
sudo apt-get --purge remove postgresql\*
sudo rm -r /etc/postgresql/
sudo rm -r /etc/postgresql-common/
sudo rm -r /var/lib/postgresql/
sudo userdel -r postgres
sudo groupdel postgres