Skip to content

Instantly share code, notes, and snippets.

@sumitpore
sumitpore / chrome-local-storage-api.js
Last active February 9, 2024 05:19
Chrome's Local StorageArea API in Synchronous way for use in Chrome extensions. Replace 'chrome.storage.local' by 'chrome.storage.sync' if you want to use Sync StorageArea
/**
* Retrieve object from Chrome's Local StorageArea
* @param {string} key
*/
const getObjectFromLocalStorage = async function(key) {
return new Promise((resolve, reject) => {
try {
chrome.storage.local.get(key, function(value) {
resolve(value[key]);
});
@sumitpore
sumitpore / r-debug.php
Created November 26, 2022 09:16
R Debug Plugin Created by Andrey "Rarst" Savchenko
<?php
/*
Plugin Name: R Debug
Description: Set of dump helpers for debug.
Author: Andrey "Rarst" Savchenko
Author URI: https://www.rarst.net/
License: MIT
*/
@sumitpore
sumitpore / convert-zip-structure-to-associative-array.php
Last active April 14, 2022 12:44
Convert Zip Structure to Associative Array using PHP
<?php
/**
* Borrowed from https://stackoverflow.com/a/38407568/1994640
*
* Fixed fatal errors and unwanted creation of empty arrays
*/
$filePath = 'hello.zip';
$za = new ZipArchive();
if ($za->open($filePath) !== true) { // check for the zip archive
@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 / .htaccess
Last active July 15, 2021 23:37
Disable XDEBUG Debugging for WordPress Admin Requests
# If you are debugging a code in editors like Visual Studio Code (VSCode) or Sublime
# Text and if you see that breakpoints are getting triggered due to WordPress Ajax
# requests, then XDEBUG Remote Debugging can be disabled for Ajax Requests by
# adding code below in .htaccess file.
<If "%{REQUEST_URI} =~ /admin-ajax/">
php_value xdebug.remote_enable 0
</If>
@sumitpore
sumitpore / pQuery.js
Created April 1, 2021 02:41 — forked from niyazpk/pQuery.js
Add or update query string parameter
// Add / Update a key-value pair in the URL query parameters
function updateUrlParameter(uri, key, value) {
// remove the hash part before operating on the uri
var i = uri.indexOf('#');
var hash = i === -1 ? '' : uri.substr(i);
uri = i === -1 ? uri : uri.substr(0, i);
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
@sumitpore
sumitpore / gist:d9c6434e16088f558149d383c02e0541
Created September 17, 2020 08:06
WordPress derive Timezone from gmt_offset option
function wp_timezone_object_from_gmt_offset() {
$min = 60 * get_option('gmt_offset');
$sign = $min < 0 ? "-" : "+";
$absmin = abs($min);
$tz = sprintf("%s%02d%02d", $sign, $absmin/60, $absmin%60);
return new DateTimeZone( $tz );
}
@sumitpore
sumitpore / modifyHtmlTagAttrsInString.php
Created August 19, 2020 03:56
Modify Html Tag Attributes in the HTML String
<?php
/**
* Modifies html tag attributes in the html string
*
* Remember, this will autofix the passed html. So if invalid html string is sent (e.g. `a` tag w/o end),
* then the o/p returned by function will be valid html string.
*
* Examples:
* 1. modifyHtmlTagAttrsInString(
@sumitpore
sumitpore / git-diff-commands.md
Last active August 4, 2020 11:48
Git Diff Commands

See changes which are going to be staged (i.e. before doing git add)

git diff

See changes which are staged (i.e. after doing git add)

git diff --cached

See Changes which were commited in last commit (i.e. after doing git commit)

git diff HEAD^..HEAD

@sumitpore
sumitpore / gist:aac8fc0b2b133c098c002fecc0ea88cd
Last active July 23, 2020 13:26
Git process to prevent overriding of other's code
git add .
git stash
git pull --rebase
git stash pop
git status
git commit
git push