• Breaking News

    Tuesday, April 13, 2021

    New to Java, need to implement a hashmap, treemap, and binary search tree. Head is spinning. Ask Programming

    New to Java, need to implement a hashmap, treemap, and binary search tree. Head is spinning. Ask Programming


    New to Java, need to implement a hashmap, treemap, and binary search tree. Head is spinning.

    Posted: 13 Apr 2021 04:55 PM PDT

    As part of an assignment, I need to "Store the pairs of each state and its capital in a Map using the HashMap function. Display the content of the Map, then use the TreeMap class to sort the map while using a binary search tree for storage. "
    I have my HashMap with my 50 key-pairs. I have the program outputting the content of the HashMap. But now I am a bit stuck and confused on the rest.

    I am very much a layman when it comes to Java. Individually I understand the three concepts vaguely.
    I understand that the HashMap is O(1), which makes me really wonder why I am being asked to use a TreeMap (O(Log n)). I understand that the HashMap doesn't preserve natural order by default, and this is evident when I print my HashMap as the output is unsorted (Or, and I could very wrong, they are sorted by the hash?) and the project is to teach me how to properly sort the data.
    That said, what is the point of having the HashMap?
    Can I directly pull the HashMap into a TreeMap?
    And if so, what is the point of having a Binary Tree? To improve search time? From what I understood, both TreeMap and Binary Trees are both O(Log n).
    And I don't know what it means to "use a binary tree for storage", isn't my HashMap doing the storage by holding my 50 key-pairs?
    I realize the assignment is meant to teach me how to use these three concepts, but I am confused because it seems like HashMaps and TreeMaps are typically mutually exclusive, and used for two different applications. People seem to use one or the other, not make one into the other.
    I feel like I am trying to go around my elbow to get to my nose.

    Should I store my 50 key-pairs in a HashMap, then populate a TreeMap from my HashMap data to sort it, then create a binary tree from my TreeMap? Or use the HashMap to create both? Or redundantly create all three independently?

    Sorry for how ignorant I am, I am sure I am completely off on every concept here by a wide margin.
    Every day I learn more about programming, I find 10 more things I know nothing about.

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

    MySQL seems to choosing a poorly-optimised execution plan for a simple query. Can I force it to do it a better way?

    Posted: 13 Apr 2021 08:19 AM PDT

    I've got a large-ish table - well, 19 million rows, slimmed down from 160 million rows. Its primary key consists of an integer (company_id), a second integer, and a DATETIME (date), as batches of data are downloaded and imported every few hours. For each value of the date column, there are a few thousand rows of data.

    company_id and date also have their own separate indexes.

    To get the latest information, I have a view which refers to another view, one which returns the latest date for each company_id (there are five distinct values for that column). That view is equivalent to:

    SELECT company_id,MAX(date) FROM table_name GROUP BY company_id

    This query is very slow (e.g. a few seconds; it's a lifetime!). I tried a simplified version and got the server to EXPLAIN it:

    https://i.imgur.com/hTpA3vq.png

    I also tried the following query which returns instantly:

    https://i.imgur.com/2SHffZh.png

    If I can get the date back instantly from the second query, just by ORDERing and LIMITing, why can't the MAX(date) query be that fast?

    Is there any way to force/rewrite the first query to operate in a similar way? I tried USE INDEX ('date') but it made no difference.

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

    Hello! I think genetic algorithms are neat but I could use some help understanding them

    Posted: 13 Apr 2021 09:49 PM PDT

    I've been enamored with the idea of a problem solver program with a success condition that randomly generates classes to evaluate the functioning ones, seeing which bring it closest to the outcome which fulfils its condition.

    Those closest are kept and replicated with variation of a set optimal percentage found by testing the process. Evaluation of that set, repeat forever until success.

    I'm a noob to coding and I only really know how to code on a basic level in Java. Really any if I have the internet for their api/documentation but then again I guess that means I'm as qualified as the average Joe.

    I learned genetic algorithms exist, but looking them up only really returned programs that simulated the idea or perhaps laid out the architecture of it. Classes that, when run, would create many instances of an object containing simple variables that were easy to make vary via pseudorandom number generation and conditions based on their results.

    Given that I'm an amateur I'm sure I'm either romanticizing the capabilities of the process or I'm fixated on some old news that's actually really basic they did on an etch-a-sketch in the 70s.

    I need help to imagine what java code could execute that would result in the generation of many at least pseudorandom (functionally random thought right?) programs. Basically with randomized code. (Or maybe randomized selections of existing useful functional code fragments now that I think). Creating many functional ones in a decent time period.

    By the end of writing this I am more confused, know less, have unlearned basic typing skills along with inheritance and Excel all while also worried I answered my own question which is really basic and just requires work and it all to be tediously mapped out in detail to understand.

    So if nothing else hello Australia reddit. Do you think perhaps Australia will evolve to be tech capital of the world? The logic is all there that eventually the country would be entirely programmers. Id think natural selection favors Australian kids who avoid going into the Australian outdoors, which is commonly known to be territorial and unnecessarily venomous.

    TLDR: Essentially how to generate random code that isn't always garbage.

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

    Theoretical question that came into my mind at 3am

    Posted: 13 Apr 2021 04:55 PM PDT

    A stupid but interesting question just came into my mind: What would happen if you remove all regex out of all code in the world?

    I would imagine that all searchengines would stop working and maybe some color coding in programs also wouldn't work but I am sure that there are a lot of things I didn't think of so I figured i would post this here and see what you guy can come up with.

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

    Storing a password in a cookie, is it safe?

    Posted: 13 Apr 2021 09:31 AM PDT

    Ofcourse not!

    But how about if the cookie is encrypted (and decrypted when the app is started up) using a pin provided by the user? The problem I am trying to solve is authenticating to a wordpress + woocommerce site, which don't support oauth by default.

    The user will need to enter his credentials in order for the app to be able to create content on the website.

    I dont want to store any user data in my database. So I want to try to save the password in the client in a safe way.

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

    Exercise 26.2.3: Find the Winner (CodeHS Data Structures Challenge Problems - Connect Four - Find the Winner)

    Posted: 13 Apr 2021 06:15 PM PDT

    Exercise 26.2.3: Find the Winner

    Program Result

    Find the Winner

    • When a player makes a move, check to see if they have four pieces in a row along a column, a row, or a diagonal.
    • If you find a winner, end the game and print a victory message!
    • Have fun! You've just built connect four!

    I need help on this one please I don't even know where to start

    submitted by /u/0d3stroyer
    [link] [comments]

    Trouble with makefile

    Posted: 13 Apr 2021 05:57 PM PDT

    Here is my makefile

    https://i.imgur.com/BPBkQMF.png

    Everything was fine until I added token.h / token.o. I get an error saying "No rule to make target 'token.o', needed by 'main'. Stop.

    This makes sense because there is no object file to make for token since I don't have a token.c. I tried removing token.o from "SHARE" but then I get a massive list of compiler errors.

    I'm now confused by my makefile and I don't know how it really works or how to fix it. Everything else works fine, I just don't know how to add a header file only to this makefile.

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

    Reading Telegram messages

    Posted: 13 Apr 2021 01:25 PM PDT

    I'm trying to read all the messages from a certain Telegram channel so as to chart their data. I have no idea how to read Telegram messages with say C++ or Java, is this something that can be easily done? If so, are there any resources available where I can learn how to do so? Thanks!

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

    Why use CNAME instead of Alias?

    Posted: 13 Apr 2021 04:07 PM PDT

    What are situations where you will choose CNAME over Alias?

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

    How does someone write down project ideas on paper (or somewhere) to manage the project ?

    Posted: 13 Apr 2021 11:36 AM PDT

    Hello everyone,

    hope you are doing well. I was wondering what are some different methods to write down our vague project idea on paper and organize it in such a way so that they can start following what is written on the paper and just write the code to represent it in real life?

    To give you some more context, I did many projects in school and during my job, BUT for school, the projects were never big enough (they were complex but not a massive project) so that we have to plan the whole thing in a complex way and write all those plans and communicate with many different people to bring the idea to life. They were pretty straightforward and had to follow the instructions and create a program that respects what was asked. When I started working in a full-time job I realized that there are SOOO many more steps to bring this simple project to the public, many things to consider, and with all these extra steps I have seen people using different methods to represent those vague ideas on paper (or computer) and making them more concrete.

    I have many different ideas to make many apps BUT they are soo vague to me that when I start to do the wireframing I just get stuck because they are not organized at all and I don't have the full picture of what I want exactly. Then if by any chance I do make the wireframe for the app in question I'm never sure how should I write the tasks that need to be done (Like user stories ?) for the front-end and Back-end. So what I am trying to ask is to

    • Share YOUR methods of doing all this or if you know other ways. - What are the different steps, what are those steps called and how can I learn?

    • What is needed before starting coding (so that we don't have to do major changes).

    • Different techniques to manage the project for a team of 1 person or many persons.

    • How should we write the structure of different parts of our project so that people can get the idea of what we are doing and we can understand what we are doing and how should we continue from here.

    • If there are other things to know then those things also.

    I did try searching on the web, but... there wasn't much about all this stuff and I think I needed to search with particular terms which I do not know. Anyway thanks in advance for your time.

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

    Small cross platform desktop UI framework

    Posted: 13 Apr 2021 03:02 PM PDT

    Does anybody know of a small UI framework that is cross-platform. I know Qt is quite popular, but the compiled app comes to around 30MB. Are there any frameworks that offer a smaller UI framework for making a cross-platform app?

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

    Who's API is better?

    Posted: 13 Apr 2021 11:01 AM PDT

    Last summer, I deployed an API for retrieving Wikipedia tables in JSON. I could not find any existing tool like this at the time so I was happy I was able to fill that gap. The app does get users, believe it or not.

    Recently, I found another API that was deployed a few months after mine (found it via indiehackers). It does the same thing but the API endpoints are different and the returned JSON is formatted differently.

    I'm interested in who's API is better. Which one is easier to use? Which one has better formatted JSON? Could mine be improved? Questions like that.

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

    I need help with OOP Design problem (C++)

    Posted: 13 Apr 2021 02:36 PM PDT

    I made Menu class which has 3 methods. First is print() which prints menu text in console. Second reads user input and check if it is valid or not and the third one has switch with several cases all representing one option. In main() I made Menu object. Now when I call the third method which is basically this:

    void Menu::third_method(){ switch (user_choice) { case 1: std::cout << "Choice 1"; break; case 2: std::cout << "Choice 2"; break; } 

    I have a problem here. I want to be able to call some methods from other classes when I enter certain case, For example in case 1 I would like to call Authentication.login() and in the case 2 I would like to call Crawler.getJSONdata(). Is there any was for me to do this without including Authentication and Crawler within Menu class, but rather including them in main and instantiating objects there. I could pass the pointer to a function as a parameter in the third method in Menu class, but determining which method should be called is done in switch case. Any suggestions how I can do this or some advice on how to design this better?

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

    [NOT ENDORSING, HONEST INQUIRY] Is it sus to include black-hat-ey projects in my portfolio site?

    Posted: 13 Apr 2021 02:34 PM PDT

    Under the guise of rule #4, I would like to preface this post with a quick disclaimer. I am in no way condoning, encouraging, inquiring about, or explaining any unethical or illegal activites. I do not intend to encourage or explain any inquiries regarding my experiences if asked - I seek advice, not discussion.

    Soooo - I'm trying for a legitimate, pretty-looking salary career right now.

    About to configure, customize, and deploy some template on GitHub pages. Planning on linking it to my custom-coded Elastic Beanstalk/AWS integrated web app - just gotta give the template a domain name, SSL, the whole shebang.

    As I'm going through messing with the front-end of this template, I'm noticing the 'experience' and 'projects' sections -- and drawing a complete blank. The whole reason for, well, me knowing what I do about programming, security, unix, linux, docker, blahblahetcetc. is due to my - say - less-than-honorable experiences. Scrapers, stuffers, scanners, sites for groups - all that shiz.

    I have a few legitimate projects that I've worked on, but nothing that I'd consider to be too special. So, this may be a really, really stupid question, but, would it be utterly stupid of me to include some of these projects, the lighter-hearted ones, maybe some streaming bots or something, in my portfolio? Where should I draw the line? I feel like some of my experiences may be attractive to employers, but also run the chance of landing a jail cell, not a job.

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

    How to maintain the Policy v/s Mechanism philosophy during development?

    Posted: 13 Apr 2021 05:00 AM PDT

    There is the Unix philosopy of implementing mechanism and pushing policy to the upper layers. While software development I try to follow this philosophy. But lately I have been struggling a bit to achieve this. How do you stay on course with this philosophy when developing medium to large scale project?

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

    Bootcamp reviews

    Posted: 13 Apr 2021 09:58 AM PDT

    Hi all, I'm trying to find credible reviews about bootcamps. Sites like switchup and coursereport are probably bullshit. Can anyone offer suggestions of how I might find honest feedback about the all the various bootcamps out there?

    And please don't bother trying to convince me that paid bootcamps aren't worth it or try to sell me on one particular bootcamp.

    Thank you!!!

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

    Been given a task to have a select box change textbox when 'other' is selected, and have it work on mobile as well as pc. I'm not a Dev, but would like to try and fix it.

    Posted: 13 Apr 2021 09:50 AM PDT

    Hello,

    I have got a simple JS to take a option from a select box, and change it to a input text box that was created by someone else who has now left.

    My goal here is for this to work on Desktops, as well as mobile devices in the same way.

    The site is a simple form site to fill out and submit info.

    The JS code we are using is:

     <script language="JavaScript"> function DropDownChanged(oDDL) { var name = oDDL.name; if(oDDL.value=='Other') { oDDL.style.display= 'none'; var oTextbox = oDDL.form.elements[name+'txt']; oTextbox.style.display = ''; oTextbox.focus(); } } function DDTEXTChange(oTextbox){ var name = oTextbox.name.substring(0,oTextbox.name.length-3); var oDDL = oTextbox.form.elements[name]; var option = document.createElement("option"); option.text = oTextbox.value; option.value = oTextbox.value; oDDL.appendChild(option); oDDL.selectedIndex =oDDL.options.length-1; oDDL.style.display = ''; oTextbox.style.display= 'none'; oTextbox.focus(); } </script> 

    and our select boxes look like

     <input type="text" name="#blahtxt" style="display: none;" onblur="DDTEXTChange(this);" /> <select name="#blah" size="1" onblur="DropDownChanged(this);" onclick="DropDownChanged(this);" onchange="DropDownChanged(this);" id= "#removed" style="display: '';" > <option value=""></option> <option value="Future">Future</option> <option value="Yes">Yes</option> <option value="No">No</option> <option value="Other">Other</option> </select> 

    I hacked together the onblur, onclick, and onchange, as the original code only has onchange. This is probably not the best way to code this I know, but it almost works for exactly what I need.

    This would work on pc, but on iOS, onchange would not work. So I changed it to onblur. This worked great for ios, but android and PC you would have to click out of the element and back into it to type your input.

    Adding onblur, then onclick. Works perfectly for iOS and PC, but android still has to click off, then back into the input box to type.

    Adding onchange, breaks iOS, and does not change the box at all, and it works great for PC and android.

    All that I need this to do, is be able to select the option 'other' Have the box change from a select box, to the text box, and focus on that box so you do not have to click back into the input field for each device.

    I'm not a programmer by trade, but have taken on this task to try and get this problem solved, so if anyone has some ideas for me to try, I would appreciate the help. I've spent hours on stackoverflow and reddit looking for hints to what I could try to do to get this to work across all devices.

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

    How to copy GitHub SSH url in web browser using a keyboard shortcut?

    Posted: 12 Apr 2021 10:31 PM PDT

    GitHub SSH url: git@github.com:user/repo.git

    Usecase:

    I clone a lot of repositories from GitHub and having to click "Code" button then copy the url is not convenient.

    What I expect:

    A Keyboard shortcut that that whenever I go to GitHub repository and upon using that shortcut key, the GitHub SSH url should be copied to clipboard.

    Additional Context:

    My guess is chrome extension or userscript could help.

    OS: Windows 10 Browser: Chrome

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

    Whatsapp Web Mirror App?

    Posted: 13 Apr 2021 05:52 AM PDT

    Hey so i was wondering. Many companys offering a multichat of WhatsApp use a method that instead of using the WhatsApp Business Api its just like a normal whatsapp web but with the difference that can be opened in multiple computers at the same time. Basically its a Mirror App for whatsapp web. So latley i was thinking if it would be possible to make a whatsapp web mirror using nodejs. What do you think? Do any of you have an idea of how could i make it?

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

    How to programmatically generate Anki cards?

    Posted: 13 Apr 2021 05:31 AM PDT

    Hello. Anki is a spaced repetition flashcard app that is used for memorization of words, facts etc. If I have a list of words with definitions, how can I create Anki cards programmatically? Does anyone know which programming language or framework could do the job?

    To give you more information, I need to enter the word in some text input and it's definition in another text input in the app, then hit the create the card button.

    Or maybe there is something that can be directly used for the creation of Anki cards?

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

    Can somebody ELI5 me what Postman, Jenkins, Jira, Selenium, Docker Kubernetes are?

    Posted: 13 Apr 2021 07:53 AM PDT

    Replace files in a strange way?

    Posted: 13 Apr 2021 01:29 AM PDT

    Hello, I need help? I need to replace textures in my game with new ones and I cant figure out how to keep the directory structure on replace, for example:

    My new textures:

    "C:\textures\floor.png"

    "C:\textures\roof.png"

    "C:\textures\carpet.png"

    "C:\textures\potato.png"

    "C:\textures\reddit_flag.png"

    "C:\textures\farm.png"

    +2026 more textures

    need to be replaced with the ones already in my game directory but that directory has folders and my replacement textures are in one big folder with no organization.

    My old textures:

    "F:\Games\GameName\textures\irish_village\floor.png"

    "F:\Games\GameName\textures\irish_village\roof.png"

    "F:\Games\GameName\textures\irish_village\carpet.png"

    "F:\Games\GameName\textures\irish_farm\potato.png"

    "F:\Games\GameName\textures\German_forces\reddit_flag.png"

    "F:\Games\GameName\textures\british_farm\farm.png"

    +2026 more textures

    basically I need to replace them but keep the directory structure intact, thank you if anyone manages to figure this out. I've been trying for hours... :/

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

    How to programmatically settle bets of different sports?

    Posted: 13 Apr 2021 06:25 AM PDT

    I'm building a sports betting website, I'm getting odds from betsapi.com and results also. but the results have scores, stats and events in the game only they don't have outcome bet markets settled.

    Is there an easy way to automatically settle bets of different sports?

    or do I have to write code for each betting market for each sport?

    Upcoming Games Format :

    https://betsapi.com/docs/samples/bet365_upcoming.json

    Prematch Odds Format :

    https://betsapi.com/docs/samples/bet365_prematch_odds.json

    Results Response :

    https://betsapi.com/docs/samples/bet365_result.json

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

    No comments:

    Post a Comment