This file contains hidden or 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
| /*! | |
| Source code to convert Roman numerals to Arabic numbers. | |
| I hope it help someone! | |
| 2014-03-07 | |
| */ | |
| var i = 0; |
This file contains hidden or 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 alphabet = [ | |
| 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', | |
| 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', | |
| 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', | |
| 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' | |
| ]; | |
| // get char position in array | |
| function stringToNumber (string) { | |
| var number = 0; |
This file contains hidden or 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
| package main | |
| import "fmt" | |
| // Cria estrutura | |
| type item struct { | |
| string | |
| w, v int | |
| } | |
This file contains hidden or 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
| package main | |
| import "fmt" | |
| func main() { | |
| urls := []string{"github.com", | |
| "twitter.com", | |
| "facebook.com", | |
| "instagram.com"} |
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "strings" | |
| ) | |
| func CompareTwoStrings(stringOne, stringTwo string) float32 { | |
| removeSpaces(&stringOne, &stringTwo) |
This file contains hidden or 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
| package block | |
| import ( | |
| "time" | |
| ) | |
| type Block struct { | |
| Index int | |
| PreviousHash string | |
| Data string |
This file contains hidden or 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
| func (b *Block) GenerateHash() { | |
| index := strconv.Itoa(b.Index) | |
| nonce := strconv.Itoa(b.Nonce) | |
| b.Hash = fmt.Sprintf("%x", sha256.Sum256([]byte(index+b.PreviousHash+b.Data+b.Timestamp.String()+nonce))) | |
| } | |
| func (b *Block) Mine() { | |
| prefix := getPrefix(b.Difficulty) |
This file contains hidden or 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
| package blockchain | |
| import ( | |
| "github.com/fernandoporazzi/blockchain-golang/block" | |
| ) | |
| type Blockchain struct { | |
| Blocks []block.Block | |
| Index int | |
| Difficulty int |
This file contains hidden or 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
| func (b *Blockchain) CreateGenesisBlock() { | |
| block := block.CreateBlock() | |
| block.Index = 0 | |
| block.PreviousHash = "0000000000000000000000000000000000000000000000000000000000000000" | |
| block.Data = "Genesis Block" | |
| block.Difficulty = b.Difficulty | |
| block.Mine() |
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "github.com/fernandoporazzi/blockchain-golang/blockchain" | |
| ) | |
| func main() { | |
| blockchain := blockchain.CreateBlockchain() |
OlderNewer