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.

COUNTRIES_WITHOUT_POSTCODES = [
[ "Angola", "AO" ],
[ "Antigua and Barbuda", "AG" ],
[ "Aruba", "AW" ],
[ "Bahamas", "BS" ],
[ "Belize", "BZ" ],
[ "Benin", "BJ" ],
[ "Bolivia", "BO" ],
[ "Botswana", "BW" ],
[ "Burkina Faso", "BF" ],
<?php
class ImmutableClass
{
protected $property1;
protected $property2;
// Clone, set value, return the clone.
public function withProperty1($value)
{
<?php
namespace App\Services;
use GuzzleHttp\Client;
class DataStoreApi
{
// set public variables
public $client;
@judgej
judgej / readme.md
Created June 2, 2018 23:14 — forked from Lemmings19/readme.md
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)
@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.

These are the four valid combinations of fields that make up a card payment type. Both reusable/save flags default to FALSE, so setting the field to "false" or leaving it blank are equivalent:

card-identifier session-key reusable save notes
first-use string string FALSE TRUE Card tokenised on the front end; saved as reusable after transaction.
first-use string string FALSE FALSE Card tokenised on the front end; not reusable after transaction.
second-use string n/a TRUE FALSE Reusing a saved card; no CVV checks.
second-use string string TRUE FALSE Reusing a saved card; with CVV checks.

The first-use string is the card identifier used for the first time. second-use is the same card identifier stored and used again.

/* 1.0.0-1409 - Tue Jun 20 13:38:59 BST 2017 */
var SagePayConfig = {
'restHost': 'https://pi-test.sagepay.com',
'restBaseURL': 'https://pi-test.sagepay.com/api/v1',
'hostedPagesSubPath': '/hosted/docs',
'pages': {
'standardCardDetails': 'card-details-form.html',
'reusableCardIdentifier': 'reusable-card-identifier-form.html'
}
};
@judgej
judgej / sagepay.js
Last active February 4, 2017 11:44
sagepay.js 2016-01-23
/* 1.0.0-1290 - Mon Jan 23 13:18:16 GMT 2017 */
var SagePayConfig = {
'restHost': 'https://pi-test.sagepay.com',
'restBaseURL': 'https://pi-test.sagepay.com/api/v1',
'hostedPagesSubPath': '/hosted/docs',
'pages': {
'standardCardDetails': 'card-details-form.html',
'reusableCardIdentifier': 'reusable-card-identifier-form.html'
}
};
<?php
namespace XeroPHP\Models\Accounting;
use XeroPHP\Remote;
class BatchPayments extends Remote\Object {
/**