Skip to content

Instantly share code, notes, and snippets.

@timjonesdev
timjonesdev / static.go
Created Sep 17, 2019
A static file server that gracefully handles resource not found errors and passes requests to the client.
View static.go
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")
View rx-docker-compose.yml
version: "3.0"
services:
# Core Spring Boot Application
app:
build:
context: ..
dockerfile: ./Dockerfile
image: "rx_mongo_example"
env_file:
- .env
@timjonesdev
timjonesdev / Dockerfile
Created Aug 22, 2019
Node + Java Dockerfile
View 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 \
View MatchupComponent.html
<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>
View TeamComponent.ts
export class TeamCardComponent implements OnInit {
@Input()
team: TeamModel;
constructor() {
}
ngOnInit() {
}
View simpleMatchupComponent.ts
export class MatchupComponent implements OnInit {
teams: TeamModel[] = [];
constructor(private teamService: TeamService) {
}
ngOnInit() {
this.loadTeams();
}
@timjonesdev
timjonesdev / teamServiceConstructor.ts
Created Aug 21, 2019
The constructor for the TeamService
View teamServiceConstructor.ts
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 Aug 22, 2019
BehaviorSubject and Observable
View teamObservable.ts
private teamWatchSource = new BehaviorSubject(new TeamModel());
_teamWatchSource: Observable<TeamModel> = this.teamWatchSource.asObservable();
@timjonesdev
timjonesdev / getTeams.ts
Last active Aug 21, 2019
Subscribe to a Server Sent Event
View getTeams.ts
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 Aug 21, 2019
Typescript Model Classes for Reactive Mongo Example
View deserializable.ts
/**
* Enforces a deserialize method to ensure a model class
* can construct itself from a JSON string
*/
export interface Deserializable {
deserialize(input: any): this;
}