Skip to content

Instantly share code, notes, and snippets.

Jan Jorissen Qaaj

Block or report user

Report or block Qaaj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View commands.sh
// 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>
@Qaaj
Qaaj / basic-express-ethereum.js
Created Nov 23, 2017
Displaying coinbase of Ethereum network
View basic-express-ethereum.js
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!'));
@Qaaj
Qaaj / docker-compose-reload.yml
Last active May 4, 2019
Docker compose file for live reload
View docker-compose-reload.yml
version: '3'
services:
web:
build: .
command: npm run dev
ports:
- "3001:3001"
depends_on:
- geth
volumes:
@Qaaj
Qaaj / Dockerfile
Last active Nov 26, 2017
Live-reload dockerfile
View Dockerfile
FROM node:7.8.0
ENV NPM_CONFIG_LOGLEVEL warn
WORKDIR /app
COPY package.json ./
RUN npm install
RUN npm install -g nodemon
@Qaaj
Qaaj / reselect.js
Created Sep 7, 2017
Reselect Playground
View reselect.js
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({
View passport_strategy_and_route.js
// 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);
View login_template.jade
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;
View express_is_authenticated.js
// 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');
}
View promises_with_co.js
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)
});
View co_example.js
co(function* () {
var result = yield Promise.resolve(true);
return result;
}).then(function (value) {
console.log(value);
}, function (err) {
console.error(err.stack);
});
You can’t perform that action at this time.