Skip to content

Instantly share code, notes, and snippets.

View mbparvezme's full-sized avatar

M B Parvez (Ron) mbparvezme

View GitHub Profile
$testUsername = "webdevronsocial";
$regEx = '/^@?([a-zA-Z0-9_]{1,15})$/';
if( preg_match( $regEx, $testUsername ) ){
/* This is valid, play your code here */
}
$testUsername = "https://twitter.com/webdevronsocial";
$regEx = '/(?:https?:\/\/)?(?:www\.)?twitter\.com\/(?:#!\/)?@?([a-zA-Z0-9_]{1,15})/';
if( preg_match( $regEx, $testUsername, $matches ) ){
/**
This is valid, play your code here
- $matches[0] will returns the profile URl
- $matches[1] will returns the Username
*/
}
@mbparvezme
mbparvezme / clicked-outside-the-target.js
Last active March 4, 2024 07:27
This code will check whether you clicked inside the target or not
var targetElem = document.querySelector("#sidebar");
window.addEventListener('click',function(e){
if( !targetElem.contains(e.target) && (!document.getElementById('navSwitch').contains(e.target))){
$(targetElem).removeClass('open')
}
})
// Button/Link: #backToTopBtn
document.getElementById('backToTopBtn').addEventListener('click', () => {
var start = window.pageYOffset, startTime = null
let step = (timestamp) => {
if (!startTime) startTime = timestamp
var progress = timestamp - startTime,
percentage = Math.min(progress / 1000, 1)
window.scrollTo(0, start * (1 - percentage))
if (progress < 1000) window.requestAnimationFrame(step)
window.addEventListener('scroll', function() {
document.querySelector('.navbar').classList.toggle('nav-transform', window.scrollY >= 50);
});
var warnings = ["First warning!! Do not try to leave or close the window.", "Last warning!! Do not try to leave or close the window.", "Sorry!! Your account locked."];
var i = 0;
window.addEventListener("mouseout", function(e) {
if (!e.relatedTarget || e.relatedTarget.nodeName == "HTML") {
i++;
if (i <= 3) {
alert(warnings[i - 1]);
if (i == 3) {
window.location.replace("http://example.com/lock-window");
}
@mbparvezme
mbparvezme / number-input.html
Created March 8, 2020 20:41
HTML number input - Best practice
<input type="text" name="inputName" inputmode="numeric" pattern="[0-9]*" />
@mbparvezme
mbparvezme / webP-to-wp.php
Last active July 4, 2021 08:09
Upload WebP image files to Wordpress
// --- TESTED WITH WordPress 5.3.2
// --- ADD BELLOW CODE TO function.php
//** Enable upload for webp image files */
function webp_upload_mimes($existing_mimes) {
$existing_mimes['webp'] = 'image/webp';
return $existing_mimes;
}
//** Enable preview / thumbnail for webp image files */
var _memberMenus = document.getElementsByTagName('button');
var _confirmed = false;
var _i = 0;
var _f = 0;
var _resetAttempted = false;
function clickMemberMenu() {
if (typeof(_memberMenus[_f]) !== 'undefined' && _memberMenus[_f].getAttribute('aria-label') == 'Member Settings') {
_resetAttempted = false;
// Copy-column.sql
UPDATE `table1` SET
`table1`.`col` = (SELECT `table2`.`col` FORM `table2` where `table1`.`ID` = `table2`.`fid`)
// REPLACE
UPDATE table SET col = REPLACE(col,',','')
// TRIM
UPDATE table SET col = TRIM(col);