Skip to content

Instantly share code, notes, and snippets.

Avatar

Braunson Yager Braunson

View GitHub Profile
@Braunson
Braunson / github_auto_enable_ignore_whitespace
Last active Mar 18, 2022
Auto ignore whitespace in GitHub Pull Requests
View github_auto_enable_ignore_whitespace
// ==UserScript==
// @name GitHub Auto Click Ignore Whitespaces in PRs
// @namespace https://braunson.ca
// @version 1.0
// @description Auto click enable whitespace by default on GitHub Pull Requests
// @author Braunson Yager
// @match https://github.com/*/*/pull/*
// @grant none
// @downloadURL https://gist.githubusercontent.com/Braunson/66b87ab02396bccc3495fccda5430559/raw/07c93d2907769768a2e5554e36d44726dea22a3d/github_auto_enable_ignore_whitespace?v=1.0
// ==/UserScript==
@Braunson
Braunson / custom-notifications.php
Created Feb 21, 2022
Plugin for WordPress to create a basic custom DB notifications table. Includes a bunch of helpers to get all, get unread, read, mark as read, and create. This was needed for a website that needed DB only notifications that would be shown to the user on a custom theme
View custom-notifications.php
<?php
/**
* Plugin Name: Custom Notifications
* Plugin URI: https://braunson.ca/?ref=wp-custom-notifications
* Description: This plugin provides custom notifications.
* Version: 1.0.0
* Author: Braunson Yager
* Author URI: https://braunson.ca/?ref=wp-custom-notifications
* Requires PHP: 7.4
*/
@Braunson
Braunson / jira-open-in-new-tab.js
Last active Jan 20, 2022
Tapermonkey / Greasyfork: Open JIRA links within the text description in a new tab
View jira-open-in-new-tab.js
// ==UserScript==
// @name JIRA Open link in new
// @namespace braunson.jira.open.links.in.new.tab
// @version 1.0.1
// @description Adds target="_blank" to any links within a card's text description
// @supportURL https://gist.github.com/Braunson/1286ea8ff8eda73b66164184926fe980
// @author Braunson Yager (geekybeaver.ca)
// @match https://*.atlassian.net/*
// @grant none
// ==/UserScript==
@Braunson
Braunson / AppServiceProvider.php
Created Jan 6, 2022
Laravel macro for Request class when needing to specify whenFilled but only for query params.
View AppServiceProvider.php
<?php
// Only when the query param is filled. Using whenFilled will check everything, not just query params
Request::macro('whenQueryFilled', function ($key, callable $callback, callable $default = null) {
if (! is_null($this->retrieveItem('query', $key, null))) {
return $callback(data_get($this->query(), $key)) ?: $this;
}
if ($default) {
return $default();
@Braunson
Braunson / AppServiceProvider.php
Created Jan 6, 2022
Detect if a request is from Livewire or not, useful when you have middleware that needs to ignore Livewire requests. Drop this in the boot method.
View AppServiceProvider.php
<?php
// Detect requests from Livewire
Request::macro('isFromLivewire', function() {
return $this->headers->has('x-livewire');
});
@Braunson
Braunson / functions.php
Created Nov 21, 2021
Dump all callbacks for a filter/hook in WordPress
View functions.php
function list_hooks( $hook = '' ) {
global $wp_filter;
if ( isset( $wp_filter[$hook]->callbacks ) ) {
array_walk( $wp_filter[$hook]->callbacks, function( $callbacks, $priority ) use ( &$hooks ) {
foreach ( $callbacks as $id => $callback )
$hooks[] = array_merge( [ 'id' => $id, 'priority' => $priority ], $callback );
});
} else {
return [];
@Braunson
Braunson / AppServiceProvider.php
Created Nov 11, 2021
whereBetweenDates macro scope for Laravel 8x.
View AppServiceProvider.php
<?php
public function boot()
{
// Extend the Query Builder
\lluminate\Database\Query\Builder::macro('whereBetweenDates', function($firstColumn, $secondColumn, $firstDate, $secondDate, $firstComparison = '>=', $secondComparison = '<=') {
return $this
->whereDate($firstColumn, $firstComparison, $firstDate)
->whereDate($secondColumn, $secondComparison, $secondDate);
});
@Braunson
Braunson / AppServiceProvider.php
Created Jul 23, 2021
Builder macro to output raw SQL with all bindings safely encoded with support for Eloquent Builder and Query Builder.
View AppServiceProvider.php
// Support for Query Builder
Illuminate\Database\Query\Builder::macro('toRawSql', function() {
return array_reduce($this->getBindings(), function ($sql, $binding) {
$binding = str_replace(['\\', "'"], ['\\\\', "\'"], $binding);
return preg_replace('/\?/', is_numeric($binding)
? $binding
: "'" . $binding . "'", $sql, 1);
}, $this->toSql());
});
@Braunson
Braunson / file.php
Created Jun 23, 2021
Laravel - Get information about a named route
View file.php
$route = \Route::getRoutes()->getByName('home');
// => Illuminate\Routing\Route {
// +uri: "/",
// +methods: [
// "GET",
// "HEAD",
// ],
// +action: [
// "middleware" => [
@Braunson
Braunson / snippet.html
Created May 28, 2021
Alpine.js + Tailwind scroll to top snippet
View snippet.html
<div x-data="{scrollBackTop: false}" x-cloak>
<button
x-show="scrollBackTop"
x-on:scroll.window="scrollBackTop = (window.pageYOffset > window.outerHeight * 0.5) ? true : false"
x-on:click="$scroll('#top')"
aria-label="Back to top"
class="fixed bottom-0 right-0 p-2 mx-10 my-10 text-white bg-gray-800 hover:bg-gray-700 focus:outline-none">
<svg viewBox="0 0 20 20" fill="currentColor" class="w-6 h-6">
<path fill-rule="evenodd" d="M14.707 12.707A1 1 0 01-1.414 0L10 9.414l-3.293 3.293a1 1 0 01-1.414-1.414l4-4a1 1 0 011.414 0l4 4a1 1 0 010 1.414z" clip-rule="evenodd"></path>
</svg>