Skip to content

Instantly share code, notes, and snippets.

View james2doyle's full-sized avatar

James Doyle james2doyle

View GitHub Profile
@james2doyle
james2doyle / sane-defaults.sql
Created December 6, 2024 17:35
Here is a list of sensible defaults when using sqlite https://briandouglas.ie/sqlite-defaults/
-- @see https://briandouglas.ie/sqlite-defaults/
-- Set the journal mode to Write-Ahead Logging for concurrency
PRAGMA journal_mode = WAL;
-- Set synchronous mode to NORMAL for performance and data safety balance
PRAGMA synchronous = NORMAL;
-- Set busy timeout to 5 seconds to avoid "database is locked" errors
PRAGMA busy_timeout = 5000;

Heading

Start a line with a hash character # to set a heading. Organize your remarks with subheadings by starting a line with additional hash characters, for example ####. Up to six levels of headings are supported.

Alternatively, on the line below the text, add any number of == characters for heading level 1 or -- characters for heading level 2.

Best practices: Markdown doesn't agree on how to handle a missing space between the number signs # and the heading name. For compatibility, always put a space between the number signs and the heading name.

@james2doyle
james2doyle / alert.blade.php
Created October 2, 2024 20:10
A simple alert Laravel Blade component that is styled with Tailwind and uses Alpine for the dismissal
<div {{ $attributes }} x-data="{ visible: true }" x-show="visible" x-cloak>
<div class="relative w-full overflow-hidden rounded-xl border border-red-600 bg-white text-slate-700 dark:bg-slate-900 dark:text-slate-300"
role="alert">
<div class="flex w-full items-center gap-2 bg-red-600/10 p-4">
<div class="rounded-full bg-red-600/15 p-1 text-red-600" aria-hidden="true">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="size-6"
aria-hidden="true">
<path fill-rule="evenodd"
d="M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16ZM8.28 7.22a.75.75 0 0 0-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 1 0 1.06 1.06L10 11.06l1.72 1.72a.75.75 0 1 0 1.06-1.06L11.06 10l1.72-1.72a.75.75 0 0 0-1.06-1.06L10 8.94 8.28 7.22Z"
clip-rule="evenodd" />
@james2doyle
james2doyle / x-cloak.css
Created September 28, 2024 17:32
Trick with v-cloak in Vuejs but updated for Alpine and x-cloak. From https://medium.com/vuejs-tips/v-cloak-45a05da28dc4
[x-cloak],
[x-cloak]>* {
display: none !important;
}
[x-cloak]::before {
content: "loading\2026";
}
@james2doyle
james2doyle / MyErrorBoundary.tsx
Created September 17, 2024 16:51
A React Error Boundary that has some basic styling and functionality
'use client';
import { ErrorBoundary } from 'react-error-boundary';
import type { ErrorInfo } from 'react';
import type { ErrorBoundaryProps, FallbackProps } from 'react-error-boundary';
import { Button } from '@components/Button';
const logError = (error: Error, info: ErrorInfo) => {
console.error({ error, info });
@james2doyle
james2doyle / x-scrolled.js
Last active August 23, 2024 21:50
An Alpinejs plugin that lets you trigger an expression if the page is being scrolled up or down
// USAGE:
// x-data="{ direction: 'up' }" x-scrolled.up="direction = 'up'" x-scrolled.down="direction = 'down'"
Alpine.directive(
'scrolled',
(_, { modifiers, expression }, { evaluateLater, cleanup }) => {
const results = evaluateLater(expression);
let scrollPos = 0;
const handler = () => {
@james2doyle
james2doyle / Card.php
Created July 11, 2024 17:47
Merge attributes with props in a Laravel class component
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class Card extends Component
{
@james2doyle
james2doyle / opcache.ini
Created June 17, 2024 16:59
Control the jit in PHP with an opcache config
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=100M
opcache.jit=tracing
@james2doyle
james2doyle / 0000_01_01_000000_set_sqlite_extensions.php
Last active October 7, 2024 13:54
Use a Laravel migration to set some PRAGMA performance settings in Sqlite
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Run the migrations.
*/
<?php
/** @see https://twitter.com/AshAllenDesign/status/1786037324775633109 */
test('strict types are used everywhere')
->expect('App')
->toUseStrictTypes();
test('globals')
->expect(['dd', 'ddd', 'die', 'dump', 'ray', 'sleep'])