Skip to content

Instantly share code, notes, and snippets.

View tillkruss's full-sized avatar
🏠
Working from home

Till Krüss tillkruss

🏠
Working from home
View GitHub Profile
@tillkruss
tillkruss / filename-based-cache-busting.php
Last active January 23, 2018 02:30
Filename-based cache busting for WordPress.
<?php
// changes CSS and JavaScript URLs from `css/style.css?ver=1.3.3.7` to `css/style.1.3.3.7.css`
if ( ! is_admin() ) {
foreach ( array( 'style_loader_src', 'script_loader_src' ) as $filter ) {
add_filter( $filter, function( $url ) {
// abort if `$url` doesn't start with `WP_CONTENT_URL`
@tillkruss
tillkruss / stream-s3-as-zip.php
Last active April 6, 2020 08:28
Stream files from S3 as ZIP file.
<?php
use Aws\S3\S3Client;
use ZipStream\ZipStream; // https://github.com/maennchen/ZipStream-PHP
use GuzzleHttp\Client as HttpClient;
protected function streamAsZip($files)
{
$s3 = S3Client::factory('...');
$zip = new ZipStream("foobar.zip");
@tillkruss
tillkruss / README.md
Last active June 22, 2020 10:11
AWS Lambda function that optimizes images uploaded to a S3 bucket using Kraken.io's API.

Lambda S3 Kraken

Trigger

  • Event type: ObjectCreated
  • Suffix: jpg

Environment variables

  • AWS_KEY
  • AWS_SECRET
  • KRAKEN_SECRET
@tillkruss
tillkruss / disable-search.php
Last active July 6, 2020 10:30
Disable WordPress front-end search functionality.
<?php
if ( ! is_admin() ) {
add_action( 'parse_query', function( $query ) {
if ( $query->is_search ) {
unset( $_GET['s'], $_POST['s'], $_REQUEST['s'] );
$query->set( 's', '' );
$query->is_search = false;
$query->set_404();
header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );
@tillkruss
tillkruss / worker.js
Created July 17, 2018 16:18
A Cloudflare worker that allow cookie/path based caching.
/**
* Time-to-live in seconds for cached requests.
*/
const cacheTtl = 300;
/**
* List of request paths to cache.
*/
const cachedPaths = [
@tillkruss
tillkruss / paste-as-plain-text.php
Last active April 2, 2021 11:54
Force the WordPress editor to always paste as plain text.
<?php
// always paste as plain text
foreach ( array( 'tiny_mce_before_init', 'teeny_mce_before_init') as $filter ) {
add_filter( $filter, function( $mceInit ) {
$mceInit[ 'paste_text_sticky' ] = true;
$mceInit[ 'paste_text_sticky_default' ] = true;
return $mceInit;
});
}
@tillkruss
tillkruss / cluster.php
Last active April 9, 2021 01:30
PhpRedis Cluster Test
<?php
var_dump('PhpRedis: '. phpversion('redis'));
$redis = new RedisCluster(
null,
[
'tls://127.0.0.1:7001',
'tls://127.0.0.1:7002',
],
@tillkruss
tillkruss / leaddyno.html
Last active July 13, 2021 17:29
Async Lead Dyno script
<script>
(function(key) {
var script = document.createElement('script');
script.src = 'https://static.leaddyno.com/js';
script.async = true;
script.onload = function () {
LeadDyno.key = key;
LeadDyno.recordVisit();
LeadDyno.autoWatch();
};
@tillkruss
tillkruss / default-mp6-color-scheme.php
Last active August 23, 2021 20:17
Change the default MP6 admin color scheme.
<?php
add_filter( 'get_user_option_admin_color', function( $color_scheme ) {
global $_wp_admin_css_colors;
if ( ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) {
$color_scheme = 'ectoplasm';
}
@tillkruss
tillkruss / AuthServiceProvider.php
Last active November 8, 2021 12:38
Case-insensitive PostgreSQL eloquent user provider for Laravel 5.
<?php
namespace App\Providers;
use Auth;
use App\Support\EloquentUserProvider;
class AuthServiceProvider extends ServiceProvider
{
public function boot(GateContract $gate)