Skip to content

Instantly share code, notes, and snippets.

View m-graham's full-sized avatar

Michael Graham m-graham

  • University of Saskatchewan
  • Saskatoon, Saskatchewan
View GitHub Profile
@m-graham
m-graham / README.md
Created July 25, 2022 20:37 — forked from matt-allan/README.md
Compound sorting Laravel collections

This is an example of sorting a Laravel collection by > 1 attribute with different sort directions. Unlike some of the other solutions mentioned in this thread it works with any type PHP can normally sort and doesn't require hashing.

That works because of how PHP's comparison functions work:

Array with fewer members is smaller, if key from operand 1 is not found in operand 2 then arrays are uncomparable, otherwise - compare value by value

The <=> operator is PHP's combined comparison operator, or 'spaceship' operator. It makes writing custom sort functions very easy.

If you need to do a compound sort but every attribute is being sorted in the same direction, you can use sortBy/sortByDesc instead of writing your own sort function.

@m-graham
m-graham / Readme.md
Created May 15, 2022 05:46 — forked from normal-carrot/Readme.md
Docker + nginx-proxy + let's encrypt + watchtower + fail2ban

Complete solution for websites hosting

This gist contains example of how you can configure nginx reverse-proxy with autmatic container discovery, SSL certificates generation (using Let's Encrypt) and auto updates.

Features:

  • Automatically detect new containers and reconfigure nginx reverse-proxy
  • Automatically generate/update SSL certificates for all specified containers.
  • Watch for new docker images and update them.
  • Ban bots and hackers who are trying to bruteforce your website or do anything suspicious.
@m-graham
m-graham / EloquentCheatSheet.md
Created April 29, 2022 00:06 — forked from avataru/EloquentCheatSheet.md
Eloquent relationships cheat sheet
@m-graham
m-graham / TestCase.php
Created April 26, 2022 22:40 — forked from fourstacks/TestCase.php
Example TestCase using Laravel 8 model factories
<?php
namespace Tests;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Str;
abstract class TestCase extends BaseTestCase
{
@m-graham
m-graham / bash_strict_mode.md
Created July 16, 2021 16:20 — forked from mohanpedala/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

set -e, -u, -o, -x pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u