Skip to content

Instantly share code, notes, and snippets.

const festiveTextStyles = `
font-size: 15rem;
text-align: center;
color: #fcedd8;
background: #BB2528;
font-family: 'Niconne', cursive;
font-weight: 700;
text-shadow: 5px 5px 0px #165B33,
10px 10px 0px #EA4630,
15px 15px 0px #146B3A,
@jwcarroll
jwcarroll / bsvalidation.ts
Last active January 24, 2017 13:13
Automatically adds bootstrap style validation to forms
import { Directive, OnDestroy, ElementRef } from '@angular/core';
import { NgForm } from '@angular/forms';
import { Subscription } from 'rxjs/Subscription';
import { Observable } from 'rxjs/Observable';
import * as _ from 'lodash';
import 'rxjs/add/observable/combineLatest';
@Directive({ selector: '[bsValidation]' })
export class BSValidationDirective implements OnDestroy {
private sub: Subscription;
@jwcarroll
jwcarroll / tag-element-recursive.js
Created September 15, 2016 18:41
Simple recursive walk over DOM tree to create unique tags based on position
//
// This can be used in Chrome console like:
// tagElementRecursive('',$0);
//
function tagElementRecursive(parentTag, node, index){
const tag = [
parentTag,
`${node.nodeName}_${index || 0}`
]
.filter(str => str)
@jwcarroll
jwcarroll / foo.ts
Created July 31, 2016 01:11
TypeScript constructor overloading
class Foo {
constructor(id:number);
constructor(name:string);
constructor(public id:string|number){}
getId(){
return this.id; // id: string|number
}
}
@jwcarroll
jwcarroll / module-using-decorator.js
Created February 26, 2016 19:13
Monkey patching angular-ui state provider
import * as ng from 'angular';
import {stateProviderDecorator} from './state-provider-decorator';
//In our module we load up the
ng.module('my-app', [])
.config(stateProviderDecorator)
.config(function($stateProvider){
//Configure states normally
$stateProvider.state('main',{
(function(){
'use strict';
function createWatchExpression(formName) {
var props = ['$pristine', '$dirty', '$valid', '$pending', '$submitted'];
return _.map(props, function (prop) {
return formName + "." + prop;
});
}
@jwcarroll
jwcarroll / screeps.d.ts
Created August 17, 2015 02:48
TypeScript Definition Files for The Game Screeps
declare var Game: screeps.IGame;
declare module screeps {
export interface IGame {
cpuLimit: number;
creeps: { [screepName: string]: ICreep };
flags: { [flagName: string]: IFlag };
map: IMap;
rooms: { [roomName: string]: IRoom };
@jwcarroll
jwcarroll / angular2.dev.js
Created July 8, 2015 15:03
Angular2-alpha.30 Bundle
This file has been truncated, but you can view the full file.
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
'use strict';
var core = require('../core');
var microtask = require('../microtask');
var browserPatch = require('../patch/browser');
var es6Promise = require('es6-promise');
if (global.Zone) {
@jwcarroll
jwcarroll / angular2.d.ts
Created July 8, 2015 14:54
Angular2-alpha.30 TypeScript Definition Files
// Type definitions for Angular v2.0.0-local_sha.6c933a4
// Project: http://angular.io/
// Definitions by: angular team <https://github.com/angular/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// ***********************************************************
// This file is generated by the Angular build process.
// Please do not create manual edits or send pull requests
// modifying this file.
// ***********************************************************
@jwcarroll
jwcarroll / DI_snipper.ts
Last active August 29, 2015 14:24
An adapter to wrap calls to fetch in order to make them API compatible with Angular2 Http
bind(Http).toClass(FetchHttpAdapter)