Skip to content

Instantly share code, notes, and snippets.

View gonzomir's full-sized avatar

Milen Petrinski gonzomir

View GitHub Profile
@kingkool68
kingkool68 / maybe-sideload.php
Created November 21, 2020 04:19
Two WordPress functions for maybe side loading URLs to the media library. Useful for content migrations that need to be run multiple times without producing duplicate downloads.
<?php
/**
* Example useage:
*
* maybe_sideload_image( 'https://dummyimage.com/600x400/000/fff.png' ); // Downloads image to the media library and returns an attachment ID
* maybe_sideload_image( 'https://dummyimage.com/600x400/000/fff.png' ); // Returns an attachment ID as the image has already been downloaded and added to the media library
*/
/**
@adactio
adactio / _polyfills.js
Created November 9, 2020 17:19
JavaScript polyfills for matches,closest, and forEach.
// https://github.com/jonathantneal/closest/blob/master/src/index.js
var ElementPrototype = window.Element.prototype;
if (typeof ElementPrototype.matches !== 'function') {
ElementPrototype.matches = ElementPrototype.msMatchesSelector || ElementPrototype.mozMatchesSelector || ElementPrototype.webkitMatchesSelector || function matches(selector) {
var element = this;
var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
var index = 0;
while (elements[index] && elements[index] !== element) {
++index;
}
@tomjn
tomjn / tomjn_http2_push.php
Created January 25, 2019 23:43
A naive and incomplete, but functional approach to http2 push
<?php
/**
* Plugin name: HTTP2 Push scripts
* Author: Tom J Nowell
*/
function tomjn_get_dep_url( /*\WP_Dependency*/ $dep ) {
global $wp_version;
$relative = str_replace( site_url(), '', $dep->src );
$ver = $dep->ver;
<?php
/**
* Plugin Name: Offload API Helper
* Plugin URI: iwritecode.blog
* Description: Offload plugins during API requests to reduce overhead.
* Author: Chris Kelley
* Author URI: iwritecode.blog
* Version: 1.0.0
*/
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active May 22, 2024 08:34
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@pento
pento / php-block.js
Last active February 29, 2024 01:31
Converting a shortcode to a block: this method is fast to do, but a mediocre UX. You should only use this as a stopgap until you can implement a full block UI.
// License: GPLv2+
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender,
TextControl = wp.components.TextControl,
InspectorControls = wp.editor.InspectorControls;
/*
* Here's where we register the block in JavaScript.
@yradunchev
yradunchev / xrupdate
Created June 17, 2018 18:27
download xr from DSK Bank to ledger-cli prices.db file
xrupdate () {
curl -s 'https://dskbank.bg/restapi/dsk/GetCurrencyRates?format=json' |
sed -e 's/[{}]/\n/g' -e 's/"//g' | sed -e '2~2d' |
awk -v date="$(date +"%Y-%m-%d")" -F[,:] 'NF && $4!=0{print "P " date" 00:00:00 "$6" "$4 " BGN"}' >> ~/L/ledger/data/prices.db
}
from RPi import GPIO
from time import sleep
clk = 17
dt = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(clk, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(dt, GPIO.IN, pull_up_down=GPIO.PUD_UP)
@pento
pento / stars-block.js
Last active January 4, 2022 14:00
Gutenberg Stars Block
( function( blocks, element ) {
var el = element.createElement;
function Stars( { stars } ) {
return el( 'div', { key: 'stars' },
'★'.repeat( stars ),
( ( stars * 2 ) % 2 ) ? '½' : '' );
}
blocks.registerBlockType( 'stars/stars-block', {
@tripflex
tripflex / functions.php
Last active February 13, 2024 19:03
WordPress Remove Filter (remove_filter converted to remove_class_filter) to remove Filter/Action without Class Object access. Works with WordPress 1.2+ (4.7+ support added 9-19-2016)
<?php
/**
* Make sure the function does not exist before defining it
*/
if( ! function_exists( 'remove_class_filter' ) ){
/**
* Remove Class Filter Without Access to Class Object
*
* In order to use the core WordPress remove_filter() on a filter added with the callback