Skip to content

Instantly share code, notes, and snippets.

View duartefdias's full-sized avatar

Duarte Dias duartefdias

View GitHub Profile
# # C1: Each room can only hold 1 class at a time
def check_C1(self, A, a, B, b):
if a[0] == b[0] and a[1] == b[1] and a[2] == b[2]:
return False
return True
# # C2: Each student (class) can only attend a class at a time
def check_C2(self, A, a, B, b):
for key in dict1:
@duartefdias
duartefdias / create-vm.yml
Last active December 30, 2020 16:10
Call powershell script with Azure data
on: [workflow_dispatch]
name: DeployAzureVM
jobs:
CreateAzureVM:
runs-on: windows-latest
steps:
@duartefdias
duartefdias / gist:9b1c917b9cc101b6dff6542868687876
Created December 30, 2020 15:04
Create VM in Azure powershell script
# Login to Azure using Service Principal credentials from Github Secrets
Write-Output "Logging in to Azure with a service principal..."
az login `
--service-principal `
--username $Env:SP_CLIENT_ID `
--password $Env:SP_CLIENT_SECRET `
--tenant $Env:SP_TENANT_ID
Write-Output "Done"
# Select Azure subscription
<script>
import Web3 from 'web3'
export default ({
data() {
return {
buttonDisabled: false,
buttonInstallText: "Click here to install Metamask",
}
},
var express = require('express');
var router = express.Router();
// Used to perfrom signature authentication
var ethUtil = require('ethereumjs-util');
// JWT generation and verification
const jwt = require('jsonwebtoken');
import passport from 'passport'
const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;
const mongoose = require('mongoose');
import User from '../models/users';
const opts = {};
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.secretOrKey = process.env.JWT_SECRET;
module.exports = passport => {
// Test authenticated route
// Use this route to test if the front-end is able to access this route
// Front-end needs to pass the token in the request header (header name: "Authorization")
router.get('/authenticated/test', passport.authenticate('jwt', { session: false }), (req, res) => {
console.log('Authentication successful');
res.json({
message: 'Successfully authenticated',
user: req.user
});
});
async connectToMetamask() {
try {
// Connect to metamask and get user accounts
const accounts = await this.$store.getters['metamask/ethereum'].request({ method: 'eth_requestAccounts' });
// Update vuex store
this.$store.commit('metamask/setMetamaskConnected', true)
this.$store.commit('metamask/setAccounts', accounts)
// Check if user is registered, if not, register them
// Get user nonce
router.get('/:wallet_address/nonce', (req, res) => {
// Check if user exists
// ... search in database for user and returns its current nonce
});
// Process signed message
router.post('/:user/signature', (req, res) => {
// Get user from db
User.findOne({wallet_address: req.params.user}, (err, user) => {
export const state = () => ({
metamaskConnected: false,
ethereum: null,
accounts: []
})
export const mutations = {
setMetamaskConnected(state, value) {
state.metamaskConnected = value
},