Skip to content

Instantly share code, notes, and snippets.

View aamsur-mkt's full-sized avatar

Aam S aamsur-mkt

View GitHub Profile
@aamsur-mkt
aamsur-mkt / my.cnf
Created September 20, 2020 16:18 — forked from fevangelou/my.cnf
Optimized my.cnf configuration for MySQL/MariaSQL (on Ubuntu, CentOS etc. servers)
# Optimized my.cnf configuration for MySQL/MariaSQL
#
# by Fotis Evangelou, developer of Engintron (engintron.com)
#
# ~ Updated January 2020 ~
#
#
# The settings provided below are a starting point for a 2GB - 4GB RAM server with 2-4 CPU cores.
# If you have different resources available you should adjust accordingly to save CPU, RAM & disk I/O usage.
#
@aamsur-mkt
aamsur-mkt / add-swap.sh
Created September 10, 2020 14:37
Add SWAP Memory 2GB Ubuntu 16.04 and up
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
sudo sysctl vm.vfs_cache_pressure=50
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
@aamsur-mkt
aamsur-mkt / exposed-string.php
Created September 10, 2020 11:40
Search Static String Variable with Regex
<?php
// regex untuk mencari static variable
$re = "/(?s)'(?:[^'\\\\]|\\\\.)*'|\"(?:[^\"\\\\]|\\\\.)*\"/";
$str = file_get_contents($_GET['file']);
preg_match_all($re, $str, $matches);
if(count($matches) <= 0){
return;
@aamsur-mkt
aamsur-mkt / stress-test.sh
Created September 9, 2020 09:25 — forked from cirocosta/stress-test.sh
naive http server stress tester using cURL
#!/bin/bash
#### Default Configuration
CONCURRENCY=4
REQUESTS=100
ADDRESS="http://localhost:8080/"
show_help() {
cat << EOF
@aamsur-mkt
aamsur-mkt / set-tz-docker.sh
Created August 28, 2020 15:35
Set Debian and Alpine Docker Timezone
## DEBIAN DOCKERFILE
ENV TZ=Asia/Jakarta
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
## ALPINE DOCKERFILE
RUN apk add --no-cache tzdata
ENV TZ Asia/Jakarta
## DEBIAN RUNNING CONTAINER
export TZ=Asia/Jakarta && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
@aamsur-mkt
aamsur-mkt / extending-no-space-left-linux-filesystem.md
Last active July 28, 2024 22:11
[increase|raise|resize] Extending Linux Filesystem in AWS, No space left on device makes some jobs failure

Example

Use the df -h command to verify that the root partition mounted under "/" is full (100%). In the following example, /dev/nvme0n1p1 is using 100% of its space.

[ec2-user ~]$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        460M     0  475M   0% /dev
@aamsur-mkt
aamsur-mkt / redis-error-memory.md
Last active June 25, 2020 03:55
REDIS - MISCONF Redis is configured to save RDB snapshots

Problem

  1. [RedisException] MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.
  2. On /var/log/redis/redis-server.log show # Can't save in background: fork: Cannot allocate memory

Explanation

This error occurs because of BGSAVE being failed. During BGSAVE, Redis forks a child process to save the data on disk. Although exact reason for failure of BGSAVE can be checked from logs (usually at /var/log/redis/redis-server.log on linux machines) but a lot of the times BGAVE fails because the fork can't allocate memory. Many times the fork fails to allocate memory (although the machine has enough RAM available) because of a conflicting optimization by the OS.

As can be read from Redis FAQ (https://redis.io/topics/faq):

Redis background saving schema relies on the copy-on-write semantic of fork in modern operating systems: Redis forks (creates a child process) t

@aamsur-mkt
aamsur-mkt / backup-import-psql.md
Created June 18, 2020 07:52
Backup Import Postgre
  1. Backup source
  2. Delete db target
  3. create db target
  4. import source to target

  1. pg_dump -U postgres -W -d example_backups > ~/Example_Dumps/ex_back_db.sql

  2. DROP DATABASE example_backups_target;

  3. CREATE DATABASE example_backups_target;

  4. psql -U postgres -W -d example_backups_target -f ~/Example_Dumps/ex_back_db.sql

@aamsur-mkt
aamsur-mkt / view-markdown-raw.md
Last active May 6, 2020 07:24
View markdown raw of Github issue comment

formula: https://api.github.com/repos/[user]/[reponame]/issues/[issue_id]/comments

example: https://api.github.com/repos/docker/compose/issues/1786/comments

then see the string value of body comment

@aamsur-mkt
aamsur-mkt / api-deploy-without-downtime.md
Last active May 15, 2020 04:31
API Deploy Without Downtime

Thanks @oelmekki for your insights. It has been very useful and encouraging when there is so few info on rolling updates with docker-compose.

I ended up writing the following script docker_update.sh <service_name>, which seems to work very decently. It relies on healthcheck command, which is not mandatory (change -f "health=healthy" accordingly) but cleaner IMHO than waiting for container to simply being up, when it takes a little time to boot (which will be the case if you run eg. npm install && npm start as a command).

#!/bin/bash

cd "$(dirname "$0")/.."

SERVICE_NAME=${1?"Usage: docker_update <SERVICE_NAME>"}