Programming thread

(Un)marshaling JSON in GoLang is the most cancerous thing ever. This is what you have to do to unmarshal a simple array.
Code:
err = json.Unmarshal(message, &[]interface{}{&trade.ChannelID, &trade.Type, &[]interface{}{&trade.Trade.MTS, &trade.Trade.ID, &trade.Trade.Amount, &trade.Trade.Price}})

I find static typed JSON decoding to be comfy:
Code:
type StationItem struct {
   Value   string
   Type    string
   TypeStr string
   Weight  string
}

type ConnectionItem struct {
   Date            uint64
   Start           StationItem
   Link            string
   Price           *float32
   Destination     StationItem
   StartTime       uint64
   DestinationTime  uint64
}

var v []ConnectionItem
if err := json.Unmarshal(msg, &v); err != nil {
    log.Fatal(err)
}
 
  • Agree
Reactions: Marvin
I find static typed JSON decoding to be comfy:
Code:
type StationItem struct {
   Value   string
   Type    string
   TypeStr string
   Weight  string
}

type ConnectionItem struct {
   Date            uint64
   Start           StationItem
   Link            string
   Price           *float32
   Destination     StationItem
   StartTime       uint64
   DestinationTime  uint64
}

var v []ConnectionItem
if err := json.Unmarshal(msg, &v); err != nil {
    log.Fatal(err)
}
This is how i do it with hashmap JSON, but I found it won't work with multi-type arrays (tuples?)
 
Oh, you can't do it like that then.
Maybe just loop through the tokens manually and handle them with a type-switch.
No the interface works, I'm not trying to detect what it is, I'm just trying to parse it into a struct. I actually unmarshal it twice, once into a small type checking struct where it reads a string included and then into the real struct once I've determined what it is.
 
Can someone tell me why its bad practice to perform arithmetic on a void pointer, but the compiler is happy if I do convoluted casting to get essentially a void pointer with arithmetic performed on it?
 
No the interface works, I'm not trying to detect what it is, I'm just trying to parse it into a struct. I actually unmarshal it twice, once into a small type checking struct where it reads a string included and then into the real struct once I've determined what it is.
Have your struct implement the json.Unmarshaler interface. Then in your implementation of json.Unmarshaler.UnmarshalJSON, unmarshal to a slice of json.RawMessages.

Then pick the slice apart and unmarshal the individual elements from there.

It's basically the same thing you're already doing, and a little more verbose, but conceptually I think it's clearer and more straightforward. You're specifically declaring: *this is my type, and it requires its own, funky, unique marshaling that isn't supported out of the box*
 
  • Informative
Reactions: CrunkLord420
Can someone tell me why its bad practice to perform arithmetic on a void pointer, but the compiler is happy if I do convoluted casting to get essentially a void pointer with arithmetic performed on it?

It's probably because void isn't considered to be a valid type, and so it's size and alignment are undefined; as such, it is undefined how far ((void*)ptr) + 1 should be from ptr. When you cast to (char*) you provide the specifications for what you want ((char*)ptr) + 1 to mean, and casting back to (void*) simply removes the type specification. Usually I just create a typedef for byte (usually uint8_t) and use that.

Apparently gcc can do void* arithmetic with a flag enabled, see https://stackoverflow.com/questions/1666224/what-is-the-size-of-void it's nonstandard of course
 
Any opinions on c++ testing frameworks? I’ve recently taken over an undocumented app with no test coverage. I’m leaning towards gtest because it appears to be commonly used.
 
I'm in the process of learning node.js etc. and using npm install feels just wrong to me, having a background in classical mechanical engineering. I have a hard time trusting the stuff inside the packages. They do what they advertise do to but at what cost, what other dependencies do they have and what gear will break the whole thing? It's reminds me of constructing a gearbox with more gears then needed, form a supplier you use for the first time. On the other hand I'm happy that packages do the Auth stuff for me, so I can focus on more basic things then getting it secure on my own. I suspect some of my worries come from being new to such a huge field and disliking complexity.
 
  • Like
