Skip to content

Instantly share code, notes, and snippets.

View huzaifaarain's full-sized avatar
🏠
Working from home

Muhammad Huzaifa huzaifaarain

🏠
Working from home
View GitHub Profile
@huzaifaarain
huzaifaarain / Customize WP Nav Markup
Last active December 2, 2018 13:27
How to customize the markup of WP Navigation
add_filter('nav_menu_css_class', function($classes, $item, $args) {
if($args->theme_location == 'location') {
$classes[] = 'list-inline-item';
}
return $classes;
}, 1, 3);
add_filter( 'nav_menu_link_attributes', function( $atts, $item, $args ) {
if($args->theme_location == 'location') {
@huzaifaarain
huzaifaarain / Custom_Theme_Logo.md
Last active December 2, 2018 13:40
Displaying the custom logo in your theme

Displaying the custom logo in your theme

A custom logo can be displayed in the theme using the_custom_logo() function. But it’s recommended to wrap the code in a function_exists() call to maintain backward compatibility with the older versions of WordPress, like this:

if ( function_exists( 'the_custom_logo' ) ) {
    the_custom_logo();
}

Generally logos are added to the header.php file of the theme, but it can be elsewhere as well.

If you want to get your current logo URL (or use your own markup) instead of the default markup, you can use the following code:

Using Git to Manage a Live Web Site

Overview

As a freelancer, I build a lot of web sites. That's a lot of code changes to track. Thankfully, a Git-enabled workflow with proper branching makes short work of project tracking. I can easily see development features in branches as well as a snapshot of the sites' production code. A nice addition to that workflow is that ability to use Git to push updates to any of the various sites I work on while committing changes.

Contents

@huzaifaarain
huzaifaarain / readme.md
Last active December 4, 2018 12:47
Git Push From One Working Directory To Remote Working Directory Without Bare Repository

GIT: PUSH TO REMOTE WORKING DIRECTORY

In this gist we are about to push changes from one working directory to another working directory without bare repository

Lets name our directories one_working , second_working.

Lets create the one_working directory

mkdir one_working
cd one_working
@huzaifaarain
huzaifaarain / readme.md
Created December 4, 2018 12:55
What's the difference between git reset --mixed, --soft, and --hard ?

What's the difference between git reset --mixed, --soft, and --hard ?

When you modify a file in your repository, the change is initially unstaged. In order to commit it, you must stage it—that is, add it to the index—using git add. When you make a commit, the changes that are committed are those that have been added to the index.

git reset changes, at minimum, where the current branch (HEAD) is pointing. The difference between --mixed and --soft is whether or not your index is also modified. So, if we're on branch master with this series of commits:

- A - B - C (master)

HEAD points to C and the index matches C.

@huzaifaarain
huzaifaarain / readme.md
Created December 6, 2018 12:49
Get list of all product categories in WooCommerce
$orderby = 'name';
$order = 'asc';
$hide_empty = false ;
$cat_args = array(
    'orderby'    => $orderby,
    'order'      => $order,
    'hide_empty' => $hide_empty,
);
 
@huzaifaarain
huzaifaarain / functions.php
Created December 6, 2018 12:53 — forked from BFTrick/functions.php
WooCommerce add an Empty Cart button
<?php
// check for empty-cart get param to clear the cart
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
global $woocommerce;
if ( isset( $_GET['empty-cart'] ) ) {
$woocommerce->cart->empty_cart();
}
}
@huzaifaarain
huzaifaarain / readme.md
Created December 7, 2018 05:33
dpkg: error: dpkg status database is locked by another process

First run:

lsof /var/lib/dpkg/lock 

Then make sure that process isn't running:

ps cax | grep PID 
@huzaifaarain
huzaifaarain / class-virtualthemedpage-bc.php
Created December 17, 2018 12:53 — forked from brianoz/class-virtualthemedpage-bc.php
WordPress Virtual page with theme
<?php
/*
* Virtual Themed Page class
*
* This class implements virtual pages for a plugin.
*
* It is designed to be included then called for each part of the plugin
* that wants virtual pages.
*
* It supports multiple virtual pages and content generation functions.
@huzaifaarain
huzaifaarain / scrape.py
Created December 24, 2018 05:02
Web Scraping for Email Addresses and Phone numbers using Python
# Small Python Script to scrape websites for
# email addresses and phone numbers(not a very great RE)
# Author: Dhruv Baldawa (@dhruvbaldawa on twitter)
# Github: http://www.github.com/dhruvbaldawa
import urllib,re
f = urllib.urlopen("http://www.example.com")
s = f.read()
re.findall(r"\+\d{2}\s?0?\d{10}",s)
re.findall(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}",s)