Skip to content

Instantly share code, notes, and snippets.

View judgej's full-sized avatar

Jason Judge judgej

View GitHub Profile
@judgej
judgej / open-ended-date-range.md
Last active January 29, 2024 17:55
Open-ended Date Range Validation

The Problem

Laravel 9, PHP 8.1. I had a form with two fields, start_date and end_date. These fields were nullable, so either could be left blank to set an pen-ended start or end of the date range.

The dates needed to be validated to ensure the end date was after the start date, and the start date was before the end date. But only when both are set. The problem with applying the before and after validation rules is that if the field being compared against is empty, then the validation rule always failed.

@GhazanfarMir
GhazanfarMir / Instructions.sh
Last active May 14, 2024 03:26
Install PHP7.2 NGINX and PHP7.2-FPM on Ubuntu 16.04
########## Install NGINX ##############
# Install software-properties-common package to give us add-apt-repository package
sudo apt-get install -y software-properties-common
# Install latest nginx version from community maintained ppa
sudo add-apt-repository ppa:nginx/stable
# Update packages after adding ppa
@kinlane
kinlane / health-check-response-format-for-http-apis.json
Created January 19, 2018 15:52
Health Check Response Format for HTTP APIs
{
"serviceID": "service:authz",
"description": "health of authz service",
"status": "pass",
"version" : "1",
"release_id" : "1.2.2",
"memory": [4096, 1024, 3456],
"cpu": [20, 40, 50],
"uptime": "1209600.245",
"connections" : 25,
@brunogaspar
brunogaspar / macro.md
Last active May 1, 2024 07:24
Recursive Laravel Collection Macros

What?

If a nested array is passed into a Laravel Collection, by default these will be threaded as normal arrays.

However, that's not always the ideal case and it would be nice if we could have nested collections in a cleaner way.

This is where this macro comes in handy.

Setup

@judgej
judgej / setphp
Last active January 24, 2020 17:28
bash script to switch between PHP versions in Plesk
#!/bin/bash
# Use the script like this:
# . setphp 7.1
# or
# source setphp 5.6
#
# It will look for the path to the current PHP version in your PATH and switch to
# the new PHP version.
# If you do not have a path to a php version, then it will add one.
@chunter
chunter / pageant-autoload-keys-at-startup.txt
Created June 20, 2017 10:51
Make Pageant autoload keys at startup
To make Pageant automatically run and load keys at startup:
- Find the location of pageant.exe
- Windows key + R to open the 'run' dialog box
- Type: 'shell:startup' in the dialog box
- Create a shortcut to the pageant.exe and put into this startup folder.
@joseluisq
joseluisq / 1README.md
Last active January 3, 2022 13:22
Configure PHP Lumen 5 HTTP Exception Handlers with common JSON responses.

Lumen 5 HTTP Exception Handlers with JSON support.

Configure PHP Lumen 5 HTTP Exception Handlers with common JSON responses.

image

Setup

Copy (replace) only the attached files to their respective directories. app/Exceptions/Handler.php and app/Http/Middleware/Authenticate.php

@Lemmings19
Lemmings19 / readme.md
Last active June 20, 2019 09:03
Set up Laravel 5.4 in an Ubuntu VM on Windows

To setup Laravel inside an Ubuntu virtual machine on Windows

Tested on Windows 10. Probably works in 7 and 8. I wrote this after I went through all of it, so let me know if I forgot a step.

In this guide:

  • VirtualBox (allows you to run a Linux operating system such as Ubuntu while you are running Windows)
  • Ubuntu 16.04 64 (a user friendly Linux installation that will be supported for many years)
  • LAMP stack (Linux, Apache, MySQL, PHP - all of the things that you will run your web application on)
  • Composer (this just manages your PHP dependencies, such as Laravel)
@taviroquai
taviroquai / ParseGeoPackage.php
Created May 8, 2016 17:58
PHP parse GeoPackage
<?php
/**
* Parse GeoPackageBinaryHeader
*
* References
*
* http://www.geopackage.org/spec/#gpb_spec
*
* https://en.wikipedia.org/wiki/Well-known_text
<?php
$stream = new GuzzleHttp\Psr7\MultipartStream([['name' => 'some-file', 'contents' => 'the contents']]);
$client = new GuzzleHttp\Client();
$r = $client->request('POST', 'http://httpbin.org/post', ['body' => $stream]);
$r->getBody()->getContents();
=> """
{\n
"args": {}, \n
"data": "", \n
"files": {}, \n