Skip to content

Instantly share code, notes, and snippets.

View PatelUtkarsh's full-sized avatar
🧘

Utkarsh Patel PatelUtkarsh

🧘
View GitHub Profile
@PatelUtkarsh
PatelUtkarsh / temperature_cron.sh
Last active April 7, 2021 08:46
Setup cron to monitor raspberry pi temperature
#!/bin/bash
# Usage ./temperature_cron.sh $HOME/pi-temp-log
timestamp=`date +%F`
temp=`/opt/vc/bin/vcgencmd measure_temp`
temp=${temp:5:16}
mkdir -p $1 # make sure dir exists
echo "$(date +%H:%M:%S) = $temp" >> $1/temperature_log_$timestamp.txt # create new file for each day.
@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 / ee-vip-go-local.sh
Created May 11, 2016 05:54
Setup vip-go in local environment for site which are already created with easyengine.
#!bin/bash
#
# NOTE:This file takes param as site name for
#
# This script currenty only works with easyengine.
#
# What this does essentially is clones mu-plugin repo of vip-mu-plugins-public
# and write nginx rule to handle static files via php.
#
# WARNING: This does not match extact vip go environment like php version and stuff
@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
Last active January 14, 2020 06:01
Send pushbullet msg on website hit.
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(request) {
@PatelUtkarsh
PatelUtkarsh / index.php
Last active August 3, 2019 05:21
Attachment custom fields
<?php
namespace Utkarsh\Attachment\Meta;
const META_NAME = 'media_credit';
/**
* Bootstrap.
*/
function bootstrap() {
@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 / 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 / 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