Skip to content

Instantly share code, notes, and snippets.

https://leetcode.com/problems/intersection-of-two-arrays/
Different ways to initialize arrays
====================================
package main
import (
"fmt"
)
html
====
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<div id="container">mm</div>
JS
Arrays are homogeneous—their elements all have the same type—whereas structs are heterogeneous. Both arrays and structs are fixed size. In contrast, slices and maps are dynamic data structures that grow as values are added.
a := [2]int{1, 2}
b := [...]int{1, 2}
c := [2]int{1, 3}
months := [...]string{1: "January", /* ... */, 12: "December"}
so January is months[1] and December is months[12]. Ordinarily, the array element at index 0 would contain the first value, but because months are always numbered from 1, we can leave it out of the declaration and it will be initialized to an empty string.
Arrays and slices are intimately connected. A slice is a lightweight data structure that gives access to a subsequence (or perhaps all) of the elements of an array, which is known as the slice’s underlying array. A slice has three components: a pointer, a length, and a capacity. The pointer points to the first element of the array that is reachable through the slice, which is not necessarily the array’s
Runes are printed with %c, or with %q if quoting is desired:
ascii := 'a'
unicode := 'D'
newline := '\n'
fmt.Printf("%d %[1]c %[1]q\n", ascii) // "97 a 'a'"
fmt.Printf("%d %[1]c %[1]q\n", unicode) // "22269 D 'D'"
fmt.Printf("%d %[1]q\n", newline) // "10 '\n'"
Float
http://openmymind.net/Introduction-To-Go-Channels/
sync.Mutex
We've seen how channels are great for communication among goroutines.
But what if we don't need communication? What if we just want to make sure only one goroutine can access a variable at a time to avoid conflicts?
This concept is called mutual exclusion, and the conventional name for the data structure that provides it is mutex.
@cc2011
cc2011 / gist:6a88c566f15b9b0ed179b0a9a7c5a78c
Last active May 5, 2016 21:57
ch5 Method (go) + Interface (go) + gorountines(go)
Method
======
package main
import (
"fmt"
"math"
)
map
===
package main
import (
"fmt"
)
func main() {
mapAge := make(map[string]int)
echo4
=====
/*
var name type = expression
Either the type or the = expression part may be omitted, but not both.
If the type is omitted, it is determined by the initializer expression.
If the expression is omitted,
the initial value is the zero value for the type, which is 0 for numbers,
false for booleans, "" for strings, and nil for interfaces and reference types
Go online docs : https://golang.org/pkg/net/http/#Get
https://github.com/adonovan/gopl.io/tree/master/ch1
echo1
======
package main
/*
import (
"fmt"
@cc2011
cc2011 / gist:89b0642d11605d41adaf
Last active February 6, 2016 03:46
javascript
Exceptions
==========
var add = function(a,b) {
if(typeof a !== 'number' || typeof b !== 'number') {
throw {
name : 'TypeError',
message: 'add needs numbers'
};
}
return a+b;