Skip to content

Instantly share code, notes, and snippets.

View alecthomas's full-sized avatar
😀

Alec Thomas alecthomas

😀
View GitHub Profile
@alecthomas
alecthomas / gist:3580090c945e0f6fbadd
Created February 23, 2015 22:32
Swift protobuf model generated by prototemplate
// Generated by https://github.com/alecthomas/prototemplate. DO NOT EDIT!
import Foundation
// This generated code relies on the serialization layer of
// https://github.com/alexeyxo/protobuf-swift
import ProtocolBuffers
// Extend protobuf-swift's Message to include deserialization directly, rather
// than via a MessageBuilder.
public protocol ProtobufMessage: Message {
@alecthomas
alecthomas / Notifications.hh
Created November 19, 2014 22:53
EntityX system for replacing all builtin events
#pragma once
#include <vector>
#include <entityx/Entity.h>
#include <entityx/System.h>
namespace entityx {
struct Notification : public Component<Notification> {
EntityManager::ComponentMask components_added, components_removed;
@alecthomas
alecthomas / dispatch_sync_result.swift
Created November 10, 2014 00:31
Convenient little Swift GCD dispatch_sync() variant that returns a value
public func dispatch_sync_result<T>(q: dispatch_queue_t, block: () -> T) -> T {
var r: T?
dispatch_sync(q, {
r = block()
})
return r!
}
@alecthomas
alecthomas / keybase.md
Created September 23, 2014 00:09
keybase.md

Keybase proof

I hereby claim:

  • I am alecthomas on github.
  • I am alec (https://keybase.io/alec) on keybase.
  • I have a public key whose fingerprint is DEB7 1627 8C8D 5DA9 8371 9C9C 8DFD C9B0 0260 EE3A

To claim this, I am signing this object:

package main
import (
"errors"
"fmt"
"strconv"
"github.com/alecthomas/kingpin"
)
@alecthomas
alecthomas / raml-0.8.md
Last active August 29, 2015 14:05
RAML 0.8 spec with TOC
@alecthomas
alecthomas / sprite.cc
Last active August 30, 2015 17:15
EntityX sprite movement example
// Compile with: c++ -std=c++11 -lentityx -lsfml-graphics t.cc
#include "SFML/Graphics.hpp"
#include "entityx/entityx.h"
using namespace entityx;
struct Movement : public Component<Movement> {
sf::Vector2f position, direction;
};
@alecthomas
alecthomas / commitorrollbackonerror.go
Last active August 29, 2015 14:02
CommitOrRollbackOnError commits or rolls back a transaction based on the value of an error reference.
// CommitOrRollbackOnError commits or rolls back a transaction based on the
// value of an error reference. It helps avoid error prone boilerplate
// rollback calls.
//
// Most useful in a defer statement:
//
// tx, err := db.Begin()
// if err != nil {
// return err
// }
@alecthomas
alecthomas / jsonreturnhandler.go
Created May 22, 2014 19:37
Convenient return handler for Martini JSON API calls
import (
"encoding/json"
"net/http"
"reflect"
"github.com/codegangsta/inject"
"github.com/go-martini/martini"
)
const (