Skip to content

Instantly share code, notes, and snippets.

View Max95Cohen's full-sized avatar

Max Cohen Max95Cohen

View GitHub Profile
@Max95Cohen
Max95Cohen / mysql
Created February 14, 2023 08:34
mysql tips
Kill sleeped connections
for i in `mysql -u root -e "show processlist" | awk '/Sleep/ {print $1}'` ; do mysql -e "KILL $i;"; done
MYSQL reset password
sudo systemctl stop mysql
sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
sudo systemctl start mysql
sudo mysql -u root
@Max95Cohen
Max95Cohen / git
Created February 14, 2023 08:33
git tips
Local and remote updates
local-pc: git reset --hard HEAD~33
local-pc: git push origin +HEAD:master
remote-pc: git reset --hard HEAD~33
remote-pc: git pull
Reset last push commit
git push -f origin last_known_good_commit:branch_name
@Max95Cohen
Max95Cohen / bind9
Created February 14, 2023 08:33
bind9 dns tips
$ sudo apt install bind9
$ cd /etc/bind
$ sudo vim named.conf.options
forwarders {
192.168.1.1; // Local office modem IP address
8.8.8.8;
};
allow-transfer {
192.168.1.1;
};
@Max95Cohen
Max95Cohen / ffmpeg
Last active November 23, 2024 05:54
ffmpeg tips
ffmpeg -i input.jpg -vf scale=320:240 output_320x240.jpg
ffmpeg -y -i input.jpg -vf "scale='min(500,iw)':'min(500,ih)'" output_500x500.png
ffmpeg -y -i input.jpg -vf "crop=in_h" output_center.png
ffmpeg -y -i input.jpg -vf "scale=w='min(500,in_h):h=-1'" output_center1.png
ffmpeg -y -i input.jpg -vf "scale=w='min(1000,in_h):h=-1',crop=out_w=in_h,scale=w='min(200,in_h):h=-1" output_center2.png
ffmpeg -i input1.mov -vcodec copy -acodec copy out1.mp4
ffmpeg -i input1.mov -q:v 0 output1.mp4
ffmpeg -i input.mkv -codec copy output.mp4
#ffmpeg -i 1000x1250.jpg -vf scale=w=300:h=300:force_original_aspect_ratio=increase,crop=300:300 temp.jpg -y
@Max95Cohen
Max95Cohen / centos
Created February 14, 2023 08:31
centos tips
# Server autologin
cp /lib/systemd/system/getty@.service /etc/systemd/system/getty@tty1.service
[Service]
ExecStart=-/sbin/agetty --autologin root --noclear %I
# Increase LVM size of root folder /
df -h
cp -a /home /home2
umount /dev/mapper/centos-home
@Max95Cohen
Max95Cohen / ubuntu
Last active March 1, 2023 05:17
ubuntu tips
# Ubuntu welcome text disable
sudo chmod -x /etc/update-motd.d/*
# Ubuntu remove/hide user from login screen
/var/lib/AccountsService/users/XXX
[User]
SystemAccount=true
# Ubuntu Server autologin
/etc/systemd/system/getty@tty1.service.d/override.conf
@Max95Cohen
Max95Cohen / prepare-commit-msg
Created February 9, 2023 05:17
prepare-commit-msg git hook to add prefix for commit message
#!/bin/bash
FILE=$1
MESSAGE=$(cat $FILE)
REGEX_ISSUE_ID="^((ISSUE|TASK)\-[0-9]+:\s)"
ISSUE_ID_IN_COMMIT=$(echo $MESSAGE | grep -o -E "$REGEX_ISSUE_ID")
if [[ -z "$ISSUE_ID_IN_COMMIT" ]]; then
BRANCH_NAME=$(git symbolic-ref --short HEAD)
echo "$BRANCH_NAME: $MESSAGE" > $FILE
@Max95Cohen
Max95Cohen / iptables
Last active February 28, 2023 09:18
iptables examples
# show, delete
iptables -t nat -v -L PREROUTING -n --line-number
iptables -t nat -D PREROUTING 5
# forward
iptables -t nat -A PREROUTING -i ens3 -p tcp --dport 33080 -j DNAT --to 10.0.27.67:33080
# Global IP to Local IP Ubuntu
iptables -t nat -A OUTPUT -p all -d 123.45.67.89 -j DNAT --to-destination 127.0.0.1
@Max95Cohen
Max95Cohen / .htaccess
Created January 31, 2023 04:23
.htaccess examples
# http://maq.kz/123/
RewriteRule ^([1-9]+)/$ index.php?article=$1 [L]
## ajax http://maq.kz/dnfksnfsk/scripts/mslmflsmfsl/
RewriteRule ^(.+)/scripts/ scripts.php [L]
## pages http://maq.kz/page/123
RewriteRule ^page/(.*)$ index.php?a=1&b=2&c=$1 [L]
##
@Max95Cohen
Max95Cohen / commit-msg
Created January 27, 2023 18:01
commit-msg git hook
#!/bin/bash
REGEX_ISSUE_ID="^((ISSUE|TASK)\-[0-9]+)"
ISSUE_ID_IN_COMMIT=$(echo $(cat "$1") | grep -o -E "$REGEX_ISSUE_ID")
if [[ -z "$ISSUE_ID_IN_COMMIT" ]]; then
BRANCH_NAME=$(git symbolic-ref --short HEAD)
RED='\033[0;31m'
NC='\033[0m' # No Color