Skip to content

Instantly share code, notes, and snippets.

View shixzie's full-sized avatar
:octocat:
weeb

Juan Alvarez shixzie

:octocat:
weeb
View GitHub Profile
// func Marshal<T>(val T) ([]byte, error)
data, err := Marshal<MyStruct>(myStruct)
// func Marshal(val interface{}) ([]byte, error)
data, err := json.Marshal(val)
func Number<T> () T
func NumberN<T>(n T) T
func (m *Map) Delete(key m.KT)
func (m *Map) Load(key m.KT) (val m.KV, ok bool)
func (m *Map) LoadOrStore(key m.KT, val m.KV) (actual m.KV, loaded bool)
func (m *Map) Range(f func(key m.KT, val m.KV) bool)
func (m *Map) Store(key m.KT, val m.KV)
type Map <KT, VT> struct {
iternalMap map[KT]VT
}
// mySyncMap := new(sync.Map<string, int>)
mySyncMap := &sync.Map<string, int>{}
func Add<T>(addr *T, delta T) (new T)
func CompareAndSwap<T>(addr *T, old, new T) (swapped bool)
func Load<T>(addr *T) (val T)
func Store<T>(addr *T, val T)
func Swap<T>(addr *T, new T) (old T)
// Why not
func Add<T>(addr *T, delta T) (new T)
otherInt32 := atomic.Add<int32>(&myInt32, 32)
// Instead of
func AddInt32(addr *int32, delta int32) (new int32)
otherInt32 := atomic.AddInt32(&myInt32, 32)
func handlerForInterface(handler interface{}) EventHandler {
switch v := handler.(type) {
case func(*Session, interface{}):
return interfaceEventHandler(v)
case func(*Session, *ChannelCreate):
return channelCreateEventHandler(v)
case func(*Session, *ChannelDelete):
return channelDeleteEventHandler(v)
case func(*Session, *ChannelPinsUpdate):
return channelPinsUpdateEventHandler(v)
func (s *Session) AddHandler(handler interface{}) func()
@shixzie
shixzie / discord-travis.go
Last active September 26, 2017 08:10
Travis webhooks for discord!!
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"os"