Skip to content

Instantly share code, notes, and snippets.

View Braunson's full-sized avatar

Braunson Yager Braunson

View GitHub Profile
@Braunson
Braunson / bookmarklet.js
Last active February 11, 2025 19:55
Quickly generate a form filler bookmarklet!
// Save this as a bookmark in your browser for the next time you want to fill in the page form!
javascript:(function() {
const fillValues = {
// Paste the object in here from the previous command
}
function fillField(element, value) {
if (!element) return;
// Handle different input types
@Braunson
Braunson / ExportTwillBlocks.php
Created January 31, 2025 19:30
Twill CMS Block exporter to JSON (WIP) - Export Twill blocks both custom and default to JSON with their respective field types and names
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use ReflectionClass;
use ReflectionMethod;
use Symfony\Component\Finder\Finder;
@Braunson
Braunson / console-table-clone.js
Created December 16, 2024 17:48
console.table behavior in a custom JS function
function customConsoleTable(data) {
// Handle GroupBy results by flattening them appropriately
function flattenGroupBy(groupedData) {
if (!groupedData || typeof groupedData !== 'object') return groupedData;
// Check if this looks like a GroupBy result
const isGroupByResult = Object.values(groupedData).every(Array.isArray);
if (!isGroupByResult) return groupedData;
// Flatten the grouped structure
@Braunson
Braunson / commands.sql
Created November 8, 2024 17:18
Changing the prefix of tables on a existing WordPress site
-- So you have an existing WP website with a prefix you need to change
-- We will need to do more than just updating the wp-config.php prefix.
-- There are row data that reference table names we'll need to update
-- Assuming we're already using the wp_ prefix and for example want to
-- change to xyzwp_ we'll need to update the data within the tables
-- Update user meta references
UPDATE wp__usermeta
SET meta_key = REPLACE(meta_key, 'wp_', 'xyzwp_')
@Braunson
Braunson / functions.php
Last active October 15, 2024 00:42
WordPress - Create a custom Settings > Theme Settings page
<?php
/**
* Class WP_Geekybeaver_Theme_Settings
*
* Configure the plugin settings page.
*/
class WP_Geekybeaver_Theme_Settings
{
/**
@Braunson
Braunson / composer.json
Created October 9, 2024 15:03
Copy .env.example to .env and generate an APP_KEY when not set on the Composer post-install-cmd hook
{
"scripts": {
"post-install-cmd": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\"",
"@php -r \"if (strlen(trim(file_get_contents('.env'))) > 0 && !preg_match('/^APP_KEY=.+/m', file_get_contents('.env'))) { echo shell_exec('php artisan key:generate --ansi'); }\"",
"@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\""
]
}
}
@Braunson
Braunson / .env
Created October 8, 2024 21:03
Support for auto-creating the env defined bucket for Minio with Laravel Sail
AWS_ACCESS_KEY_ID=sail
AWS_SECRET_ACCESS_KEY=password
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=local
AWS_ENDPOINT=http://minio:9000
AWS_USE_PATH_STYLE_ENDPOINT=true
@Braunson
Braunson / retry-failed-jobs.sh
Created September 30, 2024 18:28
Retry all (or a ton of) failed jobs in Laravel. If you want to use this in Laravel sail run this command inside your laravel.test container.
source .env
mysql -N --raw --batch \
-h"${DB_HOST}" -u"${DB_USERNAME}" -p"${DB_PASSWORD}" "${DB_DATABASE}" \
-e "SELECT uuid FROM failed_jobs ORDER BY id DESC LIMIT 100000" | \
xargs -P 4 -n 100 php /var/www/html/artisan queue:retry
@Braunson
Braunson / docker-compose.yml
Created September 12, 2024 21:07
Adding a Typesense dashboard to Laravel Sail for local development
# Add the following line to create a new container for a Typesense Dashboard
# It's accessible at laravel.test:81
typesense-dashboard:
image: ghcr.io/bfritscher/typesense-dashboard:latest
restart: always
ports:
- "81:80"
networks:
- sail
@Braunson
Braunson / snippet.js
Created September 12, 2024 17:58
Snippet to console log when Livewire components are initialized with their data
{{-- Drop this under @livewireScripts in your layout --}}
@if (app()->environment() == 'local')
<script>
document.addEventListener("livewire:init", function(event) {
Livewire.hook('component.init', ({ component, cleanup }) => {
console.log("%cComponent: " + component.name, "font-weight:bold");
console.log(component.snapshot.data);
});
});
</script>