This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add a 401 response interceptor | |
window.axios.interceptors.response.use(function (response) { | |
return response; | |
}, function (error) { | |
if (401 === error.response.status) { | |
window.location = '/login'; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const checkOrReject = (preFetch, condition, errorMessage) => preFetch() | |
.then(data => (condition(data)) | |
? Promise.resolve() | |
: Promise.reject(Boom.forbidden()); | |
const doesUserOwnFeed = (feed, userId) => feed._user === userId; | |
const doesUserOwnFeedOrReject = (feed, _user) => checkOrReject( | |
() => doesUserOwnFeed(feed, userId), | |
'Feed not found' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/user/:id', function (req, res, next) { | |
console.log('middleware 1 reached', req.params); | |
next(); | |
}, function (req, res, next) { | |
const { id } = req.params; | |
console.log('middleware 2 reached'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const squareAsync = (nbr) => { | |
return new Promise((resolve) => { | |
// mock async call, to illustrate a heavy weight backend process which returns the square of a number | |
setTimeout(() => resolve(nbr * nbr), 200); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function bubbleSort(array: number[]): number[] { | |
array = array.slice(); // creates a copy of the array | |
for(let i = 0; i < array.length; i++) { | |
for(let j = 0; j < array.length - 1; j++) { | |
if(array[j] > array[j + 1]) { | |
let swap = array[j]; | |
array[j] = array[j + 1]; | |
array[j + 1] = swap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Promise } from "es6-promise" | |
import { Thenable } from "es6-promise" | |
export class Deferred<T> { | |
public promise: Promise<T>; | |
public resolve: (value?: T | Thenable<T>) => void; | |
public reject: (error?: any) => void; | |
constructor() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Playtem.init({ | |
apiKey: "e048-4cdev", | |
container: document.getElementById("playtem-ad"), | |
modal: true, | |
userId: "WebTestUser1", | |
onAdAvailable: function() { | |
console.log("Page.onAdAvailable"); | |
}, | |
onAdClick: function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FizzBuzz { | |
private min: number; | |
private max: number; | |
constructor(min:number, max:number) { | |
this.min = min; | |
this.max = max; | |
} | |
private containsDigit(currentNumber:number, digit: number) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gulp = require('gulp'); | |
const argv = require('yargs').argv; | |
const merge = require('merge'); | |
const webpack = require('webpack'); | |
const webpackStream = require('webpack-stream'); | |
const connect = require('gulp-connect'); | |
const paths = { | |
pages: ['./src/*.html'], | |
buildDir: "./build/dev" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
font-family: sans-serif; | |
padding: 10px; | |
} | |
h2 { | |
font-weight: bold; | |
display: inline-block; | |
} | |
.refresh { | |
font-size: 80%; |