Skip to content

Instantly share code, notes, and snippets.

View wesleygrimes's full-sized avatar

Wes Grimes wesleygrimes

View GitHub Profile
@wesleygrimes
wesleygrimes / webpack.config.mjs
Created November 6, 2024 14:26
ejected webpack config from monolith
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import { readFileSync } from 'fs';
import GenerateJsonPlugin from 'generate-json-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { createProxyMiddleware } from 'http-proxy-middleware';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import * as path from 'path';
import RobotstxtPlugin from 'robotstxt-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
@wesleygrimes
wesleygrimes / cronos.py
Created December 17, 2020 01:13
Example plot generation
def get_bearwallow_mountain_station_data():
url = 'https://climate.ncsu.edu/cronos/?station=BEAR'
html = urllib.request.urlopen(url)
soup = BeautifulSoup(html, features='html.parser')
output = dict()
output['label'] = 'Bearwallow Mtn 4200ft'
output['temp'] = 0.00
output['success'] = False
try:
@wesleygrimes
wesleygrimes / app.module.ts
Last active December 11, 2019 16:11
Transloco Issue
import { HttpClientModule } from '@angular/common/http';
import { Injector, NgModule, NgZone } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { SharedLocalizationModule } from '../shared/localization';
import { environment } from '../environments/environment';
import { AppComponent } from './app.component';
@NgModule({
imports: [
@wesleygrimes
wesleygrimes / running-multiple-test-cases.spec.ts
Last active September 24, 2019 17:16
Simple iteration of test cases in Jasmine or Jest
const someMethod = (input: string) => (input === 'value' ? true : false);
describe('someMethod', () => {
const testCases: Array<[boolean, string]> = [
[true, 'value'],
[false, 'other-value']
];
testCases.forEach(([expected, input]: [boolean, string]) =>
it(`should return ${expected} given ${input}`, () => {
@wesleygrimes
wesleygrimes / arrays-in-javascript.js
Created August 30, 2019 13:48
JavaScript Arrays
const heroes = [
{ fullName: 'Spider-Man', heroId: 1 },
{ fullName: 'Iron Man', heroId: 2 },
];
const alterEgos = [
{ fullName: 'Peter Parker', heroId: 1 },
{ fullName: 'Tony Stark', heroId: 2 },
];
@wesleygrimes
wesleygrimes / ngrx-higher-order-action-creators.ts
Created July 21, 2019 21:44
NgRx v8 Higher-Order Action Creators
import { createAction, props } from '@ngrx/store';
import { Joke } from 'src/app/models';
export const createJokeSuccessAction = (actionType: string) =>
createAction(actionType, props<{ jokes: Joke[] }>());
export const createJokeFailureAction = (actionType: string) =>
createAction(actionType, props<{ error: any }>());
export const loadAll = createAction('[Jokes Page] Load All');
@wesleygrimes
wesleygrimes / upgrading-to-angular-ngrx-8.md
Created June 12, 2019 19:17
Upgrading to Angular v8 and NgRx v8

Upgrading to Angular 8 and NgRx 8

Overview

Do you have an awesome application written with Angular v7 using NgRx v7, but have been feeling left out will all the mentions online and at conferences about Angular v8 and NgRx v8? Well you are in luck! Today we will explore together, how to upgrade our applications to use Angular v8 using the Angular CLI tooling. We will also explore upgrading to NgRx v8. This will allow us to take advantage of the new features provided in NgRx v8. Included with NgRx v8 is a shiny set of creators, or type-safe factory functions, for actions, effects, and reducers.

Upgrading Dependencies

Upgrading Angular

The Angular team has provided a great website that walks through the process of upgrading in-depth. This website can be found at Angular Update Tool. We will touch on some of the information today.

@wesleygrimes
wesleygrimes / npx-version.sh
Created May 16, 2019 18:47
npx-cli-specific-version
npx @angular/cli@next new my-app
@wesleygrimes
wesleygrimes / pure-validator-functions.ts
Last active May 10, 2019 20:00
Angular - Pure vs Impure Validator Functions
// impure function: (this.allowedStates may return undefined)
private validState(): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } | null => {
const currentState = control.value;
const foundState = this.allowedStates.find(state => currentState === state);
return foundState ? null : { state: 'State not allowed' };
};
}
// pure function
@wesleygrimes
wesleygrimes / file-upload.service.ts
Created March 19, 2019 17:33
ngrx-file-upload/src/app/file-upload.service.ts
import { HttpClient, HttpEvent, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class FileUploadService {
private API_BASE_URL = environment.apiBaseUrl;