Skip to content

Instantly share code, notes, and snippets.

View kumikoda's full-sized avatar
🧎‍♂️
Summoning AI God

Anson Chu kumikoda

🧎‍♂️
Summoning AI God
View GitHub Profile
@kumikoda
kumikoda / return.js
Created May 12, 2014 23:49
returning callbacks early
function someAsyncFn (cb) {
if (somethingWrong) {
cb(err)
} else {
cb(null, 'yay')
}
...
// potentially some things happen here
@kumikoda
kumikoda / error.js
Created June 7, 2014 22:04
why you should not wrap callbacks inside of a try block
function getData (callback) {
try {
var data = JSON.parse('hello world!') // attempt something dangerous here
callback(null, data);
} catch (e) {
// we only want to catch errors if JSON.parse fails
console.log('i should never print since above parsing always works')
callback(e)
}
@kumikoda
kumikoda / 0_reuse_code.js
Last active August 29, 2015 14:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@kumikoda
kumikoda / slices.go
Last active August 29, 2015 14:13
Golang tutorial two-dimensional slices
// https://tour.golang.org/moretypes/14
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
s := make([][]uint8, dy)
for x := range s {
s[x] = make([]uint8, dx)
@kumikoda
kumikoda / maps.go
Last active August 29, 2015 14:13
Golang tutorial maps
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
"fmt"
)
func WordCount(s string) map[string]int {
result := make(map[string]int)
@kumikoda
kumikoda / fibonacci.go
Last active August 29, 2015 14:13
Golang tutorial function closures
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
a,b := 0,1
return func() int {
a,b = b, a+b
@kumikoda
kumikoda / string-method.go
Last active August 29, 2015 14:14
Methods
package main
import "fmt"
type IPAddr [4]byte
// TODO: Add a "String() string" method to IPAddr.
func (ip IPAddr) String() string {
return fmt.Sprintf("%v.%v.%v.%v", ip[0], ip[1], ip[2], ip[3])
}
@kumikoda
kumikoda / error.go
Last active August 29, 2015 14:14
Golang tutorial sqrt function with error
package main
import (
"fmt"
"math"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
better manager positive
fierce leader inspire find things cool (go)
communication, responsiveness, on call awesomeness
interaction with other teams
----------
@kumikoda
kumikoda / ro13.go
Created February 8, 2015 01:33
goland tutorial rot13 reader
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader