Skip to content

Instantly share code, notes, and snippets.

View WebSofter's full-sized avatar
🌴
On vacation

David Amirkhanov WebSofter

🌴
On vacation
View GitHub Profile
@WebSofter
WebSofter / script.js
Last active November 12, 2024 03:11
Alwais add country code in phone number input with JavaScript
document.querySelector('.reg_phone').addEventListener('input', (e) => {
const code = '7'
const phone = e.target.value?.replace(/\D+/g, '');
if(phone.indexOf(`+${code}`) !== 0) {
if(phone.indexOf(code) === 0) {
e.target.value = `+${phone}`
} else {
e.target.value = `+${code}${phone.replace('+', '')}`
}
}
@WebSofter
WebSofter / script.php
Created August 19, 2024 00:10
wordpress get id by name in hierarchical custom categories
function get_term_id_by_name_and_parent($term_name, $taxonomy, $parent_id = 0) {
// Get the term by name within the specified taxonomy
$term = get_term_by('name', $term_name, $taxonomy);
// Check if the term exists and if it has the specified parent
if ($term && $term->parent == $parent_id) {
return $term->term_id;
}
// If the term wasn't found or the parent didn't match, return null
@WebSofter
WebSofter / rubrics.txt
Created August 18, 2024 11:14
Hierarchical import into wordpress custom taxonomies from structured txt file
#1 Авто и мото | avtomoto
АЗС | azs
Автобизнес | avtobizness
Автосалоны | avtosalon
Автосервисы | avtoservis
Автострахование | avtostrahovanie
Автофорумы и блоги | avtoforum
Автохимия | avtohim
Автошколы | avtoshkola
@WebSofter
WebSofter / fix.sh
Last active November 12, 2024 03:11
PyTorch CUDA is not available problem on Ubuntu Desktop
### VARIANT 1
#Run command
sudo nvidia-settings
#Ant check getting error: "ERROR: NVIDIA driver is not loaded"
#Your next steps:
sudo prime-select intel
sudo reboot
sudo prime-select nvidia
@WebSofter
WebSofter / fix.sh
Last active November 12, 2024 03:12
Ubuntu hard disk mount problem
This steps should fix "Error mounting /dev/sda2 at media/ Data:unknown error when mounting /dev/sda2"
$ sudo apt install --reinstall ntfs-3g
$ sudo ntfsfix /dev/sda2
$ sudo mount -o ro /dev/sda2 /media/websofter
@WebSofter
WebSofter / export_db.sh
Created April 25, 2023 00:40
Export mysql dump with command bash script
#!/bin/sh
location=./`date +%Y%m%d_%H%M%S`_your_db.sql
mysqldump -u root --password='your_password' your_db > $location
gzip $location
@WebSofter
WebSofter / plugin.php
Created May 10, 2022 06:13
wordpress plugin list
/********************** */
if( is_admin() && !class_exists( 'WP_List_Table' ) )
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
class B5F_WP_Table extends WP_List_Table
{
private $order;
private $orderby;
private $posts_per_page = 5;
@WebSofter
WebSofter / .env
Last active November 12, 2024 03:13
Snippet for MySQL database in docker-compose
APP_TAG=doska
MYSQL_ROOT_PASSWORD=secret
MYSQL_DB=doska
MYSQL_USER=doska
MYSQL_PASSWORD=secret
@WebSofter
WebSofter / README.md
Last active December 31, 2021 09:18
Mailu configuration for SMTP implementation

Instruction

1. Domain settings

Before you must have domain and setting it:

Type Host Value
A mail Your IP address
MX @ mail.yourdomain.com 10

Next, you have to set the hostname

@WebSofter
WebSofter / script.js
Created September 24, 2021 12:29
Get file extension in JS
function getFileExtension(filename){
let ext = /^.+\.([^.]+)$/.exec(filename)
return ext == null ? '' : ext[1].length < 5 ? ext[1] : '';
}