Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mrvdot's full-sized avatar

Alex Vanston mrvdot

View GitHub Profile

Keybase proof

I hereby claim:

  • I am mrvdot on github.
  • I am mrvdot (https://keybase.io/mrvdot) on keybase.
  • I have a public key ASCKW7tcpW8QQGfZe-OgBxrVr0T9Z3s9w0thHospu3VamAo

To claim this, I am signing this object:

@mrvdot
mrvdot / Gruntfile.js
Last active August 29, 2015 14:07 — forked from fastdivision/Gruntfile.js
Recommended Gruntfile.js for use with Divshot and Angular.JS/Yeoman
// Generated on 2014-10-16 using generator-angular 0.9.7
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
@mrvdot
mrvdot / save.go
Created November 24, 2013 20:22
Convenience method to save any object into the GAE datastore using Go. For a full walk-though of what and why, see the article at http://www.mrvdot.com/all/creating-a-universal-save-method-in-go-on-gae
func Save(c appengine.Context, obj interface{}) (key *datastore.Key, err error) {
kind, val := reflect.TypeOf(obj), reflect.ValueOf(obj)
str := val
if val.Kind().String() == "ptr" {
kind, str = kind.Elem(), val.Elem()
}
if str.Kind().String() != "struct" {
return nil, errors.New("Must pass a valid object to struct")
}
dsKind := kind.String()
@mrvdot
mrvdot / jsonphandler.go
Last active December 21, 2015 10:58
If you've ever wanted to handle JSONP callbacks within a Go powered API, here's a simple wrapper that you can use to intercept the callback query variable and properly wrap the response. It's designed to take an entire http.Handler, so works particularly well when using a router such as mux from gorilla, however can work with any handler.
import (
"io"
"net/http"
)
//With HandlerFunc
func main () {
http.Handle("/", JsonpHandler(http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
w.Write("Hello World")
})))