Reactions: Marvin
I'm in the process of learning node.js etc. and using npm install feels just wrong to me, having a background in classical mechanical engineering. I have a hard time trusting the stuff inside the packages. They do what they advertise do to but at what cost, what other dependencies do they have and what gear will break the whole thing? It's reminds me of constructing a gearbox with more gears then needed, form a supplier you use for the first time. On the other hand I'm happy that packages do the Auth stuff for me, so I can focus on more basic things then getting it secure on my own. I suspect some of my worries come from being new to such a huge field and disliking complexity.
Reinventing the wheel is the biggest source of security issues. Though npm is dogshit.
 
I'm aware of the trap that a beginner thinks he can reinvent the wheel. So using the code of people who know their field is reasonable. But the course I took felt to much like listen and chase the shiney new thing, while skipping a lot of basics in favor of some, simple require(x) lines.
 
  • Like
Reactions: Marvin
I'm aware of the trap that a beginner thinks he can reinvent the wheel. So using the code of people who know their field is reasonable. But the course I took felt to much like listen and chase the shiney new thing, while skipping a lot of basics in favor of some, simple require(x) lines.
Gotcha. Yeah, if this is a non critical project and you're trying to exercise your coding skills, go for it.
 
For now I'm just writing code for my home monitoring and in the spring my planned automated veggie garden watering system. The home monitoring system is made up of a few esp8266 with dht22 sensors, who send their data to a orange pi. I'm using this setup to redo the code with different patterns, and later some ui to control some basic stuff like the coffee machine in the morning/remote.
 
  • Like
Reactions: Marvin
For now I'm just writing code for my home monitoring and in the spring my planned automated veggie garden watering system. The home monitoring system is made up of a few esp8266 with dht22 sensors, who send their data to a orange pi. I'm using this setup to redo the code with different patterns, and later some ui to control some basic stuff like the coffee machine in the morning/remote.
Nice.

My next project (not really programming but...) is to run gigabit ethernet in my house. A wall plate in every room. Gonna put a freenas server in a closet because 4tb platter hard drives suck for a /home mount.

Main thing holding me back is my electrician friend says I've got mold in my crawlspace, so he's not going down there. Pussy. So sometime I'm gonna need to put on overalls and climb under there.
 
aliexpress and chinese hobby grade electronics are a blessing if you like tinkering and know how to tame pixies. i'm using it also to monitor the mailbox and to open the gate in our fence with rfid tags. hacking the arduino to open the gate would be more work then just climbing over the fence, so i deem the whole system as save enough.

if you really have mold in your crawlspace i would rather recommend you spend the money on removing it. the mold will just get worse with time same for your health.
 
i would rather recommend you spend the money on removing it. the mold will just get worse with time same for your health.
There's no air connection between the crawlspace and the house. And I think he's just being whiny. There's always going to be some water down there and I got my sump pump working (after some fuckery). I also have a humidifier running down there.

He's a friend so he'll do easy work for free but not everything. I think it's more that than anything.
 
There's no air connection between the crawlspace and the house. And I think he's just being whiny. There's always going to be some water down there and I got my sump pump working (after some fuckery). I also have a humidifier running down there.

He's a friend so he'll do easy work for free but not everything. I think it's more that than anything.

Mold is scarey shit, I would watch it like a hawk.

Sounds like a nice contract he would do for free. And having friends do bigger jobs for free or cheap rarely ends well in my experience.
 
  • Thunk-Provoking
Reactions: Marvin
What is the actual use case for the Javascript delete keyword?
 
What is the actual use case for the Javascript delete keyword?
Removing a key from an object?

I guess sometimes you want the object to match a very specific format. Maybe if you're serializing JSON for a REST API that validates particularly strictly.
 
  • Like
Reactions: Kosher Salt
Yeah, but why isn't that just a method that exists on all objects? I don't understand why this requires a keyword.
 
Back