Skip to content

Instantly share code, notes, and snippets.

Avatar

Andy Park nosequeldeebee

View GitHub Profile
View main.go
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:
View main.go
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"))
View main.go
// 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)
View main.go
// 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
View main.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
View fabcar.go
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)
View main.go
// Block represents each 'item' in the blockchain
type Block struct {
Index int
Timestamp string
BPM int
Hash string
PrevHash string
Validator string
}
View transfer.sol
function transfer(address _to, uint256 _value) {
require(balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]);
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
}
View main.go
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:
View main.go
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)
}
You can’t perform that action at this time.