Learn Programming

Subscribe to Learn Programming feed
A subreddit for all questions related to programming in any language.learn programming
Updated: 28 min 45 sec ago

Why when I fork something on Github, am I not getting the latest version?

34 min 2 sec ago

I am attempting to fork this repo: https://github.com/adafruit/BOSSA/tree/arduino

And on it you can see the following directory:

src add samr21 5 months ago

But when I fork it, I don't get that version, I get a much older version:

src Added email contact and website to about dialog and help text 2 years ago

I checked that I am looking at the same branch as that tripped me up earlier when directories seemingly disappeared entirely, but that's not the issue.

I also see this notification on the fork: This branch is 3 commits behind mattairtech:arduino.

And that may be the source of my issue, but I can't seem to update the fork so it's not behind. I tried the "pull request" button, but the wording of what I get back sounds weird:

mattairtech:arduino is up to date with all commits from scswift:arduino. Try switching the base for your comparison.

That sounds like what I'd call a push, not a pull, but admittedly I'm unfamiliar with all this stuff. Shouldn't it say that scswift:arduino is up to date with all commits from mattairtech:arduino? (Which it appears not to be, but that's besides the point.)

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

c++: bit confused about dynamic_cast

59 min 55 sec ago
if (CheckingsAccount* cptr = dynamic_cast<CheckingsAccount*>(account[i])) { //if account[i] is in fact a checkings account: cptr->setTransactionFee(5); cptr->credit(0, secondAdjustment); }

I wrote this bit of code and I'm confused about the if (CheckingsAccount* cptr = dynamic_cast<CheckingsAccount*>(account[i])) statement.

So it automatically sets cptr to `account[i], and that also causes the if-statement to check to see if cptr is in fact an CheckingsAccount class?

If that's the case then does dynamic_cast return true if it's able to successfully convert a base class to a derived class?

If that's what happens and the first if-statement fails, then do both cptr and sptr point to the newly converted account object? And is this generally bad programming practice?

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

Been learning for years, but i still feel like an idiot

1 hour 25 min ago

I have been learning programming for about 2 years. All different languages, but mainly C# and Python. The problem is, i feel like i can't really do anything. I can make a stupid windows forms app here and there, and maybe a bot in Python, but i feel like when i have an idea for something, i just can't do it. Am i just stupid and should i give up with programming and maybe find a new hobby?

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

[C] Loop passing data between child and parent process hangs indefinitely.

1 hour 34 min ago

I posted a previous thread for the similar assignment and you guys were extremely helpful, but I ran into another snag.


The program will run, and will pass data now (thanks again for that), but when running large batches of data the program will hang after the loop has run and processed few hundred times. I'm specifically testing against /usr/share/man which is about 6800 files.

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

I need a simple explanation that explains hash functions

2 hours 24 min ago

What is the purpose/benefit of hash functions?

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

Can't get Java download to play nicely with Php

Fri, 03/16/2018 - 23:46

Hello, I have followed the top answer from https://stackoverflow.com/questions/157318/resumable-downloads-when-using-php-to-send-the-file and placed that onto a web server. I have then followed this tutorial https://stackoverflow.com/questions/15349296/implement-pause-resume-in-file-downloading top rated answer and implemented the Java downloader. I can run the Java application and have it start the download, I then pause the download and attempt to restart the application to continue the download, at this stage the server seems to respond with a 200 OK (you would expect I believe a 206 PARTIAL for partial download) and then a 'StringIndexOutOfBoundsException: String index out of range: -5'. Have been racking my brain trying to work this one out of the passed few hours and would appreciate some insight as to why its not working, it seems simple enough. Cheers

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

Java Issue with a while loop "NullPointerException

Fri, 03/16/2018 - 23:37

Hey Guys, I have a block of code that I'm trying to run that am having an issue with. I'm trying to just get the index number of a Linked List (p) element that contains an Object (g) that has a matching string (gcmName). Below is the block of code in a method;

public int getIndex (String gcmName) { int index = 0; Node p = first;

String tName = p.g.getfName() + " " + p.g.getlName(); while (tName != gcmName) { index ++; p = p.next; }

return index; }

If I comment out the while loop, of course the index 0 is returned which I can then send to my remove method but with the loop in there, it bombs out. It must be something small I'm missing but i'm 30 minutes in to trouble shooting. Thanks

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

How to setup a JS server that links to projects made with different languages

Fri, 03/16/2018 - 23:22

Hi. I want to make a portfolio website for the projects I've done. There are some made with Django, another with pure html css, and several others with Node JS.

I have a digitalocean droplet, but i'm stuck figuring out how to have 1 central server that hosts all the other projects. Can I go about this with Node and Express? For example, the base url would be foo.com, and it would have pages such as foo.com/about, foo.com/contact, etc. What about project urls in that case? foo.com/project1/projectabout, foo.com/project2/projectcontact, etc.

Thanks for any help! I guess for an alternative I can deploy the projects to Heroku, but I'd like to know how to keep everything on one server.

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

[HELP] Beginner and Stuck with Compiler Issues

Fri, 03/16/2018 - 23:15

Wrote a program for recursive Towers of Hanoi solution and when it was submitted to professor, there were compiling issues. I have absolutely no clue what it could be.

The issue is: "Exception in thread 'main' java.lang.Error: Unresolved compilation problem at line 49.

Bulk of the code here:

public class TowersOfHanoiRec {

static File file = new File("OutputRec.txt"); //Creates Output File static FileWriter fw; private static void discMoves(int n, String startPeg, String destPeg, String tempPeg) throws IOException { if (n <= 0) { //Could also be executed as switch cases fw.write("At least one disc is needed to execute program."); System.out.println("At least one disc is needed to execute program."); } else if (n == 1) { fw.write("Move Disc 1 from " + startPeg + " to peg " + destPeg + "\n"); System.out.println("Move Disc 1 from " + startPeg + " to peg " + destPeg + "\n"); //Base Case. When Disc is 0 move from start to dest } else { //Recursive Step for all other cases (3 Steps) discMoves(n - 1, startPeg, tempPeg, destPeg); fw.write("Move Disc " + n + " from peg " + startPeg + " to peg " + destPeg + "\n"); System.out.println("Move Disc " + n + " from peg " + startPeg + " to peg " + destPeg + "\n"); discMoves(n - 1, tempPeg, destPeg, startPeg); } } public static void main(String[] args) throws IOException { fw = new FileWriter(file); TowersOfHanoiRec towersOfHanoi = new TowersOfHanoiRec(); System.out.println("-----------------------"); System.out.println("Enter number of discs: "); //Requests input in console submitted by /u/I_Cerberus_l
[link] [comments]

Assistance Needed

Fri, 03/16/2018 - 23:10

Hello reddit I’m a college junior majoring in political science. Currently I’m taking a data literacy class and am not doing so hot to say the least. Much of the class revolves around using r and r/studio. If you know how to use this any help you could offer me would help! Thanks

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

[c++] matching keys between two maps

Fri, 03/16/2018 - 22:46


Essentially I'm making a program (I have to use C++98) that will join these two files based on the keys. I've tried using maps in order to do this, but I'm unclear as how to use the key from one map and search the other map using that key.

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

How do I limit a centered text so that there are borders?

Fri, 03/16/2018 - 22:22

Right now I'm working on the very start of a website in HTML using Brackets and I want to give it a sort of centered look while still remaining on the left. Here's an example article: https://www.scientificamerican.com/article/black-hole-pretenders-could-really-be-bizarre-quantum-stars/#

I was looking at other websites to get an idea of what mine could look like and want to add the side areas for other features and a nicer, more centered text group that I can implement later once I'm slightly more knowledgeable or at least done learning and implementing the very basics.

I'm brand new to programming, I literally started today and I'm only asking here because I'm not really sure how to word it in Google. Sorry if it seems really obvious.

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

High School Math & Physics Class for Computer Science Degree

Fri, 03/16/2018 - 22:04

Hi everyone,

I'll be starting my OSSU Computer Science Degree very soon. The program asks the following as a prerequisite:

Core CS assumes the student has already taken high school math and physics, including algebra, geometry, and pre-calculus.

I did not attend a US school, nor do I have a science or maths background. I found resources in Khan Academy to go through. Since I'm not familiar with the US high school studies, I'm not sure which math and physics courses to choose from Khan Academy. Can you advise?


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

Stupid but curious question about typing skills

Fri, 03/16/2018 - 22:03

Hi everyone

I’m starting out in python with the help of a book and I’m wondering this:

To improve on efficiency (ie not looking at the keyboard and just type away at each problem), does everyone type over the quotes with the same quote or do you just hit the end button to go to the end of the line and then enter to the next line of code? I’m proficient at typing but this auto stuff (), “”, ‘’, really slows me down. Thanks.

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

How can I create a self-destructing video file?

Fri, 03/16/2018 - 22:03

Let's say I wanted to send a 10 minute long video that allows users to watch once, then it's gone forever.

Think Snapchat but for larger video files.

Is there a language that would enable me to do so? Is this even feasible currently? I'm guessing a completely new video player would have to be created for this but is there no way one could write video data that infiltrates players such as VLC and Quicktime?

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

[Java][Homework] Reading a file with multiple digits separated by spaces

Fri, 03/16/2018 - 21:49

I have a simple text file that looks like this


13 21 5 37 15

That is a number, followed by how many subsequent numbers follow it.

I'm trying to read it with this

import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; public class FileIO { private static final String file = "C:\\Users\\tamar\\Desktop\\stuff\\CS stuff\\p1small-1.txt"; private ArrayList<Integer> list = new ArrayList<>(); public void parseFile() { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); String text; while ((text = reader.readLine()) != null) { list.add(Integer.parseInt(text)); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { } } } public ArrayList<Integer> getList() { return list; } public void printList() { for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } } }

it's producing

Exception in thread "main" java.lang.NumberFormatException: For input string: "13 21 5 37 15" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at java.base/java.lang.Integer.parseInt(Integer.java:770) at FileIO.parseFile(FileIO.java:21) at Project1Main.main(Project1Main.java:5)

I don't know why its producing an exception nor what this one means

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

Want to make apps (games and non game apps) what language should I learn??

Fri, 03/16/2018 - 21:35

Hey, I'm new to programming and I've tried it in the past, but I'm really trying to get into at the moment. I have some ideas I want to make into an app and maybe make some small games later on. I just need to know what language to learn so I can start right now.

Would any language be good? Java? Python? I really don't care too much but I would rather get some advice first. Thanks.

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


Fri, 03/16/2018 - 21:32

Cannot insert the value NULL into column 'OrderNum', table 'TestPremierProducts.dbo.OrderLine'; column does not allow nulls. INSERT fails.

create procedure AddOrderItem ( @ordernum int output, @customernum int output, @custname varchar(50), --name of the customer placing the order @orderdate int, --date associated with the order @part int, --ID of part being ordered @qty int, --how many they desire @price money --price that we quoted them ) as IF(Exists(select* from Customer where CustomerNum = @customernum)) begin Update Customer Set CustomerName = @custname Where CustomerNum = @customernum end


Insert Into Orders (OrderDate, CustomerNum, Billed) Values(@orderdate, @customernum, 0)

Set @OrderNum = @@IDENTITY

end go

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

[Java][Homework] Issues making a multiple root factorization program.

Fri, 03/16/2018 - 21:18

I have gotten to the point where I can input a number and it will give me the correct factors, however I would like it to solve and simplify afterwards. For example, if I input 216 and choose the option for cube root, it'll output 2, 2, 2, 3, 3, 3. How can I get it to output just 2, 3? I have the same problem with the other roots too, square root of 25 factoring out as 5, 5 and not just 5. Any help or suggestions are appreciated! Thanks in advance!

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

First Small Side Project, Need Guidance.

Fri, 03/16/2018 - 20:59

I've finished learning the basic syntax and basic concepts of OOP in Java a while ago ,and thought it was time to start my own side project. I have an idea in mind and how I want to execute, as I have also mapped it out on paper. However, I'm struggling with actually starting coding it. (Not sure where to start).

I was wondering if someone who has some experience and doesn't mind assisting me throughout the project would be kind to help me via DM's until I get going with the project?

I promise I won't take much of your time, just a few questions here and there to help get me going!

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