Skip to content

Instantly share code, notes, and snippets.

Avatar
🐪
Working on something new

Joe Chasinga jochasinga

🐪
Working on something new
View GitHub Profile
@jochasinga
jochasinga / func.go
Created Sep 30, 2014
Function in Go
View func.go
package main
import "fmt"
func colormap(r uint8, g uint8, b uint8) (color map[string]uint8) {
color := map[string]uint8{
"r" : r
"g" : g,
"b" : b,
}
@jochasinga
jochasinga / swap.go
Created Sep 30, 2014
Multiple return values in Go
View swap.go
package main
import "fmt"
func swap(a, b int) (int, int) {
_a := a
_b := b
a, b = _b, _a
@jochasinga
jochasinga / file.go
Created Sep 30, 2014
Using defer to close file in Go
View file.go
package main
import "os"
func main() {
file, err := os.Open("test.txt")
defer file.Close()
if err != nil {
// handle the error here
return "", err
@jochasinga
jochasinga / panic_recover.go
Created Sep 30, 2014
Defer-panic-recover suite in Go
View panic_recover.go
package main
import "fmt"
func main() {
// makes sure recover gets call when faced with panic
defer func() {
str := recover()
fmt.Println(str)
}()
@jochasinga
jochasinga / struct.go
Last active Aug 29, 2015
Struct in Go
View struct.go
package main
import "fmt"
type Gopher struct {
kingdom string
color map[string]int
num_legs int
height float
}
@jochasinga
jochasinga / struct_func.go
Last active Aug 29, 2015
Function that takes struct as an argument in Go
View struct_func.go
package main
import "fmt"
type Gopher struct {
kingdom string
color map[string]int
num_legs int
height float32
}
@jochasinga
jochasinga / interface1.go
Last active Aug 29, 2015
Basic method calling before implementing interfaces
View interface1.go
package main
import "fmt"
type Man struct {
language string
// other factors to decide if the girl would like you (for fun)
name, nationality, build, eye_color string
age, height uint8
@jochasinga
jochasinga / interface2.go
Created Oct 1, 2014
Abstracting a method to an interface
View interface2.go
package main
import "fmt"
type Greeter interface {
Greet()
}
type Man struct {
language string
@jochasinga
jochasinga / interface3.go
Last active Aug 29, 2015
Inheriting and reusing through structs and interfaces in Go
View interface3.go
package main
import(
"fmt"
"io/ioutil"
"os"
)
type Greeter interface {
Greet()
@jochasinga
jochasinga / pot.js
Last active Aug 29, 2015
Johnny-five potentiometer code for adjusting RGB LED colors and updating values to Firebase
View pot.js
var Firebase = require("firebase");
var five = require("johnny-five");
// Create a new reference of Firebase db
var firebaseRef = new Firebase(
// fictional URL, replace it with your own from Firebase
"https://burning-limbo-6666.firebaseio.com/colors"
);
five.Board().on("ready", function() {
You can’t perform that action at this time.