Skip to content

Instantly share code, notes, and snippets.

@tortuetorche
tortuetorche / dom.js
Created March 15, 2021 12:36 — forked from rainerborene/dom.js
rails-ujs is a past thing. Here is how you can accomplish almost the same behaviour with Stimulus and Hotwire.
export function reduceToParams(elements) {
return elements.reduce((hash, node) => Object.assign(hash, { [node.name]: node.value }), {})
}
export function stopEverything(e) {
e.preventDefault()
e.stopPropagation()
e.stopImmediatePropagation()
}
@tortuetorche
tortuetorche / Select2.php
Created December 10, 2020 09:35
Select2 v4.0+ helpers for the WebDriver module of Codeception 4.1 (and certainly older versions)
<?php // @codingStandardsIgnoreFile
namespace Helper;
use Exception;
// Select2 helpers for Codeception
// See: https://select2.org
//
// Works with Select2 version 4.0 or greater
// Which is a jQuery based replacement for select boxes.
@tortuetorche
tortuetorche / quick-slugify.sh
Created November 9, 2016 10:24 — forked from oneohthree/quick-slugify.sh
Quick bash slugify
echo "$STRING" | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z
@tortuetorche
tortuetorche / FiniteAuditTrailTrait.php
Created July 12, 2016 15:32
FiniteStateMachine and FiniteAuditTrail Traits for Laravel 5.1 (WIP)
<?php namespace App\Finite;
/**
* The FiniteAuditTrail Trait.
* This plugin, for the Finite package (see https://github.com/yohang/Finite), adds support for keeping an audit trail for any state machine.
* Having an audit trail gives you a complete history of the state changes in your stateful model.
* Prerequisites:
* 1. Install Finite package (https://github.com/yohang/Finite#readme)
* 2. Use FiniteStateMachine in your model (https://gist.github.com/tortuetorche/6365575)
* Usage: in your Stateful Class use this trait after FiniteStateMachine trait, like this "use FiniteAuditTrailTrait;".
@tortuetorche
tortuetorche / CacheRepository.php
Last active September 11, 2015 18:03 — forked from tillkruss/Database.php
[Laravel 5.1] Use Redis PECL/HHVM extension
<?php
namespace App\Repositories;
use Illuminate\Cache\Repository;
class CacheRepository extends Repository
{
public function has($key)
{
@tortuetorche
tortuetorche / Select2.php
Last active May 28, 2021 10:41
Select2 v3.5 helpers for the WebDriver module of Codeception 2.1 (WIP)
<?php
namespace Helper;
// Select2 helpers for the jQuery based replacement for select boxes.
// See: http://select2.github.io/select2
// Author: Tortue Torche <tortuetorche@spam.me>
// License: MIT
//
// Installation:
// * Put this file in your 'tests/_support/Helper' directory
@tortuetorche
tortuetorche / 01_README.md
Last active June 11, 2016 21:17
Legacy browsers compatibility (like IE 8 and 9, Android 2.3, Safari 5...) for Turbolinks.replace() ⚠️ Alpha version ⚠️

⚠️ This gist has moved to its own Github repository

You can grab the code HERE 😼

@tortuetorche
tortuetorche / INSTALL4Windows.md
Last active April 12, 2020 23:06
Redis for Windows as a Memcache successor for PHP applications and as a queue driver for Laravel

Install Redis as a service on Windows

Installation instructions

  1. Download and extract the last Redis version (2.8.4)
  2. Copy all extracted binaries to c:\redis\bin
  3. Create another folder at c:\redis\inst1
  4. Download and extract the RedisWatcher binaries from the 2.4 branch
  5. Run InstallWatcher.msi with administrator rights. This should create a Windows service called Redis watcher.
@tortuetorche
tortuetorche / 01.FiniteAuditTrail.README.md
Last active May 28, 2022 03:39
FiniteAuditTrail Trait For Laravel 4 with Example. Support for keeping an audit trail for any state machine, borrowed from the Ruby StateMachine audit trail gem.

FiniteAuditTrail Trait

Support for keeping an audit trail for any state machine, borrowed from the Ruby StateMachine audit trail gem. Having an audit trail gives you a complete history of the state changes in your model. This history allows you to investigate incidents or perform analytics, like: “How long does it take on average to go from state a to state b?”, or “What percentage of cases goes from state a to b via state c?”

Requirements

  1. PHP >= 5.4
  2. Laravel 4 framework
@tortuetorche
tortuetorche / README.md
Last active March 12, 2021 12:07
Compile and install runkit PHP PECL extension

Install runkit PHP PECL extension

On Ubuntu

sudo apt-get install gcc php-pear php5-dev
cd ~/Downloads
git clone https://github.com/zenovich/runkit.git