Skip to content

Instantly share code, notes, and snippets.

View westonruter's full-sized avatar

Weston Ruter westonruter

View GitHub Profile
@Rarst
Rarst / CommentsFeed.php
Last active July 28, 2021 10:27
Build Gist comments feed for specific user, using GitHub API.
<?php
namespace Rarst\GitHub\Gist;
use GuzzleHttp\Client;
use GuzzleHttp\Command\Guzzle\Description;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
/**
* Build Gist comments feed for specific user, using GitHub API.
@franz-josef-kaiser
franz-josef-kaiser / MinFilterIterator.php
Last active January 18, 2021 19:15
An example plugin to show the use of the PHP SPL and subsidiary loops with a FilterIterator.
<?php
// Reduced to the minimum
class ThumbnailFilter extends FilterIterator
{
private $wp_query;
public function __construct( Iterator $iterator, WP_Query $wp_query )
{
NULL === $this->wp_query AND $this->wp_query = $wp_query;
parent::__construct( $iterator );
@ericandrewlewis
ericandrewlewis / a.md
Last active October 27, 2020 18:44
The WordPress Customizer

The WordPress Customizer

The WordPress Customizer is an interface for drafting changes to content while previewing the changes before they are saved. This is an alternative to the "save and suprise" model of changing settings without knowing what exactly will happen.

The customizer can be accessed in the admin interface under Appearance > Customize.

A screenshot of the customizer

#19909 is the trac ticket that introduced the Customizer during the 3.4 release cycle.

@madrobby
madrobby / README.md
Created May 17, 2011 16:34 — forked from 140bytes/LICENSE.txt
Luhn10 algorithm

Implementation of the Luhn 10 algorithm to check validity of credit card numbers. See http://en.wikipedia.org/wiki/Luhn_algorithm for details on the algorithm.

var validCreditCard = function(a,b,c,d,e){for(d=+a[b=a.length-1],e=0;b--;)c=+a[b],d+=++e%2?2*c%10+(c>4):c;return!(d%10)};

validCreditCard('378282246310005'); //=> true
validCreditCard('378282246310006'); //=> false

// some numbers to test with
// 378282246310005 371449635398431 378734493671000
(( items ) => {
const lines = [];
for ( const item of items ) {
const title = item.querySelector('.zhc-issues-list-item__title > a').textContent;
const number = item.querySelector('.zhc-issues-list-item__issue_number').textContent;
const isPullRequest = Boolean( item.querySelector( '.zhc-icon--pull-request-closed' ) || item.querySelector( '.zhc-icon--pull-request-open' ) );
lines.push( `${number} [${isPullRequest ? 'PR' : 'IS'}] ${title}` );
}
@tomjn
tomjn / gist:6140909
Last active February 21, 2020 06:35
If you're thinking of using WP_Query, try using this iterator instead, cleaner boilerplate, auto-cleans up after itself
<?php
$pages = new query_loop( array(
'post_type' => 'page'
));
foreach( $pages as $id => $post ) {
the_title();
// etc...
}
@ericandrewlewis
ericandrewlewis / gist:a1b127aefbd58c210666
Last active January 19, 2019 00:02
Towards a data model for scalable queries against rich WordPress post attribute data

Towards a data model for scalable queries against rich WordPress post attribute data

This document is in draft status, and is being made available for peer review. If you have feedback, comment on this gist or email me.

Let's say you're a web developer. A client of yours is a gemstone dealer in Manhattan. This dealer has an inventory of gemstones that they'd like to put on their website.

Gemstones have a plethora of attributes: type of gemstone (e.g. sapphire or emerald), price, weight, width, height, depth, color, shape, country of origin, treatment (if it's heat treated), who certified these details, whether the stone is a single stone or a pair.

You're offered the task to make a website to display the gemstone inventory, which will include a search interface. So a user can say "I want to see sapphires that are no heavier than 1.33 karats that are oval, between $750 and $1250, between 1.11mm and 1.20mm that weren't heat treated, because heat treatment is cheap."

@westonruter
westonruter / crontab
Last active November 22, 2018 08:15
Script to ping URLs defined in urls.txt and alert you if they do not return 200 OK. You'll need to `sudo apt-get install bsd-mailx` to get the email, and you'll want to add a filter to make sure that $from is never sent to spam. A log is also kept in log.txt including timestamp, status code, and URL.
*/5 * * * * /home/pi/pinger/pinger.sh > /dev/null 2>&1
@tobitailor
tobitailor / def.js
Created July 13, 2010 23:32
Simple Ruby-style inheritance for JavaScript
/*
* def.js: Simple Ruby-style inheritance for JavaScript
*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*
*
* Example:
*
* def ("Person") ({
@pwenzel
pwenzel / google-maps-oembed-wordpress.php
Created February 1, 2013 22:45
Faux Google Maps oEmbed for Wordpress
<?php
/* Faux Google Maps oEmbed
* Embed google maps in a nicer iframe without using their provided embed code
* @usage Paste a Google Maps link in your post and it will be replaced with an iframe when published
* @link http://bigsaturday.net/oembed-google-maps-wordpress/
*/
wp_embed_register_handler( 'google_map', '#https://maps\.google\.com/maps(.*)#i', 'embed_google_map' );
function embed_google_map( $matches ) {
$query = parse_url($matches[0]);