Skip to content

Instantly share code, notes, and snippets.

@junaidtk
junaidtk / To check a javascript object is empty or not
Created December 8, 2020 04:42
Empty Javascript Object check
To check a javascript object is empty, then you can use below code.
In Newer browser empty checking:
================================
const empty = {};
Object.keys(empty).length === 0 && empty.constructor === Object;
First method:
function badEmptyCheck(value) {
return Object.keys(value).length === 0;
for node module install.
npm install
package.json:
{
"name": "test-plugin",
"description": "TODO",
"version": "2.2.0",
"main": "Gruntfile.js",
@junaidtk
junaidtk / Admin Minimum hooks
Created February 13, 2021 04:16
Plugin Development
To enqueue admin scripts.
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles_and_scripts' );
To add admin menu
$this->loader->add_action( 'admin_menu', $plugin_admin, 'admin_menu' );
public function admin_menu() {
$capability = 'manage_options';
@junaidtk
junaidtk / Grunt and npm
Created February 19, 2021 12:15
Grunt install and npm
Node.js is javacsript based environment, whcih can use to create webserver and networked applivcation.
You can also use it to perform helpful tasks on your computer such as concatenating and minifying JavaScript files and
compiling Sass files into CSS.
NPM is a “package manager” that makes installing Node “packages” fast and easy. A package, also called a module, is just a code library that extends Node by adding useful features. For example, the “request” module simplifies the process of making HTTP requests so you can easily get web resources from other sites.
NPM is installed when you install Node.js®.
https://treehouse.github.io/installation-guides/mac/node-mac.html
https://treehouse.github.io/installation-guides/mac/homebrew
1. Arrow Function
===============
In arrow function we don't need to use the key word: function
if the function contain only contain one single line, then there is no need for using the opening body bracket({}) and return key word.
if the function has only one argument, there is no need of argument paranthesis.
eg:
const sum = (a, b)=> {
return a+b;
}
@junaidtk
junaidtk / SQL vs NoSQL
Created June 3, 2021 05:51
Database Systems
SQL:
=====
They are relational database managment systems.
SQL data base uses structured query language for defining and managing data.
These have fixed, static or predefined schema.
Best suited for complex queries.
Vertically scalable (You can increase the load on a server by increasing the RAM, CPU, SSD).
Follow ACID property.
SQL data bases are tabale structure
1)Using transform styling:
=====================
.child {
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
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.
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";
@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,