Skip to content

Instantly share code, notes, and snippets.

copy := reflect.New(reflect.TypeOf("*event.Model").Elem()).Interface().(proto.Message)
func NewProtoByName(protoType string) (proto.Message, error) {
// reflect.Type of a pointer to the Go struct representing protoType.
msgPtr := proto.MessageType(protoType)
if msgPtr == nil {
return nil, errors.New("failed to reflectively find a proto message named " + protoType)
}
// Dereference the pointer and get a struct reflect.Type.
msgType := msgPtr.Elem()
newMsg := reflect.New(msgType)
import (
"sync"
)
// Storage - in-memory simple storage
type Storage struct {
data []DashboardRow
ids map[string]bool
mu *sync.Mutex
}
@Haleluak
Haleluak / gist:b14f6a18df9f88c44d79f640c7642760
Created August 1, 2019 08:17
Simple Vue.js filters that I usually need
/**
* Changes value to past tense.
* Simple filter does not support irregular verbs such as eat-ate, fly-flew, etc.
* http://jsfiddle.net/bryan_k/0xczme2r/
*
* @param {String} value The value string.
*/
Vue.filter('past-tense', function(value) {
// Slightly follows http://www.oxforddictionaries.com/us/words/verb-tenses-adding-ed-and-ing
var vowels = ['a', 'e', 'i', 'o', 'u'];