Skip to content

Instantly share code, notes, and snippets.

// go/doc/GoCourseDay1.pdf Initialization example
package transcendental
import "math"
var Pi float64
func init() {
Pi = 4 * math.Atan(1) //init() function computes Pi
}
#python 3.1
x = 'hello'
y = 'world'
print(x + " " + y)
package main
import "fmt"
func main() {
m := make(map[string]int) //initialize
//map[keyType]valueType
m["Alice"] = 21 //Store Values to initialized
@gregworley
gregworley / composite literal expansion
Created April 28, 2011 16:54
From Gary Burd's Oauth.go package
var noEscape = [256]bool{
'A': true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
'a': true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
'0': true, true, true, true, true, true, true, true, true, true,
'-': true,
'.': true,
'_': true,
'~': true,
}
//working example of func(*iter)Next from: http://goneat.org/pkg/launchpad.net/mgo/#Iter.Next
package main
import (
"fmt"
"launchpad.net/mgo"
)
type Person struct {
@gregworley
gregworley / gist:1198903
Created September 6, 2011 20:45
almost lost
//http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html#PrivateContent_AuthExamples
//Amazon CloudFront Developer's Guide (API Version 2010-11-01) Using Amazon Cloudfront>Serving Private Content > Creating a Signed URL
package main
import (
"os"
"strconv"
"fmt"
"io/ioutil"
@gregworley
gregworley / trivialTemplate.go
Created October 7, 2011 20:48
Golang's New Template pkg
package main
import ("template" ;"os")
const templ = `Hello {{.Name}}`
type Person struct {Name string}
func main() {
me := &Person{Name: "greg"}
var t = template.Must(template.New("first").Parse(templ))
@gregworley
gregworley / gobfun.go
Created October 13, 2011 20:33
fun with gob
//Encoding a map to a gob. Save the gob to disk. Read the gob from disk. Decode the gob into another map.
package main
import (
"fmt"
"gob"
"bytes"
"io/ioutil"
)
func main() {
@gregworley
gregworley / gist:1294450
Created October 18, 2011 02:10 — forked from bradfitz/gist:1190721
go x11 mpeg stream viewer
// X11 viewer for a MJPEG stream, such as the one obtained from the
// Android app https://market.android.com/details?id=com.pas.webcam
package main
import (
"exp/gui/x11"
"flag"
"http"
"image"
@gregworley
gregworley / gist:1314449
Created October 25, 2011 21:52
jwplayer problem
<!doctype html>
<head> <meta charset="utf-8">
<title></title>
<link rel="sytlesheet" href="css/sytle.css">
<script type="text/javascript" src="http://worleyworks.com.s3.amazonaws.com/jwscript.js"></script>
</head>
<body>
<div id="container">Loading the player...</div>
<script type="text/javascript">
jwplayer("container").setup({