Skip to content

Instantly share code, notes, and snippets.

@duzun
duzun / psmem
Created March 15, 2017 08:33
Process Memory consumption - Linux
#!/bin/bash
#############################################
# Process Memory consumption #
# #
# Usage: psmem <process_name> [<user_grep>] #
# psmem nginx #
# psmem php5-fpm www-data #
# #
# Author: Dumitru Uzun (DUzun.me) #
@duzun
duzun / arch_enable_bbr.sh
Last active March 3, 2023 09:07
Enable TCP BBR
#!/bin/bash
#
# A script to enable TCP BBR on a Linux system.
#
# @author Dumitru Uzun (DUzun.Me)
# @version 1.0.0
# @distro ArchLinux/Manjaro
#
old_cc=`sysctl net.ipv4.tcp_congestion_control | awk -F= '{print $2}' | sed -e s/\^\\s//`
@duzun
duzun / Dockerfile
Created August 29, 2017 13:10
SSHD for Alpine container
FROM httpd:2.4-alpine
# SSHD #################################
RUN apk update && \
apk add openssh augeas && \
mkdir -p ~root/.ssh /etc/authorized_keys && chmod 700 ~root/.ssh/ && \
augtool 'set /files/etc/ssh/sshd_config/AuthorizedKeysFile ".ssh/authorized_keys /etc/authorized_keys/%u"' && \
augtool 'set /files/etc/ssh/sshd_config/PermitRootLogin yes' && \
augtool 'set /files/etc/ssh/sshd_config/PasswordAuthentication yes' && \
augtool 'set /files/etc/ssh/sshd_config/Port 22' && \
@duzun
duzun / findByKey.php
Last active February 7, 2018 09:29
Find a value in an array by key recursively
<?php
// Note:
// Whether $list contains a NULL value for $needle at some level, or there is no $needle at all,
// in both cases this function returns NULL.
// If you want to find non-NULL $needle only, replace `array_key_exists` with `isset`
function findByKey($list, $needle) {
$stack = [$list];
while( !empty($stack) ) {
@duzun
duzun / cron_eye_safe.sh
Last active August 6, 2018 12:49
Install notifications every 20 min and 2 hours to rest your eyes - KDE on Linux
#!/bin/sh
#
# Keep your eyes safe on cron
#
# @author Dumitru Uzun (DUzun.Me)
# @web https://gist.github.com/duzun/99bd0d1cba6c8ad1b5bf321c2689a257
#
_user=${USER:-$(whoami)}
@duzun
duzun / fix_lib_links.sh
Created December 25, 2018 23:04
Fix /usr/lib/lib*.so links, in the case you `cp`ed lib folder from a backup (use `rsync -a`, not `cp`!)
@duzun
duzun / php_sess_to_redis.sh
Last active July 4, 2019 10:36
Bash script to import PHP session files into redis
#!/bin/bash
export REDISCLI_AUTH=my-supper-strong-password-4-redis-server
TTL=$(( 24 * 3600 ))
# cd "/var/sess"
for i in sess_*; do
ex=$(( $(date +%s) - $(stat -c %Y "$i") + $TTL ))
@duzun
duzun / downlist
Last active February 7, 2020 10:59
Download media files from a m3u8 URL
#!/bin/bash
# Download a file listed in a list file
# @author Dumitru Uzun (DUzun.Me)
# @version 1.0.1
_me_="$(basename "$0")"
_start_time_=$(date +%s)
referer=
_cat_=
@duzun
duzun / shiftsrt.js
Last active February 7, 2020 10:59
Shift time in .srt subtitles file
#!/bin/node
/*jshint esversion: 9*/
/**
* Time-shift video subtitles in a .srt file.
*
* Usage:
* shiftsrt.js seconds input_file|- [output_file|-]
*
* Examples:
@duzun
duzun / casign
Created February 24, 2020 14:23
Create a SSL certificate signed by your CA root certificate.
#!/usr/bin/env bash
##
# Sign a certificate using my root_ca.
#
# Note: duzun_root_ca.crt must be in the trusted root ca (see https://www.archlinux.org/news/ca-certificates-update/)
#
# @author Dumitru Uzun (DUzun.Me)
# @version 1.1.0
##