Skip to content

Instantly share code, notes, and snippets.

@timjonesdev
timjonesdev / static.go
Created September 17, 2019 21:56
A static file server that gracefully handles resource not found errors and passes requests to the client.
func StaticFileServer(r chi.Router, public string, static string) {
// everything up to the r.Get call is executed the first time the function is called
if strings.ContainsAny(public, "{}*") {
panic("FileServer does not permit URL parameters.")
}
root, _ := filepath.Abs(static)
if _, err := os.Stat(root); os.IsNotExist(err) {
panic("Static Documents Directory Not Found")
version: "3.0"
services:
# Core Spring Boot Application
app:
build:
context: ..
dockerfile: ./Dockerfile
image: "rx_mongo_example"
env_file:
- .env
@timjonesdev
timjonesdev / Dockerfile
Created August 22, 2019 04:19
Node + Java Dockerfile
####################
### Node Setup ###
####################
FROM node:10.13-alpine as node-angular-cli
#Linux setup
RUN apk update \
&& apk add --update alpine-sdk \
&& apk del alpine-sdk \
&& rm -rf /tmp/* /var/cache/apk/* *.tar.gz ~/.npm \
&& npm cache verify \
<mat-grid-list *ngIf="teams !== undefined && teams.length > 0"
cols="2"
rowHeight="2:1">
<mat-grid-tile *ngFor="let team of teams" class="grid-fit">
<app-team-card [team]="team"></app-team-card>
</mat-grid-tile>
</mat-grid-list>
export class TeamCardComponent implements OnInit {
@Input()
team: TeamModel;
constructor() {
}
ngOnInit() {
}
export class MatchupComponent implements OnInit {
teams: TeamModel[] = [];
constructor(private teamService: TeamService) {
}
ngOnInit() {
this.loadTeams();
}
@timjonesdev
timjonesdev / teamServiceConstructor.ts
Created August 21, 2019 22:47
The constructor for the TeamService
private teamWatchSource = new BehaviorSubject(new TeamModel());
_teamWatchSource: Observable<TeamModel> = this.teamWatchSource.asObservable();
constructor(private http: HttpClient, private zone: NgZone) {
this.getTeamsStream().subscribe(data => {
this.teamWatchSource.next(new TeamModel().deserialize(data));
}, error => console.log('Error: ' + error),
() => console.log('done loading team stream'));
}
@timjonesdev
timjonesdev / teamObservable.ts
Last active August 22, 2019 04:29
BehaviorSubject and Observable
private teamWatchSource = new BehaviorSubject(new TeamModel());
_teamWatchSource: Observable<TeamModel> = this.teamWatchSource.asObservable();
@timjonesdev
timjonesdev / getTeams.ts
Last active August 21, 2019 21:52
Subscribe to a Server Sent Event
import {Injectable, NgZone} from '@angular/core';
import {environment} from '../../environments/environment';
import {BehaviorSubject, Observable} from "rxjs";
import {TeamModel} from "../models/team.model";
@Injectable({
providedIn: 'root'
})
export class TeamService {
private teamsWatchUrl = environment.backendUrl + environment.watchTeamsPath;
@timjonesdev
timjonesdev / deserializable.ts
Last active August 21, 2019 20:58
Typescript Model Classes for Reactive Mongo Example
/**
* Enforces a deserialize method to ensure a model class
* can construct itself from a JSON string
*/
export interface Deserializable {
deserialize(input: any): this;
}