Skip to content

Instantly share code, notes, and snippets.

View mrizwan47's full-sized avatar
👋
Open to work

Rizwan mrizwan47

👋
Open to work
View GitHub Profile
@mrizwan47
mrizwan47 / full_code.php
Last active March 22, 2024 21:20
Show multiple WP Objects on same permalink structure with add_rewrite_rule and pre_get_posts.
<?php
// Adding a custom rewrite rule
add_action('init', 'custom_rewrite_rule');
function custom_rewrite_rule() {
add_rewrite_rule('^([^/]*)/?', 'index.php?page_or_city=$matches[1]', 'top');
}
// Registering the custom query variable
add_filter('query_vars', 'custom_query_vars_filter');
@mrizwan47
mrizwan47 / script.py
Last active April 21, 2023 15:05
ShipHero GraphQL API to add Webhook Listener
import requests, json
username = "email@domain.com"
password = "YOURPASSWORDHERE"
webhook = "https://yoursite.com/?shiphero-webhook=819284691"
shop_name = "ShopName"
# Authenticate
auth = requests.post("https://public-api.shiphero.com/auth/token", json={
"username": username,
@mrizwan47
mrizwan47 / script.py
Created March 27, 2023 09:05
Use Python Selenium to Delete bulk delete posts in WordPress (without WP REST API)
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from chromedriver_py import binary_path
# Your WordPress credentials
username = "your_username"
@mrizwan47
mrizwan47 / pandas_df_to_csv_in_chunks.py
Created January 26, 2023 11:30
Save Pandas dataframe to csv in chunks
import pandas as pd
df = pd.read_csv('large_file.csv')
n = 49000 # Max number of rows you want each chunk to have
chunks = [df[i:i+n].copy() for i in range(0,df.shape[0],n)]
k = 1
for chunk in chunks:
chunk.to_csv('data/chunk_{}.csv'.format(k), index=False)
@mrizwan47
mrizwan47 / email_sender.py
Created October 18, 2022 12:37
Send Email with Python using Google SMTP
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def notify(receiver_address, subject, mail_content):
sender_address = 'your_email@domain.com'
sender_pass = '16_CHARACTER_PASS_HERE'
message = MIMEMultipart()
@mrizwan47
mrizwan47 / instructions.md
Created August 5, 2022 11:42
wp-env | increase upload_max_filesize
  1. CD into the theme/plugin dir: cd /path-to-your-theme-or-plugin
  2. Edit .htaccess file using vi inside the docker container using this command: wp-env run cli vi .htaccess
  3. Add the following line at the end of the file: php_value upload_max_filesize "8M"
  4. Close the vi by pressing escape a few times and then writing this: :wq and hit enter.
@mrizwan47
mrizwan47 / lazy-load.html
Last active April 12, 2022 19:30
Minimal VanillaJS LazyLoad Images using Intersection Observer
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<img loading="lazy" data-lazy
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkqAcAAIUAgUW0RjgAAAAASUVORK5CYII="
@mrizwan47
mrizwan47 / function.php
Created March 28, 2022 10:19
PHP - Get google uule by location name
// Following the direction from https://moz.com/blog/geolocation-the-ultimate-tip-to-emulate-local-search
function convert_uule( $location_name )
{
// Code for length that resets at 64
$len = strlen($location_name) % 64;
// uule mapping array
$uule_map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
@mrizwan47
mrizwan47 / commands
Created September 19, 2021 12:32
systemd service for jupyter notebook
systemctl daemon-reload
systemctl enable jupyter.service
systemctl start jupyter.service
@mrizwan47
mrizwan47 / add_users.sql
Last active July 8, 2021 18:00
Create new WP user in wpengine through phpmyadmin
INSERT INTO
`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`)
VALUES (
NULL, 'rizwan', MD5('PASSWORD_HERE'), 'Riz', 'hi@iamrizwan.me', '', NOW(), '', '0', 'Rizwan');
SET @WPUserID = LAST_INSERT_ID();