Skip to content

Instantly share code, notes, and snippets.

Avatar

Rob Wormald robwormald

View GitHub Profile
@robwormald
robwormald / AuthController.js
Created Dec 6, 2013
Sails + passport + oauth2orize stuffs
View AuthController.js
/**
* AuthController
*
* @module :: Controller
* @description :: Contains logic for handling auth requests.
*/
var passport = require('passport');
var GoogleStrategy = require('passport-google').Strategy;
View rc6-config.md

If you're using SystemJS in the browser, you'll want to update your System config to point at the bundles, if you're not already.

System.config({
  //use typescript for simple compilation (no typechecking)
  //transpiler: 'typescript',
  //typescript compiler options
  //typescriptOptions: {
    //emitDecoratorMetadata: true
  //},
View angular2.jspm.md

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

View rollup.config.js
import node from 'rollup-plugin-node-resolve'
import buildOptimizer from '@angular-devkit/build-optimizer/src/build-optimizer/rollup-plugin'
import terser from 'rollup-plugin-terser'
export default {
input: {
app: './lib/app.js'
},
output: {
dir: 'public'
View tagged-template-literals.md

Thinking about tagged template literals and HTML templating.

(Disclaimer: I work on the Angular team, but this isn't something the Angular team is considering (yet). This is simply me capturing some thoughts...)

ES2015 added Template Literals to JavaScript (Template Literals is the current term, they were known as "Template Strings" in the first edition)

They're useful for all kinds of things, the most obvious of which is interpolating values in a much more concise way than concatting strings together:

View templates.ts
@Component({
selector: 'wt-greeting',
template: (ctx: WtGreeting) => ngHtml`<h1>Hello ${uppercase(ctx.name)}</h1>`
})
class WtGreeting {
@Input() name: string;
}
@Component({
View build.js
import {rollup} from 'rollup'
import * as path from 'path'
class RollupNG2 {
constructor(options){
this.options = options;
}
resolveId(id, from){
if(id.startsWith('angular2/')){
return `${__dirname}/node_modules/angular2/es6/prod/${id.split('angular2/').pop()}.js`;
View typescript.js
This file has been truncated, but you can view the full file.
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
View comp-a.ts
function toResponseActions(successSelector, errorSelector){
return (requests$) => requests$.pipe(
catchError(err, => errorSelector(err)),
map(res => successSelector(res))
)
}
const buttonClicks = fromEvent('button', 'click');
const requests = buttonClicks.pipe(switchMap(() => http.get('foo.json')));
View zone-build.js
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :