Skip to content

Instantly share code, notes, and snippets.

@darthberen
darthberen / keybase.md
Last active November 6, 2018 22:53
keybase proof

Keybase proof

I hereby claim:

  • I am suicidejack on github.
  • I am pricelessfox (https://keybase.io/pricelessfox) on keybase.
  • I have a public key ASAct477De1Qpst4g1BotrdOrOHXg3P5ZyLP57mCyB3BkQo

To claim this, I am signing this object:

@darthberen
darthberen / decode1.go
Created February 8, 2015 19:32
excerpt of decode.go code
// lines 559-583 in decode.go in encoding/json package
var f *field
fields := cachedTypeFields(v.Type())
for i := range fields {
ff := &fields[i]
if bytes.Equal(ff.nameBytes, key) {
f = ff
break
}
if f == nil && ff.equalFold(ff.nameBytes, key) {
Example 1 (works as expected with both fields included on struct):
JSON: {"_eventId": "cased"}
_eventid:
_eventId: cased
Example 2 (works as expected with both fields included on struct):
JSON: {"_eventid": "no case"}
_eventid: no case
_eventId:
@darthberen
darthberen / go-json-unmarshalling-code.go
Last active August 29, 2015 14:15
POC code demostrating an interesting side effect of Go JSON unmarshalling
package main
import (
"encoding/json"
"fmt"
)
type eventWithBoth struct {
EventId string `json:"_eventId"`
Eventid string `json:"_eventid"`
@darthberen
darthberen / go-case-json-new-event
Created October 11, 2014 18:46
Sample event after the transformation code move
{
"_eventId": "ad23ef1-156a-03b7-e1826fcd",
"_eventid": "1234567890"
}
@darthberen
darthberen / go-case-json-old-event
Created October 11, 2014 18:43
Sample event before transformation code move
{
"_eventId": "ad23ef1-156a-03b7-e1826fcd"
}
@darthberen
darthberen / go-json-decoding-output
Created October 9, 2014 07:21
go JSON decoding {} into a map[string]string output
map1: map[]
map2: map[]
mapNil: map[]
Length of map1: 0
Length of map2: 0
Length of mapNil: 0
1) map1 == map2: false
2) map2 == mapNil: true
3) map1 == mapNil || len(map1) == len(mapNil): true
@darthberen
darthberen / go-json-decoding-code
Last active August 29, 2015 14:07
go JSON decoding {} into a map[string]string
func main() {
map1 := make(map[string]string)
var map2 map[string]string
json.Unmarshal([]byte("{}"), map2)
var mapNil map[string]string
mapNil = nil
fmt.Println("map1:", map1)
fmt.Println("map2:", map2)
fmt.Println("mapNil:", mapNil)
@darthberen
darthberen / go-map-comparison-output
Last active August 29, 2015 14:07
go map comparison output
map1: map[]
map2: map[]
mapNil: map[]
Length of map1: 0
Length of map2: 0
Length of mapNil: 0
1) map1 == map2: true
2) map1 == mapNil: false
3) map1 == mapNil || len(map1) == len(mapNil): true
@darthberen
darthberen / go map comparisons code
Last active August 29, 2015 14:07
go map comparison code
func main() {
map1 := make(map[string]string)
map2 := make(map[string]string)
var mapNil map[string]string
mapNil = nil
fmt.Println("map1:", map1)
fmt.Println("map2:", map2)
fmt.Println("mapNil:", mapNil)