Skip to content

Instantly share code, notes, and snippets.

View nathanbarrett's full-sized avatar

Nathan Barrett nathanbarrett

View GitHub Profile
@nathanbarrett
nathanbarrett / edmunds.service.js
Created November 7, 2015 16:42
Angular service that interacts with Edmunds Api
/*
* Angular service for working with the edmunds api
*
* How to use:
* 1. Include in controller
* 2. $scope.vehicle = EdmundsService.vehicle
* 3. Put a watcher on $scope.vehicle and send the new value to EdmundsService.updateVehicle(vehicle)
* 4. Check edmundsConfig and constants. Adjust as necessary.
*
* @params $http, ExceptionService
@nathanbarrett
nathanbarrett / auth.service.js
Created April 25, 2016 18:59
Basic Auth Service for Angular
/*
* Angular Service for authentication
*
* @params none
*
* @returns none
*/
AuthService.$inject = ['$location', 'ExceptionService'];
@nathanbarrett
nathanbarrett / exception.service.js
Created April 25, 2016 19:00
Basic exception logging service for Angular
/*
* Angular service for exception handling and reporting
*
* @params none
*
* @returns none
*/
ExceptionService.$inject = ['$log', '$http'];
/*
* Gets the distance in meters from two coordinate objects
*
* @params coord1 (object|required), coord2 (object|required)
*
* @returns int meters
*/
function distanceBetweenCoords(coord1, coord2){
var R = 6371000; // earth's radius in meters
@nathanbarrett
nathanbarrett / newlaravel
Created July 18, 2016 17:29
bash function for setting up a laravel project with stuff I almost always use
function newlaravel
{
# Modify to suit your own system
YAML=/home/users/Nathan/Homestead.yaml
PROJECTSDIR="/media/nathan/Secondary Storage/Github"
HOMESTEADDIR="/media/nathan/Secondary Storage/Github"
HOSTFILE=/etc/hosts
PROJECTNAME=$1
#
@nathanbarrett
nathanbarrett / UsStates.php
Created December 12, 2016 16:49
PHP Class that allows you to access AND format the US States in an array format of your choosing
<?php
namespace App\Helpers;
/*
* Access the US States in a format of your choosing by simply calling:
* UsStates::getStates(array $format, bool $stateAllCaps, bool $includeTerritories)
* check the getStates method below for more details on how to format
*/
class UsStates
{
public static $usStates = [
@nathanbarrett
nathanbarrett / crud.service.js
Last active January 9, 2017 20:50
Angular 1.X helper service for helping with crud tasks
/*
* A backend service for other services wanting crud operations
*
* @params
*
* @returns none
*/
(function () {
@nathanbarrett
nathanbarrett / getFromGPlace.ts
Last active March 30, 2017 23:20
Typescript function to get address components from a google place result. Some aliases thrown in for help
class Utils {
placeAddressComponents = {
street_number: {
selector: 'street_number',
defaultName: 'long_name',
},
route: {
selector: 'route',
defaultName: 'short_name',
@nathanbarrett
nathanbarrett / planets.js
Created October 2, 2017 17:44
A list of all the planets and distances
var solarSystem = [
{
name: 'The Sun',
diameter: 1391400000,
distance: 0
},
{
name: 'Mercury',
diameter: 4879000,
distance: 57909227000
@nathanbarrett
nathanbarrett / dom-script-loader.service.ts
Created December 9, 2017 18:29
A helper service for async loading of libraries such as google maps , google charts , etc
import { Injectable } from '@angular/core';
import Promise from 'bluebird'
@Injectable()
export class DomScriptLoaderService {
constructor() { }
/**
* Returns a Promise with a boolean value as to whether is was previously loaded or not