Skip to content

Instantly share code, notes, and snippets.

View brianmriley's full-sized avatar

Brian Riley brianmriley

View GitHub Profile
@pnutmath
pnutmath / angular-add-to-home-screen.component.ts
Last active March 12, 2021 20:15
Angular - Add to home screen POC (app.component.ts)
import { Component, HostListener } from '@angular/core';
@Component({
selector: 'app-root',
template: '<button (click)="addToHomeScreen()" *ngIf="showButton">Add to Home Scree</button>',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
deferredPrompt: any;
@ThomasBurleson
ThomasBurleson / understand-rxjs-defer.md
Last active October 11, 2020 17:52
Why is RxJS::defer() important!

Quite simply, because Observables can encapsulate many different types of sources and those sources don't necessarily have to obey that interface. Some like Promises always attempt to eagerly compete.

Consider:

const promise = $.get('https://www.google.com');
@Toilal
Toilal / api.module.ts
Last active February 21, 2023 10:30
@auth0/angular2-jwt Authorization Service and HttpInterceptor supporting JWT Refresh Token (Angular 4.3+ & 5+)
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { JWT_OPTIONS, JwtInterceptor, JwtModule } from '@auth0/angular-jwt';
import { AuthorizationService } from './authorization.service';
import { environment } from '../../environments/environment';
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
import { RefreshTokenInterceptor } from './refresh-token-interceptor';
function jwtOptionsFactory (authorizationService: AuthorizationService) {
return {
@jpswade
jpswade / devops_best_practices.md
Last active May 3, 2024 11:49
Devops Best Practices Checklist

Find the original here article here: Devops Best Practices

DevOps started out as "Agile Systems Administration". In 2008, at the Agile Conference in Toronto, Andrew Shafer posted an offer to moderate an ad hoc "Birds of a Feather" meeting to discuss the topic of "Agile Infrastructure". Only one person showed up to discuss the topic: Patrick Debois. Their discussions and sharing of ideas with others advanced the concept of "agile systems administration". Debois and Shafer formed an Agile Systems Administrator group on Google, with limited success. Patrick Debois did a presentation called "Infrastructure and Operations" addressing

@Tuizi
Tuizi / test-helper.spec.ts
Last active March 19, 2021 19:47
MockStore for Angular ngrx/store unit tests
import { Action, ActionReducer, Store } from '@ngrx/store';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operator/map';
import { Observer } from 'rxjs/Observer';
// TODO: How to initialize those variables?
const dispatcherMock: Observer<Action>,
reducerMock: Observer<ActionReducer<any>>,
stateMock: Observable<any>;
@singledigit
singledigit / cognito.yaml
Last active April 28, 2024 15:12
Create a Cognito Authentication Backend via CloudFormation
AWSTemplateFormatVersion: '2010-09-09'
Description: Cognito Stack
Parameters:
AuthName:
Type: String
Description: Unique Auth Name for Cognito Resources
Resources:
# Creates a role that allows Cognito to send SNS messages
SNSRole:
@TomDunn
TomDunn / .upload.sh
Created April 26, 2017 07:34
Upload zip to S3 from Bitbucket pipelines
BUCKET="!!!!!!!!YOUR_AMAZON_S3_BUCKET_NAME_HERE!!!!!!!!!!"
CONTENT_TYPE="application/zip"
DATE=`date -R`
IN_FILE="revision.zip"
KEY="demo/revision.zip"
RESOURCE="/${BUCKET}/${KEY}"
HMAC="PUT\n\n${CONTENT_TYPE}\n${DATE}\n${RESOURCE}"
zip -r --exclude=*.git* "$IN_FILE" .
@Quramy
Quramy / README.md
Last active September 4, 2020 17:24
Performance Angular unit testing

Performance of unit testing Angular app

I'm loving Angular, but running unit tests on Karma gets my nerves. It's too slow for me.

In this post, I explain mechanics under Angular's testing module and how to improve the performance.

What makes my tests slow?

To evaluate Angular unit testing performance I captured the CPU profiling with running Karma.

https://medium.com/@ExplosionPills/rxjs-switch-switchmap-and-other-map-operations-e8ccdfb7e5a9 is more up-to-date.

Exploring RxJS still feels like a jungle to me. Even when I think I understand something, I find out that I actually don't understand it. In my quest to truly understand it, I end up learning quite a lot more about some other topics or operations than the one I was originally trying to understand. This is generally a positive thing, but it still feels like traveling deep into a jungle to me.

Just today I was trying to learn how to use ngrx/store with ngrx/effects to use http requests with an ngrx/store-backed app. This introduced me to the RxJS Observable switchMap operator that I was not familiar with. The main question I came up with -- the question that I usually have when

@vespertilian
vespertilian / conditional_effects.ts
Created February 9, 2017 04:09
Two options for conditional ngrx effects
@Effect()
selectAndLoadStore$: Observable<Action> = this.actions$
.ofType(storeActions.SELECT_AND_LOAD_STORE)
.withLatestFrom(this.store.select(ngrx.storeState))
.map(([action, storeState]) => [action.payload, storeState])
.switchMap(([storeName, storeState]) => {
const existsInStore = Boolean(storeState.urlNameMap[storeName]);
return Observable.if(
() => existsInStore,
Observable.of(new storeActions.SetSelectedStore(storeName)),