Skip to content

Instantly share code, notes, and snippets.

@sumitpore
sumitpore / Commands.txt
Created April 4, 2020 09:09
Installing pcov extension on MacOS to be used with Local by Flywheel
git clone https://github.com/krakjoe/pcov.git
cd pcov
/usr/local/bin/phpize
./configure
export INCLUDE_PATH=/Applications/Local.app/Contents/Resources/extraResources/lightning-services/php-7.3.5+3/bin/darwin/include
make CPPFLAGS="-I${INCLUDE_PATH}/php -I${INCLUDE_PATH}/php/main -I${INCLUDE_PATH}/php/TSRM -I${INCLUDE_PATH}/php/Zend -I${INCLUDE_PATH}/php/ext -I${INCLUDE_PATH}/php/ext/date/lib"
sudo make install
sudo cp $(php-config --extension-dir)/pcov.so /usr/local/php/extensions
@sumitpore
sumitpore / download-object-as-json-file-from-developer-tools.js
Created March 22, 2020 06:52
Downloading Object as a JSON file from Developer Tools
// Copy below code in console tab of developer tools
// Define JSON.decycle function
if (typeof JSON.decycle !== "function") {
JSON.decycle = function decycle(object, replacer) {
"use strict";
var objects = new WeakMap(); // object to path mappings
return (function derez(value, path) {
@sumitpore
sumitpore / clone-object-excluding-keys.js
Created March 22, 2020 06:46
Copy/Clone Object excluding specific keys
function _objectWithoutProperties(obj, keys) {
var target = {};
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
}
return target;
}
@sumitpore
sumitpore / replace-tags.php
Created March 21, 2020 06:05
Example of Replacing Tags using PHP
<?php
/**
* Replaces <i> and <b> tags with <em> and <strong> tags.
*
* @param string $string The input string.
* @return string The filtered text.
*/
function replaceTagsIB($string) {
$pattern = array('`(<b)([^\w])`i', '`(<i)([^\w])`i');
$replacement = array("<strong$2", "<em$2");
@sumitpore
sumitpore / git merge using CLI.txt
Last active March 17, 2020 09:27
Merging Through CLI
git fetch origin
git checkout -b "source-branch" "origin/source-branch"
git checkout "origin/target-branch"
git merge --no-ff "source-branch"
git commit -m "Commit Message"
git push origin HEAD:target-branch
@sumitpore
sumitpore / process.md
Created February 20, 2020 15:11
How deliciousbrains's WordPress Backgrounnd Processing class work behind the scene

Usually, we first create a object of a class extending WP_Background_Processing class. Then we create a queue, save queue & dispatch queue.

Calling dispatch method does two things

1. Schedule Healthcheck cron to run every 5 minutes. @see `schedule_cron_healthcheck`
2. Call Ajax request that processes queue.

Ajax Request's callback is maybe_handle. @see WP_Background_Processing::maybe_handle(); This maybe_handle terminates itself if any batch of respective background class is already in process. So essentially, only one batch is allowed to execute at any point.

@sumitpore
sumitpore / default-values.php
Last active February 3, 2020 16:34
Sample WordPress Settings Page Examples. With and Without Tabs Both!
<?php
/**
* This file contains common functions required in both implementations.
*/
/**
* Provides default values for the Social Options.
*/
function sandbox_settings_default_social_options() {
@sumitpore
sumitpore / sample-directory-structure.txt
Last active January 29, 2020 04:07
WordPress Plugin Directory Structure
.
├── admin-resources # Holds Admin related CSS, JS and Templates
│   ├── css
│   ├── js
│   └── templates
├── frontend-resources # Holds Frontend related CSS, JS and Templates
│   ├── css
│   ├── js
│   └── templates
├── custom-packages # Composer packages built or modified for Project
@sumitpore
sumitpore / email-link-issue.patch
Created November 5, 2019 12:58
WP Socializer Patch
@sumitpore
sumitpore / nginx-service.sh
Created November 1, 2019 03:09
nginx-service
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon