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 / w3tc-minify-cache-buster.php
Created August 12, 2014 04:29
add query string cache buster to stylesheets minified by W3 Total Cache
<?php
// add query string cache buster to W3TC minified stylesheet links
add_action( 'init', function() {
// is css minify enabled?
if ( isset( $GLOBALS[ '_w3tc_ob_callbacks' ][ 'minify' ] ) && $GLOBALS[ '_w3tc_ob_callbacks' ][ 'minify' ][0]->_config->get_cache_option( 'minify.css.enable' ) ) {
// store original minify callback
$GLOBALS[ '_w3tc_ob_callbacks' ][ 'minify-org' ] = $GLOBALS[ '_w3tc_ob_callbacks' ][ 'minify' ];
@tillkruss
tillkruss / wp-api-timeouts.php
Last active January 23, 2018 02:28
Prevent `api.wordpress.org` requests timeouts: "Warning: An unexpected error occurred. Something may be wrong with WordPress.org or this server's configuration. If you continue to have problems, please try the support forums. (WordPress could not establish a secure connection to WordPress.org.)"
<?php
// increase `timeout` for `api.wordpress.org` requests
add_filter( 'http_request_args', function( $request, $url ) {
if ( strpos( $url, '://api.wordpress.org/' ) !== false ) {
$request[ 'timeout' ] = 15;
}
return $request;
@tillkruss
tillkruss / Database.php
Last active March 4, 2016 05:02
[Laravel 5.1] Use Redis PECL/HHVM extension
<?php
namespace App\Redis;
use Redis;
use Illuminate\Redis\Database as RedisDatabase;
use Illuminate\Contracts\Redis\Database as DatabaseContract;
class Database extends RedisDatabase implements DatabaseContract
{
@tillkruss
tillkruss / app\Http\Kernel.php
Last active March 9, 2023 14:26
Running Laravel 5 on Heroku behind CloudFlare
<?php
class Kernel extends HttpKernel
{
protected $middleware = [
\App\Http\Middleware\TrustedProxies::class,
];
}
@tillkruss
tillkruss / redis-test.php
Last active August 20, 2016 18:46
[WordPress] Redis Test MU-Plugin
<?php
/*
Plugin Name: Redis Test
Plugin URI: https://wordpress.org/plugins/redis-cache/
Description: Redis connection test.
Author: Till Krüss
Version: 1.0
Author URI: https://till.im/
*/

Keybase proof

I hereby claim:

  • I am tillkruss on github.
  • I am tillkruss (https://keybase.io/tillkruss) on keybase.
  • I have a public key whose fingerprint is 6490 DEB6 8D18 F0A3 49BD CB9C 8874 10C6 42BC 23BB

To claim this, I am signing this object:

@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)
@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 / AppServiceProvider.php
Last active July 27, 2019 11:47
ElasticSearch engine for Laravel Scout
<?php
resolve(EngineManager::class)->extend('elasticsearch', function ($app) {
return new ElasticsearchEngine(
ElasticBuilder::create()->setHosts(config('scout.elasticsearch.hosts'))->build()
);
});