Skip to content

Instantly share code, notes, and snippets.

View PatelUtkarsh's full-sized avatar
🧘

Utkarsh Patel PatelUtkarsh

🧘
View GitHub Profile
@PatelUtkarsh
PatelUtkarsh / feedback.js
Created April 5, 2021 11:38
Download active collab attachments from discussion
Array.from(document.getElementsByClassName('attachment_download')).forEach(function(elem) {
setTimeout(() => {
elem.click();
}, key * 2000 )
});
@PatelUtkarsh
PatelUtkarsh / amp-media-size.php
Created May 26, 2020 09:31
AMP Extract Image without external request
<?php
add_filter( 'amp_extract_image_dimensions_batch', function ( $dimensions ) {
$home_url = get_home_url();
foreach ( $dimensions as $url => &$data ) {
if ( false !== strpos( $url, $home_url ) ) {
$attachment_id = wpcom_vip_attachment_url_to_postid( $url );
if ( false !== $attachment_id ) {
$src = wp_get_attachment_image_src( $attachment_id );
$height = $src[1];
$width = $src[2];
@PatelUtkarsh
PatelUtkarsh / index.js
Created February 19, 2020 13:25
Refresh WordPress media library images - useful when editors are uploading image via 3rd party tool using REST API - Example: Mediawires so editor do not need to reload page to get new images on existing article.
jQuery( document ).ready( function () {
// Refresh media library each time on click of add media.
if ( wp.media ) {
wp.media.view.Modal.prototype.on( 'open', function () {
if ( wp.media.frame.content.get() !== null ) {
// this forces a refresh of the content.
wp.media.frame.content.get().collection._requery( true );
}
} );
}
@PatelUtkarsh
PatelUtkarsh / index.php
Last active March 6, 2025 13:51
Attachment custom fields
<?php
namespace Utkarsh\Attachment\Meta;
const META_NAME = 'media_credit';
/**
* Bootstrap.
*/
function bootstrap() {
@PatelUtkarsh
PatelUtkarsh / dnsmasq.conf
Last active June 20, 2022 00:23
stubby cloudflare ipv4 and ipv6
no-resolv
proxy-dnssec
server=::1#5353
server=127.0.0.1#5353
listen-address=::1,127.0.0.1
# Put any other line here like laravel valet using .test domain.
address=/.test/127.0.0.1
@PatelUtkarsh
PatelUtkarsh / snippet.js
Last active February 26, 2019 15:44
Get all hostname from homepage <a>
var anchors = document.querySelectorAll('a');
var hosts = new Set();
anchors.forEach((anch) => {
hosts.add(anch.hostname);
});
console.table(Array.from(hosts));
@PatelUtkarsh
PatelUtkarsh / class-demo.php
Last active December 5, 2018 08:31
Singletone trait
<?php
/**
* The Demo class.
*
* @package xyz
*/
namespace UtkarshPatel\Demo
/**
@PatelUtkarsh
PatelUtkarsh / easyengine-cask.rb
Last active November 23, 2018 16:22
Easyengine Brew core and cask formula
cask 'easyengine' do
version '4.0.0'
homepage 'https://easyengine.io/'
url 'https://github.com/EasyEngine/easyengine/releases/download/v4.0.0/easyengine.phar'
sha256 '5d7f7ec95911883240717458024f0e7c69309f7bd3646353a0594e1b0900eaa6'
name 'Easyengine'
depends_on formula: 'php'
depends_on cask: 'docker'
container type: :naked
@PatelUtkarsh
PatelUtkarsh / notify.sh
Last active January 3, 2019 01:54
Get notification when internet is up, This uses pushbullet api.
function notifynet(){
isdown=0
echo "Pres CTRL+C to stop..."
while :
do
sleep 5
if [ $(ping -q -c 1 -W 1 8.8.4.4 >/dev/null) ]; then
echo -n "1"
if [ $isdown -eq 1 ]; then
isdown=0
@PatelUtkarsh
PatelUtkarsh / fix-symlink-url.php
Last active October 29, 2018 11:03
Fix url when wp-content and mu-plugins are added as symlink.