Skip to content

Instantly share code, notes, and snippets.

View icholy's full-sized avatar
💥
breaking things

Ilia Choly icholy

💥
breaking things
View GitHub Profile
@icholy
icholy / http.md
Last active November 28, 2018 08:03

Experiments with the http.Handler interface

When using net/http, handling errors is kinda annoying.

http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
	thing, err := storage.Get("thing")
	if err != nil {
		http.Error(w, err.Error(), 500)
@icholy
icholy / httpx.go
Last active April 10, 2023 19:34
package httpx
import (
"net/http"
)
func WithStatus(code int, handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(code)
handler.ServeHTTP(w, r)
@icholy
icholy / cgi.go
Last active February 17, 2018 20:04
package main
import (
"fmt"
"net/http"
"net/http/cgi"
"os"
)
type Handler func(http.ResponseWriter, *http.Request)
package main
import (
"fmt"
)
func main() {
for i := 0; i < 360; i++ {
fmt.Println(DegreeDifference(0, i))
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Category SYSTEM "asterix.dtd">
<!--
Asterix Category 048 v1.14 definition
Author: dmarkus
Created: 13.2.2009.
Modified: 3.11.2013 : added items I048/55, I048/065 and I048/SP (FPS117-specific)
package server
import "time"
type Service struct{}
type ConsumerType int
const (
SingleConsumer ConsumerType = iota
// Simple Arithmetics Grammar
// ==========================
//
// Accepts expressions like "2 * (3 + 4)" and computes their value.
Filter
= "//" path:Path { return path }
Expression
= Path
package main
import (
"encoding/xml"
"fmt"
"log"
)
func main() {
msg := &Message{
package main
import (
"encoding/binary"
"fmt"
"log"
"time"
)
// Layout: [8 bytes: unix timestamp][4 bytes: sequence id]
package structmap
import (
"fmt"
"reflect"
"strings"
)
type Options struct {
Strict bool