Skip to content

Instantly share code, notes, and snippets.

@sumitpore
sumitpore / .cursorfile
Last active January 20, 2025 05:34
Temp cursorfiles
This file has been truncated, but you can view the full file.
This comprehensive guide outlines best practices,
conventions,
and standards for development with modern web technologies including VueJS,
ReactJS,
NextJS,
Redux,
TypeScript,
JavaScript,
HTML,
CSS,
@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 / 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 / phpv8js-installer.sh
Last active July 18, 2020 07:15
Installing v8js pecl extension on php 7.3
#!/bin/bash
echo "=================================="
echo "Installing Dependencies"
echo "=================================="
sudo apt-get update
sudo apt-get install \
git \
build-essential \
@sumitpore
sumitpore / closest.js
Created May 3, 2020 07:28
jQuery closest's in Pure JavaScript
if (window.Element && !Element.prototype.closest) {
Element.prototype.closest =
function(s) {
var matches = (this.document || this.ownerDocument).querySelectorAll(s),
i,
el = this;
do {
i = matches.length;
while (--i >= 0 && matches.item(i) !== el) {};
} while ((i < 0) && (el = el.parentElement));
@sumitpore
sumitpore / sort-object-by-keys.js
Last active April 28, 2020 08:56
Sort Object by Keys
function sortObjectByKeys(obj) {
var keys = Object.keys(obj).sort(function keyOrder(k1, k2) {
if (k1 < k2) return -1;
else if (k1 > k2) return +1;
else return 0;
});
var i, after = {};
for (i = 0; i < keys.length; i++) {
@sumitpore
sumitpore / chrome-local-storage-api.js
Last active October 7, 2024 11:02
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]);
});