Skip to content

Instantly share code, notes, and snippets.

@manveru
manveru / http_hello.go
Created May 21, 2010 12:11
Little hello world server in Go
package main
import (
. "fmt"
"http"
)
func handler(c *http.Conn, r *http.Request) {
Fprintf(c, "Hi there, I love %s!", r.URL.Path[1:])
}
@manveru
manveru / gears.go
Created May 24, 2010 13:06
Gears with SDL/OpenGL in Go
package main
import (
"sdl"
"gl"
"time"
. "math"
. "fmt"
)
package main
import "math"
type Point struct {
x int
y int
}
func (p0 Point) distanceTo(p1 Point) float64{
package main
import (
"gl"
"sdl"
)
func main() {
if sdl.Init(sdl.INIT_VIDEO) < 0 {
panic("Video initialization failed: " + sdl.GetError())
Bacon: {
contexts: []
errors: []
}
Bacon.describe: (name, context) ->
@contexts.push([name, context])
assume: (code) ->
if code() isnt true
require('../oxid')
bacon: require('../bacon')
sys: require('sys')
assert: require('assert')
Array.prototype.compareArrays: (arr) ->
if @length != arr.length
return false
for elem, i in arr
if elem.compareArrays # likely nested array
start = Void program:Program Void { return program }
Void = Space*
Space "Space" = [\t ]+
Stop "Stop" = [\n\r;]+ Void
EOF "End of File" = !.
Comment "Comment" = c:"#" t:(&[^\n\r] .)* (Stop / EOF) {
return c + t.map(function(a){ return a[1] }).join("")
}
String << = (other|
self concat: other
)
String from:to: = (start end|
temp = ""
(start to: end) do: [i|
char = self at: i
(char == nil) unless: [|
temp concat: char
Morse = Object clone
Morse translation-table = [
"A", ".-"
"B", "-..."
"C", "-.-."
"D", "-.."
"E", "."
"F", "..-."
"G", "--."
"H", "...."
Integer bottles = (|
(self == 0) if: [|
"No more bottles"
] else: [|
(self == 1) if: [|
"1 bottle of beer"
] else: [|
(self to-s) + " bottles of beer"
]
]