Skip to content

Instantly share code, notes, and snippets.

Benjamin Charity benjamincharity

Block or report user

Report or block benjamincharity

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View qeury.ts
public queryStates(query: string): State[] {
query = query.toLowerCase();
if (query) {
const letters = query.split('').map(l => `${l}.*`).join('');
const regex = new RegExp(letters, 'ig');
return this.states.filter(s => !!s.name.match(regex));
} else {
// if no query, return first 10 states
return STATES.slice(0, 10);
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
View optionalTemplateExample.html
<ng-content *ngIf="!optionTemplate">
</ng-content>
<ng-container
*ngIf="optionTemplate"
[ngTemplateOutlet]="optionTemplate"
[ngTemplateOutletContext]="{$implicit: option}"
></ng-container>
View keyofError.sh
BUILD ERROR
ngx-tools/src/jwt-token-managment/reducer.ts(33,7): error TS2536: Type 'keyof C' cannot be used to index type '{ [x: string]: string; }'.
ngx-tools/src/jwt-token-managment/utilities/token-extractor.mock.ts(34,10): error TS2416: Property 'extractJwtToken' in type 'TokenExtractorMock<CM>' is not assignable to the same property in base type 'TokenExtractor<ClaimMap>'.
Type '<T extends Object | HttpResponse<any>>({ tokenName, isDefaultToken }: ExtractTokenParams<CM>) => ...' is not assignable to type '<T extends Object | HttpResponse<any>>({ tokenName, resetAllOtherTokens, isDefaultToken }: Extrac...'.
Types of parameters '__0' and '__0' are incompatible.
Type 'ExtractTokenParams<ClaimMap>' is not assignable to type 'ExtractTokenParams<CM>'.
Types of property 'tokenName' are incompatible.
Type 'string | number' is not assignable to type 'keyof CM'.
Type 'string' is not assignable to type 'keyof CM'.
ngx-tools/src/jwt-token-managment/utilities/retry-with-escala
@benjamincharity
benjamincharity / custom-date-adapter.ts
Created Aug 28, 2018
Custom date adaptor for material
View custom-date-adapter.ts
import { NativeDateAdapter } from '@angular/material/core';
export const TS_DATE_FORMATS = {
parse: {
dateInput: {month: 'short', year: 'numeric', day: 'numeric'},
},
display: {
dateInput: 'input',
monthYearLabel: 'inputMonth',
View removeByKey.js
removeByKey(array, params) {
array.some(function(item, index) {
if (array[index][params.key] === params.value) {
array.splice(index, 1);
return true;
}
return false;
});
return array;
}
View mockStore.ts
import { Action, Store } from '@ngrx/store';
import { Subject } from 'rxjs/Subject';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
/**
* Standard mockstore that can be used in unittests to mock a @ngrx/store
*
* https://github.com/ngrx/store/issues/128#issuecomment-316654714
*/
View rollup-globals.ts
export const rollupGlobals = {
'tslib': 'tslib',
'moment': 'moment',
// lodash
'lodash': 'lodash',
'lodash-es': 'lodash-es',
'lodash-es/at': 'lodash-es/at',
'lodash-es/cloneDeep': 'lodash-es/cloneDeep',
'lodash-es/concat': 'lodash-es/concat',
@benjamincharity
benjamincharity / app-version.component.ts
Last active Dec 4, 2017
From: https://stackoverflow.com/a/41299263/722367 It's worth to mentioned that if someone encounter on error "Cannot find name require" after applying your solution then needs to add "node" type inside "types" property in tsconfig.app.ts file. << "types": ["node"] >>.
View app-version.component.ts
const { version: appVersion } = require('../../package.json')
// this loads package.json
// then you destructure that object and take out the 'version' property from it
// and finally with ': appVersion' you rename it to const appVersion
@Component({
selector: 'stack-overflow',
templateUrl: './stack-overflow.component.html'
})
export class StackOverflowComponent {
You can’t perform that action at this time.