Skip to content

Instantly share code, notes, and snippets.

View mamedshahmaliyev's full-sized avatar

Mamed Shahmaliyev mamedshahmaliyev

View GitHub Profile
@mamedshahmaliyev
mamedshahmaliyev / rsync_remote_to_remote.sh
Created August 26, 2021 11:22
rsync remote to remote
ssh -R 5000:to_ip:22 root@from_ip 'rsync -e "ssh -p 5000" -vuar from_path/* localhost:to_path'
@mamedshahmaliyev
mamedshahmaliyev / linux_partitions.sh
Last active August 20, 2021 12:10
Create partitions in linux
fdisk -l # /dev/sda hdd 1, /dev/sdb hdd 2, etc
fdisk /dev/sdb. #chooose desired disk
# press m for help, press n to create partition, press w to save changes
partprobe # inform system about changes
mkfs -t ext4 /dev/sdb1 # format partition
mkdir /disk1 # create mount point
mount /dev/sdb1 /disk1 # mount created partition
# make mount permanent
#!/bin/bash
sudo firewall-cmd --permanent --zone=public --add-service=https --add-service=http
sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp.
sudo firewall-cmd --reload
sudo firewall-cmd --permanent --list-all
#!/bin/bash
sudo dnf install chrony -y
sudo systemctl enable chronyd
sudo systemctl start chronyd
timedatectl set-ntp true
timedatectl status
@mamedshahmaliyev
mamedshahmaliyev / search_replace.sh
Last active June 13, 2021 10:29
Search and Replace - grep sed
grep -rl "old" . | xargs sed -i '' 's/old/new/g'
escape single quote with: '\''
@mamedshahmaliyev
mamedshahmaliyev / aws_centos_extend_volume.sh
Last active October 7, 2021 12:48
aws extend centos free tier volume
yum install cloud-utils-growpart -y
df -hT
lsblk
sudo growpart /dev/xvda 1
sudo xfs_growfs -d /
partprobe # for system recognition
pvresize /dev/xvda 1
lvextend -r centos/root /dev/xvda1
@mamedshahmaliyev
mamedshahmaliyev / php_undefined_key_property.php
Last active February 16, 2021 06:55
Fix PHP warnings: undefined array key, property, offset etc.
<?php
/**
* Access keys or properties of array or object
* @variable array|object - array or object variable
* @key_list array|string - list of keys, valid inputs are: ['key1', 'key2'], 'key1', 'key1->key2->key3', etc.
* @default_value mixed, the default value to return if key/property does not exist
*/
function get_key($variable, $key_list, $default_value=null) {
if (!isset($variable)) return $default_value;
if (is_string($key_list)) {
# random between 10 and 5
select FLOOR(RAND()*(10-5+1)+5)
@mamedshahmaliyev
mamedshahmaliyev / HtmlTableFillPopulateVanillaJS.js
Created October 26, 2020 07:04
Populate or fill HTML table with random data in vanilla JavaScript
var table_selector = '#table_id';
var i = 0;
var content_length = 15;
document.querySelectorAll(table_selector + ' tr').forEach((row, i) => {
row.querySelectorAll('td').forEach((td, j) => {
td.innerHTML = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, content_length);
});
});
su - postgres
psql
# change user password
ALTER USER user_name WITH PASSWORD 'new_password';
\l #list databases
\c db_name # use database
\dt # list tables