Skip to content

Instantly share code, notes, and snippets.

View chrisl8888's full-sized avatar
πŸ’­
🏈

Chris Lee chrisl8888

πŸ’­
🏈
View GitHub Profile
@chrisl8888
chrisl8888 / README.md
Last active November 3, 2018 13:42
Simple project setup with webpack, typescript and hot reloading

Angular 2.x Quickstart

This is shell project for configuring a typical project for angular 2.x. It includes the most naive example of an angular 2.x project. This uses some of the typical tools: webpack, karma, jasmine, typescript, sass.

Inspired by https://github.com/jeffbcross/aim

@chrisl8888
chrisl8888 / error-catch.es
Created March 18, 2016 15:25
Handling Promise errors
promise.catch(error => {
if (error instanceof OkayError) {
return Observable.of('okay');
} else {
throw error
}
})
@chrisl8888
chrisl8888 / protractor-is-present.js
Created January 22, 2016 05:34
protractor wait for item to be present with promise - stolen from http://docsplendid.com/archives/209
browser.wait(function() {
var deferred = protractor.promise.defer();
element(by.id('some-element')).isPresent()
.then(function (isPresent) {
deferred.fulfill(!isPresent);
});
return deferred.promise;
});
var gulp = require('gulp');
var connect = require('gulp-connect');
var cors = function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', '*');
next();
};
gulp.task('server:test', function () {
// Define gulp before we start
var gulp = require('gulp');
// Define Sass and the autoprefixer
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
// This is an object which defines paths for the styles.
// Can add paths for javascript or images for example
// The folder, files to look for and destination are all required for sass
@chrisl8888
chrisl8888 / angularjs-inject-example.js
Last active January 13, 2016 19:20
Example angular inject es5 format.
(function (ng) {
"use strict";
function MyController($scope) {
// Use Controller As syntax
// https://github.com/johnpapa/angular-styleguide#style-y032
var vm = this;
@chrisl8888
chrisl8888 / react-component-lifecycle.js
Last active January 5, 2016 04:33
Reactjs component lifecycle
/**
* ------------------ The Life-Cycle of a Composite Component ------------------
*
* - constructor: Initialization of state. The instance is now retained.
* - componentWillMount
* - render
* - [children's constructors]
* - [children's componentWillMount and render]
* - [children's componentDidMount]
* - componentDidMount
function traverse(x, level) {
if (isArray(x)) {
traverseArray(x, level);
} else if ((typeof x === 'object') && (x !== null)) {
traverseObject(x, level);
} else {
console.log(level + x);
}
}