Skip to content

Instantly share code, notes, and snippets.

View lancegliser's full-sized avatar

Lance Gliser lancegliser

View GitHub Profile
// The date input stores the time in local timezone format
// To output the string 'as it appears' rather than shifted by local
// We have to shift the date by the offset before displaying it
var displayDate = field.valueAsDate;
displayDate.setMinutes(displayDate.getTimezoneOffset());
return displayDate.toLocaleDateString();
@lancegliser
lancegliser / IUser.ts
Last active April 24, 2019 02:50
Publishing Redux state data through the Context API for React
// src/contexts/UserContext/IUser.ts
/**
* A representation of the user returned from the Microsoft Graph api.
*/
export default interface IUser {
"@odata.context"?: string, // "https://graph.microsoft.com/v1.0/$metadata#users/$entity"
displayName: string, // "Lance Gliser"
givenName?: string, // "Lance"
jobTitle?: string, // "Developer"
mail?: string, // "lance@fragmentedthought.com"
@lancegliser
lancegliser / actions.api.js
Created January 12, 2018 01:46
An example React Redux Saga set for Google Yolo
/**
* Api actions
*/
import * as constants from './constants.api';
// POST auth
export function apiAuthCredentialsStartAction(credentials) {
return { type: constants.API_AUTH_CREDENTIALS_REQUEST_SUCCESS, credentials };
}
@lancegliser
lancegliser / ReactRouterDomFabricUILink.css
Last active November 4, 2019 02:23
A Higher Order Component (HOC) to integrate React Router Dom with Fabric UI's link
@lancegliser
lancegliser / AxiosServiceInterceptors.ts
Created November 6, 2019 15:36
A module providing an axios based service that uses interceptors for handling authentication, logging, and errors in calls
import axios, {AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse} from "axios";
import {Constants} from "./Constants";
import AxiosUtilities from "./Utilities/AxiosUtilities";
import {
GetServiceCredentials,
IServicesCredentials,
} from "./IServiceTypes";
/**
* Provides constants and functionality common to and api service.
@lancegliser
lancegliser / GuzzleClientTrait.php
Last active December 2, 2019 03:01
An base example, without real end points of creating a reusable trait for PHP that allows for API clients to quickly wrap and dispatch standard Guzzle HTTP client behaviors.
<?php
namespace App\Traits\ApiLibrary;
use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
use Exception;
use GuzzleHttp\Middleware;
use Psr\Http\Message\RequestInterface;
@lancegliser
lancegliser / ErrorBoundary.tsx
Created December 2, 2019 03:02
A basic error boundary component for React that can be imported for reuse. The fallback UI is separated and will need to be created.
import * as React from 'react';
import IErrorBoundary from "./IErrorBoundary";
import ErrorBoundaryFallbackUI from './ErrorBoundaryFallbackUI';
type ErrorBoundaryState = {
error?: Error,
};
/**
* Note that this component can not be refactored using hooks yet.
@lancegliser
lancegliser / ExampleContext.ts
Created December 2, 2019 03:09
A generic context example including a higher order component for providing context to class based components or hooks
import ExampleService from "..";
export default interface IExampleContext {
service: ExampleService
}
@lancegliser
lancegliser / .rollup.config.js
Last active December 26, 2019 15:15
A basic roll up config file that allows for typescript and dynamic external dependencies
import typescript from 'rollup-plugin-typescript2'
import pkg from './package.json'
const dependencies = Object.keys(pkg.dependencies || {});
const peerDependencies = Object.keys(pkg.peerDependencies || {});
const external = [...dependencies, ...peerDependencies];
export default {
input: 'src/index.ts',
output: [
@lancegliser
lancegliser / .vueEmitEventsFromModule.ts
Created January 3, 2020 22:54
Provides a method for emitting root events onto the correct root instance of an application.
import vm from "@/main";
const emitOnMain = (event) => {
vm.$root.$emit(event);
};