Learn Programming

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

Upload multiple files from Angular 5 to Sharepoint, wait for all files to be uploaded before closing the modal, what am I doing wrong?

43 min 52 sec ago

I have an Angular 5 app, a C# .NET Web Api and as "database" you could imagine Sharepoint.

The flow of actions are, firstly the user logs into my angular app, selects an item from the list (data gotten from Sharepoint via my web api) and receive a modal/pop-up to add some comments, check some checkboxes and upload multiple files. When they click save, my app should send the line of comments typed in to a Sharepoint list and should upload any files selected by the user, this could be 1 or 10, to another Sharepoint list.

I disable the save/cancel buttons and display a spinner when the user has clicked on "Save". When all files are uploaded correctly, the modal should close. If any of them result in an error, it should throw an error to the modal to signal the user of the failure to upload.

Here's my code:

save() { if (this.EADModal.comments === '') { this.EADModal.comments = null; } // ...files = "FileList" item, NOT an Array! this.filesToUploadLength = this.filesToUpload.nativeElement.files.length; if (this.filesToUploadLength > 0 || this.EADModal.comments != null) { if (this.errorMessage != null) { this.errorMessage.nativeElement.value = ''; } this.showSpinner = true; this.showErrorMessage = false; this.saveButton.nativeElement.disabled = true; this.closeButton.nativeElement.disabled = true; if (this.EADModal.comments != null) { this.uploadComments(this.EADModal.comments); } if (this.filesToUploadLength > 0) { this.uploadAllFiles(this.filesToUpload.nativeElement.files); } } }

Here's my "uploadAllFiles":

public uploadAllFiles(files) { const observableArray: Array<Observable<any>> = new Array; for (const file of files) { observableArray.push(this.getBase64(file)); } Observable.forkJoin(observableArray).subscribe( data => { this.modalRef.close(this.EADModal.EOTAFileNr); }, error => { this.showSpinner = false; this.showErrorMessage = true; this.saveButton.nativeElement.disabled = false; this.closeButton.nativeElement.disabled = false; // this.errorMessage.nativeElement.value += 'File failed to upload! '; } ); }

Here's my "getBase64" function:

public getBase64(file): Observable<any> { const $this = this; const reader = new FileReader(); const fileReaderObs = Observable.create((observer: any) => { reader.onload = function() { $this.fillJsonVariable(reader.result); }; // observer.next(); observer.complete(); }); reader.readAsDataURL(file); return fileReaderObs; }

And here's my "fillJsonVariable":

public fillJsonVariable(readerResult): Observable<any> { const folderYear = '20' + this.EADModal.EOTAFileNr.substring(0, 2); this.json = { ... : ... }; return this.tableService.postModalDataFile(this.json); }

I've got limited experience in Angular and working with Observables as you might be able to see. What am I doing wrong here? The files simply aren't posted to Sharepoint. I know for sure this isn't an API/Sharepoint problem, because calling the observable/function once (not in a for loop) does upload the file!

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

What choices I`ve got in making native mobile apps

1 hour 8 min ago

I am assigned to create a mobile application at work. I heard about "Pybee", but is it a good choice? Or should I stick with java/swift? And are there any other alternatives for building native apps?

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

I'm not sure what language I should begin to learn for my first project

1 hour 40 min ago


I've set my first project to be some kind of sleep diary app for android, as I have a bit of trouble with my sleep schedule rn. I imagined the UI(if i can call it that) to have the visuals of a calendar. Select a day and you can type in the amount of sleep, how well you slept, what you did to help you get sleepy, etc. I read the 'read this first' post here, but the only recommendation i could see was Java. The link to more recommendations was broken.

Soo should I begin to learn Java? Can I even make this app with that?

Thanks in advance

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

What frameworks or libraries help me build “shared experiences“ on the web?

1 hour 48 min ago

I’d like to build a webapp where a user in the webapp can can request help from a company representative. I want the rep to be able to hook into the user’s session and be able to “point” at things (via a 2nd cursor image). like an interactive screen share. Think Fire tablet’s old Mayday button feature that connected amazon employees to a user’s tablet.

What is this kind of “shared session” technology called? i am having trouble querying for this on google.

are there existing tools to get started building this sort of experience? I can imagine how I’d build it myself via web sockets connecting the customer’s session and the rep’s session, and exchanging information like the mouse position so the other session can render it to the other persons web page.

thanks for any direction or pointers!

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

[C] Putchar overwriting a character rather than adding to the end of line as expected on Mac, but works normally on Windows

2 hours 31 min ago

Hello everyone, long time lurker but first time poster here. I tried to stick to the posting guidelines!

So the first assignment for a C/Assembly course I'm taking this term was to modify code given to us by a professor to rotate a text input from a file, so that say "abcd" became "bcda" [the first character in a given string is moved to the end]. Though I know I could've taken the time to figure out the syntax/tools for an algorithm, I wrote out a quick way since this was just an in-class assignment to "dust off' and code something small on the first day back.

The following is my modified code to complete the assignment:

#include <stdio.h> #define BUFFER_SIZE 81 int main(int argc, char **argv) { char string[BUFFER_SIZE]; while(fgets(string, BUFFER_SIZE, stdin)) { int numChars = 0; while(string[numChars] && string[numChars] != '\n') ++numChars; int i; for(i = 1; i < numChars; ++i) // This loop prints out the input starting at the second letter { putchar(string[i]); } putchar(string[0]); /* This is supposed to add the first character from the input to the end of the string prior to printing to console*/ putchar('\n'); fflush(stdout); } return 0; }

I also have an input.txt to pass to the program. Let's say that the original text in the file was "ABCDEFG". The desired output is "BCDEFGA".

The trouble is, after compiling and running this code on Mac and passing my input file to it, I get "ACDEFG".

After tinkering with the code, it looks like the for loop is printing out the input starting from the second letter as it should, but when it goes to "putchar(string[0])", it replaces the first letter rather than adding it to the end.

I was at wits end trying to modify this to work properly, but I'd always end up with a variation of the same issue - putchar seemed to revert to the start of the line, overwrite characters from there, and then print that line after calling fflush. After having a friend look over it and telling me it compiled and completed properly on his machine, I thought to try it on my PC......and sure enough, it worked properly x_x. 3-4 hours or so of reading documentation, trying new code, and searching for similar problems only to realize that it worked the first time, just not on my platform.

In trying to learn more about the issue, I added more "putchar" statements beneath the one next to my second comment, and noticed that the second putchar would overwrite the second character, and a third putchar would overwrite the third, etc. So say I added 3 "putchar(string[0])", the output would be "AAAFG", rather than "CDEFGAAA".

My question is - why the difference in output with the exact same code? I figure it's a cross-platform issue, but it seems like such an odd issue...though I do realize my knowledge on this subject is incredibly limited, as this is my very first day with C. How could I modify this code to give me the desired output on Mac? I've searched far and wide, and couldn't find anything relating to the problem of putchar overwriting characters.

For what it's worth - I'm using Visual Studio Code and compiling in terminal using gcc. I've also already submitted my assignment, and plan on coding C in a VM to avoid these sorts of issues in the future. I would just like to know how this could be coded differently/potentially avoided, or some insight as to what exactly is going on here for my own benefit and understanding.

Thanks in advance!!

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

Can someone please tell me how I could improve my portfolio website?

2 hours 52 min ago

Here is the link:


Any comments would be greatly appreciated.

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

self-taught programmer looking to expand my skills to apply for a job

2 hours 52 min ago

Been working hard for a year now and I am pretty solid in python, but mainly java and already have a couple of projects to show for future employers. But since I am self-taught and have no college degree or anything to show except for my projects on git I am not interesting enough to get an actual interview for a junior position.

So as I said I'm pretty solid in python but prefer working with java. What would you guys recommend I should look into to expand my skill set? Would something like SQL be useful?


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

Help me with this stupid math problem i dreamed of figuring out for months

3 hours 19 min ago

My brain just cant do math. i am finally reaching for help

basically in C++ i made a hack of a GTA game that reads car position X.Y and rotation. and when i press a button. i can store a waypoint coordinate x.y in the memory.

What i'm trying to understand is how do i use math to detect if the way point is for example Forward left. Forward right . backward left . backwards right, relative to the car . Accurately

Please see this image https://imgur.com/EFem1lV

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

How to make a minesweeper solving algorithm, which is able to scan the screen and determine where the board is [Java]

3 hours 25 min ago

I'm currently in a course in Uni where I'm required to make a program using a complicated algorithm and self-made data-structures. Suggested topics include pathfinding, cave generators, compilers and AIs. I'm particularly interested in problem-solving for games, especially minesweeper.

I looked into the subject and found a couple of good posts like this and this thesis from Harvard. I'm not the best programmer and some aspects seem quite difficult to implement. However, I think that a program of this sort is achievable. What I'm most concerned about is how to make the program "read" the board; how can I make the algorithm see what's happening on the screen and how is it able to know what and where is the minesweeper board? I'm hoping to code this program in Linux and use an online minesweeper to test the functionality.

Creating my own minesweeper seems far to difficult to fulfill, taking into account the duration of the course. Is this topic too difficult for me to handle? Should I just admit my defeat and switch to a different subject before I fall behind? As I mentioned earlier, the logical side I believe I'll be able to manage, it's just the "screen reading" that's causing me to doubt myself.

Sorry about any grammar, English isn't my native tongue.

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

Why has error?

3 hours 58 min ago

The code: https://pastebin.com/Mw2y040U


im trying to make file encryptor & decryptor but having no success.

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

Help porting python 2 script to python 3

4 hours 4 min ago

I am struggling with this now for a few days and I simply cant solve it.

I need to transfer users from a python 2 system to a python 3 system and KEEP the hashed and salted PW's.

For this I need to convert the python 2 check hash function to python 3, but even after I fixed all errors, the function does not work (It tells a wrong PW has been entered, eventhough its correct)

I have the whole question and explanation on SO, hope this is ok:


Thanks a lot to the people who take the time.

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

Am I too stupid to code?

4 hours 44 min ago

Cut a long story short I work in DevOps but I don't really bring the Dev part to that position I'm more of an infrastructure guy and POC. There is lots I want to do to automate my job so I thought now would be a good time to learn to code as it is something that has always interested me.

I picked up Automate the boring Stuff with Python on Udemy and I'm about 43% through the course and honestly I can remember a few bits like if I re watch the but sit me in front of a blank Idle and my mind is blank... Do I just not have the ability to retain information or will it start sticking the more I persevere and start writing code?

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

What should i focus on?

6 hours 20 min ago

I have been studying C# for 2 years, around 200 hours of courses + whatever I've been doing at home at highschool/college (I'm 18) and now I have been given the opportunity to take a course of 50 hours specializing in whatever I want with a personal teacher. Is there something you think would be beneficial if I aim to work within this field in the future?

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

THREEjs Having Trouble With OrbitControls and Lighting

6 hours 34 min ago

Hi there,

I've loaded a 3D Model GTL File and I am having trouble implementing TrackpadControls as well as getting the lighting and shadows to show up correctly

The live site can be seen here and here is the jsfiddle

any help is appreciated. thank you!

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

Write 256 in binary while padding the binary numbers with zeroes to the nearest four . bits?

7 hours 27 min ago

This isn't making any sense to me. How Am I supposed to write 256 and it says pad the binary numbers on the left with zeroes to the nearest four bits.

The answer I got is 00000001 00000000

How am I supposed to pad that to 4 bits? He makes no sense. You can't.

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

[HOMEWORK] n-th composition of a function in python

7 hours 35 min ago

So the question is as such.

"Implement the repeated function, which takes a one-argument function f, a positive integer n, and a parameter x. It returns the result of composing, or applying, f n times on x, i.e., f(f(...f(x)...))."

So these are the functions I defined in global to use

def identity(x):

return x

def compose1(f,g):

def h(x): return f(g(x)) return h

def square(x):

return x*x

I figured that I needed compose1 and identity to combine f and x together first and assign it to another name so that I can input the name into the function for it to repeat itself. Then I use a while loop to repeat that n times.

so this is my code.

def composition(f,n,x):

counter = 0 while counter<n:

However, basically i got a lot of wrong answers and spent many hours trying to figure out what I don't know. Can anyone post some hints to guide me? Thank you very much!

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

Early Career People, How Can I Best Add Value to This Community?

7 hours 39 min ago

I've been a long time lurker of this, and related subs. Been in the industry for a few years now.

Graduated university in Canada a year and a half ago, currently a Senior Engineer at a large software company in The Bay Area (Silicon Valley)  

I'm looking for ways I can give back to this community.
Specifically I'd like to add value to people considering a career in CS, currently in school, or just graduating.  

What do you wish there was more of?

  • AMAs?
  • 1-on-1 conversations with someone knowledgable?
  • More guides/tutorials/videos on interview prep?
  • General information about what life at Big Tech Companies is like?
  • Something else?

I know I wouldn't be where I am today if it wasn't for some great mentors in my life.
If I'm able to help even one person with their career, I'll feel like this is successful.

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

Converting byte array to hex string in java

7 hours 39 min ago

My program uses DatatypeConverter.printHexBinary to convert a byte array to a hex string, but my output isn't correct. The only difference between my code and the example code I'm emulating is that the latter uses Apache's Hex.encodeHexString, but wouldn't that give the same output?

submitted by /u/rat-butter
[link] [comments]

Need recommendation of a library for a loop station...

7 hours 39 min ago


I'm new to programming with audio so I don't know how 'things' work yet.... But I don't want to pay 30$ for software I can possibly make myself(http://sonnit.co.uk/software.html)!

Basically, all I need to do is:

- Record audio into a buffer(simultaneously)

- Play audio from the buffer(simultaneously)

- Overdub

So... What's the easiest library for me to get started? Oh... and language doesn't matter.... It's probably going to be terminal only anyways.

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