Skip to content

Instantly share code, notes, and snippets.

View lkrych's full-sized avatar

Leland Krych lkrych

  • Cisco
  • San Francisco, CA
View GitHub Profile
@lkrych
lkrych / aws_config.go
Created February 16, 2018 15:29
go aws config
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"
)
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
@lkrych
lkrych / save_idention.go
Created December 18, 2017 04:09
save identicon output to computer
func main() {
//helper functions
newPNGfile := "../../../Desktop/identicon.png"
myimage := image.NewRGBA(image.Rect(0, 0, 250, 250))
//drawing logic
// ... save image
@lkrych
lkrych / draw_identicon.go
Created December 18, 2017 04:08
Main function for drawing the identicon
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 {
@lkrych
lkrych / filter_odd.go
Created December 18, 2017 04:03
filter out all the odd numbers from the identicon grid
func filterOddSquares(grid []byte) []byte {
for i, el := range grid {
if el%2 != 0 {
grid[i] = 0
}
}
return grid
}
@lkrych
lkrych / build_grid.go
Created December 18, 2017 04:03
build grid for identicon generator
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{}
@lkrych
lkrych / draw_color.go
Created December 18, 2017 04:02
part of the main func in identicon_generator
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
}
@lkrych
lkrych / readandhash.go
Created November 21, 2017 16:25
Read user input and hash the input
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
}
# 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
@lkrych
lkrych / pass_by.go
Last active November 10, 2017 17:01
Comparing pass by value to pass by reference
package main
import "fmt"
func main() {
//passing by value //////////////////
X := 3
incrementByVal(X)