Skip to content

Instantly share code, notes, and snippets.

@sasin91
sasin91 / CacheAdaptor.php
Created January 21, 2016 22:27
Cache Adapter
<?php
namespace Vitanova\Utilities;
use Illuminate\Contracts\Cache\Repository;
use Psr\Cache\CacheItemInterface,
Psr\Cache\CacheItemPoolInterface,
Psr\Cache\InvalidArgumentException;
@sasin91
sasin91 / TrinityCoreInstaller.sh
Created March 26, 2016 13:29
TrinityCore Installer bash script
#! /bin/bash
# Since bash is following a Procedural execution, defining functions first is required.
runInstaller ()
{
ValidateAndInstallDependencies
valiteUserAndEnterHome
cloneRepoAndEnterDirectory
setupDatabase
@sasin91
sasin91 / helpers.php
Created April 9, 2018 11:43
Determine whether given input is a valid date or not
function is_date($value): bool
{
if ($value instanceof DateTime) {
return true;
}
if ((! is_string($value) && ! is_numeric($value)) || strtotime($value) === false) {
return false;
}
@sasin91
sasin91 / DateRange.php
Created April 13, 2018 11:55
Easily create a collection of dates within range of two dates.
<?php
namespace App\Support;
use ArrayIterator;
use Countable;
use DatePeriod;
use DateTime;
use DateInterval;
use IteratorAggregate;
@sasin91
sasin91 / file-queue.js
Last active April 15, 2018 11:32
Js file queue
import { map, forEach } from 'lodash';
class FileUploadQueue {
/**
* Create the upload queue
*
* @param Array | Object supported [{name:'photos', mime:'image'}]
* @return void
*/
constructor (supported = []) {
@sasin91
sasin91 / helpers.php
Created April 24, 2018 10:12
Incensitive string contains
if (! function_exists('istr_contains')) {
/**
* Insensitively check if given haystack contains anything like the given needle(s).
*
* @param string $haystack
* @param string[] $needles
* @return boolean
*/
function istr_contains($haystack, $needles = [])
{
@sasin91
sasin91 / DatabaseOptimizeCommand.php
Created June 11, 2018 13:08
Defragment your MySQL database
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
class DatabaseOptimizeCommand extends Command
{
@sasin91
sasin91 / toFlatValuePairs.php
Created July 10, 2018 12:26
Map a collection into paired values while retaining the key
<?php
use Illuminate\Support\Collection;
/**
* Map the values of given collection into a collection of each pair, retaining the key.
*
* @return Collection
*/
Collection::macro('toFlatValuePairs', function () {
@sasin91
sasin91 / HasModelStates.php
Created July 12, 2018 09:48
Factory model story with model states
<?php
trait HasModelStates
{
/**
* The registered model states.
*
* @var array
*/
protected $states = [];
@sasin91
sasin91 / RemovesInvalidNestedValues
Created July 16, 2018 14:17
Strip invalid nested values from data validated in a form request
<?php
namespace App\Http\Requests;
use function array_dot;
use function fnmatch;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;