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 / getpatch.cmd
Last active September 10, 2024 13:55
Download a patch file from a GitHub branch. Arguments: repo name, branch name (e.g. `getpatch Rarst/wp-date trac-38771`).
curl https://github.com/%1/compare/master...%2.diff > patches/%2.diff
@Rarst
Rarst / github-release-download.php
Last active May 13, 2019 02:27
Quick and dirty WP endpoint to redirect to a download of attached file for a latest GitHub release.
<?php
declare( strict_types=1 );
new class( 'Rarst', [ 'laps' ] ) {
private $owner, $repos;
private $endpoint = 'download';
public function __construct( string $owner, array $repos ) {
@Rarst
Rarst / wp-email-log.php
Created March 31, 2019 07:51
A simple mu–plugin snippet for overriding and logging WP emails in development.
<?php
class R_Mailer {
function Send() {
error_log( wp_debug_backtrace_summary() );
}
}
add_action( 'phpmailer_init', function( &$mailer ) {
$mailer = new R_Mailer();
@Rarst
Rarst / hugo-remote-api.html
Last active June 11, 2024 14:13
Remote API example in Hugo static site build.
{{ with getJSON "https://noti.st/rarst.json" }}
<h3 class="text-left">Latest Talk</h3>
{{ $talks := (index .data 0).relationships.data }}
{{ $latest :=index $talks 0 }}
<a href="{{ $latest.links.self }}">
<img src="{{ $latest.attributes.image.src }}" alt="{{ $latest.attributes.title }}"
class="img-responsive" style="max-height: 210px;border: 1px solid #eee" loading="lazy"/>
</a>
{{ end }}
@Rarst
Rarst / git-gc.php
Created March 3, 2020 12:25
Find and garbage collect all Git repositories in path `php git-gc.php /path/to/walk`.
<?php
declare( strict_types=1 );
$path = $argv[1];
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $path ),
RecursiveIteratorIterator::SELF_FIRST
);
@Rarst
Rarst / style-guide.js
Last active April 28, 2020 12:48
Automagically add Tailwind–like CSS from Frontend Mentor style guide files. https://www.frontendmentor.io/
fetch('style-guide.md')
.then((response) => {
return response.text();
})
.then((markdown) => {
parseMarkdown(markdown)
});
function parseMarkdown(markdown) {
let css = '';
@Rarst
Rarst / ruleset.xml
Created August 27, 2020 12:57
My personal PHPCS ruleset for WP projects.
<?xml version="1.0"?>
<ruleset name="WordPress-Modified">
<description>A custom coding standard.</description>
<rule ref="CognitiveComplexity.Complexity.MaximumComplexity">
<properties>
<property name="maxCognitiveComplexity" value="5"/>
</properties>
</rule>
@Rarst
Rarst / render-link.html
Last active June 10, 2022 09:09
Autoembed tweet links in Hugo with markdown render hook https://gohugo.io/templates/render-hooks/