Skip to content

Instantly share code, notes, and snippets.

View thecreazy's full-sized avatar
🍺
Beer > Code

Riccardo Canella thecreazy

🍺
Beer > Code
View GitHub Profile
@thecreazy
thecreazy / router_adddelete.js
Created January 21, 2019 11:55
Add and remove functions to the router
class Router{
routes: []
mode: null
root: '/'
constructor(){
this.mode = !!(history.pushState) ? 'history' : 'hash';
}
add: (path, cb) => {
@thecreazy
thecreazy / router.js
Last active January 21, 2019 11:37
Start the router implementation
class Router{
routes: []
mode: null
root: '/'
constructor(){
this.mode = !!(history.pushState) ? 'history' : 'hash';
}
}
@thecreazy
thecreazy / chiccocoin.js
Created January 24, 2018 10:36
Gist used for the blockchain article on medium
const Blockchain = require('./blockchain')
const { validationResult } = require('express-validator/check')
class Chiccocoin {
constructor () {
this.blockchain = new Blockchain()
this.getChain = this.getChain.bind(this)
this.mine = this.mine.bind(this)
this.newTransaction = this.newTransaction.bind(this)
}
@thecreazy
thecreazy / pow.js
Created January 24, 2018 10:16
Gist for my medium article on blockchain
validProof (lastProof, proof) {
const guessHash = crypto.createHmac(process.env.HASH_TYPE, process.env.CRYPTO_SECRET)
.update(`${lastProof}${proof}`)
.digest('hex')
return guessHash.substr(0, 5) === process.env.RESOLUTION_HASH
}
proofOfWork (lastProof) {
let proof = 0
while (true) {
class Blockchain {
constructor () {
// Create chain and transaction
this.chain = []
this.current_transactions = []
// Binding of this
this.newBlock = this.newBlock.bind(this)
this.newTransaction = this.newTransaction.bind(this)
this.lastBlock = this.lastBlock.bind(this)
@thecreazy
thecreazy / block.js
Created January 16, 2018 13:48
Gist for my medium article on blockchain
const block = {
'index': 1,
'timestamp': 1506057125.900785,
'transactions': [
{
'sender': "8527147fe1f5426f9dd545de4b27ee00",
'recipient': "a77f5cdfa2934df3954a5c7c7da5df1f",
'amount': 5,
}
],
@thecreazy
thecreazy / blockchain_start.js
Created January 16, 2018 13:40
Gist for my medium article on blockchain
class Blockchain {
constructor () {
// Create chain and transaction
this.chain = []
this.current_transactions = []
// Binding of this
this.newBlock = this.newBlock.bind(this)
this.newTransaction = this.newTransaction.bind(this)
this.lastBlock = this.lastBlock.bind(this)