Skip to content

Instantly share code, notes, and snippets.

View Rarst's full-sized avatar
Otherwise occupied.

Andrey Savchenko Rarst

Otherwise occupied.
View GitHub Profile
<?php
add_action( 'template_redirect', function () {
if ( ! isset( $_GET['crash'] ) ) {
return;
}
$urls = [];
@Rarst
Rarst / headings.less
Created July 14, 2017 16:08
Less mixin to calculate vertical rhythm styling for headings [in Bootstrap]. Don’t ask me how this works because I don’t remember and this made my brain hurt enough.
.heading-line-height( @line-height ) when ( @line-height < 1 ) {
line-height: unit(@line-height * 2, em);
}
.heading-line-height( @line-height ) when ( @line-height >= 1 ) {
line-height: unit(@line-height, em);
}
.heading-rhythm ( @font-size-base, @font-size-increase ) {
@heading-font-size: @font-size-base * @font-size-increase;
@Rarst
Rarst / dumper.php
Last active December 11, 2016 21:01
Dump included PHP files from specific path.
<?php
add_action( 'shutdown', function () {
if ( ! defined( 'WPSEO_PATH' ) ) {
return;
}
$path = str_replace( '\\', '/', WPSEO_PATH );
$includes = array_reduce( get_included_files(), function ( $plugin_includes, $include_path ) use ( $path ) {
<?php
$bench = new Ubench();
$total = 15000;
$count = 10;
$sql = "
SELECT l.ID, post_title, post_content, post_name, post_parent, post_author, post_modified_gmt, post_date, post_date_gmt
FROM (
SELECT {$wpdb->posts}.ID
@Rarst
Rarst / RoboFile.php
Last active December 1, 2019 19:41
Robo command to build a release zip for Composer package.
<?php
class RoboFile extends \Robo\Tasks {
/**
* Creates release zip
*
* @param string $package Composer package in vendor/name format.
* @param string $version Version to build.
*/
@Rarst
Rarst / matrix.php
Last active November 11, 2016 12:20
Travis matrix generator for Yoast SEO.
<?php
$php_max = 7.0;
$php_min = 5.2;
$php_versions = array_filter( range( $php_max, $php_min + 0.1, 0.1 ), function ( $version ) {
return version_compare( $version, 5.6, '<=' ) || version_compare( $version, 7.0, '>=' );
} );
$wp_max = 4.6;
@Rarst
Rarst / doge.php
Last active December 27, 2019 10:34
Doge snippet for WordPress
<?php
add_filter('gettext',fn($t)=>
@$t[4]&&@$GLOBALS['wp_locale']
?["Such $t","Very $t",'Wow'][rand(0,2)]
:$t);
@Rarst
Rarst / composer.json
Last active January 4, 2016 15:00
Converter from Facebook's locales XML to PHP array.
{
"name": "yoast/facebook-util",
"require": {
"symfony/dom-crawler": "^2.6",
"symfony/css-selector": "^2.6"
}
}
@Rarst
Rarst / class-global-sniffer.php
Last active October 4, 2017 14:14
Discover where is array global being modified, because WordPress.
<?php
namespace Rarst;
/**
* Discover where is array global being modified, because WordPress.
*/
class Global_Sniffer implements \ArrayAccess {
protected $name;
@Rarst
Rarst / wp-core-contributors-by-version.php
Last active July 28, 2019 17:31
WordPress core contributors by version. Input data from https://api.wordpress.org/core/credits/1.1/?version=x.x
<?php
$data_dir = 'c:/server/www/dev/data/';
$releases = [ ];
foreach ( range( 3.2, 4.0, 0.1 ) as $version ) {
$version = number_format( $version, 1 );
$data = json_decode( file_get_contents( $data_dir . $version . '.json' ), true );
$groups = wp_list_pluck( $data['groups'], 'data' );