Skip to content

Instantly share code, notes, and snippets.

View icfantv's full-sized avatar

Adam Gordon icfantv

View GitHub Profile
import {Injectable} from 'angular2/core';
import {Http} from 'angular2/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';
const GITHUB_API_URL = 'https://api.github.com';
export class Repository {
name: string;
full_name: string;
@icfantv
icfantv / angular-material.css
Last active June 10, 2016 20:41
Bootstrap-ish Chips from Stripped-down Material
[tabindex='-1']:focus {
outline: none;
}
input[type="search"] {
-webkit-appearance: textfield;
box-sizing: content-box;
-webkit-box-sizing: content-box;
}
@icfantv
icfantv / service-module.js
Created May 29, 2016 21:48
Sample NG1 Service (ES5)
angular.module('services', [])
.service('MyService', ['$resource', MyService]);
function MyService($resource) {
var resource = $resource(...);
this.getAll() {
return resource.$get(...);
}
@icfantv
icfantv / FilterService.ts
Last active May 27, 2016 01:47
Subject Observer Example
import {Observer} from 'rxjs/Observer';
import {Subject} from 'rxjs/Subject';
export class FilterService {
private subject: Subject = new Subject();
private _name: string;
private _tags: CollectionMatcher = {
values: [],
allMustMatch: false
@icfantv
icfantv / AlphaNumComparator.ts
Created May 13, 2016 20:02
Alpha-Numeric comparator in TypeScript
export class StringUtils {
// shamelessly ripped from http://www.davekoelle.com/alphanum.html
/**
* Returns whether or not the specified value is a string.
* @param value the value to check for a string type.
* @returns {boolean} whether or not the specified value is a string.
*/
public static isString(value: any): boolean {
@icfantv
icfantv / alert.json
Last active May 9, 2016 19:48
NGBS API Layout
{
"inputs": [
{
"key": "close()",
"value": "A callback function that gets fired when an alert is closed. If the attribute exists, a close button is displayed as well."
}
],
"outputs": [
]
}
@icfantv
icfantv / OneServiceTest.spec.js
Last active May 4, 2016 16:09
Webpack, Karma, and You
import {IngredientService} from './IngredientService';
describe('test ingredient service', () => {
let service, _$httpBackend;
beforeEach(() => {
inject(($http, $httpBackend) => {
_$httpBackend = $httpBackend;
service = new IngredientService($http);
});
});
@icfantv
icfantv / resolveSnippet.js
Created April 22, 2016 18:40
Resolve Function
{
resolve: {
foo: ['$q', 'ModalService', 'MyService', ($q, ModalService, MyService) => {
return $q.resolve(ModalService.open()
.then(() => {
console.log('modal resolved');
return MyService.doSomething(someData);
})
.catch((error) => {
console.log('rejected');
@icfantv
icfantv / ScrollShadow.js
Created April 18, 2016 22:21
Angular Component
class ScrollShadowCtrl {
static get $inject() {
return ['$window', '$scope', '$elment'];
}
constructor($window, $scope, $element) {
this.$window = $window;
this.$element = $element;
@icfantv
icfantv / BadPromise.js
Last active April 13, 2016 14:56
How to NOT do a nested promise
someFunction() {
// do some stuff
MyService.doSomething().then(() => {
// do some stuff
AnotherService.doSomethingElse().then((blah) => {