Skip to content

Instantly share code, notes, and snippets.

View Shakil-Shahadat's full-sized avatar
🏠
Working from home

Shakil Shahadat Shakil-Shahadat

🏠
Working from home
View GitHub Profile
@Shakil-Shahadat
Shakil-Shahadat / miscellaneous.php
Last active June 30, 2022 11:40
Miscellaneous PHP Codes
<?php
// Todays' date in the format 2022-01-12
echo date( 'Y-m-d' );
// Decode 'encodeURIComponent' encoded string
urldecode( );
// Sanitize $_POST array
foreach ( $_POST as $key => $value )
{
@Shakil-Shahadat
Shakil-Shahadat / loopOverArray.js
Last active December 18, 2021 01:24
Summary of 'for / in' & 'for / of' loop
let fruits = [ 'apple', 'orange', 'mango' ];
// for / of loop
for ( e of fruits )
{
// e is now an element of the array
console.log( e ); // Output: apple, orange, mango
}
// for / in loop
@Shakil-Shahadat
Shakil-Shahadat / miscellaneous.js
Last active April 18, 2024 08:23
★ Miscellaneous JavaScript Codes
// Reload current page
location.reload();
// Ref: https://developer.mozilla.org/en-US/docs/Web/API/Location/reload
// Reload page at an interval
setTimeout( function(){ location.reload(); }, 30 * 1000 ); // Reload at every 30 seconds
// Alternative
setTimeout( () => { location.reload(); }, 30 * 1000 ); // Reload at every 30 seconds
// Ref: https://developer.mozilla.org/en-US/docs/Web/API/setTimeout
@Shakil-Shahadat
Shakil-Shahadat / timing.js
Last active December 18, 2021 01:30
JavaScript Timing Events
// One time event
setTimeout( function(){}, 1000 );
// Repetitive event
setInterval( function(){}, 1000 );
// If these need to be canceled, then assign them
// to a variable and then clear them like this.
clearTimeout( assignedVar );
clearInterval( assignedVar );
@Shakil-Shahadat
Shakil-Shahadat / query.js
Last active July 6, 2022 16:51
Functions to shorten querySelector* calls in JavaScript
function qs( cls )
{
return document.querySelector( cls );
}
function qsa( cls )
{
return document.querySelectorAll( cls );
}
@Shakil-Shahadat
Shakil-Shahadat / element.js
Last active December 18, 2021 01:38
Create an Element in JavaScript
// Create an Element
let ele = document.createElement( 'div' ); // Replace 'div' with required element
// Insert Text
ele.innerText = 'Hello World!';
// or
ele.innerHTML = 'Hello World!';
// or, not recommended
let textNode = document.createTextNode( 'Hello World!' ); // Create a text node
ele.appendChild( textNode );
[{"quote": "Life isn’t about getting and having, it’s about giving and being.", "author": "Kevin Kruse"},
{"quote": "Whatever the mind of man can conceive and believe, it can achieve.", "author": "Napoleon Hill"},
{"quote": "Strive not to be a success, but rather to be of value.", "author": "Albert Einstein"},
{"quote": "Two roads diverged in a wood, and I—I took the one less traveled by, And that has made all the difference.", "author": "Robert Frost"},
{"quote": "I attribute my success to this: I never gave or took any excuse.", "author": "Florence Nightingale"},
{"quote": "You miss 100% of the shots you don’t take.", "author": "Wayne Gretzky"},
{"quote": "I’ve missed more than 9000 shots in my career. I’ve lost almost 300 games. 26 times I’ve been trusted to take the game winning shot and missed. I’ve failed over and over and over again in my life. And that is why I succeed.", "author": "Michael Jordan"},
{"quote": "The most difficult thing is the decision to act, the rest is merely tenacity.", "author": "
@Shakil-Shahadat
Shakil-Shahadat / common.css
Last active November 23, 2020 22:49
Some Common CSS Styles I Regularly Use
body
{
font-family: 'Segoe UI', Verdana, Arial, Helvetica, sans-serif;
background-color: whitesmoke;
line-height: 26px;
}
.container
{
background: white;
border: 1px solid silver;
@bbrochier
bbrochier / gotop.css
Last active May 27, 2018 19:00
Go Top Sticky button
/* Go Top */
.go-top {
position: fixed;
bottom: 2em;
right: 2em;
text-decoration: none;
color: white;
background-color: #f6f6f6;
background-color: rgba(0, 0, 0, 0.3);
font-size: 12px;
@ingowennemaring
ingowennemaring / scrolltotop.js
Created April 18, 2013 14:16
Scroll to top of page
$('.goto-top').on(
'click',
function(e){
e.preventDefault();
$('html, body').animate( { scrollTop: 0 } );
}
);