Skip to content

Instantly share code, notes, and snippets.

View memandip's full-sized avatar
🎯
Focusing

Mandip Tharu memandip

🎯
Focusing
  • Kathmandu, Nepal
View GitHub Profile
@memandip
memandip / db_backup.sh
Created February 7, 2021 10:43
Bash script to backup MySQL data
#!/bin/bash
monthname=$(date +%b)
monthdayname=$(date +%d)
yearname=$(date +%Y)
hour=$(date +%H)
minute=$(date +%M)
exportname="db_backup_${monthname}_${monthdayname}_${yearname}_${hour}_${minute}.sql"
// You may need to pass db credentials depending on your mysql-server setup
@memandip
memandip / fix-docker-run-permission
Created February 4, 2021 08:14
Fix docker run issue without SUDO
# sudo chmod 666 /var/run/docker.sock
@memandip
memandip / es-docker-max-file
Last active February 2, 2021 11:11
Update file max, max map count and ulimit for linux
-------------------------------------------------------------
You can use the following config in docker-compose.yml
ulimits:
nofile:
soft: 65536
hard: 65536
OR
-------------------------------------------------------------
fs.file-max = 65535
@memandip
memandip / add_ssh_remote_server
Created January 20, 2021 09:37
add ssh key to remote server from terminal
ssh remote_user@remote_ip "echo "$(cat ~/.ssh/id_rsa.pub)" >> ~/.ssh/authorized_keys"
@memandip
memandip / mysql-remote-connection
Created January 10, 2021 18:53
Allow remote connections to remote mysql server
1. vim /etc/mysql/mysql.conf.d/mysqld.cnf or /etc/mysql/my.cnf
2. Add following code to any one of above file
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
log-error = /var/log/mysql/error.log
bind-address = 0.0.0.0
@memandip
memandip / unicode-slugify
Created December 19, 2020 19:07
Create slug preserving unicode characters
function slugify($title){
$slug = preg_replace('/\s+/u', '-', trim($title));
$slug = preg_replace("/[~`{}.'\"\!\@\#\$\%\^\&\*\(\)\_\=\+\/\?\>\<\,\[\]\:\;\|\\\]/", "", $slug);
return $slug;
}
@memandip
memandip / swap
Last active November 10, 2022 08:35
create or update swap ubuntu
If swapfile already exists
sudo swapoff -a
sudo fallocate -l 2G /swapfile
If the fallocate utility is not present on your system, or you get an error message saying fallocate failed: Operation not supported, use the following command to create the swap file:
sudo dd if=/dev/zero of=/swapfile bs=1024 count=2097152 (2 * 1024 * 1024)
Set the file permissions to 600 to prevent regular users to write and read the file:
sudo chmod 600 /swapfile
@memandip
memandip / g-recaptcha.php
Last active August 18, 2020 10:44
Google recaptcha v2 validation server side implementation in PHP
public function validate($response = "captcha token generated from client side")
{
$url = "https://www.google.com/recaptcha/api/siteverify";
$data = [
'secret' => 'google_site_secret',
'response' => $response
];
$options = [
'http' => [
@memandip
memandip / .htaccess
Last active July 31, 2020 17:57
htaccess configuration for symfony 3 app
Options +FollowSymLinks
RewriteEngine On
# For all URL starting with nice-admin, assets, limitless
RewriteCond %{REQUEST_URI} ^/?(nice-admin|assets|limitless)(/.*)?$ [NC]
RewriteRule ^.*$ /web/%1%2 [L]
RewriteRule ^ web/app.php [L]

Zip excluding specific directories

Exclude .git file and node_modules directory

$ zip -r9 [target_file] [source_file] -x *.git* node_modules/\*

Exclude .git file and files in node_modules directory, but keep node_modules directory

$ zip -r9 [target_file] [source_file] -x *.git* node_modules/**\*