Skip to content

Instantly share code, notes, and snippets.

View jakewtaylor's full-sized avatar

Jake Taylor jakewtaylor

View GitHub Profile
<?php
/*
* This will still be mutable
*/
use Carbon\Carbon;
$date = Carbon::now();
/*
@jakewtaylor
jakewtaylor / AppServiceProvider.php
Created March 6, 2019 09:59
How to use CarbonImmutable Laravel 5.8
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
// The Date facade
use Illuminate\Support\Facades\Date;
// And the CarbonImmutable class
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use App\Models\Patient;
use App\Models\Practice;
use App\Models\Lab;
class CreateLabOrderRequest extends FormRequest
const ordinal = n => {
const options = ['th', 'st', 'nd', 'rd'];
const v = n % 100;
return options[(v - 20) % 10]
|| options[v]
|| options[0];
};
export const arrayEqual = (arr1, arr2) => {
// If either item is falsey we can short circuit and warn
if (!arr1 || !arr2) {
console.warn('arrayEqual(): One of the supplied arrays is falsey.');
return false;
}
// If they're equal we can short circuit
if (arr1 === arr2) return true;
@jakewtaylor
jakewtaylor / maybe.js
Last active January 10, 2019 09:15
Maybe function
const maybe = (item, fallback = null) => item ? item : new Proxy({}, {
get () {
return fallback;
}
});
// Usage:
const items = [{ id: 1, value: 'a' }, { id: 2, value: 'b' }];
maybe(items.find(itm => itm.id === 1)).value; // 'a'
@jakewtaylor
jakewtaylor / GoogleFontLoader.js
Last active November 28, 2018 23:19
GoogleFontLoader React Component.
import React from 'react';
class GoogleFontLoader extends React.PureComponent {
link = null;
createLink = () => {
const { fonts } = this.props;
const families = fonts.reduce((acc, font) => {
const family = font.font.replace(/ +/g, '+');
@jakewtaylor
jakewtaylor / problem.md
Last active November 19, 2018 16:47
help me pls

Folders

There is a table that contains data about a set of folders. Each folder can be a child of another. If folder_id is null, then it's a root level folder. If folder_id is a number, it is a child of the folder with that number.

id name folder_id
1 images null
2 css null
3 home 1
@jakewtaylor
jakewtaylor / Tooltip.js
Created November 13, 2018 14:10
useMouseCoordinates()
const Tooltip = (props) => {
const [x, y] = useMouseCoordinates();
return (
<p>Mouse is at x: {x}, y: {y}.</p>
);
}
@jakewtaylor
jakewtaylor / Extensions.md
Last active October 9, 2018 14:19
VS Code Settings