Skip to content

Instantly share code, notes, and snippets.

@atif089
atif089 / medium-article-batch-inserts
Created September 7, 2023 23:04
medium-article-batch-inserts
const { generateFakeVote } = require('./generate-votes');
const mysql = require('mysql2/promise');
const TOTAL_INSERTS = 500_000;
const CONCURRENCY_LIMIT = 20;
const BATCH_SIZE = 10000;
const INSERT_INTERVAL = 100; // in milliseconds
const pool = mysql.createPool({
uri: `mysql://root:aa@127.0.0.1:33061/bb_votes`,
@atif089
atif089 / ab.js
Created April 21, 2023 19:54
Simple A/B Test Randomization
const crypto = require('crypto');
const { faker } = require('@faker-js/faker');
function abTest(user) {
const sessionId = user.sessionId || '';
const userAgent = user.userAgent || '';
const language = user.language || '';
const referrer = user.referrer || '';
const hash = crypto.createHash('md5').update(`${sessionId}${userAgent}${language}${referrer}`).digest('hex');
@atif089
atif089 / fix.md
Created February 22, 2023 21:42
Fix: Delete WooCommerce Analytics Cache and Re-Import Customer & Order Data

Fixes WooCommerce Analytics not reporting correctly on large websites.

Clear Exiting Cache

wp wc tool run clear_woocommerce_analytics_cache --allow-root --user=admin

If the username for admin account is different than admin

Get a list of Admins

wp user list --role=Administrator --fields=user_login --allow-root

@atif089
atif089 / gist:e8d60f9c49fea2474741866ef34b60be
Created December 14, 2022 22:46
Clone WordPress Script created by ChatGPT
#!/bin/bash
# This script assumes that wp-cli is installed and available in the system path.
# Define the name of the staging site
STAGING_SITE_NAME="staging-site"
# Define the URL of the existing WordPress website
EXISTING_SITE_URL="https://www.example.com"
@atif089
atif089 / Query
Created October 4, 2021 19:44 — forked from lukecav/Query
MySQL script to get all WooCommerce orders including metadata
select
p.ID as order_id,
p.post_date,
max( CASE WHEN pm.meta_key = '_billing_email' and p.ID = pm.post_id THEN pm.meta_value END ) as billing_email,
max( CASE WHEN pm.meta_key = '_billing_first_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_first_name,
max( CASE WHEN pm.meta_key = '_billing_last_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_last_name,
max( CASE WHEN pm.meta_key = '_billing_address_1' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_address_1,
max( CASE WHEN pm.meta_key = '_billing_address_2' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_address_2,
max( CASE WHEN pm.meta_key = '_billing_city' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_city,
max( CASE WHEN pm.meta_key = '_billing_state' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_state,
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@atif089
atif089 / docker-commands.MD
Created April 8, 2020 00:53
Docker Quick Commands

Clean up everything

docker container prune -f; docker image prune -af; docker system prune -f; docker volume prune -f;

Compose Start / Stop

docker-compose up -d --remove-orphans
docker-compose down
@atif089
atif089 / wordpress-ubuntu.sh
Last active January 21, 2020 23:50 — forked from bfocht/wordpress-ubuntu.sh
Install WordPress on ubuntu, PHP72 , apache, mysql, configure WordPress, wp-cli, phpUnit, WP Coding standards, letsencrypt
#!/bin/bash
#set the servername
SERVERNAME=
EMAIL=
mkdir /wpinstall
cd /wpinstall
#generate password for mysql
@atif089
atif089 / www-data.sh
Created May 12, 2019 06:19
Bash shell with www-data permissions
su -l www-data -s /bin/bash
@atif089
atif089 / install_wp-cli.sh
Last active May 12, 2019 06:13
Install WP CLI
## Install WP-CLI
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info
## Bash Completions
cd ~
wget https://github.com/wp-cli/wp-cli/raw/master/utils/wp-completion.bash
mv wp-completion.bash ~/wp-completion.bash