Skip to content

Instantly share code, notes, and snippets.

@armamini
armamini / check-services.sh
Created July 4, 2024 10:03
A full picture of all services and their nodes in the stack
#!/bin/bash
STACK_NAME=$1
if [ -z "$STACK_NAME" ]; then
echo "Usage: $0 <stack_name>"
exit 1
fi
services=$(docker stack services $STACK_NAME --format '{{.Name}}')
@armamini
armamini / playbook.yml
Created June 25, 2024 16:09
Ansible and Set Up Docker
---
- hosts: all
become: true
vars:
container_count: 4
default_container_name: docker
default_container_image: ubuntu
default_container_command: sleep 1d
tasks:
@armamini
armamini / nx.conf
Created June 16, 2024 09:06
NginX - Define a zone to track connections from each IP
http {
limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;
# Define a zone to track requests from each IP
limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=10r/s;
server {
listen 80;
server_name example.com;
# Rate limit requests
limit_req zone=req_limit_per_ip burst=20;
# Limit maximum number of connections from a single IP
@armamini
armamini / shepherd.config.sh
Created June 9, 2024 09:49
Shepherd Config
docker service create --name shepherd \
--constraint "node.role==manager" \
--env SLEEP_TIME="2m" \
--env ROLLBACK_ON_FAILURE="true" \
--env IMAGE_AUTOCLEAN_LIMIT="5" \
--env UPDATE_OPTIONS="--update-delay=30s" \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock,ro \
containrrr/shepherd
@armamini
armamini / dc.sh
Created June 1, 2024 09:34
Docker installation in EC2
#!/bin/bash
apt-get upgrade -y
apt-get install ca-certificates curl gnupg lsb-release
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get install apache2
apt-get update
@armamini
armamini / delog.js
Last active February 8, 2024 09:11
Delete all 'console.log' lines across anywhere of your project
const fs = require('fs');
const path = require('path');
// Recursive function to get all .ts and .js files in a directory
function getFiles(dir) {
let files = [];
fs.readdirSync(dir).forEach(file => {
const filePath = path.join(dir, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
@armamini
armamini / couline.js
Created January 24, 2024 09:28
Count your TS project Lines
const fs = require('fs');
const path = require('path');
function countLinesInFile(file) {
const content = fs.readFileSync(file, 'utf8');
return content.split('\n').length;
}
function countLinesInDirectory(dir) {
let totalLines = 0;