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
// This function will return a promise that will fetch data from a certain URL | |
function getURLPromise(url) { | |
return new Promise((resolve, reject) => { | |
http.get(url, (rs) => { | |
var data = '' | |
rs.on('data', (chunk) => data += chunk); | |
rs.on('end', ()=> resolve(data.length)); | |
}); | |
}); |
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
co(function* () { | |
var result = yield Promise.resolve(true); | |
return result; | |
}).then(function (value) { | |
console.log(value); | |
}, function (err) { | |
console.error(err.stack); | |
}); |
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
co(function *() { | |
// yield any promise | |
var a = yield getURLPromise('http://www.google.com') | |
var b = yield getURLPromise('http://www.apple.com') | |
var c = yield getURLPromise('http://www.microsoft.com') | |
debug([a, b, c]); | |
}).catch((error) =>{ | |
debug("Something went wrong: ", error) | |
}); |
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
div.login-page | |
form(class='form-login', action='/web-login', method='POST') | |
input(type='text', name='username', placeholder='Username',required, autofocus) | |
input(type='password', name='password', placeholder='Password', required) | |
input(type='hidden', id='url', name='url') | |
button(class='btn', type='submit') Sign in | |
script(type='text/javascript'). | |
document.getElementById("url").value = window.location.hash; |
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
// Login strategy. Enable passing through of the req object by setting passReqToCallback to true. | |
passport.use(new Strategy({ passReqToCallback: true }, | |
function (req,username, password, done) { | |
let user = your_user_auth(username,password); // returns the user object if valid, otherwise null | |
if(user) | |
// Extract the redirect hash from the request body and store it in the request session object | |
req.session.redirect_url = req.body.url; | |
return done(null, user); | |
} | |
return done(null, false); |
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
// User requests the /app/ route -> Check if he is authenticated | |
router.get('/app/', isAuthenticated, (req, res) => res.render('app') ); | |
// The isAuthenticated function is using passport.js here to see if the user is logged in (req.isAuthenticated) | |
// It that's not the case, we redirect them to the login route. | |
const isAuthenticated = (req, res, next) => { | |
if(req.isAuthenticated()) return next(); | |
res.redirect('/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
var createStructuredSelector = require('reselect').createStructuredSelector; | |
var createSelector = require('reselect').createSelector; | |
// Example of structured selector | |
const mySelectorA = (state) => state.first_user; | |
const mySelectorB = (state) => state.second_user; | |
const mySelectorC = (state) => state.second_user + state.first_user; | |
const structuredSelector = createStructuredSelector({ |
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 express = require('express'); | |
const Web3 = require('web3'); | |
const app = express(); | |
const web3 = new Web3(new Web3.providers.HttpProvider("http://geth:8545")); | |
app.get('/', async (req, res) => res.send(`Coinbase: ${await web3.eth.getCoinbase()}`)); | |
app.listen(3001, () => console.log('Listening on port 3001!')); |
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
FROM node:7.8.0 | |
ENV NPM_CONFIG_LOGLEVEL warn | |
WORKDIR /app | |
COPY package.json ./ | |
RUN npm install | |
RUN npm install -g nodemon |
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
// Tag and custom dockerfile | |
docker build -t cryptotracker . -f Dockerfile.txt | |
docker container prune | |
// ENV file | |
docker run -e REDIS_URL='...' --env-file vars -p 3001:3001 cryptotracker | |
// Networks | |
docker network list | |
docker network create <network> |
OlderNewer