Skip to content

Instantly share code, notes, and snippets.

@maxk42
maxk42 / tiny.go
Created May 10, 2018 19:43
Tiny "Hello World" server in go with no dependencies except net/http
package main
import "net/http"
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r * http.Request) {
w.Write([]byte("Hello, World!\n"))
})
http.ListenAndServe(":80", nil)
}
// Node.js CheatSheet.
// Download the Node.js source code or a pre-built installer for your platform, and start developing today.
// Download: http://nodejs.org/download/
// More: http://nodejs.org/api/all.html
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html
@maxk42
maxk42 / website.go
Last active January 16, 2022 01:08
Serving static and dynamic content together in golang
// This assumes your web app is running in a directory which has a subdirectory named 'public/' and
// that there is an 'img/' subdirectory in 'public/' containing an image named 'kitten.jpg'
package main
import (
"fmt"
"net/http"
)
@maxk42
maxk42 / README.md
Last active May 19, 2018 06:11
Simple demonstration of generics-like features in Go.

POLYMORPHISM AND GENERICS IN GO

Lately, Go has been getting a lot of flack for its lack of generics and parametric polymorphism. Whereas it doesn't have a specific language feature called "generics", generic type operations are very simple to implement. Here is a simple implementation of a generic collection type in Go demonstrating how it's done. Essentially, the type interface{} acts as a placeholder for any type. By making use of the empty interface, you can pass any type to a function much like you can in dynamically-typed languages.

Edit: Thanks to https://gist.github.com/mfenniak and https://gist.github.com/dominikh for pointing out that the add() function was equivalent to go's built-in append()