• Breaking News

    Thursday, December 24, 2020

    How do I access an array in one class from another? Ask Programming

    How do I access an array in one class from another? Ask Programming


    How do I access an array in one class from another?

    Posted: 24 Dec 2020 10:23 AM PST

    I have a project where I have to create some kind of league table. So I have a class for the players with functions only the players can access such as register,login and to play a match. When a player has logged in it adds them to the player array. I also want to make a class for the admin, where the admin functions are stored where the admin functions can add or remove players. How would I go about doing this?

    I think it is done using the set and get functions but I don't fully understand them. I want to do something like setPlayer(0) = James, setPlayer(1) = jake. and when I use the get functions getPlayer(0) = James and getPlayer(1) = jake.

    submitted by /u/leetyeetmcfeet
    [link] [comments]

    How often do you leave an algorithm unoptimized?

    Posted: 24 Dec 2020 02:40 PM PST

    This is probably a weird question but I wrote a quick function in one of our applications that finds the values in the first list that aren't present in the second list.

    I just used two nested loops because that was the simplest way. I thought about optimizing it, but the lists are never really going to be above length of like 5 elements because of the nature of the data. Also because of what this data represents, it will never need to handle larger lists. Knowing this, my plan was to just leave it alone and not optimize it.

    How often do you guys leave things unoptimized? I feel that this is often something people are afraid to do and maybe should be. But in this case, I'm completely ok with it.

    submitted by /u/BigfootTundra
    [link] [comments]

    Is a on UDP implementation of a TCP-like behavior be better than simple and straight TCP socket?

    Posted: 24 Dec 2020 04:59 PM PST

    Actually i have a lot of questions but i will start with this one I'm making a networking library because i want to learn how to do networking protocols for a game and do everything from nearly scratch is a lot better than copying and pasting someone elses code into your project

    The question is: I heard that TCP blocks everything and waits for the missing packet to arrive and until that it doesn't not want to know about anything else, and i also heard that the new http version it will get implemented over UDP instead so maybe is better a TCP kind of approach over UDP (i will end up using UDP anyway for other "packet types") I called my approach TCPly, basically every packet arrives and the program checks for "packet gaps" alias missing packets, if there are gaps it will be request the missing packet(s) via a different approach alias it will get request until arrived (also the other side knows how to handle these continuous requests correctly obv), while doing this other threads will keep to recieve packets and do other things But TCP is low level so might because of this is a lot more faster therefore efficient in comparison with of my C# application Side question: can multithreading cause more packet loss (deadlocks apart)? i'm talking about a single thread per client+two more for special functions like general serverwide tasks)

    submitted by /u/gabrielesilinic
    [link] [comments]

    How do you return an int if you need to return it?

    Posted: 24 Dec 2020 07:19 PM PST

    I am on a CodeWars problem and I am stuck. It asks to declare any number above 5 to be declared as 1 and any number below 5 as 0. I first used parseInt to turn the string into an int and tried to return inside the an if statement. Now I am stuck. Please help

    submitted by /u/Danielk0926
    [link] [comments]

    How do i group the data on Django?

    Posted: 24 Dec 2020 06:58 PM PST

    i have these 2 models

    class Car(TimeStampedModel): name = models.CharField(_('Car Name'), max_length=50) manager = models.ForeignKey( 'cars.Manager', verbose_name=_('Car Manager'), related_name='cars', on_delete=models.CASCADE ) def __str__(self): return self.name class Manager(models.Model): name = models.CharField(_('Name'), max_length=25) class Meta: verbose_name = _('Car Manager') verbose_name_plural = _('Car Managers') def __str__(self): return self.name 

    i also created these serializer

    class CarManagerSerializer(serializers.ModelSerializer): class Meta: model = Manager fields = '__all__' 

    and then on the view, i try to get number_of_managed_cars by each manager using this way

    def get(self, request): cars_managers = Manager.objects.all().annotate(number_of_managed_cars=Count('cars')) serializer = CarManagerSerializer(cars_managers, many=True) serializer_data = serializer.data return Response(serializer_data, status=status.HTTP_200_OK) 

    then i try to hit the endpoint:

    { { "id": 1, "name": "John Doe", } } 

    there's no number_of_managed_cars on the result.

    i followed this : https://docs.djangoproject.com/en/3.1/topics/db/aggregation/

    still cant get the results right.

    where did i miss ?

    submitted by /u/dexdagr8
    [link] [comments]

    Does unicode include symbols for specific businesses as in "adopt a character"? Cuz if it does I intend to drop unicode support for those characters.

    Posted: 24 Dec 2020 06:33 PM PST

    https://home.unicode.org/adopt-a-character/about-adopt-a-character/

    I intend to drop support, and actively block the display of, any character which does not occur in some language or form of communication and is instead certainly an attempt to inject advertising into our methods of communication. So far I am not aware any of that is happening, but this url may imply to look for it.

    submitted by /u/isananimal
    [link] [comments]

    I am having a deplorable time trying to link this javascript file to my HTML and it's killing me.

    Posted: 24 Dec 2020 06:31 PM PST

    https://github.com/armanterrell7947/RPS-game

    Pardon my language, but I'm losing my fucking mind. I was working on this earlier and I was able to access all of my functions in my app.js file.

    NOW I CAN'T EVEN GET THE CONSOLE TO RECOGNIZE THE FUNCTION

    I legit don't know what happened. I was working on it earlier and it was fine, then I edited some code around, and now I can't see what computerPlay() would output! Which is SUPER SIMPLE, CHOOSING A RANDOM STRING FROM MY ARRAY

    I can't do this anymore. Everyone on the odinprojects discord keeps giving me run around answers, implying that I haven't looked everywhere to solve this. Rude AF sometimes.

    Anyways. I'm using VS Code and Live Server as well.

    I feel fucked -_- this is SO SIMPLE, and I've spent hours trying to figure out this problem with zero luck.

    submitted by /u/yeoldecotton_swab
    [link] [comments]

    How would you rewrite this piece of code?

    Posted: 24 Dec 2020 06:10 PM PST

    The following is a snippet of python code:

    from collections import deque stack = deque() def duplicate(stack): assert isinstance(stack, deque), 'stack must be of type deque.' x = stack.pop() stack.append(x) stack.append(x) 

    The goal of the function is to duplicate the top element of the stack. This implementation looks ugly to me so I am trying to think of a better way of writing this out.

    submitted by /u/Swagut123
    [link] [comments]

    How to use python subprocess Popen to open a psd(Photoshop template)?

    Posted: 24 Dec 2020 06:03 PM PST

    app = 'C:\\Users\\0\\Desktop\\tag-generator\\template.hfp\\Adobe Photoshop 2020\\photoshop.exe'

    file = 'C:\\Users\\0\\Downloads\\imageOutput\\720template.psd'

    pid = subprocess.Popen([app, file]).pid

    above code doesn't work

    Message=[WinError 2] The system cannot find the file specified

    *why Popen? Because I don't want the program to wait for photoshop's return

    submitted by /u/hwpcspr
    [link] [comments]

    Netflix Recommendation Engine

    Posted: 24 Dec 2020 11:53 AM PST

    How does Netflix Recommendation engine actual work and how and where this Recommendation engine is stored?

    submitted by /u/RstarPhoneix
    [link] [comments]

    I need help to understand static members in python.

    Posted: 24 Dec 2020 05:49 PM PST

    Hi all,

    My college is unfortunately forcing us to learn python, my background is in C#, python seems to logically not have static members, here's what I'm talking about:

    C# - https://pastebin.com/hEB7kiJJ
    Python - https://pastebin.com/9ckQhBgM

    Surely if I can change the value of dog.limbs then the member cannot be static as that member is not shared between all instances at that point.

    submitted by /u/BarjiYT
    [link] [comments]

    Best place to do programming exercises?

    Posted: 23 Dec 2020 11:34 PM PST

    I recently started using the website edabit.com to stay fresh with python over break and my free trial just expired. I just took my first programming course over the fall semester so I am not an experienced programmer by any means. Are there any other websites like this?

    submitted by /u/sadlionsfan69
    [link] [comments]

    Sort an array

    Posted: 24 Dec 2020 03:28 PM PST

    Hello a friend of mine gave me a problem to write an algorithm that sorts an array from lowest to highest value, and i did it. Was a bit complex but i did it then i asked myself doesn't it look a bit complex because just to sort a 1d array i had to put like 3 for loops and i did some calculations and found out that it does x3 number of iterations before it has sorted the array and to me it kinda feels time consuming for a computer to do that many iterations just to sort an array and i googled and stumbled upon a dude's video about that problem(sorting an array it's this guy if anyone wants to watch his video) it was fairly simple and easy to understand it also kinda felt faster because it only has 1 while loop and 1 for loop don't know how many iterations is that but it sure is less than mine and i wanted to check is it really fast if yes then how much. Wrote the program twice one in my way and one in his, compiled both of them and surprisingly mine is faster by 0.006 seconds. Can anyone tell me why mine turns out to faster? I didn't changed the array elements nor their location.

    submitted by /u/noyankurrd
    [link] [comments]

    I made an App! How do I get more users ?

    Posted: 24 Dec 2020 07:56 AM PST

    Hey everyone,

    I'm 17 and coded my own App.

    The first step is complete, the second step is to launch it and get some users.

    But as a 17 y/o I have no Idea how to get a lot or even a few users to my app.

    What would be a efficient way to get more users ?

    submitted by /u/ExudeApps
    [link] [comments]

    Any algorithm for detecting all cycles in a graph that are smaller than a given length?

    Posted: 24 Dec 2020 02:40 AM PST

    Given that I have all nodes and edge lengths in a graph, I need to find all of the possible cycles starting (well, and ending) on a specific node.

    I can also set a maximum length so that each cycle that starts to be longer than this value can be discarded.

    Since I don't know much about graphs, I am having a bad time knowing how to look for it on the internet. Does anyone know any algorithm that matches what I need?

    PS.: even better if there's already a Python module :D

    Thanks a lot!

    submitted by /u/croissantdechocolate
    [link] [comments]

    How to learn when reading a programming book?

    Posted: 24 Dec 2020 09:54 AM PST

    I started reading some books about programming but didn't finish them. Because of the problem which I want, I am not able to find them. I like to learn from books but when working with projects, should I read the complete book to solve that problem if I am not sure what is missing?

    The Specific solution to a problem is not available all the time online. Another thing is that before making a project every book can't be memorized. It can only possible when someone faces the problem and finds its solution.

    submitted by /u/ibilalkayy
    [link] [comments]

    How do I fix this? Confused why mxmlc is even in the code

    Posted: 24 Dec 2020 01:34 PM PST

    [Errno 2] No such file or directory: 'mxmlc'

    [cmd: ['mxmlc', '/Users/user/go/src/github.com/drk1wi/Modlishka/plugin/autocert.go', '-library-path+=/libs', '-output', '/bin/.swf', '-debug=false', '-static-link-runtime-shared-libraries=true']]

    [dir: /Users/user/go/src/github.com/drk1wi/Modlishka/plugin]

    [path: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]

    [Finished]

    submitted by /u/slimjim6997
    [link] [comments]

    Learning assistance

    Posted: 24 Dec 2020 12:40 PM PST

    I want to learn the Java programming language and know great object oriented programming. Now I want to expand my knowledge but I am not taught that way. Can I learn Java by coming up with something I want to do and then doing part by part what I envisioned learning and expanding my knowledge.

    submitted by /u/jankezaxd
    [link] [comments]

    How to check a text document for grammatical accuracy?

    Posted: 24 Dec 2020 01:03 AM PST

    Hello all

    I know of Lingua::EN::Grammarian in Perl which attempts to check the grammar of a document but this module is very immature and it has a lot of false positives and false negatives.

    Does anything similar exist in any other languages?

    I have a bunch of English-language text documents and I want to check them for grammar mistakes.

    Even if the module is not perfect, at this point, anything is better than nothing.

    Thanks

    submitted by /u/FuzzyBear2017
    [link] [comments]

    Proposition to work in a new project with old technologies

    Posted: 24 Dec 2020 10:45 AM PST

    As a temporary profile in the current project, I have got an offer today to move to another project, in the same company, that uses old technologies like :

    • GWT
    • Plain JEE without a framework
    • SVN

    I'm more familiar and ambitious about new technologies like angular and JEE frameworks. In the other hand I have never had any experience with GWT and SVN, well it's not a problem because I know I can get my way through these techs, but it feels like I am going to kill my career with this experience.

    Shall I accept the offer?

    I'm 25 years, 2.5 years career.

    submitted by /u/Croverit
    [link] [comments]

    Is there any book that covers the topic "how to rank items in my app"?

    Posted: 24 Dec 2020 04:22 AM PST

    I've created a marketplace app which has some product listing. I want to rank those products on the basis of the quality, price etc. I want to optimize this for max sales/revenue. Is there any book that takes me through the process of creating a ranking ML Model or a microservice.

    Edit: Ideally, the book should deal with topics such as Creating Data Pipelines, Feature Creation, ML Model Building, Integrating these model into real time applications, deploying the said service. I have doubts regarding the latency of the service, figuring out if the ML Model if working properly or not etc.

    submitted by /u/wsb_soothsayer
    [link] [comments]

    Places to look to find Distributed Optimization advice and/or techniques

    Posted: 24 Dec 2020 07:23 AM PST

    I have a multi-dimensional optimization task where I have access to a high performance computing ring to run individual tasks in parallel as well as to run them on my local machine. I have implemented/used a few optimization algorithms like MCS and Nelder-Mead that run iterations in series trying to minimize or maximize a cost function.

    I'm trying to find any reading or advice on what kind of methods can leverage parallel computation to reduce runtime for a task like this, especially for tasks where single iterations can take ~5minutes or longer. If anyone know where to ask this question if its better suited to another subreddit, let me know as well.

    It is important to note that this is Derivative Free optimization since I have no information about the cost function, other than its values where I evaluate them.

    submitted by /u/SteelFi5h
    [link] [comments]

    Editting Inspect Element HTML/JS/JQUERY/ETC to view Contact Email?

    Posted: 24 Dec 2020 06:03 AM PST

    Hello, I am trying to send a rather long email to a company but their content box is cutting me off. I tried googling their email to no avail, so now I'm trying to see if there's anyway it could be viewed within the Contact Us query, but I see a lot of stuff like this:

    $("#contact_submit").click(function(e) { e.preventDefault(); if($('#contact_name').val() &&$('#contact_email').val() && $('#contact_comment').val()){ var contactus = {}; $("#contact_name, #contact_email, #contact_comment").each(function() { contactus[this.name] = this.value;}); $("#contact_name, #contact_email, #contact_comment").prop("disabled",true); var eml = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i; if(eml.test($('#contact_email').val())){ $("#msgs #eml,#msgs #req").hide(); $.post('/contactus/',contactus,function(resp) { if(resp){ $("#msg-sucs").show(); } else { $("#msgs #req").show(); } }); } else { $("#contact_name, #contact_email, #contact_comment").prop("disabled",false); $('#msgs #eml').show(); } } else { $("#contact_name, #contact_email, #contact_comment").prop("disabled",false); $("#msgs #req").show(); } }); $("#contact_reset").click(function(e) { $("#msg-sucs,#msgs #eml,#msgs #req").hide(); $("#contact_name, #contact_email, #contact_comment").val('').prop("disabled",false); }); 

    I'm sorry my programming is pretty rudimentary, but is there anyway to edit the Inspect box and get it to reload and show the hidden elements? (I.e., Delete the .prevent part, change disabled to enabled...? Even just the page reloading to show the email when you hover over the button, would be sufficient.) I look around all the .CSS/.JS files and everything seems to be linked to open locations, I just don't see any email domains even while I try to CTRL-F for possible results...? Of course I don't really know where to look when I do, so there's that... but does anybody have any suggestions? I would think the domain has gotta be there somewhere, if it's redirecting to something... Thanks.

    submitted by /u/Owlworld1992
    [link] [comments]

    Linked List getters and setters vs instance variables

    Posted: 24 Dec 2020 12:20 AM PST

    Prepping for a data structures class and I've been looking at linked list. However through my research I've noticed that some articles use getters and setters and some use purely instance variables. Java, addNode method example; head.setNext(cur) vs. head.next = cur. Is there an advantage over the other or is there no difference between both?

    submitted by /u/sahwest
    [link] [comments]

    No comments:

    Post a Comment