Skip to content

Instantly share code, notes, and snippets.

View pdashford's full-sized avatar

Paul Ashford pdashford

View GitHub Profile
@pdashford
pdashford / form-group-state.ts
Last active June 28, 2021 12:44
Custom Angular FormGroup which maintains the initial form state. Provides a valuesChanged Observable which only provides real modified values
import { EventEmitter } from '@angular/core'
import {
FormGroup,
AbstractControl,
ValidatorFn,
AbstractControlOptions,
AsyncValidatorFn
} from '@angular/forms'
/**
@pdashford
pdashford / general.helper.ts
Created July 27, 2020 10:46
NodeJS Typescript function to return IP Address meta information
export async function getIpMeta(ipAddr) {
try {
const url = `http://api.ipstack.com/${ipAddr}?access_key=youraccesskey`
const result = await request.get(url, {
headers: { 'content-type': 'application/json; charset=utf-8' }
})
return JSON.parse(result)
} catch (e) {
console.error('error', e)
return undefined
@pdashford
pdashford / general.helper.ts
Last active July 27, 2020 10:45
Some of my helper routines commonly used within my Angular projects
import { Observable } from 'rxjs'
import moment from 'moment'
export const isEmpty = (obj) => {
return !obj || Object.keys(obj).length === 0
}
export const isObservable = (obj: any) => {
return obj instanceof Observable
}
@pdashford
pdashford / api.service.ts
Created July 27, 2020 10:39
Generic API service for Angular HTTP requests
import { Injectable } from '@angular/core'
import { Observable } from 'rxjs'
import { HttpClient, HttpHeaders, HttpEvent } from '@angular/common/http'
import { environment } from '../../../environments/environment'
import { IApiResult } from '../interfaces/api-result.interface'
import { tap, map } from 'rxjs/operators'
@Injectable()
export class ApiService {
@pdashford
pdashford / environment.ts
Created July 27, 2020 09:56
Angular HTTP interceptor to remove 'Authorization' token when accessing external sites
export const environment = {
api: 'http://yourapi.com'
}
@pdashford
pdashford / gh-download.py
Created January 18, 2017 04:01
Python script to download folders from Github repo
"""
Downloads folders from github repo
Requires PyGithub
pip install PyGithub
"""
import os
import sys
import base64
import shutil