Skip to content

Instantly share code, notes, and snippets.

@vlakoff
vlakoff / convert_lz4_header.php
Last active August 13, 2021 23:17
Convert from Mozilla's LZ4 format to LZ4 v1.3
<?php
/**
* Convert from Mozilla's LZ4 format to LZ4 v1.3
*
* @link https://searchfox.org/mozilla-central/source/toolkit/components/lz4/lz4.js
* @link https://lz4.software.informer.com/1.3/
*
* @param string $input File content in Mozilla's LZ4 format
* @return string File content converted to LZ4 v1.3
@vlakoff
vlakoff / adobe_flash_automatic_install.cmd
Created October 30, 2017 11:42
I got tired of "click click click" each and every time a new Adobe Flash version is released. Still UAC prompts, though. Includes a check of installed versions before and after the setups.
:: Installers download page:
:: https://helpx.adobe.com/flash-player/kb/installation-problems-flash-player-windows.html#main-pars_text_4
@ECHO.
@ECHO == CURRENT VERSIONS ==
@REG QUERY HKLM\SOFTWARE\Macromedia\FlashPlayerActiveX /v Version
@REG QUERY HKLM\SOFTWARE\Macromedia\FlashPlayerPlugin /v Version
@REG QUERY HKLM\SOFTWARE\Macromedia\FlashPlayerPepper /v Version
@vlakoff
vlakoff / lazy-typer.md
Last active October 25, 2017 12:54
Composer candy

Tired of typing composer selfupdate, composer install... ?
Good news, I just noticed you can omit most of the characters, it works as well.

You can cut down up to composer sel, composer ins...

Time saved, equals money, PROFIT! One more step to WORLD DOMINATION.

@vlakoff
vlakoff / custom_logging.php
Created April 1, 2017 04:21
Custom logging in Laravel: one dir per month, one file per day
<?php
// logs in one dir per month, one file per day
// storage/logs/YYYY-MM/YYYY-MM-DD.log
// paste in bootstrap/app.php, after $app assignation
// reference: https://laravel.com/docs/5.4/errors#custom-monolog-configuration
$app->configureMonologUsing(function () {
/*
highlight v3 !! Modified by Jon Raasch (http://jonraasch.com) to fix IE6 bug !!
Highlights arbitrary terms.
<http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html>
MIT license.
<?php
namespace App;
class Article extends \Illuminate\Database\Eloquent\Model
{
protected function getAttributeFromArray($key)
{
global $BENCHMARK_1;
@vlakoff
vlakoff / call-private-methods.php
Created March 19, 2016 22:14
Call private/protected PHP methods. Danger zone. Don't do this at home.
<?php
// we'll do nasty things to this instance
$instance = new Foo;
// pass instance or class name
$method = new ReflectionMethod($instance, 'privateMethod');
$method = new ReflectionMethod('Foo', 'privateMethod');
// milkshakes to the yard
@vlakoff
vlakoff / OrderByRandomTrait.php
Created July 31, 2015 19:37 — forked from vluzrmos/HasRandomStatementTrait.php
Laravel Eloquent Agnostic Random Statement
<?php
trait OrderByRandomTrait
{
/**
* Scope to order by random.
*
* @param \Illuminate\Database\Query\Builder $query
* @return \Illuminate\Database\Query\Builder
*/
@vlakoff
vlakoff / Str-replaceFirst-replaceLast.php
Created February 24, 2016 16:35
Add Str::replaceFirst, replaceLast and corresponding helpers to Laravel 5.1 LTS
<?php
use Illuminate\Support\Str;
Str::macro('replaceFirst', function ($search, $replace, $subject) {
$position = strpos($subject, $search);
if ($position !== false) {
@vlakoff
vlakoff / orderByRandom.php
Created February 24, 2016 04:30
Add orderByRandom() to Laravel query builder
<?php
// github.com/laravel/framework/issues/5223
// github.com/laravel/framework/pull/5435
use Illuminate\Database\Query\Builder;
Builder::macro('orderByRandom', function () {
$randomFunctions = [