Skip to content

Instantly share code, notes, and snippets.

View jarhoads's full-sized avatar

Josh jarhoads

  • Pittsburgh
View GitHub Profile
@jarhoads
jarhoads / KeyBindings.json
Created February 19, 2020 20:28
VSCode Key Bindgings to toggle between terminal and active editor
[
{
"key": "ctrl+;",
"command": "workbench.action.terminal.focus"
},
{
"key": "ctrl+;",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
}
@jarhoads
jarhoads / log.service.ts
Last active February 7, 2020 19:11
A simple angular logging service
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {LogLevel, LogEntry, ILoggable, ConsoleLog, LocalStorageLog, WebApiLog} from './models/logModels';
import { Observable, of } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class LogService {
@jarhoads
jarhoads / logModels.ts
Last active February 7, 2020 19:18
Models for a simple angular logging framework
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { timeout, map, catchError } from 'rxjs/operators';
export enum LogLevel {
Web = -1,
All = 0,
Debug = 1,
Info = 2,
Warn = 3,
@jarhoads
jarhoads / package.json
Created June 7, 2019 19:58
npm package.json for Angular v7 (Since Angular is at v8 default install no longer works with v7)
{
"name": "con-fusion-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
@jarhoads
jarhoads / decorators.ts
Last active January 31, 2021 03:57
typescript decorators
// Decorator Function
function logDec(target: any, key: string, descriptor: any) {
// square
console.log(key);
}
class Calculator {
// Using the decorator
@logDec
@jarhoads
jarhoads / interfaces.ts
Created June 4, 2019 19:21
typescript interfaces
// Interfaces are declared with the interface keyword and
// contain a series of annotations to describe the contract that they represent.
// Interfaces do not result in any compiled JavaScript code
// this is due to type erasure
// Interfaces are used at design time to provide autocompletion and
// at compile time to provide type checking.
interface Point {
// Properties
@jarhoads
jarhoads / functions.ts
Created June 4, 2019 19:20
typescript functions
function getAverage(a: number, b: number, c: number): string {
const total = a + b + c;
const average = total / 3;
return `The average is: ${average}`;
}
const result = getAverage(4, 3, 8);
console.log(result);
@jarhoads
jarhoads / generics.ts
Created June 4, 2019 19:19
typescript generics
// it is possible to create generic functions, including generic methods, generic interfaces, and generic classes.
// Functions
// To make a function generic, you add a type parameter enclosed in angle brackets (< >)
// immediately after the function name.
// When you call a generic function, you can specify the type argument by
// placing it in angle brackets after the function name.
function reverse<T>(list: T[]) : T[] {
@jarhoads
jarhoads / classes.ts
Created June 4, 2019 17:14
typescript classes
// constructors
// All classes in TypeScript have a constructor, whether you specify one or not.
// If you leave out the constructor, the compiler will automatically add one.
// For a class that doesn't inherit from another class, the automatic constructor will be
// parameterless and will initialize any class properties.
// Where the class extends another class, the automatic constructor will
// match the superclass signature and will pass arguments to the superclass before
// initializing any of its own properties.
@jarhoads
jarhoads / app.component.ts
Created May 24, 2019 18:08
angular directives example (component code)
import { Component } from '@angular/core';
import { Model } from './repository.model';
import { Product } from './product.model';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {