Skip to content

Instantly share code, notes, and snippets.

@junaidtk
junaidtk / ES6 Features
Created October 5, 2022 06:33
Javascript ES6 Features
ES6 Features:
Classes.
Arrow functions.
Variable (let, var, const)
Array methods like .map().
Destructuring.
Modules.
Ternary Operator.
Spread Operator.
@junaidtk
junaidtk / Temporal Dead Zone and Hoisting
Created October 5, 2022 05:55
Temporal Dead Zone (TDZ) and Hoisting in JavaScript
Temporal Dead Zone (TDZ) and Hoisting in JavaScript:
Temporal Dead Zone:
===================
Area of a block where the javascript variable is inaccessible untill the moment the computer completely intialised.
Block is a pair of braces used to group multiple braces.
Initialisation means: assigning a value to a variable.
WP-CLI
=======
WP-CLI is a command line interface for wordpress. You can install WP, update plugin, install plugin, configure multisite and Much more without using web browser.
Download the wp-cli.phar file using wget or curl.
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Then, check if it works:
@junaidtk
junaidtk / gist:083cc795bb0b1518fd2e3c136461bc69
Created November 9, 2021 05:28
How to transfer a repository into a new repository using source tree
When we need to transfer/import a repository into new repository without loosing the all the prior commits.
Then follow the below steps.
1) Create a new repo with no any previous/initial commits like gitignore files or readme files.
Because this will create conflict with existing repo file of old repository.
2) Then clone the remote repo into a desired folder on your local system.
3) Checkout all the required remote branches in to the local branch.
@junaidtk
junaidtk / WordPress Some Basic Snippets
Last active October 22, 2021 05:24
WordPress Basics Snippets
1) is_admin() check and AJAX Call
=================================
// Is admin, but not doing ajaax
if( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
require_once('admin/functions_admin.php');
}
// Is doing AJAX
else if ( is_admin() && ( defined( 'DOING_AJAX' ) || DOING_AJAX ) ) {
require_once('functions_ajax.php');
}
@junaidtk
junaidtk / CSV export in php
Created October 22, 2021 04:30
Export data as CSV
<?php
$csv_data = generate_csv_file_data($from_date, $to_date);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"report.csv\";" );
@junaidtk
junaidtk / Regular Expression creation basics
Last active September 3, 2021 07:35
Regex or Regular Expression.
Regular expression are patterns/combination of charactor used to match character, group of character or any combinations in a string.
$regular_expression = '';
Regular expression is pattern which is enclosed between slashes.
So our reqular expression become,
$regular_expression = '//';
^ This will match the begining of a line.
$ will indicate the end of a line.
So $regular_expression become,
The eval is used to execute the a string value. If you want to execute a string value like
an arithmetic string eg: "4+3*6", then you can use the eval function to calculate the string.
In php and javascript you can use the eval() function.
Javascript:
===========
The eval() function will leads to many syntax error whenever the statement inside the function is not executable.
So you can use the try{}catch{} method.
var statement = "4+3*6";
1)Get the last element of array:
===============================
let numbersArr = [4, 8, 9, 34, 100];
numbersArr[numbersArr.length - 1]; //return 100
2)Get a random number in a specific range:
=========================================
// Random number between 0 and 4.
Math.floor(Math.random() * 5);
// Random number between 0 and 49.
1)Using transform styling:
=====================
.child {
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}