Skip to content

Instantly share code, notes, and snippets.

@0rka
0rka / .go
Last active July 13, 2017 14:34
Unmarshalling JSON structs containing interfaces in Go
package main
import (
"encoding/json"
"fmt"
"time"
)
type Playable interface {
Play() error
@0rka
0rka / .go
Created January 28, 2018 10:56
playable interface
type Playable interface {
Play() error
}
@0rka
0rka / .go
Last active January 28, 2018 11:28
TVGuide
type Playables []Playable
type TVGuide struct {
Company string `json:"company"`
Notices string `json:"notices"`
ID string `json:"id"`
Library Playables `json:"library"`
}
@0rka
0rka / .go
Created January 28, 2018 11:29
Movie
type Movie struct {
Title string `json:"title"`
Length int `json:"length"`
}
func (m *Movie) Play() error {
time.Sleep(time.Duration(m.Length) * time.Minute)
return nil
}
@0rka
0rka / .go
Created January 28, 2018 11:30
UnmarshalJSON
func (p *Playables) UnmarshalJSON(b []byte) error {
var LibraryFields map[string]*json.RawMessage
if err := json.Unmarshal(b, &LibraryFields); err != nil {
return err
}
for LFKey, LFValue := range LibraryFields {
if LFKey == "movies" {
var LibraryMovies []*json.RawMessage
if err := json.Unmarshal(*LFValue, &LibraryMovies); err != nil {
return err
@0rka
0rka / .json
Created January 28, 2018 11:31
json example
{
"company": "0rkaTV",
"notices": "NO RUNNING WITH SCISSORS",
"id": "0x1337H4X0R",
"library": {
"movies": [
{
"title": "Titanic",
"length": 194
},
@0rka
0rka / .go
Created January 28, 2018 11:32
usage example
func main() {
myjson := []byte(`{"company":"0rkaTV","notices":"NO RUNNING WITH SCISSORS","id":"0x1337H4X0R","library":{"movies":[{"title":"Titanic","length":194},{"title":"Matrix","length":150}]}}`)
var OrkaTVGuide TVGuide
if err := json.Unmarshal(myjson, &OrkaTVGuide); err != nil {
fmt.Println(err)
}
fmt.Println(OrkaTVGuide)
fmt.Println("Hello, playground")
}
@0rka
0rka / .sql
Created January 28, 2018 11:35
scheme layout
CREATE TABLE methods (id, class_name, method_name, parameters, return_value, calling_to, called_from, data)
@0rka
0rka / .py
Last active January 28, 2018 11:38
self.cursor.execute('''SELECT id FROM methods where calling_to LIKE "%" || ? || "%"''', (method,))
@0rka
0rka / .py
Created January 28, 2018 11:39
re.compile(ur'^\.class.*\ (.+(?=\;))', re.MULTILINE)
re.compile(ur'^\.method.+?\ (.+?(?=\())\((.*?)\)(.*?$)(.*?(?=\.end\ method))', re.MULTILINE | re.DOTALL)
re.compile(ur'invoke-.*?\ {(.*?)}, (.+?(?=;))\;\-\>(.+?(?=\())\((.*?)\)(.*?)(?=$|;)', re.MULTILINE | re.DOTALL)
re.compile(ur'move-result.+?(.*?)$', re.MULTILINE | re.DOTALL)