Skip to content

Instantly share code, notes, and snippets.

View Braunson's full-sized avatar

Braunson Yager Braunson

View GitHub Profile
layout title permalink
checklist_page
The Side Project Marketing Checklist
/marketing-checklist/

Pre-Launch

Market Research

@Braunson
Braunson / custom-notifications.php
Created February 21, 2022 00:49
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
<?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 January 20, 2022 21:22
Tapermonkey / Greasyfork: Open JIRA links within the text description in a new tab
// ==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 January 6, 2022 22:47
Laravel macro for Request class when needing to specify whenFilled but only for query params.
<?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 / binary-trees-as-arrays.php
Last active December 8, 2021 02:42
Dealing with binary trees represented as arrays and determining weather the left or right branch of the tree is larger. The size of each branch is the sum of the node values. (`-1` is considered a non-existent node)
<?php
function solution($arr)
{
// If the array is empty or there is only 1 value
if (count($arr) <= 1) {
return '';
}
// A quick check as to not redefine the function
@Braunson
Braunson / functions.php
Created November 21, 2021 21:49
Dump all callbacks for a filter/hook in WordPress
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 November 11, 2021 19:36
whereBetweenDates macro scope for Laravel 8x.
<?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 July 23, 2021 16:31
Builder macro to output raw SQL with all bindings safely encoded with support for Eloquent Builder and Query Builder.
// 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 June 23, 2021 19:05
Laravel - Get information about a named route
$route = \Route::getRoutes()->getByName('home');
// => Illuminate\Routing\Route {
// +uri: "/",
// +methods: [
// "GET",
// "HEAD",
// ],
// +action: [
// "middleware" => [
@Braunson
Braunson / gist:8aa2e0084098c84f0d8f
Created February 8, 2015 21:03
jQuery $.browser is deprecated, here's a drop in working fix to resolve $.browser errors so you can continue using $.browser.
(function( $ ){
jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || [];
return {