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
@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 / 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 / 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 / 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.
*/
<?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 / 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 ) {
@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;
<?php
add_action( 'template_redirect', function () {
if ( ! isset( $_GET['crash'] ) ) {
return;
}
$urls = [];
@Rarst
Rarst / .scrutinizer.yml
Last active August 13, 2019 11:37
Scrutinizer config to install PHPUnit on the fly, without shipping in project dependencies.
filter:
excluded_paths:
- 'tests/*'
checks:
php: true
build:
environment:
php:
version: 7.2
dependencies:
@Rarst
Rarst / jekyll.md
Created January 9, 2018 08:57
What worked for me to install GitHub Pages (Jekyll) on Windows 7x64.

GitHub Pages (Jekyll) installation on Windows 7x64

Main install

  1. Install Ruby 2.4.3 via RubyInstaller (not 2.5, conflicts with things later)
  2. Let it install MSYS2 or do it yourself.
  3. gem install bundler
  4. gem install github-pages (this includes jekyll itself and is where things break most)
  5. jekyll -v (3.6.2 at the time of writing, a little behind latest 3.7)
  6. jekyll new myblog
  7. Edit myblog/Gemfile to comment out jekyll line and uncomment github-pages line.