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
PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\] \[\033[33;1m\]\w\[\033[0;31m\] (\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)) \[\033[37m\]\$ " | |
alias clp="xclip -selection clipboard" | |
#shared bash history | |
export PROMPT_COMMAND="history -a; history -n" |
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
[ | |
{ "keys": ["alt+right"], "command": "next_view" }, | |
{ "keys": ["alt+left"], "command": "prev_view" } , | |
{ "keys": ["ctrl+shift+r"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true}} | |
] |
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
fallocate -l 4G /swapfile | |
sudo chmod 600 /swapfile | |
mkswap /swapfile | |
swapon /swapfile |
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
sudo apt-get install bridge-utils | |
sudo pkill docker | |
sudo iptables -t nat -F | |
sudo ifconfig docker0 down | |
sudo brctl delbr docker0 | |
sudo service docker start |
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 Block { | |
constructor(index, previousHash, timestamp, data, hash) { | |
this.index = index; | |
this.previousHash = previousHash.toString(); | |
this.timestamp = timestamp; | |
this.data = data; | |
this.hash = hash.toString(); | |
} | |
} |
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 calculateHash = (index, previousHash, timestamp, data) => { | |
return CryptoJS.SHA256(index + previousHash + timestamp + data).toString(); | |
}; |
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 generateNextBlock = (blockData) => { | |
var previousBlock = getLatestBlock(); | |
var nextIndex = previousBlock.index + 1; | |
var nextTimestamp = new Date().getTime() / 1000; | |
var nextHash = calculateHash(nextIndex, previousBlock.hash, nextTimestamp, blockData); | |
return new Block(nextIndex, previousBlock.hash, nextTimestamp, blockData, nextHash); | |
}; |
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 getGenesisBlock = () => { | |
return new Block(0, "0", 1465154705, "my genesis block!!", "816534932c2b7154836da6afc367695e6337db8a921823784c14378abed4f7d7"); | |
}; | |
var blockchain = [getGenesisBlock()]; |
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 isValidNewBlock = (newBlock, previousBlock) => { | |
if (previousBlock.index + 1 !== newBlock.index) { | |
console.log('invalid index'); | |
return false; | |
} else if (previousBlock.hash !== newBlock.previousHash) { | |
console.log('invalid previoushash'); | |
return false; | |
} else if (calculateHashForBlock(newBlock) !== newBlock.hash) { | |
console.log('invalid hash: ' + calculateHashForBlock(newBlock) + ' ' + newBlock.hash); | |
return 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
var replaceChain = (newBlocks) => { | |
if (isValidChain(newBlocks) && newBlocks.length > blockchain.length) { | |
console.log('Received blockchain is valid. Replacing current blockchain with received blockchain'); | |
blockchain = newBlocks; | |
broadcast(responseLatestMsg()); | |
} else { | |
console.log('Received blockchain invalid'); | |
} | |
}; |
OlderNewer