Skip to content

Instantly share code, notes, and snippets.

View lhartikk's full-sized avatar

Lauri Hartikka lhartikk

  • Helsinki, Finland
View GitHub Profile
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"
@lhartikk
lhartikk / gist:235a32912c5bd701ca3a
Created March 4, 2015 08:40
Sublime Keybindings
[
{ "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}}
]
fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
@lhartikk
lhartikk / gist:9121dc311d3df07cdc33
Last active July 2, 2016 22:59
docker "network/bridge flush"
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
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();
}
}
var calculateHash = (index, previousHash, timestamp, data) => {
return CryptoJS.SHA256(index + previousHash + timestamp + data).toString();
};
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);
};
var getGenesisBlock = () => {
return new Block(0, "0", 1465154705, "my genesis block!!", "816534932c2b7154836da6afc367695e6337db8a921823784c14378abed4f7d7");
};
var blockchain = [getGenesisBlock()];
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;
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');
}
};