Last active
December 11, 2016 20:17
-
-
Save pestophagous/a40eae87daae9225078cd14654d0de21 to your computer and use it in GitHub Desktop.
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 ( | |
"flag" | |
"fmt" | |
"os" | |
) | |
type Celsius float64 | |
type Fahrenheit float64 | |
const ( | |
FreezingC Celsius = 0 // %T will print main.Celsius | |
Other = 0 // %T will print int | |
BoilingC Celsius = 100 | |
) | |
var abc int | |
var def int | |
func init() { | |
abc = 9 | |
} | |
func init() { | |
def = 10 | |
abc = 88 | |
} | |
func init() { | |
abc = 7 | |
// def = 7 | |
} | |
func main() { | |
var hi_int uint8 = 255 | |
hi_int++ | |
fmt.Printf("uint8 255 + 1 = %v\n", hi_int) | |
var hi_intb int8 = 127 | |
hi_intb++ | |
fmt.Printf("int8 127 + 1 = %v\n", hi_intb) | |
var hi_intc int8 = int8(hi_int) | |
fmt.Printf("%v\n", hi_intc) | |
// it does let me cast the SIGNED one to unsigned. (wouldn't compile without cast) | |
if uint8(hi_intc) == hi_int { | |
fmt.Println("equals but one is signed") | |
} | |
fmt.Println() | |
// var abc int | |
abc := "hey" | |
fmt.Printf("init vals. abc %v; def %v;\n", abc, def) | |
fmt.Println() | |
fmt.Printf("FreezingC is %T; Other is %T;\n", FreezingC, Other) | |
fmt.Printf("BoilingC-FreezingC: %g\n", BoilingC-FreezingC) | |
fmt.Printf("BoilingC - 0: %g\n", BoilingC-0) // surprise! literal 0 compiles! where use of a float64 doesn't | |
var somefloat float64 = 20 | |
var someint int = 20 | |
// fmt.Printf("BoilingC - somefloat: %g\n", BoilingC-somefloat) // <-- will not compile | |
// fmt.Printf("BoilingC - someint: %g\n", BoilingC-someint) // <-- will not compile | |
fmt.Printf("somefloat %T; someint %T;\n", somefloat, someint) | |
fmt.Println() | |
/* mutli linae alksdgj fkasdgjkasdfg asdlgkjasdl gl asdgk gjaeg zodifjva drgjad rg zdfgi jadrpg jaerl g aerg | |
/* ;oaerigj alergkjareg | |
*/ | |
var nn int64 | |
nn = 100 | |
xx := 99.99 | |
nn = int64(xx) | |
fmt.Println(nn) | |
//nn = "0" | |
var n *bool | |
n = flag.Bool("n", false, "some bool") | |
flag.Parse() | |
if *n { | |
fmt.Println("yes n") | |
} else { | |
fmt.Println("nope nope not n") | |
} | |
// comment | |
// hi | |
// here is a comment | |
fmt.Println(`this is a message | |
to all my peeps | |
many of whome bla bla`) | |
printArgs() | |
var a, b, c, d = true, // a is bool | |
1, // b is int | |
2.5, // c is float64 | |
"blort" // d is string | |
fmt.Printf("a is %T\nb is %T\nc is %T\nd is %T\n", a, b, c, d) | |
//forStuff() | |
} | |
func printArgs() { | |
defer func() { | |
if p := recover(); p != nil { | |
fmt.Printf("RECOVERY from: %v\n", p) | |
} else { | |
fmt.Println("all clear in defer") | |
} | |
}() | |
yours := func() { | |
fmt.Println("does yours work") | |
} | |
yours() | |
os.Args[99] = "blorp" | |
for _, arg := range os.Args { | |
fmt.Println(arg) | |
} | |
} | |
func ForStuff() { | |
/* | |
// NOTE: ALWAYS TWO semi-colon except for the "While" example | |
// 1 1 1 | |
for i := 0; i < 5; i++ { | |
// 1 1 0 | |
for i := 0; i < 5; { | |
// 1 0 1 | |
for i := 0; ; i++ { | |
// 1 0 0 | |
for i := 0; ; { | |
// 0 1 1 | |
for ; aa < 8; aa++ { | |
// 0 1 0 <--- the while loop | |
for bb <= 8 { | |
// 0 0 1 | |
for ; ; cc++ { | |
*/ | |
// ----------------- | |
put := fmt.Println | |
// 1 1 1 | |
for i := 0; i < 5; i++ { | |
put(i) | |
} | |
put() | |
// 1 1 0 | |
for i := 0; i < 5; { | |
put(i) | |
i++ | |
} | |
put() | |
// 1 0 1 | |
for i := 0; ; i++ { | |
if i < 3 { | |
continue | |
} | |
put(i) | |
if i >= 5 { | |
break | |
} | |
} | |
put() | |
// 1 0 0 | |
for i := 0; ; { | |
put(i) | |
i++ | |
if i == 10 { | |
break | |
} | |
} | |
put() | |
// 0 1 1 | |
aa := 3 | |
for ; aa < 8; aa++ { | |
put(aa) | |
} | |
put() | |
// 0 1 0 <--- the while loop | |
bb := 4 | |
for bb <= 8 { | |
put(bb) | |
bb++ | |
} | |
put() | |
// 0 1 1 | |
cc := 5 | |
for ; ; cc++ { | |
put(cc) | |
if cc == 9 { | |
break | |
} | |
} | |
put() | |
} |
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" | |
"image" | |
"image/jpeg" | |
_ "image/png" | |
"io" | |
"os" | |
) | |
func main() { | |
if err := toJPEG(os.Stdin, os.Stdout); err != nil { | |
fmt.Fprintf(os.Stderr, "jpeg: %v\n", err) | |
os.Exit(1) | |
} | |
} | |
func toJPEG(in io.Reader, out io.Writer) error { | |
img, kind, err := image.Decode(in) | |
if err != nil { | |
return err | |
} | |
fmt.Fprintln(os.Stderr, "Input format = ", kind) | |
return jpeg.Encode(out, img, &jpeg.Options{Quality: 95}) | |
} |
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" | |
"net/http" | |
"os" | |
) | |
var count int | |
func main() { | |
http.HandleFunc("/", handler) | |
http.HandleFunc("/countup", countup) | |
err := http.ListenAndServe("localhost:8765", nil) | |
log.Fatal(err) | |
} | |
func handler(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "count is %d\n", count) | |
fmt.Fprintf(w, "URL.path = %q\n", r.URL.Path) | |
fmt.Fprintf(os.Stderr, "type of w = %T\n", w) | |
fmt.Fprintf(os.Stderr, "type of req = %T\n", r) | |
} | |
func countup(_ http.ResponseWriter, _ *http.Request) { | |
count++ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment