Skip to content

Instantly share code, notes, and snippets.

View Braunson's full-sized avatar

Braunson Yager Braunson

View GitHub Profile
@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>
@Braunson
Braunson / breakdown.md
Created August 7, 2024 01:32
Technical Challenge Investigation Breakdown - Optimizing a complex query in Laravel

Optimizing a complex query in Laravel

The Issue

In one of my recent projects, I encountered a significant performance issue (with some digging found out this was due to a slow-running query) in an existing Laravel application. The application relied heavily on a query that fetched data from multiple related tables, causing delays and affecting user experience.

The Challenge

The challenge was to find the affecting queries and optimize them to improve performance witout affecitng the accuracy or integrity of the data.

Approach

@Braunson
Braunson / file.ts
Created November 24, 2023 01:49
OBC IFC loader, on IFC loaded, show a disappearing 'Loaded the component' modal -- For https://github.com/IFCjs/components/
const ifcLoader = new OBC.FragmentIfcLoader(component)
ifcLoader.onIfcLoaded.add(() => {
// Create a new div element with the desired content
const messageDiv: HTMLDivElement = document.createElement('div');
messageDiv.textContent = 'Loaded the component';
messageDiv.style.position = 'fixed';
messageDiv.style.bottom = '10px';
messageDiv.style.left = '10px';
messageDiv.style.backgroundColor = 'lightgreen';