Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephen Fluin StephenFluin

View GitHub Profile
View lcp.ts
let lcp = await page.evaluate(() => new Promise((resolve, reject) => {
try {
// Create a variable to hold the latest LCP value (since it can change).
let lcp;
// Create the PerformanceObserver instance.
const po = new PerformanceObserver((entryList) => {
const entries = entryList.getEntries();
const lastEntry = entries[entries.length - 1];
View lazy-images.directive.ts
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: 'img'
})
export class LazyImagesDirective {
constructor(ref: ElementRef) {
ref.nativeElement.loading = 'lazy';
}
@StephenFluin
StephenFluin / contributors.md
Last active May 28, 2019
8.0.0 Contributors
View contributors.md

angular/angular

Adam Bradley, Adam Plumer, Adam Yi, Ahsan Ayaz, Alan, Alan Agius, Alberto Garza, Alex Eagle, Alexey Zuev,

View emits.ts
import { Component, Output } from '@angular/core';
import { Subject } from 'rxjs';
@Compnent({
template: '<child-component (myCustomEvent)="myOtherEvent.next($event)"></child-component>',
})
export class EmitComponent {
@Output() myOtherEvent = new Subject<any>();
}
@StephenFluin
StephenFluin / angular-install.sh
Created Jul 11, 2018
Install Angular on a *nix system
View angular-install.sh
# NVM
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install 10
# Yarn
curl -o- -L https://yarnpkg.com/install.sh | bash
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
View test.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const ts = require("typescript");
const plugin_1 = require("./plugin");
const refactor_1 = require("./refactor");
const loaderUtils = require('loader-utils');
const NormalModule = require('webpack/lib/NormalModule');
// This is a map of changes which need to be made
const changeMap = {
View md-select
<div>
From: {{from}}
<md-select [(ngModel)]="from">
<md-option value="200">2.0</md-option>
<md-option value="201">2.1</md-option>
<md-option value="202">2.2</md-option>
<md-option value="203">2.3</md-option>
<md-option value="204">2.4</md-option>
<md-option value="400">4.0</md-option>
<md-option value="500">5.0</md-option>
@StephenFluin
StephenFluin / generate-http2-push-headers.js
Created Mar 20, 2017
NodeJS Command to generate firebase compatible headers for your Angular app
View generate-http2-push-headers.js
fs = require('fs');
fs.readdir('dist/', (err, files) => {
files = files.filter(file => {
if(file.indexOf('.gz') != -1) {
return false;
}
if(file.indexOf('favicon') != -1) {
return false
}
@StephenFluin
StephenFluin / try-angular-upgrade.sh
Created Mar 10, 2017
Give the 2.4.x to 4.0.0-rc upgrade a try!
View try-angular-upgrade.sh
ng new my-project
cd my-project
# We have a working v2.4.x project now!
ng build -prod
# Let's save a working copy of the 2.4.x project
mv dist dist-2.4.x
# Now let's update to the latest version of Angular
@StephenFluin
StephenFluin / npm-link.sh
Last active Mar 7, 2017
Angular package switching
View npm-link.sh