How do you go about making sure user’s username is unique from other users? Posted: 31 May 2020 04:42 PM PDT Currently I am using algolia which indexes everything and I just search. If search is found then not unique. How does big companies go about it? submitted by /u/MuskIsAlien [link] [comments] |
How do I make a title logo in html? Posted: 31 May 2020 06:23 PM PDT Here is what I mean. There is a Google logo next to "How to make....". What tags do I use to make a logo next to the <title>string</title>, instead of it being a picture of a 2D, black and white globe? Thanks in advance. submitted by /u/8blackears [link] [comments] |
How do I reference a .js file in another .js file? Posted: 31 May 2020 11:18 AM PDT The script that contains most of the content of the page depends on another .js file, but I don't know how to reference that 2nd file in the first file. submitted by /u/Hidden_R3D [link] [comments] |
Help with printing function [C++] Posted: 31 May 2020 08:01 PM PDT Hello guys, so I need to write a print function in C++ for my Flight class. This class has atributes: char flight_destination[30], flight_mark[10]; int gate, flight_hour, flight_minutes, flight_duration, delay; 1) If there is no delay of the flight, function Print() needs to: - predict width of 10 for flight_mark, 20 for flight_destination (if flight_destination is longer than 20, it should be cut to that length) - predict width of 8 for take-off time and 8 for landing time - predict width of 6 for gate number - flight_mark and flight_destination need to be aligned left, and other need to be aligned right - hour and minutes always need to be written as two-digit numbers (for example if flight_hour is 12 and flight_minutes is 9 it should print "12:09" and not "12:9") Example: JFK 327 New York 12:50 19:30 5 2) If there is delay of the flight: - flight_mark, flight_destination and take-off time are like in first case but after this we add "(Expected <time> , Delay: <delay> mins)" Example: IST 932 Istanbul 15:50 (Expected 15:30, Delay: 20 mins) Here is what I've done so far: void Flight::Print() const { if(delay == 0) { int temp = flight_hour * 60 + flight_minutes; temp += flight_duration; int hour = temp / 60; int minutes = temp - (hour * 60); std::cout << std::setw(10) << std::left << flight_mark << std::setw(20) << std::left << flight_destination << std::setw(8) << std::right << std::setfill(' '); if(flight_hour < 0) std::cout << "0" << flight_hour << ":" << std::setw(2) << std::setfill('0') << flight_minutes; else std::cout << flight_hour << ":" << std::setw(2) << std::setfill('0') << flight_minutes; std::cout << std::setw(8) << std::right << std::setfill(' '); if(hour < 10) std::cout << "0" << hour << ":" << std::setw(2) << std::setfill('0') << minutes; else std::cout << hour << ":" << std::setw(2) << std::setfill('0') << minutes; std::cout << std::setw(6) << std::right << std::setfill(' ') << gate; } else { int temp = flight_hour * 60 + flight_minutes; temp += delay; int hour = temp / 60; int minutes = temp - (hour * 60); std::cout << std::setw(10) << std::left << flight_mark << std::setw(20) << std::left << flight_destination << std::setw(8) << std::right << std::setw(2) << std::setfill('0') << hour << ":" << std::setw(2) << minutes << " (Expected " << std::setw(2) << std::setfill('0') << flight_hour << ":" << std::setw(2) << flight_minutes << ", Delay " << delay << " min)"; } std::cout << std::endl; } Unfortunately it's not working well. It's not aligned well and I don't know how to fix it. Also I don't know how to cut off the text to 20 characters if it's longer than that, setw doesn't help and I've tried with cout.write() but it's not working either. Also the take-off and landing times are aligned more to the right than they should be like in that example. Since I haven't given the class, I made this program for testing purposes: #include <iostream> #include <iomanip> void Print(const char[] flight_mark, const char[] flight_destination, int flight_hour, int flight_minutes, int flight_duration, int delay) { if(delay == 0) { int temp = flight_hour * 60 + flight_minutes; temp += flight_duration; int hour = temp / 60; int minutes = temp - (hour * 60); std::cout << std::setw(10) << std::left << flight_mark << std::setw(20) << std::left << flight_destination << std::setw(8) << std::right << std::setfill(' '); if(flight_hour < 0) std::cout << "0" << flight_hour << ":" << std::setw(2) << std::setfill('0') << flight_minutes; else std::cout << flight_hour << ":" << std::setw(2) << std::setfill('0') << flight_minutes; std::cout << std::setw(8) << std::right << std::setfill(' '); if(hour < 10) std::cout << "0" << hour << ":" << std::setw(2) << std::setfill('0') << minutes; else std::cout << hour << ":" << std::setw(2) << std::setfill('0') << minutes; std::cout << std::setw(6) << std::right << std::setfill(' ') << gate; } else { int temp = flight_hour * 60 + flight_minutes; temp += delay; int hour = temp / 60; int minutes = temp - (hour * 60); std::cout << std::setw(10) << std::left << flight_mark << std::setw(20) << std::left << flight_destination << std::setw(8) << std::right << std::setw(2) << std::setfill('0') << hour << ":" << std::setw(2) << minutes << " (Expected " << std::setw(2) << std::setfill('0') << flight_hour << ":" << std::setw(2) << flight_minutes << ", Delay " << delay << " min)"; } std::cout << std::endl; } int main() { char flight_mark[10] = "JFK 327", flight_destination[30] = "New York"; int flight_hour = 12, flight_minutes = 50, flight_duration = 400, delay = 0; Print(flight_mark, flight_destination, flight_hour, flight_minutes, flight_duration, delay); return 0; } Any help is appreciated, thank you in advance. submitted by /u/temp000321 [link] [comments] |
If working remotely does become much more prevalent in the years to come, could that give a big boost to niche languages? Posted: 31 May 2020 09:50 PM PDT I'll quote the example I gave on the F# subreddit, but you can mentally replace C# and F# with the mainstream and niche languages of your choice: F# developers are scarce compared to C# developers. But wouldn't that be less problematic if it becomes typical to recruit from around the entire world instead of just your own city? And for developers to apply at companies based all around the world? submitted by /u/danysdragons [link] [comments] |
Just graduated a coding bootcamp, what should I learn next? Posted: 31 May 2020 08:14 PM PDT Not really looking for a job right now, but I would like to take my programming/coding skills to the next level (but I don't know what to move onto next). Currently, I know Python, JS, React, MySQl and MongoDB. Should I start learning a new language? Should I move into more advanced topics in the stuff I already know? Start building a project? Just feeling a bit lost here. Thanks all submitted by /u/mogo3 [link] [comments] |
Node js vs Go for the first back-end language Posted: 31 May 2020 01:58 AM PDT Hi, I am having a hard time choosing between Node and Go to learn as a backend language. I am trying to learn a backend that I can use with flutter and vue.js. So I am from (familiar with) Dart and Javascript background. I have seen that lots of people are saying Go is really fast,it's performance is faster than Node and also has an easy learning curve and lots of companies are adopting it. Does it really have easy learning curve? If Go really has an easy learning curve then I am thinking to learn Go. submitted by /u/milanpoudel [link] [comments] |
Which is better? Competitive programming 3 by felix Halim vs Programming Challenges: by Steven Skiena Posted: 31 May 2020 02:02 AM PDT |
Spring Boot learning material? Posted: 31 May 2020 02:57 PM PDT Hello, I was wondering if any of you know of any good Spring boot learning material. Thank you. submitted by /u/ArturoGJ [link] [comments] |
Showing proportion of growth on each graph? Posted: 31 May 2020 02:48 PM PDT |
Ecommerce Website Posted: 31 May 2020 02:46 PM PDT Hey, guys, I want to create my own e-commerce website but I am a beginner at it. So far I found WordPress e-commerce plan. Is there any better way to create my first eCommerce website? It would be great if you can recommend some tutorials or something. Thanks in advance. submitted by /u/hamiddev [link] [comments] |
How to build a user rights and file management system that works like Google Drive easily? Posted: 31 May 2020 06:16 AM PDT I'm trying to build a web-app that creates data objects in a custom format and I'm thinking about the easiest way to build the user rights management a la Google Drive. I want to be able to grant Read, Write or Comment rights to either a single or a group of users, as well as grouping them up in folders for neater display. Ideally my web-app should be another app in the Google ecosystem (like Docs, Sheets, Slides) and clicking on a file in Google Drive will just open it up in a new browser tab. Saving files in my app will just save it back to Google Drive in my proprietary format (like *.xyc) and all the security and user rights complexity will be entirely taken care of by Google. What would be the best way to do this with Google, and if not, with SaaS off-the-shelf or Opensource solutions? submitted by /u/gmkung [link] [comments] |
How can I implement a super simple cache for a slack bot (or any tiny web app)? Posted: 31 May 2020 01:47 PM PDT I have a slack bot that fetches some JSON configs, but the operation to do so takes longer than Slack's 3 second response deadline. Since the JSON hardly changes I figured that caching it would be a good option. I know nothing about implementing cache. I'm working in python, with a flask api framework, and the needed data is in a single AWS S3 bucket. Any hints? Thanks! submitted by /u/work_acc_1 [link] [comments] |
Java. addAll not adding elements. Posted: 31 May 2020 01:46 PM PDT public class MySet<T> implements java.util.Set<T> { /** * The list used to implement the elements within the set. */ private java.util.List<T> list = new ArrayList<T>(); private List<T> duplicatedObjects = new ArrayList<T>(); @Override public boolean addAll(Collection<? extends T > c) { for (int i = 0; i < c.size(); i++) { T element = (T) c; if (list.contains(element)){ duplicatedObjects.add(element); } list.add(element); } return false; } } . public class Driver2 { public static void main(String[] args) { MySet mySet = new MySet(); mySet.add("First"); mySet.add("Second"); mySet.add("Third"); mySet.add("Fourth"); MySet mySet2 = new MySet(); mySet2.add("Add"); mySet2.add("All"); mySet2.add("Test"); mySet.addAll(mySet2); System.out.println(mySet[1]); //Iterator myIterator2 = mySet2.iterator(); for (Object o : mySet) { System.out.println(o); } } } The console output is: First Second Third Fourth MySet@6acbcfc0 MySet@6acbcfc0 MySet@6acbcfc0 Process finished with exit code 0 Why is this happening? Are the variables that I am using in addAll incorrect? Could someone please help me figure out what is causing this problem. Thanks. submitted by /u/Baamji [link] [comments] |
Weird Question for You Guys: A Book about a Programming Job Posted: 31 May 2020 01:28 PM PDT So one of my summer reading topics is a book who's main character is a job you who want to have. Couldn't find any. Preferably a realistic fiction or something like that submitted by /u/natezebossthe2 [link] [comments] |
How to plan object structure? Posted: 31 May 2020 11:22 AM PDT I am writing a game in python. The game involves lots of objects (a map with tiles, images that appear on the map, loading screen) you know, the works. I have gotten to the point where I'm second guessing whether I structured my objects and methods in the way that is most efficient to navigate and understand. I'm just wondering what the best way to go about designing an application like this is from the ground up. submitted by /u/graciousgroob [link] [comments] |
Java programming help when dividing. Posted: 31 May 2020 11:17 AM PDT I'm making a program for my class to displays calculations when the user inputs two numbers. When I put in 5 divided by 3 I get 1 and I know why I get one but when I set it to double it doesn't give back the decimals. How can I make it where it gives back a decimal. I put my program down below so you have a better understanding of what I'm trying to do. import javax.swing.JOptionPane; public class MyCalculator { public static void main(String[] args){ String x = JOptionPane.showInputDialog(" Please enter the 1st number:"); String y = JOptionPane.showInputDialog(" Please enter the 2nd number:"); int a = Integer.parseInt(x)+Integer.parseInt(y); int b = Integer.parseInt(x)-Integer.parseInt(y); int c = Integer.parseInt(x)*Integer.parseInt(y); double d = Integer.parseInt(x)/Integer.parseInt(y); int e = Integer.parseInt(x)%Integer.parseInt(y); double f = Math.pow(Integer.parseInt(x), Integer.parseInt(y)); int g = Math.max(Integer.parseInt(x),Integer.parseInt(y)); int h = Math.min(Integer.parseInt(x),Integer.parseInt(y)); JOptionPane.showMessageDialog(null, "The sum of "+x+" and "+y+" is:"+a+ "\nThe difference of "+x+"and "+y+" is:"+b+ "\nThe product of "+x+" and "+y+" is:"+c+ "\nThe quotient of "+x+" and "+y+" is:"+d+ "\nThe reminder of "+x+" and "+y+" is:"+e+ "\n"+x+" raised to the power "+y+" is:"+f+ "\nThe largest value between "+x+" and "+y+" is:"+g+ "\nThe smallest value between "+x+" and "+y+" is:"+h); } } submitted by /u/RANDOM7474 [link] [comments] |
JavaScript or Web Design Posted: 31 May 2020 07:03 AM PDT I have learned html and some css and now i and not sure what to do next Should I learn web design as I want to be a front end web developer or should I learn JavaScript first submitted by /u/jay_chatwani [link] [comments] |
Which one is should I learn first python or Javascript? Posted: 31 May 2020 10:18 AM PDT |
Best OAuth 2.0 practice for Java Posted: 31 May 2020 10:09 AM PDT I have been asked to make an OAuth 2.0 integration with an external company. All of our REST APIs are written in Java and I was hoping someone could direct me to an example of how this implementation is suggested these days. submitted by /u/nsoifer [link] [comments] |
Java polymorphism: Tell compiler to ignore the fact that the superclass does not have the subclass's function Posted: 31 May 2020 06:16 AM PDT I have Java-Code like this: ``` public class Animal { } public class Dog extends Animal { public void bark() { System.out.println("Woof!"); } } public class Main { public static void main(String args[]) { Animal dog = new Dog(); dog.bark(); } } `` which uses polymorphism. For some complicated reason, I am not allowed to add the function barkto the class Animal(Because I am using Feature IDE for a uni project). The compiler says, that Animal does not have the function bark`, which is absolutely right. How do I tell the compiler to ignore the fact that a superclass does not have the function of the subclass when I am using polymorphism? I know that there's a setting, but my Google-Fu is just too bad. Thanks in advance :) submitted by /u/_Cane_ [link] [comments] |
ASP.NET vs Java Posted: 31 May 2020 09:45 AM PDT Hi all. Just wondering which option to take first to further my skills and gain a career in web application development. As well as my sound knowledge with HTML, CSS, JS and PHP, I have experience with VB.NET and a little with C#, but I know there is a bigger market for Java at the moment. I'm aware of the similarities, I just don't want to learn a new language if I can't get a job with it. If you have the time, please comment your choice and why. Thank you! submitted by /u/lm31 [link] [comments] |
People who have switched from Linux to MacOS, which one do you prefer and why? Posted: 31 May 2020 09:24 AM PDT |
I need help with a Recursively Maze Solving Algorithm Posted: 31 May 2020 12:05 AM PDT Edit - It's in C++ I am trying to solve a Maze, composed of two 4 x 4 objects. One of them is a Robot (the starting object) and the other is the Player (the end object/point). In order to get the Player, the Robot cannot touch a '.' or a 'B'. I'm 99% sure that these functions work: - bool isValid(int dir, int x, int y) - returns true if the given point is valid
- void move(int dir, Robot& r) - moves the Robot when the path is valid
Here is my program, I have left in helpful comments: #include <iostream> #include <ostream> #include <string> #include <vector> #include <queue> using namespace std; string maze[65] = { "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "....................BBBB.................................... ", "....................BBBB.................................... ", "....................BBBB.................................... ", "....................BBBB.................................... ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", ".... ", ".... ", ".... ", ".... ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ ", "............................................................ " }; class Robot { public: Robot() { for(int x = rX; x < rX + 4; x++) { for (int y = rY; y < rY + 4; y++) { maze[x][y] = 'R'; } } } int rX = 60; ///4 - 1; // smallpx = up, biggpx = down // 14 x 4 + 4 int rY = 60; ///4 - 1; // smallpx = left, biggpx = right }; class Player { public: Player() { for(int x = pX; x < pX + 4; x++) { for (int y = pY; y < pY + 4; y++) { maze[x][y] = 'P'; } } } int pX = 30; ///4; // if odd, divide || if even, divide and subtract one // 7 x 4 + 2 int pY = 50; // /4 - 1; }; vector<std::string> directions; //queue<std::string> directions; Player p; Robot r; bool isValid(int dir, int x, int y) { int tempX; int tempY; switch(dir) { case 1: // up - x tempX = x - 1; if (tempX < 0 || y < 0 || tempX > 63 || y > 63 || maze[tempX][y] == '.' || maze[tempX][y] == 'B' || maze[tempX][y] == 'r') { return false; } return true; case 2: // right +y tempY = y + 4; if (x < 0 || tempY < 0 || x > 63 || tempY > 63 || maze[x][tempY] == '.' || maze[x][tempY] == 'B' || maze[x][tempY] == 'r') { return false; } return true; case 3: // down -x tempX = x + 4; if (tempX < 0 || y < 0 || tempX > 63 || y > 63 || maze[tempX][y] == '.' || maze[tempX][y] == 'B' || maze[tempX][y] == 'r') { return false; } return true; case 4: // left -y tempY = y - 1; if (x < 0 || tempY < 0 || x > 63 || tempY > 63 || maze[x][tempY] == '.' || maze[x][tempY] == 'B' || maze[x][tempY] == 'r') { return false; } return true; } return true; } void move(int dir, Robot& r) { // remroves Robot from maze for (int i = 0; i < 64; i++) { for(int j = 0; j < 64; j++) { if(maze[i][j] == 'R') { maze[i][j] = ' '; } } } switch(dir) { case 1: // up for(int i = r.rY; i < r.rY + 4; i++) { maze[r.rX + 3][i] = 'r'; } r.rX--; for(int tempX = r.rX; tempX < r.rX + 4; tempX++) { for (int tempY = r.rY; tempY < r.rY + 4; tempY++) { maze[tempX][tempY] = 'R'; } } break; case 2: // right for(int i = r.rX; i < r.rX + 4; i++) { maze[i][r.rY] = 'r'; } r.rY++; for(int tempX = r.rX; tempX < r.rX + 4; tempX++) { for (int tempY = r.rY; tempY < r.rY + 4; tempY++) { maze[tempX][tempY] = 'R'; } } break; case 3: // down for(int i = r.rY; i < r.rY + 4; i++) { maze[r.rX][i] = 'r'; } r.rX++; for(int tempX = r.rX; tempX < r.rX + 4; tempX++) { for (int tempY = r.rY; tempY < r.rY + 4; tempY++) { maze[tempX][tempY] = 'R'; } } break; case 4: // left for(int i = r.rX; i < r.rX + 4; i++) { maze[i][r.rY + 3] = 'r'; } r.rY--; for(int tempX = r.rX; tempX < r.rX + 4; tempX++) { for (int tempY = r.rY; tempY < r.rY + 4; tempY++) { maze[tempX][tempY] = 'R'; } } break; } } bool test(string str) { directions.push_back(str); return true; } bool pathPresent(string maze[], int rx, int ry, int px, int py) { if (rx < 0 || ry < 0 || px < 0 || py < 0 || rx > 63 || ry > 63 || px > 63 || py > 63) { return false; } if (maze[rx][ry] == 'P') { return true; } //maze[rx][ry] = 'r'; for (int i = 0; i < 64; i++) { cerr << maze[i] << endl; } cerr << endl; // bool isValid(int dir, int x, int y) // void move(int dir, Robot& r) // 1 - up // 2 - right // 3 - down // 4 - left //up if (isValid(1, rx - 1, ry)) { move(1, r); if (pathPresent(maze, rx - 1, ry, px, py)){ //for (int i = 0; i < 64; i++) { cerr << maze[i] << endl; } cerr << endl; return test("Up"); // 1 = up }} //up if (isValid(1, rx - 1, ry)) { move(1, r); if (pathPresent(maze, rx - 1, ry, px, py)){ //for (int i = 0; i < 64; i++) { cerr << maze[i] << endl; } cerr << endl; return test("Up"); // 1 = up }} //right if (isValid(2, rx, ry + 1)) { move(2, r); if (pathPresent(maze, rx, ry + 1, px, py)) { //for (int i = 0; i < 64; i++) { cerr << maze[i] << endl; } cerr << endl; return test("Right"); // 2 = right }} //down if (isValid(3, rx + 1, ry)) { move(3, r); if (pathPresent(maze, rx + 1, ry, px, py)) { //for (int i = 0; i < 64; i++) { cerr << maze[i] << endl; } cerr << endl; return test("Down"); // 3 = down }} //left if (isValid(4, rx, ry - 1)) { move(4, r); if (pathPresent(maze, rx, ry - 1, px, py)) { //for (int i = 0; i < 64; i++) { cerr << maze[i] << endl; } cerr << endl; return test("Left"); // 4 = left }} cout << "Invalid path!" << endl << endl; return false; } int main() { for (int i = 0; i < 64; i++) { cerr << maze[i] << endl; } cerr << endl; //maze[r.rX][r.rY] = 'v'; cerr << endl << endl; if(pathPresent(maze, r.rX, r.rY, p.pX, p.pY)) { cerr << "guchi" << endl; } else { cerr << "not guchi" << endl; } int distance; // = directions.size() } I'm honestly at a loss right now. Any help will be greatly appreciated! submitted by /u/Warren-Binder [link] [comments] |
No comments:
Post a Comment