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 ( | |
"log" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/credentials" | |
"github.com/aws/aws-sdk-go/aws/session" | |
) |
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" | |
"log" | |
"os" | |
"strings" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/credentials" |
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() { | |
//helper functions | |
newPNGfile := "../../../Desktop/identicon.png" | |
myimage := image.NewRGBA(image.Rect(0, 0, 250, 250)) | |
//drawing logic | |
// ... save image |
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() { | |
// helper function from above | |
myimage := image.NewRGBA(image.Rect(0, 0, 250, 250)) | |
white := color.RGBA{255, 255, 255, 255} | |
// backfill entire surface with white | |
draw.Draw(myimage, myimage.Bounds(), &image.Uniform{white}, image.ZP, draw.Src) | |
for idx, el := range filtered { |
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 filterOddSquares(grid []byte) []byte { | |
for i, el := range grid { | |
if el%2 != 0 { | |
grid[i] = 0 | |
} | |
} | |
return grid | |
} |
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 buildGrid(hash [16]byte) []byte { | |
chunked := [5][]byte{} | |
//chunk the bytes | |
for i := 0; i < len(hash)-1; i++ { | |
chunked[i/3] = append(chunked[i/3], hash[i]) | |
} | |
// mirror the first and zeroth index of the chunks | |
// flatten into slice | |
flattened := []byte{} |
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() { | |
hashedInput := readAndHashInput() | |
c := hashedInput[:3] | |
colorDraw := color.RGBA{c[0], c[1], c[2], 255} | |
grid := buildGrid(hashedInput) | |
filtered := filterOddSquares(grid) | |
// code for drawing the identicon | |
} |
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 readAndHashInput() [16]byte { | |
reader := bufio.NewReader(os.Stdin) //create a stdIn reader | |
fmt.Print("Enter text to create an identicon: ") //prompt the user | |
text, _ := reader.ReadString('\n') | |
return md5.Sum([]byte(text)) //hash user input | |
} |
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
# ruby is also a pass by value language | |
def increment(x) | |
x+=1 | |
end | |
x = 3 | |
increment(x) | |
puts x # 3 | |
#assign x to the new value and address generated by increment |
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" | |
func main() { | |
//passing by value ////////////////// | |
X := 3 | |
incrementByVal(X) |