Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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.
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 / 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.
@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.