Skip to content

Instantly share code, notes, and snippets.

Angular2 + JSPM cheat sheet

First time setup

  • install jspm beta: npm install -g jspm@beta
  • set up your project: jspm init
  • install dependencies: jspm install angular2 reflect-metadata zone.js es6-shim

This will create a jspm_packages folder, and a config.js file.

Open the config.js file - this file manages options for the System.js loader - tweak it as appropriate

Work in progress!

A little while ago I started using Typescript with the Angular 1.5 app I'm working on, to help ease the migration path to Angular 2. Here's how I did it. We'll go example by example through migrating real world code living in a large, mostly non-Typescript codebase.

Let's start with a few of the basic angular building blocks, then we'll go through some of the higher level patterns we derived.

Filters

Javascript

@dburner
dburner / angular-bootstrap-multiselect.js
Created May 8, 2016 22:13 — forked from ethanph5/angular-bootstrap-multiselect.js
AngularJS directive using bootstrap-multiselect, works on Chrome and FF.
// AngularJS: 1.3.15
// bootstrap-multiselect: 0.9.6
angular.module('yourApp')
.directive('yourDirective', function () {
return {
link: function (scope, element, attrs) {
element.multiselect({
buttonClass: 'btn',
buttonWidth: 'auto',
@dburner
dburner / gp-regression-demo.r
Last active November 23, 2016 21:12 — forked from jkeirstead/gp-regression-demo.r
Demo of Gaussian process regression with R
# Demo of Gaussian process regression with R
# James Keirstead
# 5 April 2012
# Chapter 2 of Rasmussen and Williams's book `Gaussian Processes
# for Machine Learning' provides a detailed explanation of the
# math for Gaussian process regression. It doesn't provide
# much in the way of code though. This Gist is a brief demo
# of the basic elements of Gaussian process regression, as
# described on pages 13 to 16.
@dburner
dburner / Awaiter.cs
Created March 16, 2016 09:08
C# Awaiter compiler implementation
// from http://stackoverflow.com/a/12661431/1317953
// By Stephen Cleary
var temp = e.GetAwaiter();
if (!temp.IsCompleted)
{
SAVE_STATE()
temp.OnCompleted(&cont);
return;
cont:
@dburner
dburner / LICENCE
Last active August 29, 2015 14:26 — forked from markembling/LICENCE
Google Drive & Spreadsheets Using OAuth 2.0 Service Account Example. See http://markembling.info/2012/12/google-spreadsheet-dotnet-oauth2-service-account
Copyright (c) 2012, Mark Embling
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Mark Embling nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
@dburner
dburner / async.cs
Last active August 29, 2015 14:20 — forked from dgrunwald/async.cs
// Copyright (c) 2012 Daniel Grunwald
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
@dburner
dburner / Visual Studio Get SN Public Key
Last active August 29, 2015 14:18
Visual Studio sn.exe external tools configuration
Title: Get SN public key
Command: C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\sn.exe
Arguments: -Tp $(TargetPath)
Use Output window: *checked*
@dburner
dburner / promises.md
Last active August 29, 2015 14:17 — forked from domenic/promises.md

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
Function.prototype.inheritsFrom = function (base) {
this.prototype = Object.create(base.prototype);
this.prototype.constructor = this;
this.prototype._super = base.prototype;
return this;
};
var Base = function () {
if (!(this instanceof Base))
throw ('Constructor called without "new"');