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
#!/usr/bin/env python | |
def distance(start:int, blocks:list) -> int: | |
frog1, frog2 = start, start | |
for i in range(start, 0, -1): | |
if blocks[i-1] < blocks[i]: | |
break | |
frog1 = i-1 | |
for i in range(start, len(blocks)-1): | |
if blocks[i+1] < blocks[i]: |
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
Marshal | Encode | ||
---|---|---|---|
Type of Component | Function | Method | |
Processing | Whole data at once | A chunk of data at once depending upon the inputs to it |
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
jsonData, err = json.Marshal(data) | |
if err != nil { | |
// Handle Error | |
} | |
err = ioutil.WriteFile("filename.json", jsonData, 0777) | |
if err != nil { | |
// Handle Error | |
} |
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
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
jsonData, err = json.Marshal(data) | |
if err != nil { | |
// Handle Error | |
} | |
_, err = w.Write(jsonData) | |
if err != nil { | |
// Handle Error | |
} | |
}) |
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 jsonData []byte | |
jsonData, err = json.Marshal(data) | |
if err != nil { | |
// Handle Error | |
} | |
fmt.Println(jsonData) // JSON data in bytes | |
fmt.Println(string(jsonData)) // String for format verification |
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
type Character struct { | |
Name string `json:"name"` | |
Designation []string `json:"designation"` | |
Age int `json:"age"` | |
Moves []Move `json:"moves"` | |
} | |
type Move struct { | |
Name string `json:"move"` | |
Power int `json:"power"` |
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 "fmt" | |
// PrimeGenerator creates a generator goroutine that returns prime numbers, least first | |
func PrimeGenerator(close <-chan int) chan int { | |
var current int | |
var flag bool | |
ch := make(chan int) |
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
// Channel is a custom type to hold channel and context variables. | |
type Channel struct { | |
// Only unexported fields | |
ch chan interface{} | |
ctx context.Context | |
cancelFunc context.CancelFunc | |
} | |
// runProducer is creates a separate goroutine that continuously produces given message. |
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 ( | |
"fmt" | |
"net/http" | |
"os" | |
) | |
// HashMap is the implementation of a hash map in Go | |
type HashMap map[interface{}]interface{} |
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 randomStrings | |
import ( | |
"context" | |
"math/rand" | |
"time" | |
) | |
// randInt is local function that returns a random integer between provided min, max. | |
func randInt(min int, max int) int { |
NewerOlder