Skip to content

Instantly share code, notes, and snippets.

View codeBelt's full-sized avatar
💭
I may be slow to respond.

Robert S. codeBelt

💭
I may be slow to respond.
View GitHub Profile
static requestShow() {
return async (dispatch, getState) => {
const showId = getState().show.currentShowId;
dispatch(ActionUtility.createAction(ShowAction.REQUEST_SHOW));
const model = await ShowEffect.requestShow(showId);
const isError = model instanceof HttpErrorResponseModel;
dispatch(ActionUtility.createAction(ShowAction.REQUEST_SHOW), model, isError);
export const createArrayChunk = <T>(arr: T[], size: number): T[][] => {
const chunkSize: number = Math.ceil(arr.length / size);
return Array.from({ length: chunkSize }, (_, i: number) => {
const startIndex: number = i * size;
const endIndex: number = startIndex + size;
return arr.slice(startIndex, endIndex);
});
};
class SomeClass {
public static singleton: SomeClass;
constructor(){
if(SomeClass.singleton){
return SomeClass.singleton;
}
SomeClass.singleton = this;
function isObject(o) {
return Object.prototype.toString.call(o) === '[object Object]';
}
function deepClone(data) {
if (Array.isArray(data)) {
return data.map(deepClone);
} else if (isObject(data)) {
return Object.keys(data).reduce(function(o, k) {
o[k] = deepClone(data[k]);
function isObject(o) {
return Object.prototype.toString.call(o) === '[object Object]';
}
function deepClone(data) {
if (Array.isArray(data)) {
return data.map(deepClone);
} else if (isObject(data)) {
return Object.keys(data).reduce(function(o, k) {
o[k] = deepClone(data[k]);
private static _getWidthAndLeftPercentage(beginningDateTime: string, endingDateTime: string): WidthLeftMethodUnion {
const beginningDateTimeInSeconds: number = moment(endingDateTime).diff(beginningDateTime, 'seconds');
return (startDateTime: string, endDateTime: string): IWidthLeft => {
const startSeconds: number = moment(startDateTime).diff(beginningDateTime, 'seconds');
const endSeconds: number = moment(endDateTime).diff(beginningDateTime, 'seconds');
const leftPercentage: number = (startSeconds / beginningDateTimeInSeconds) * 100;
const widthPercentage: number = ((endSeconds - startSeconds) / beginningDateTimeInSeconds) * 100;
console.log(`leftPercentage`, leftPercentage);
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot} from '@angular/router';
import {Observable, of} from 'rxjs';
import {catchError, filter, first, switchMap, tap} from 'rxjs/operators';
import {select, Store} from '@ngrx/store';
import {IStore} from '../../../stores/i-store';
import {AuthAction} from '../stores/auth/auth.action';
@Injectable()
export class AuthGuard implements CanActivate {
export default class TimeUtility {
public static SECONDS_IN = {
WEEK: 604800,
DAY: 86400,
HOUR: 3600,
MINUTE: 60,
};
public static getCountdownFromSeconds(seconds: number): string {
if (seconds < 60) {
@codeBelt
codeBelt / SizeMap.ts
Created June 5, 2019 18:21
TypeScript Types
type SizeUnion =
| 'title1'
| 'title2'
| 'title3'
| 'headline'
| 'subhead'
| 'caption1'
| 'caption2'
| 'body1'
| 'callout'
export default class Util {
/**
* Recursive function that makes a clone of an object.
*
* @param src {Object} The object you to clone.
* @param renamePropertyNameFunction {(keyName: string) => string} Optional function to rename property names
* @returns {any} Returns a clone object of the one passed in.
* @example
* let cloneOfObject = Util.clone(obj);
*/