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
func handleGetTweets(w http.ResponseWriter, r *http.Request) { | |
var maxIDQuery string | |
var tweets []Tweet | |
vars := mux.Vars(r) | |
userID := vars["id"] | |
// httpClient will automatically authorize http.Requests | |
httpClient := config.Client(oauth1.NoContext, token) | |
Outer: |
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
func main() { | |
err := godotenv.Load() | |
if err != nil { | |
log.Fatal(err) | |
} | |
// Load API credentials | |
config = oauth1.NewConfig(os.Getenv("APIKEY"), os.Getenv("APISECRET")) | |
token = oauth1.NewToken(os.Getenv("TOKEN"), os.Getenv("TOKENSECRET")) |
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
// makeMuxRouter defines and creates routes | |
func makeMuxRouter() http.Handler { | |
muxRouter := mux.NewRouter() | |
muxRouter.HandleFunc("/{id}", handleGetTweets).Methods("GET") | |
return muxRouter | |
} | |
func respondWithError(err error, w http.ResponseWriter) { | |
log.Println(err) | |
w.WriteHeader(500) |
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
// Tweet is a collection of important info in each Tweet | |
type Tweet struct { | |
Date string `json:"created_at"` | |
Text string `json:"text"` | |
ID string `json:"id_str"` | |
} | |
var config *oauth1.Config | |
var token *oauth1.Token |
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"os" | |
"regexp" |
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
func (s *SmartContract) changeCarOwner(APIstub shim.ChaincodeStubInterface, args []string) sc.Response { | |
if len(args) != 2 { | |
return shim.Error("Incorrect number of arguments. Expecting 2") | |
} | |
carAsBytes, _ := APIstub.GetState(args[0]) | |
car := Car{} | |
json.Unmarshal(carAsBytes, &car) |
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
// Block represents each 'item' in the blockchain | |
type Block struct { | |
Index int | |
Timestamp string | |
BPM int | |
Hash string | |
PrevHash string | |
Validator string | |
} |
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
function transfer(address _to, uint256 _value) { | |
require(balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]); | |
balanceOf[msg.sender] -= _value; | |
balanceOf[_to] += _value; | |
} |
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
func main() { | |
t := time.Now() | |
genesisBlock := Block{} | |
genesisBlock = Block{0, t.String(), 0, calculateHash(genesisBlock), ""} | |
Blockchain = append(Blockchain, genesisBlock) | |
// LibP2P code uses golog to log messages. They log with different | |
// string IDs (i.e. "swarm"). We can control the verbosity level for | |
// all loggers with: |
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
func writeData(rw *bufio.ReadWriter) { | |
go func() { | |
for { | |
time.Sleep(5 * time.Second) | |
mutex.Lock() | |
bytes, err := json.Marshal(Blockchain) | |
if err != nil { | |
log.Println(err) | |
} |
NewerOlder