• What Do You Need Help With? V8
    1,074 replies, posted
You need a many to many relationship. You have EnterpriseId on Contact, which is the only relation connecting Enterprise and Contact, therefore you can only store one reference to Enterprise. You try to add a contact to another Enterprise, it will override EnterpriseId. You update method seems a little convoluted. Why are you doing all the added/deleted stuff. Surely when you need to add a delete a contact you can just have an "add" and "delete" method that will save changes to the database? You shouldn't really need to mix them together.
Thanks, it makes sense. The contacts are coming from a multiselect and the changes are only saved when the user click on a save button. Which is why my update method is like that. EF needs to track what changes have been made to existingEntreprise.
Anyone know if it's possible to store an 8-bit palettised image in .dds format? I'm looking at https://msdn.microsoft.com/en-us/library/windows/desktop/bb943984(v=vs.85).aspx and it looks like it doesn't but it's not really explicit and can't find anything to confirm or deny.
Turns out you can't - .bmp it is.
SELECT * FROM rounds WHERE name LIKE '%@MyName%' LIMIT 20 OFFSET @Offset Trying to prepare this statement with C#'s MySql.Data package. I've got: MySql.Data.MySqlClient.MySqlCommand Command = Initialize("SELECT * FROM rounds WHERE name LIKE '%@MyName%' LIMIT 20 OFFSET @Offset"); Command.Prepare(); Command.Parameters.AddWithValue("@MyName", Name); Command.Parameters.AddWithValue("@Offset", Offset); Checking the MySQL logs, this comes out as: SELECT * FROM rounds WHERE name LIKE '%@MyName%' LIMIT 20 OFFSET 0 I'm guessing it has something to do with the % wildcard operator. Anyone have any ideas?
How to use the wildcard% in mysqlcommand using c# You need to concatenate the percentages in your AddWithValue call. I guess it''s not getting properly, strange behavior though.
Weird. Thanks!
Why is Python so popular with people doing Machine Learning/AI? I know that Numpy is a really useful package, but if you're training with a lot of data, wouldn't you want to use a lower level language like C/C++ to try to increase speed when do 10,000 iterations of training? Or is it more common to just use Python code and focus on hardware
I think it comes from the fact that it's easier/faster to develop in Python, there's a lot of built-in tools/extra packages for scientific purposes. If you want performance, you can always write a wrapper in cython for your C/C++ algorithm.
It's not uncommon to do your initial network design in Python, and export the graph to be loaded in C/C++ for acceleration using tools that can load graphs but have an OpenCL/CUDA backend
Probably a question that gets asked a lot, what resources would you guys point me to to learn C++? I'm currently using learnCPP.com, but are there any other websites/books that you've found invaluable in learning this language? Many thanks
Good list of books: c++ faq http://en.cppreference.com/w/ for the standard library Why is linking so messed up
C++ Primer is definitely the one I'd recommend first, as it starts from barest basics and covers C++11. I've yet to see a site that does very well, and LearnCPP.com is mediocre at best to be honest. Effective Modern C++ is also good. beyond that, reading blogs (commonly featured on /r/cpp) can be helpful, like: http://www.bfilipek.com/ https://www.fluentcpp.com/ recent videos from conventions/meetups can also be quite good, along with just browsing github repos that use modern C++ semantics
Does the 5th edition of C++ Primer assume no previous knowledge of the language, and will it be an issue that it only covers up to the C++11 and not the C++14 standard down the line? Thanks for the replies btw guys, I've learnt little so far but what I've managed has been a blast. Aching to really get stuck in
Hello. I need help with socket data send-receive in Python, on Raspberry Pi I have 2 Raspberry Pi. No 2 is sending data to No 1. I speak into No 1 microphone, and No 1 will send data to No 2 when it detect my voice. No 2 will play a response sound using a .wav file. There is absolutely no problem with No 1 - No 2 data transmission. But I noticed that the loop will stuck at this line, until data is received from No 1. dataByte, addr = sock.recvfrom(1024) # buffer size is 1024 bytes Then the loop will continue, until it's stuck there again when there is no data received. How can I make the loop progress, regardless of whether data is received or not? How can I un-stuck the program loop from that socket waiting for data? Thanks in advance. Any idea is appreciated. This is the full code on the receiving Pi: # receive.py import time import socket import pprint import pygame soundstarttime = time.time() soundendtime = time.time() soundplaytime = time.time() soundplaying = 0 #Initialise pygame and the mixer pygame.init() pygame.mixer.init() #load the sound file voicepath = pygame.mixer.Sound("/home/pi/Desktop/voice/yaaa.wav") voicepath.play() mainloop = 1 #--------------------------------------------------------------------------- UDP_IP = "192.168.1.5" UDP_PORT = 5005 sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) while mainLoop == 1: #while True: dataByte, addr = sock.recvfrom(1024) # buffer size is 1024 bytes dataString = dataByte.decode("utf-8") print("received message: ", dataString) #------------------------------------------------------------------------ # PROBLEM!!!! loop stuck at sock.recvfrom(1024) if no data received by LAN if dataString == "cibo": voicepath = pygame.mixer.Sound("/home/pi/Desktop/voice/yaaa.wav") voicepath.play()
I can not say if this is a good practice, but I believe that you can do `socket.settimeout(x)` where `x` is a non-negative float. After that, `recv` will raise a `timeout` exception if it has not received anything after `x` seconds have elapsed.
No, it's not an issue that it only goes to C++11. C++11 was where the largest changes occurred and C++14/17 are just refinements of that. C++14 has stuff covered by "Effective Modern C++", which is a good text to read after C++ Primer.
Set a timeout with socket.settimeout like ^ suggested Set the socket to non-blocking via socket.setblocking Use select.select with a timeout With either option you have to handle the timeout/no-data errors.
Thank you guys for the suggestion. I have successfully applied the non-blocking socket. I havent tried the socket.settimeout method yet, but it sounds more direct method, i will try it. Is this code alright? Is that the correct way to handle the exception? I'm ashamed that I'v never used a 'select.select' method. Can you guys give an example on how to apply it on this code? Thanks in advance, # receive.py import time import socket import pprint import pygame soundstarttime = time.time() soundendtime = time.time() soundplaytime = time.time() soundplaying = 0 #Initialise pygame and the mixer pygame.init() pygame.mixer.init() #load the sound file voicepath = pygame.mixer.Sound("/home/pi/Desktop/voice/yaaa.wav") voicepath.play() mainloop = 1 #--------------------------------------------------------------------------- UDP_IP = "192.168.1.5" UDP_PORT = 5005 sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) sock.setblocking(0)  while mainLoop == 1: try:         dataByte, addr = sock.recvfrom(1024) # buffer size is 1024 bytes         dataString = dataByte.decode("utf-8")         print("received message: ", dataString)     except socket.error:         mainLoop = 1 #------------------------------------------------------------------------ # PROBLEM!!!! loop stuck at sock.recvfrom(1024) if no data received by LAN if dataString == "cibo": voicepath = pygame.mixer.Sound("/home/pi/Desktop/voice/yaaa.wav") voicepath.play()
Anyone know an efficient way to import a (very simple) MySQL table into an existing MongoDB database? Creating a matching schema is no issue, just importing the data.
Is your data simple enough to be exported to csv format? If so you could do mysql -> csv -> mongdb.
It's literally an id, URL string and hit counter. So yeah probably will try that!
I'm trying to create an entity component system using .NET, and right now I'm storing my components into individual Lists. Every component is derived from IComponent, and so the components are created like this: let physics = System.Collections.Generic.List<Components.Physics>() let renders = System.Collections.Generic.List<Components.Render>() This is working fine, but I also want to have a list of all component lists, so that I can use foreach to quickly remove all of an entity's components, or create new blank ones. However, the following doesn't work. let componentLists = List<List<IComponent>>() I've tried just setting componentLists to a List<obj>, then casting every access of it to List<IComponent>, but I get an InvalidCastException. Is there any specific way of doing this? I don't have much experience working with generics in .NET, or the .NET framework itself, so I'm not sure how to go about doing this. I know how to do this in Scala with covariant generics, but I can't seem to find anything like this for .NET.
Don't know .NET but usually the correct answer in this situation is a tuple, because you want your components stored contiguously. Either that or a language that supports what you mentioned, but C# does not probably (but I don't know for sure).
Just a general rule with casts, a cast from List<object> to List<insert-class-here> won't work, because you are casting the list itself, you'll have to cast the individual elements. As for the List<List<IComponent>> not working, you'll need to be specific. Is there any reason it's a multi-dimensional list?
So use a tuple of all the possible components, with a bitmask showing which components are in use? That makes sense, and seems like it would work a lot better than what I'm doing now. Right now I'm having non-blank entities be created by a passed in function that creates an array of components. If that entity isn't overwriting an old one's spot in the lists, I want to be able to extend all component lists, and then overwrite those for what new components they actually have, something like this (using pseudocode since the Facepunch's formatting ruins the normal code). if entityID > entities.Count then { var components = createComponents() for list in componentLists { list.Add(null) } for comp in components { list[comp.ID][entityID] = comp } }
Sorry you need to give some more info. Do you have a fixed list of components? Or is it just anything derived from IComponent? And how do you map a component's type to the list it is stored in?
Ah, sorry. I do have a fixed list of components, all of which are derived from IComponent. Each component has a given ID, and in my current solution using that ID as the index in componentLists gives the list for that component. For the individual lists, every list has an entry for every entity, even if that entry is null (not having that component). I was keeping the lists separate so that each system that uses the components only needs to see the lists of components that are relevant to it. From the tuple suggestion, I was planning on moving all components that represent one entity into one tuple, with a bitmask storing whether each component has be initialized and can be used or if it hasn't. I could then drop IComponent, since it wouldn't be needed anymore in this, and use structs for the component types
I suggest not having an entry for every entity because that's a lot of wasted space. On top of this if the lists only store pointers to the components (I don't know how C# works sorry) then you lose a big benefit of ECS which is contiguous data access. May not be a concern yet but something to keep in mind. Same issue with tuples, you have a lot of wasted space if you have a tuple of each component for each entity. You will also have systems that require two or more components. Have you considered how to deal with that?
C# can do both pointers and value. Right now the lists only store pointers, so I'll probably want to fix that. But if I wanted to use values instead of pointers, then I'm not sure how to go about it without wasting space, since then for each empty one, I'd still have to have the uninitialized memory for that component stored in its spot in each list. I'd like to keep the indices for each component an entity has the same (so that if an entity is 5, then physics[5] and render[5] both are its components), but if there's a better way then I'd like to know about it. For multiple components right now I've decided to pass the lists of the needed components to the system (i.e. the Render system receives both the list of Render components, and Physics components). If a tuple was used, I could just pass the whole tuple, but then it might be considered breaking encapsulation by letting every system see every component.
Sorry, you need to Log In to post a reply to this thread.