What language should I use for a program to control and output?

Learn Programming - Fri, 11/16/2018 - 20:10

I want to make a program that turns off my laptop's built-in keyboard when I have an external keyboard plugged in. I am wondering what are some good programming languages for doing something like this. I am familiar with java and python so those two would probably be the easiest for me but I'm willing to learn new languages for this as well.

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

Do I need to know c++/c to be a good programmer?

Learn Programming - Fri, 11/16/2018 - 19:57

I've seen many places that you need to know C/C++ (or probably anything lower) to be a good programmer; I've also heard that other programmers whether it is your co-workers (if you do stuff with programming) or someone on the internet won't take you seriously, or will think you know nothing because you don't know C. Is this true? (I'm not worried about what they people think, just want to know if it is really that worth it to learn)

I've tried learning c++ I just don't see me using it for anything really and I always get unmotivated (probably because I don't see me using it) and I'm wondering if I should just tough it out and just learn it.

The ideal person to answer this would be someone who has done some programming for a couple years or longer then learned C/C++, but if you have something of value to say then please say it

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

I took the challenge to explain RxJS to developers in a simplistic way

Learn Programming - Fri, 11/16/2018 - 19:57

Here's a link to this tutorial and let me know your thoughts for on this Tutorial.

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

Is there a library that is memory efficient for storing large, dense matrices?

Learn Programming - Fri, 11/16/2018 - 19:38

I implemented my own C# matrix library recently, which uses jagged arrays of doubles. It was designed to be efficient in terms of time and numerical stability, while sacrifing some memory. Now I wanted to use it for multiple linear regression, including statistical tests, and it turned out that speed really isn't the issue, but memory. My question now would be if one of you knows a matrix library that can deal with 50k by 50k matrices without running out of memory. Open source woul be preferred, for the learning.

I already tried using floats instead of doubles and decimals, implemented the arithmetic in-place, and still run out of memory. I'm actually thinking about writing to the disk and making some coffee while the calculationd are running. But I wouldn't be surprised if someone already managed to solve the problem of storing and working with large dense matrices, which is why I'm asking if you know a library that deals with that - doesn't matter for what language, to be honest, though C# would be preferred.

Thanks for your time

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

[JAVA] Converting a GUI application to an applet

Learn Programming - Fri, 11/16/2018 - 19:35

Hey, everyone. I've been tasked with building an MPG calculating GUI app and then converting it into an applet. I do not know where to begin. I have, for the GUI app, two separate classes, MPGGUI and MPGGUIApp (the driver). Also, if there's anything you'd recommend to improve my code in any way, please let me know. I'd really appreciate it. Thank you!

The teacher's instructions were "Assume that you have completed Part I. Convert it as an applet (JApplet). Must use meaningful names for fields, variables, methods and classes. Must document each of your source codeName your applet as MPGGUIApplet (Note applet itself is a driver class). It is OK to run your applet in Eclipse without coding HTML file by yourself."

This is the class MPGGUI, with the nested exception class NegativeException

package mpggui; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DecimalFormat; public class MPGGUI extends JFrame{ public MPGGUI() { buildFrame(); } private void buildFrame() { JFrame window = new JFrame(); //creating the window JPanel panel1 = new JPanel(); //creating the component panel panel1.setBackground([Color.RED](https://Color.RED)); //setting the color of the panel to red window.getContentPane().add(panel1); JLabel rangePrompt = new JLabel("Please enter the distance in miles your vehicle can travel on a full tank");//prompting the user to enter the vehicle range panel1.add(rangePrompt); //adding it to the panel JTextField rangeInput = new JTextField(30); //creating a field for it panel1.add(rangeInput);//adding the field JLabel capacityPrompt = new JLabel("Please enter the capacity of the vehicle's fuel tank in gallons");//prompting the user to enter the vehicle fuel capacity panel1.add(capacityPrompt);//adding it to the panel JTextField capacityInput = new JTextField(30);//creating a field for it panel1.add(capacityInput);//adding the panel JButton calcMPG = new JButton("Calculate MPG");//creating the button for calculating mpg calcMPG.addActionListener(new ActionListener() {//creating the action listener so things happen when button is pushed public void actionPerformed(ActionEvent e) {//the method for what happens when the calc button is pushed String Capacity = capacityInput.getText();//getting text from the capacity and range fields respectively String Range = rangeInput.getText(); capacityInput.setText(""); //setting the two input fields to empty when calculate is clicked. rangeInput.setText(""); try { //exception handling double capacity = Double.parseDouble(Capacity); //turning the string into a double for processing double range= Double.parseDouble(Range); MPGGUI.inputMethod(capacity, range); //calling the method which validates the inputs } catch (Exception e1) { //if the input isn't a number then a valid input is demanded JOptionPane.showMessageDialog(null, "Please enter a valid input", "Invalid input", JOptionPane.PLAIN_MESSAGE); } } } ); panel1.add(calcMPG);//adding the Calculate button to the panel JButton exitButton = new JButton("Exit");//creating the exit button exitButton.addActionListener(new ActionListener() {//activating the exit button public void actionPerformed(ActionEvent f) {//method for exit button click JFrame exitWindow = new JFrame();//creating the goodbye window JPanel panel2 = new JPanel();//creating the goodbye window component panel panel2.setBackground(Color.RED); //color exitWindow.getContentPane().add(panel2); JLabel exitMess = new JLabel("Thank you for using my MPG calculator."); //displaying goodbye message JButton bye = new JButton("Goodbye"); //button window.setVisible(false);//this hides the main input window for looks sake panel2.add(exitMess);//adds the goodbye message to the goodbye window component panel exitWindow.setSize(new Dimension(300, 100)); //setting the size exitWindow.setLocationRelativeTo(null); //centering exitWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //when the x in the corner is pressed the window is closed exitWindow.setTitle("Goodbye"); //title exitWindow.setResizable(false);//no resizing allowed exitWindow.setVisible(true); //so that you can see it panel2.add(bye);//adding the goodbye button to the component panel bye.addActionListener(new ActionListener() {//activating the goodbye button public void actionPerformed(ActionEvent f) { System.exit(0);//when the goodbye button is pressed the whole app is terminated }}); } } ); panel1.add(exitButton); window.setSize(new Dimension(450, 200)); //setting the parameters for the main window. window.setLocationRelativeTo(null); window.setDefaultCloseOperation(JFrame.EXIT\_ON\_CLOSE); window.setTitle("MPG SOLVER"); window.setResizable(false); window.setVisible(true); } public static void inputMethod(double capacity, double range) { try { negativeVerify(capacity, range); } catch(Exception e) { JOptionPane.showMessageDialog(null, "Please enter a valid input", "Invalid input", JOptionPane.PLAIN\_MESSAGE); } } public static void negativeVerify(double capacity, double range) throws NegativeException {//the method that checks whether positive or negative if (capacity < 0 || range < 0) //if true, an exception is thrown { throw new NegativeException("Please enter a valid input. No letters or negative values are allowed"); } else { MPGGUI.mpgCalc(capacity, range); //if false, the values for capacity and range are thrust into the next method } } public static void mpgCalc(double capacity, double range) { //this method is the heart of it. The method with the division operation. double mpG = range / capacity; DecimalFormat mpgDF = new DecimalFormat(); double mpg = Double.parseDouble(mpgDF.format(mpG)); MPGGUI.output(mpg); //the next method being called, the engine behind the output window. } public static void output(double mpg) {//output window method JFrame solwindow = new JFrame(); //creating solution window JPanel panel3 = new JPanel(); //creating solution compopnent panel panel3.setBackground([Color.RED](https://Color.RED)); //color solwindow.getContentPane().add(panel3); //adding the comp panel to the window JLabel answer = new JLabel("Your vehicle gets " + mpg + " miles to the gallon");//the output label panel3.add(answer);//adding the output label to comp panel JButton another = new JButton("Run Again");//the button to do more operations panel3.add(another);//adding to panel another.addActionListener(new ActionListener() {//activating the run again button public void actionPerformed(ActionEvent f) { solwindow.setVisible(false);// hiding the solution window to access the main input window }}); solwindow.pack(); //specs of solution window. Pack makes the size adjust with the contents solwindow.setLocationRelativeTo(null); //centering it solwindow.setDefaultCloseOperation(JFrame.EXIT\_ON\_CLOSE); //close on x press solwindow.setTitle("Solution"); //title solwindow.setResizable(false); //no resizing for you solwindow.setVisible(true); //it is visible public static class NegativeException extends Exception{ //making the exception class for negative values private static final long serialVersionUID = 1L; NegativeException(String s){ //constructor super (s); } } }

And here is the driver class, containing the main method

package mpggui; import javax.swing.*; public class MPGGUIApp { public static void main(String [] args) { SwingUtilities.invokeLater(new Runnable() { public void run(){ MPGGUI mpgApp = new MPGGUI(); //calling the constructor to begin the chain of events } }); } }

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

I'm totally new, and can't get code to work in visual studio - i've been trying to solve this for a couple days, and nothing online is helping. any help would be appreciated immensely.

Learn Programming - Fri, 11/16/2018 - 19:02

Whenever I try to run any code, I get a list of errors that say "cannot find or open pdb file". so as was advised according to the information i found online, I enabled "microsoft symbol servers". That just gives me a new error, 'DLL Initialization Failed'. I cannot find any explanation for this, and nothing online referring to it. I'm completely new so I'm pretty lost (so i have no idea whatsoever what's going on or what any of this means), and still can't get any simple code running. I've never gotten anything to work before in visual studio. If anyone could help I'd be super grateful.

The language is c++, and I chose "windows console application"

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

Why does this not work.

Learn Programming - Fri, 11/16/2018 - 18:39

[Error] 'else' without a previous 'if'

#include <iostream> #include <windows.h> using namespace std; int main(void) { HWND hwnd = FindWindowA(NULL, "Rechner"); if (hwnd == NULL); { cout << "0" << endl; Sleep(10000); } else { cout << "1" << endl; Sleep(10000); } return 0; } submitted by /u/Delfyni
[link] [comments]

How to use a with statement to create an object? (Using PySimpleGUI and statement in the docs is unclear)

Learn Programming - Fri, 11/16/2018 - 18:39

Looking at this:

it tells me to "create a window object with the desired customization" and then lists the line of code:

with Window('Everything bagel', auto_size_text=True, default_element_size=(30,1)) as window:

I'm not sure what's going on here. I'm not sure how with statements work, but I've read that they're usually used in tandem with try-catch statements, and I don't know how they apply in the context of initializing an object.

For starters, this line of code itself will throw and error since the colon implies something should come after it. I'm not sure what that something is, and I don't think the docs mention it.

Can anyone clarify what the docs are talking about with this with statement? How exactly do I create a new window whose properties I can adjust? Maybe I'm just missing something because I'm still a beginner? Any help is greatly appreciated.

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

How do I point a free domain to an app on Python Anywhere?

Learn Programming - Fri, 11/16/2018 - 18:37

I made a simple Flask app for a game and deployed it on Python Anywhere. But the domain currently still has in the name. You can see it here. I recently just registered for a free domain name at Freenom and I wanted it to point to the web app I have. However, since the PAW account I have is free, the web app only responds to the provided domain and I couldn't change the domain name.

The other option is for me to use Frame Forwarding on Freenom. But that's not what I wanted to do. Is there a way for me to navigate around this restriction without purchasing hosting?

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

Struggling with Objects in Javascript

Learn Programming - Fri, 11/16/2018 - 18:17

Going through exercises and I want to cry. I see it, I get it, I can't figure it out and end up looking up the answer. I type it letter for letter to remember the syntax, and next problem it's almost identical and get stuck all over again. Any advice? Videos? Exercises?

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

javafx webview - Can I load an external page without it's CSS?

Learn Programming - Fri, 11/16/2018 - 17:57

As an experiment I'm creating a Java web browser that loads webpages without their CSS, using JavaFX and WebView. I've spent the past hour using a PHP page (don't ask) before giving up and going back to Javascript, which didn't work at all just like I'd previously tried.

I'm using this code, with some modifications of course. Is it possible to load a webpage this way without the stylesheet, or load it and then remove the stylesheet? The only answers I've gotten thus far don't include any of the imports so I end up with errors from importing the wrong packages.

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

Java - Help with converting seconds in to hours/minutes/seconds

Learn Programming - Fri, 11/16/2018 - 17:45

I've been given a set of exercises to complete and one of them is converting a specific number of seconds (7724) in to hours/minutes/seconds. It's part of pre-course work for a Java class. This is what I have so far:

public class Math3 {

`public static void main(String[] args) {` `Integer totalTime = 7724;` `Integer minutes = (totalTime / 60);` `Integer hours = (minutes / 60);` `Integer minutes2 = (totalTime / 60) % 60;` `Integer dumbatMath = (hours * 60 * 60) + (minutes2 * 60);` `Integer seconds2 = (totalTime - dumbatMath);` `System.out.println(hours + "hrs: " + minutes2 + "mins: " + seconds2 + "secs");` `}`


I know there is a better way to fix the dumbatMath variable but for some reason my brain just isn't getting it. Note that this section of the course is before conditional logic and functions so they are looking for solving this with just math and variables. There is also a bonus section to figure out the average pace of running 26.2 miles in 7724 seconds with the output expected in minutes as a double.

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

An ASCII Stereogram in C++ displayed on the Windows Console?

Learn Programming - Fri, 11/16/2018 - 17:45

This caught my eye:

And it's easy to do so in HTML, but what about C++? Once you print something on the console, you can't replace it. I came up with this, using the \b non-printic char:

#include <iostream> #include <vector> #include <ctime> #include <string> #include <random> std::vector<char> numbers = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; auto seed = std::time(NULL); int main() { std::mt19937 engine(seed); std::uniform_int_distribution<int> dist(0, numbers.size() - 1); char achar = numbers[dist(engine)]; while(true) { std::cout << achar; achar = numbers[dist(engine)]; std::cout << '\b'; } std::cout << "This was a presentation of ASCII Stereogram! Tune in for more!" << std::endl; return 0; }

But it doesn't work. At the risk of people thinking I want everything spoonfed to me and that I'm lazy and lethargic who can't use Google (which isn't true, I've been searching since 1:30 AM and it's not 2:13 AM and even before posting, I searched "delete cout" in numerous terminologies), is it even possible to delete std::cout results? Thanks for your help.


It seems like I can't do this at all because C++ can't clear console.

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

Does anyone actually use EJS and NPM's Express?

Learn Programming - Fri, 11/16/2018 - 17:31

I'm doing an online bootcamp (The Web Developer Bootcamp by Colt Steele, definitely would recommend) and the teacher's using EJS and Express. I don't think I've seen them in use anywhere, so I was just wondering if there's a point in using them?

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

Do While loop failure and auto increment failure

Learn Programming - Fri, 11/16/2018 - 17:29

so the goal of this program is to create a list of students with a max number of 20, each with a max number of classes 5.

the issue I'm having is the do while loop isn't looping no matter what I enter, and the auto increment on variable 'e' isn't resetting with each loop of the last for loop, it's just counting up even between students.

Thank you in advance for your help


#include <stdio.h> #include <stdlib.h> int main(){ int a, b, c, d, e; c=0; char N; struct grades{ char D[15]; int E;}graid[5]; do{ for(a=0;a<1||a>20;){ printf("How many students do you have?"); scanf("%i", &a); } struct Students{ char A[25], B[25]; int C; struct grades *graidP; graidP= &graid[5]; }students[a]; for(b=0;b<a;b++){ c++; printf("what is student %i's name?: [FirstName LastName]", c); scanf("%s %s",&students[b].A, &students[b].B); for(students[b].C=0; students[b].C<1 || students[b].C>5;) {printf("How many classes does %s %s have?\n", students[b].A, students[b].B); scanf("%i", &students[b].C);} for(d=0;d<students[b].C;d++){ printf("Name of course:"); scanf("%s", &students[b].*(graidP+d)->D); printf("Marks:"); scanf("%i", &students[b].*(graidP+d)->E); } } b=0; c=0; printf("{~}Student records are{~}\n"); for(b=0; b<a; b++){ e=0; c++; printf("Student %i\n", c); printf("Name: %s %s\n", students[b].A, students[b].B); printf("Enrolled in '%i' courses\n", students[b].C); for(d=0; d<students[b].C; d++){ e++; printf("%i - %s : %i\n", e, students[b].*(graidP+d)->D, students[b].*(graidP+d)->E); } printf("\n\n"); } printf("do you want to try this again? [Y/N]\n"); N=getch(); }while(N='Y' || N='y'); return 0; }

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