Skip to content

Instantly share code, notes, and snippets.

View LegitDongo's full-sized avatar

LegitDongo

View GitHub Profile
@LegitDongo
LegitDongo / !RequiredIfIn.php
Last active May 24, 2023 19:17
RequiredIfIn - Laravel validation rule requiring a field when a value exists in another field that is an array.
<?php
namespace App\Rules;
use App\Traits\Instantiate;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Contracts\Validation\DataAwareRule;
use Illuminate\Contracts\Validation\ValidatorAwareRule;
use InvalidArgumentException;
@LegitDongo
LegitDongo / bootstrap-5-spacing-shiv.scss
Last active January 18, 2023 22:52
Bootstrap 4's margin/padding classes. Bootstrap changed their margin/padding right + left classes to start + end, this adds the old ones back to your SCSS file. Be sure to tree-shake!
// Notes
// * If adding alongside Bootstrap 5's margin/padding classes, you'll have to remove some stuff from this file so that there's not duplicate definitions.
// * Check the comments for details
// * XXL sizing was not included in Bootstrap 4, but added here for compatibility
////// remove the following variables if bootstrap is included in your SCSS //////////
$grid-breakpoints: (
xs: 0,
sm: 576px,
md: 768px,
@LegitDongo
LegitDongo / LaravelMysqlColumnLengthRule.php
Last active December 1, 2022 19:35
A validation rule for Laravel that sets min/max boundries based on the mysql column type. Excludes variable-length column types.
<?php
/**
* this file is app/Providers/AppServiceProvider@boot
*
* adds the global "col" key for validators
* possible values are as follows:
* string types:
* `varchar`, `tinytext`, `text`, `mediumtext`, `longtext`
* NOTE: `varchar` assumes the default for Laravel, 255; don't use this if you use a specific column size
@LegitDongo
LegitDongo / NovaTrackedExternalImage.php
Last active January 7, 2020 20:39
I wanted a good way to not include the folder name in the database entry for Nova images, and also be able to track a file on any filesystem. Image name is based on the actual filename. Use at own risk, I made this for a personal project.
<?php
namespace Dongo\NovaTrackedExternalImage;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Image;
use Storage;
class NovaTrackedExternalImage extends Image
{
@LegitDongo
LegitDongo / grid-border.scss
Last active April 29, 2019 21:29
Create a responsive grid border system - for when you want borders on all middle items, but not the last one. Assumed imports of bootstrap and the use of the common block-grid system.
@mixin grid-border($subSelector, $color, $direction: 'right'){
@each $key, $width in $grid-breakpoints {
@media(min-width: $width) {
@for $i from 12 through 1 {
&.block-grid-#{$key}-#{$i} {
> #{$subSelector}:not(:nth-child(#{$i}n)) {
border-#{$direction}: 1px solid #{$color};
}
> #{$subSelector}:nth-child(#{$i}n){
border-#{$direction}: 0;
@LegitDongo
LegitDongo / email-compatibility-articles.md
Last active June 17, 2019 21:25
The best articles with dealing with compatibility issues with HTML emails and differences between all of the clients.
@LegitDongo
LegitDongo / rocketmap.sql
Created December 15, 2018 21:00
Fresh Rocketmap Database Schema
CREATE TABLE `gym` (
`gym_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
`team_id` smallint(6) NOT NULL,
`guard_pokemon_id` smallint(6) NOT NULL,
`slots_available` smallint(6) NOT NULL,
`enabled` tinyint(1) NOT NULL,
`park` tinyint(1) NOT NULL,
`latitude` double NOT NULL,
`longitude` double NOT NULL,
`total_cp` smallint(6) NOT NULL,
@LegitDongo
LegitDongo / sqlsrv-php.sh
Last active January 26, 2023 16:57
SQLSRV PHP Drivers that work for Laravel Homestead
# Best if added to `after.sh` so that this gets run every time the box is provisioned
# Adjust versions as needed; most of this script is forcing php7.2
# composer won't be able to download updates with an active proxy, and will hang trying to get the newest file
# You may want to comment this out based on your network configuration
sudo bash -c 'echo "export NO_PROXY=*" >> ~/.profile'
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
sudo apt-get install php7.2-dev php7.2-xml mcrypt php-pear php-mbstring unixodbc unixodbc-dev -y --allow-unauthenticated
# How to use
# Required: 'image-switch' class on the image element
# Optional:
# 'image-switch-hover' class on the parent that you want to trigger the switch on hover
# data-replace-background-position - will replace the background position that is on the image on hover
# data-image-switch - will replace the image ('src' or 'background-image' auto detected)
#
# Example:
# <a href="#" class="image-switch-hover">
# <div class="image-switch" data-replace-background-position="0 36px"
@LegitDongo
LegitDongo / organize_json.py
Created February 27, 2018 04:01
Organize PA json
import json
import os
from glob import glob
ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
class SortedListEncoder(json.JSONEncoder):
def encode(self, obj):
def sort_lists(item):