Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View kisielk's full-sized avatar
🔈

Kamil Kisiel kisielk

🔈
View GitHub Profile
@kisielk
kisielk / jsonhandler.go
Created February 15, 2013 16:42
Simple HTTP handler wrapper for conveniently dealing with JSON requests
// JSONResponseWriter wraps an http.ResponseWriter and provides convenience methods for creating JSON responses
type JSONResponseWriter struct {
writer http.ResponseWriter
}
// Response writes an HTTP response with the value v encoded in JSON format.
func (w JSONResponseWriter) Response(v interface{}) {
w.writer.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w.writer)
enc.Encode(v)
@kisielk
kisielk / handlers.go
Created January 18, 2013 00:58
Experimenting with Go http handlers.
package httphandlers
import (
"net/http"
)
type MethodHandler struct {
handlers map[string]http.Handler
}
for(item in Jenkins.instance.items) {
println("job $item.name")
prop = item.getProperty(ParametersDefinitionProperty.class)
if(prop != null) {
newdefs = prop.getParameterDefinitions().findAll{p -> p.name != "TEST_FFDB_ROOT" && p.name != "NODE_VERSION"}
for(d in newdefs) {
println("$d.name")
}
newprop = ParameterDefinitionProperty(newdefs)
}
kyoto:mux kamil$ cat mux_test.diff
diff --git a/mux_test.go b/mux_test.go
index 19e0daf..158ce54 100644
--- a/mux_test.go
+++ b/mux_test.go
@@ -23,150 +23,126 @@ func TestRoute(t *testing.T) {
return idValue
}
- // Host -------------------------------------------------------------------
@kisielk
kisielk / persona.go
Created October 4, 2012 05:17
An example of Google Persona login in Go
// An example of implementing Mozilla's Persona authentication system.
// follows the instructions from https://developer.mozilla.org/en-US/docs/Persona/Quick_Setup
// and doesn't do much else.
package main
import (
"encoding/json"
"github.com/gorilla/mux"
"github.com/gorilla/sessions"
"html/template"
package arco
import (
"database/sql"
pq "github.com/bmizerany/pq"
"time"
)
type DB struct {
db *sql.DB
type Executor struct {
conn net.Conn
}
func NewExecutorDecoder(r io.Reader) ExecutorDecoder {
d := ExecutorDecoder{}
d.Messages = make(chan string)
d.Decoder = gob.NewDecoder(r)
return d
}
@kisielk
kisielk / gist:3475026
Created August 26, 2012 06:29
My god what have I done...
var units = map[string]int{
"s": 1,
"sec": 1,
"secs": 1,
"second": 1,
"seconds": 1,
"m": 60,
"min": 60,
"mins": 60,
"minute": 60,
@kisielk
kisielk / client.py
Created August 1, 2012 21:44
Server in golang
#!/usr/bin/env python
import jsonrpclib
s = jsonrpclib.Server('http://localhost:1234/rpc')
s.Say('Kamil')
@kisielk
kisielk / gist:3094615
Created July 12, 2012 00:08
Spawning an editor from within a Go program
package main
import (
"os"
"os/exec"
)
func main() {
c := exec.Command("vim")
c.Stdout = os.Stdout