Skip to content

Instantly share code, notes, and snippets.

<?php
function memoize($target) {
static $memo = new WeakMap;
return new class ($target, $memo) {
function __construct(
protected $target,
protected &$memo,
) {}
@juampi92
juampi92 / KeyedSession.php
Created December 4, 2022 13:46
KeyedSession
<?php
namespace App\Support;
use Illuminate\Session\Store;
use RuntimeException;
/**
* Helper class that transforms all sessions into a specific key.
*
@valorin
valorin / Middleware-CSP.php
Last active May 2, 2024 19:29
CSP Middleware - the simple CSP middleware I use across all of my projects.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Vite;
use Illuminate\Support\Str;
/**
* Simple Content Security Policy middleware.
<?php
namespace {{ factoryNamespace }};
use Illuminate\Database\Eloquent\Factories\Factory;
use {{ namespacedModel }};
/**
* @method {{ model }}|\Illuminate\Support\Collection<{{ model }}> create($attributes = [], ?Model $parent = null)
* @method \Illuminate\Support\Collection<{{ model }}> createMany(iterable $records)
const _ = require('lodash')
module.exports = function ({addUtilities, e, theme, variants}) {
const gradients = theme('gradients', {})
const gradientsVariants = variants('gradients', [])
const utilities = _.map(gradients, ([start, end, direction], name) => ({
[`.bg-gradient-${e(name)}`]: {
backgroundImage: `linear-gradient(${direction}, ${start}, ${end})`
}
@leMaur
leMaur / tailwind-plugin.grid.js
Last active September 5, 2019 07:18
Basic Grid box
const _ = require('lodash')
module.exports = function ({addBase, addUtilities, e, theme, variants}) {
const gridGaps = theme('gridGap', {})
const gridTemplates = theme('gridTemplate', {})
const gridGapVariants = variants('gridGap', [])
const gridTemplateVariants = variants('gridTemplate', [])
const gapUtilities = _.map(gridGaps, (size, name) => ({
[`.grid-gap-${e(name)}`]: {gridGap: `${size}`},
@leMaur
leMaur / tailwind.colors.js
Created September 5, 2019 07:04
Custom colors for Tailwindcss taken from Mineral-ui project
// ******************************
// https://mineral-ui.com/color
// ******************************
module.exports = {
colors: {
transparent: 'transparent',
black: '#1d1f24',
white: '#ffffff',
@laravel-shift
laravel-shift / .php-cs-fixer.php
Last active April 9, 2024 14:08
PHP CS Fixer - Laravel Coding Style Ruleset
<?php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$rules = [
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'default' => 'single_space',
@leMaur
leMaur / tabbing.js
Last active September 5, 2019 07:19
(function (window, document) {
'use strict';
let className = 'tabbing';
let handleFirstTab = function (e) {
if (e.keyCode === 9) {
document.body.classList.add(className);
window.removeEventListener('keydown', handleFirstTab);
window.addEventListener('mousedown', handleMouseDownOnce);
@mattdfloyd
mattdfloyd / CreateProductJob.php
Created June 21, 2018 02:26
Laravel's firstOrCreate race conditions
<?php
namespace App\Jobs;
use App\Product;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Redis;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;