Skip to content

Instantly share code, notes, and snippets.

View jakewtaylor's full-sized avatar

Jake Taylor jakewtaylor

View GitHub Profile
@jakewtaylor
jakewtaylor / usage.jsx
Last active August 31, 2022 18:21
useStyles() React Hook
import React from 'react';
import { useStyles } from '../hooks/useStyles';
export const Sidebar = ({ colourful = false }) => {
const styles = useStyles(stylesheet);
return (
<div className={styles.sidebar}>
<p
className={styles.compose(
const ordinal = n => {
const options = ['th', 'st', 'nd', 'rd'];
const v = n % 100;
return options[(v - 20) % 10]
|| options[v]
|| options[0];
};
<?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
@jakewtaylor
jakewtaylor / example.php
Created March 6, 2019 09:41
Carbon 2.0 Immutable demonstration
<?php
$mutable = Carbon::now();
$immutable = CarbonImmutable::now();
$modifiedMutable = $mutable->add(1, 'day');
$modifiedImmutable = CarbonImmutable::now()->add(1, 'day');
var_dump($modifiedMutable === $mutable); // bool(true)
var_dump($mutable->isoFormat('dddd D')); // string(8) "Sunday 3"
var_dump($modifiedMutable->isoFormat('dddd D')); // string(8) "Sunday 3"
@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
/*
* This will still be mutable
*/
use Carbon\Carbon;
$date = Carbon::now();
/*
const delay = (ms, token = null) => new Promise((resolve, reject) => {
const cancelled = () => reject({ cancelled: true });
if (token && token.cancelled) {
return cancelled();
}
const timeout = setTimeout(() => {
if (!token || !token.cancelled) {
resolve();
<?php
namespace App\Helpers;
use Illuminate\Support\Collection;
class Piper
{
/**
* The symbol that will be replaced with the current value.
@jakewtaylor
jakewtaylor / extensions.sh
Created October 11, 2019 15:27
Latest VS Code settings
code --install-extension akamud.vscode-theme-onedark
code --install-extension be5invis.vscode-custom-css
code --install-extension bmewburn.vscode-intelephense-client
code --install-extension bradlc.vscode-tailwindcss
code --install-extension codingyu.laravel-goto-view
code --install-extension cpylua.language-postcss
code --install-extension dbaeumer.vscode-eslint
code --install-extension dollyn.line-counter
code --install-extension ericadamski.carbon-now-sh
code --install-extension esbenp.prettier-vscode
import { useMemo } from 'react';
export const makeUseStyles = cb => (...args) => {
const styleObj = useMemo(() => cb(...args), args);
const styleSheet = useMemo(() => {
return Object.entries(styleObj).reduce((acc, [className, classes]) => {
acc[className] = classes.join(' ');
return acc;