Skip to content

Instantly share code, notes, and snippets.

View robertdrakedennis's full-sized avatar

Robert Dennis robertdrakedennis

View GitHub Profile
@robertdrakedennis
robertdrakedennis / .dockerignore
Created September 3, 2022 01:05
Astrojs image for fly.io
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.git
dist
@robertdrakedennis
robertdrakedennis / editor.blade.php
Created December 16, 2021 05:14
Alpine tiptap editor + livewire
<div x-data="setupEditor(@entangle($attributes->wire('model')).defer)" x-init="() => init($refs.editor)" wire:ignore
{{ $attributes->whereDoesntStartWith('wire:model')->merge(['class' => 'editor !w-full !max-w-full']) }}>
<template x-if="editor">
<div class="flex space-x-4 items-center dark:text-neutral-100 fill-current py-2">
<button @click.prevent="Alpine.raw(editor).chain().toggleBold().focus().run()">
<x-icon-bold class="w-4 h-4" />
</button>
<button @click.prevent="Alpine.raw(editor).chain().toggleItalic().focus().run()">
<x-icon-italic class="w-4 h-4" />
</button>
@robertdrakedennis
robertdrakedennis / SetupColors.php
Created November 17, 2021 01:57
Tailwind shade generator using Spatie/Color
<?php
namespace App\Traits;
use Spatie\Color\Hex;
use Spatie\Color\Rgb;
trait SetupColors
{
protected function darken(Hex $hex, float $intensity): Rgb
@robertdrakedennis
robertdrakedennis / color-picker.blade.php
Created October 2, 2021 06:08
Laravel color picker using vanilla-colorful and skypack
@props([
'id' => null,
'value' => null,
'text' => null,
'name' => null,
'default' => null,
])
<div
@robertdrakedennis
robertdrakedennis / SetupEditor.php
Created August 16, 2021 18:26
Server side character counting for tiptap v3
<?php
namespace App\Traits;
trait SetupEditor
{
public function exceedsCharacterCount($delta): bool
{
$renderedHtml = (new \ProseMirrorToHtml\Renderer)->render($delta);
@robertdrakedennis
robertdrakedennis / MongoDatabaseManager.php
Last active April 29, 2021 18:26
a hacky way to have tenants create with mongo
<?php
namespace App\Drivers;
use Illuminate\Database\Connection;
use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Exceptions\NoConnectionSetException;
@robertdrakedennis
robertdrakedennis / TiptapJsonParser.php
Created December 31, 2019 01:58
Super primitive tiptap json parser
<?php
/**
* Strips the json from a tiptap body.
*
* @param array $body
* @return string
*/
function strip_json_body(array $body): string
{
$string = '';
@robertdrakedennis
robertdrakedennis / ColorComponent.vue
Created November 11, 2019 08:46
Dead simple way to mount pickr with vue.
<template>
<div>
<input type="hidden" name="color" v-model="color">
<div class="flex flex-row items-center">
<div class="color-picker h-16 w-16 rounded shadow"></div>
<div class="ml-2 text-neutral-200">
<div class="flex flex-col text-sm">
<span>Color:</span>
@robertdrakedennis
robertdrakedennis / CachesMediaUrl.php
Last active May 30, 2023 18:44
Simple spatie media library caching to avoid n+1 queries
<?php
namespace App\Traits\Models;
trait CachesMediaUrl
{
/**
* Caches Media urls to avoid duplicate calls
@robertdrakedennis
robertdrakedennis / GenerateSlug.php
Created October 27, 2019 17:56
Generating and attaching slug to array.
<?php
if (! function_exists('generate_slug')) {
/**
* @param array $data
* @param string $key
* @param bool $unqiue
* @return array
* @throws Exception
*/