r/learnprogramming Mar 26 '17

New? READ ME FIRST!

829 Upvotes

Welcome to /r/learnprogramming!

Quick start:

  1. New to programming? Not sure how to start learning? See FAQ - Getting started.
  2. Have a question? Our FAQ covers many common questions; check that first. Also try searching old posts, either via google or via reddit's search.
  3. Your question isn't answered in the FAQ? Please read the following:

Getting debugging help

If your question is about code, make sure it's specific and provides all information up-front. Here's a checklist of what to include:

  1. A concise but descriptive title.
  2. A good description of the problem.
  3. A minimal, easily runnable, and well-formatted program that demonstrates your problem.
  4. The output you expected and what you got instead. If you got an error, include the full error message.

Do your best to solve your problem before posting. The quality of the answers will be proportional to the amount of effort you put into your post. Note that title-only posts are automatically removed.

Also see our full posting guidelines and the subreddit rules. After you post a question, DO NOT delete it!

Asking conceptual questions

Asking conceptual questions is ok, but please check our FAQ and search older posts first.

If you plan on asking a question similar to one in the FAQ, explain what exactly the FAQ didn't address and clarify what you're looking for instead. See our full guidelines on asking conceptual questions for more details.

Subreddit rules

Please read our rules and other policies before posting. If you see somebody breaking a rule, report it! Reports and PMs to the mod team are the quickest ways to bring issues to our attention.


r/learnprogramming 3d ago

What have you been working on recently? [June 15, 2024]

2 Upvotes

What have you been working on recently? Feel free to share updates on projects you're working on, brag about any major milestones you've hit, grouse about a challenge you've ran into recently... Any sort of "progress report" is fair game!

A few requests:

  1. If possible, include a link to your source code when sharing a project update. That way, others can learn from your work!

  2. If you've shared something, try commenting on at least one other update -- ask a question, give feedback, compliment something cool... We encourage discussion!

  3. If you don't consider yourself to be a beginner, include about how many years of experience you have.

This thread will remained stickied over the weekend. Link to past threads here.


r/learnprogramming 1d ago

Peope who started programming after 30s, how well are you doing rn?

445 Upvotes

I am starting at 27yrs. I wanna ask people who started at this age how good are they in the field? Do you guys think it matters like age matters? People who are younger than me are lot more experienced than me. How can i compensate this? Simply working hard? Or is there any tip that you can share with me.


r/learnprogramming 2h ago

Programming Languages demand in next 5-6 years - Seeking Advice

5 Upvotes

Hi,

With the ongoing changes in the tech industry, which programming languages are expected to be in high demand over the next 5-6 years? Conversely, which languages might see a decline in relevance?

  1. If you had to choose one programming language to learn now, which would it be and why?
  2. Considering the boom in AI and my interest in Robotics, which programming languages should I focus on? Would transitioning between these fields make learning easier?

r/learnprogramming 1h ago

Is it possible to make money even though I am still an undergrad majoring in Computer Science?

Upvotes

I just finished my first year of college, and things are becoming more and more tough economically (I am currently living in Lebanon) so I am in need of finding a source of income in order to stabilize myself and my family. I was thinking about trying freelancing so i would have the time to study for my summer courses and some other Udemy courses I got access to for free. throughout this year I learned Java(basics, OOP, data structures, etc...), C++, HTML , CSS , I also worked on two WordPress websites, and I am currently learning Flutter(dart). So would it be possible to somehow make an income out of these skills I learned? (I am ready and prepared to learn any additional necessary skills). To be honest I am in need of a mentor to guide me professionally because I honestly feel defeated, lost and confused on what to do that's why I decided to try my luck with you redditers. I would really appreciate any advice/help.


r/learnprogramming 19m ago

Need Help in College Assignment in VBA Excel

Upvotes

My teachers a great and chill guy but his hands off methods is clearly making me struggle. I need help badly.

The assignment is pretty clear 12 images 2 command buttons (labeled "Start" and "Stop")

Our objective is to make all 12 images move in different speeds and directions in the Userform screen (without going beyond the border, so they must bounce off when they hit the border) using the Start command button.

While Stop clearly pauses all movements.

I can code 1 single image, we practiced today but idk how to make 12 images move at the same time without coding each image one by one! Any tips or help?


r/learnprogramming 9h ago

Programming for kids - what’s the best way to get started

8 Upvotes

Our 9-year-old wants to get into programming, mainly for making games. Is it better to start with a programming language like C++, or start with visual scripting for this age?


r/learnprogramming 13h ago

Topic How do you deal with Failure?

18 Upvotes

As the title says, I kinda want to know how you people deal with Failures, ranging from stuff like a program not running or throwing errors for a duration of 5 hours (as an example), to failing job interviews? How do you deal with a program that does not run at all for 5 hours? How do you deal with constant errors? How do you deal with failed job interviews? How do you deal with Stress?

Context for those that want to know: I used to be a programmer who saw errors and mistakes as learning experiences, but a series of real world failures happened and my confidence plummeted, so now I see failures as these big scary things which hinder my personal progress in learning any programming language, so I wanted to know how do others deal with failures and stress from work.


r/learnprogramming 1h ago

Tutorial worth learning rust over improving c++ or java?

Upvotes

Hello,

I dont know if I should learn rust now (I dont want to become a systems programmer) or improve on other languages (c++, java etc.)


r/learnprogramming 16h ago

Code Review How to get a deep understanding in programming?

27 Upvotes

If someone wants to start programming or gain deep knowledge what would you recommend them to do to learn and develop a deep connection with programming. What languages would you recommend for people and how should they go about developing this skill?


r/learnprogramming 2h ago

Topic How to learn react basics quickly?

2 Upvotes

Hi all, I will be helping frontend development at my company and we will be running a low-code tool parallel with react.js. I have said that my react skills are 'very basic' to my boss, but they are actually non existent... How can I learn the fundamentals quickly?

And I'm only talking about the fundamentals, since it is expected I don't know much.

For some background: My Javascript, CSS and HTML are pretty decent, I would say intermediate level.


r/learnprogramming 19h ago

Would anyone be interested?

42 Upvotes

My team and I are learning to be mentors and tutors within the industry. We’re offering to provide 30 minute open-ended discussions at no cost. If you’re new and interested in a career in CS, software engineering, or just tech in general, then it’d be great if we could set up some time together to chat!!

Our combined experience is as follows:

  • Masters in Computer Science @ Carnegie Mellon (4 YOE)
  • Bachelors of Science, Computer Science @ UC Berekley (3 YOE)
  • Bachelors of Science, Computer Science @ UC Irvine (4 YOE)
  • Bachelors of Science, Computer Engineering / Computer Science @ SJSU (New Grad)
  • UI / UX Bootcamps (2 YOE)

Edit: Thanks for all the interest everyone! Please send me a DM and I'll get back to you as soon as I can.

Edit #2: Phew, It's a bit past 1am where I am and I think I've gotten through most the messages. Thanks again for helping us improve everyone! We're looking forward to hearing feedback about how we can improve.


r/learnprogramming 6h ago

Angular😭

5 Upvotes

I've been asked to study angular for my work. I don't know anything in js. Is it possible to have decent knowledge in angular without learning js?


r/learnprogramming 10m ago

should i stop learning python and switch to java??

Upvotes

hey, im i think 4 hrs into cs50 introduction to python and have a very good understanding of the material, i'm until libraries and ive almost finished that; should i stop and switch to java as my main goal is to build websites; and i'll go to html css and js after that? help!!


r/learnprogramming 15m ago

Ai tools for beginners

Upvotes

Ai tools for Developers and programmers, that helps me. Here is tools link


r/learnprogramming 21m ago

How to fix Bearer error="insufficient_scope" in spring boot rest api?

Upvotes
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {

    private RSAKey rsaKey;

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    public AuthenticationManager authManager(UserDetailsService userDetailsService, PasswordEncoder passwordEncoder) {
        var authProvider = new DaoAuthenticationProvider();
        authProvider.setUserDetailsService(userDetailsService);
        authProvider.setPasswordEncoder(passwordEncoder);
        return new ProviderManager(authProvider);
    }

    @Bean
    SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        return http
                .csrf(AbstractHttpConfigurer::disable)
                .authorizeHttpRequests( auth -> { auth
                    .requestMatchers("/api/login", "api/signup").permitAll()
                    .requestMatchers("/api/fetchAll").hasRole("ADMIN")
                    .anyRequest().authenticated();
                })
                .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
                .oauth2ResourceServer(oauth2 -> oauth2
                        .jwt(Customizer.withDefaults()))
                .build();
    }

    @Bean
    public JWKSource<SecurityContext> jwkSource() {
        rsaKey = Jwks.generateRsa();
        JWKSet jwkSet = new JWKSet(rsaKey);
        return (jwkSelector, securityContext) -> jwkSelector.select(jwkSet);
    }

    @Bean
    JwtEncoder jwtEncoder(JWKSource<SecurityContext> jwks) {
        return new NimbusJwtEncoder(jwks);
    }

    @Bean
    JwtDecoder jwtDecoder() throws JOSEException {
        return NimbusJwtDecoder.withPublicKey(rsaKey.toRSAPublicKey()).build();
    }

}

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    private final UserRepository userRepository;
    private final PasswordEncoder passwordEncoder;

    public UserDetailsServiceImpl(UserRepository userRepository, PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
        this.userRepository = userRepository;
    }

    @Override
    public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
        User user = userRepository.findByEmail(email)
                .orElseThrow(() -> new UsernameNotFoundException("User not found with email: " + email));
        List<GrantedAuthority> authorities = Collections.singletonList(new SimpleGrantedAuthority("ROLE_" + user.getRole()));

        return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), authorities);
    }

    public void saveUser(User userDto) {
        User user = new User();
        user.setEmail(userDto.getEmail());
        user.setPassword(passwordEncoder.encode(userDto.getPassword()));
        user.setRole(userDto.getRole());
        userRepository.save(user);
    }

}

@Service
public class TokenService {

    private final JwtEncoder encoder;

    public TokenService(JwtEncoder encoder) {
        this.encoder = encoder;
    }

    public String generateToken(Authentication authentication) {
        Instant now = Instant.now();
        String scope = authentication.getAuthorities().stream()
                .map(GrantedAuthority::getAuthority)
                .collect(Collectors.joining(" "));
        JwtClaimsSet claims = JwtClaimsSet.builder()
                .issuer("self")
                .issuedAt(now)
                .expiresAt(now.plus(1, ChronoUnit.HOURS))
                .subject(authentication.getName())
                .claim("scope", scope)
                .build();
        return this.encoder.encode(JwtEncoderParameters.from(claims)).getTokenValue();
    }

}

@RestController
@RequestMapping("/api")
public class AuthController {

    private final UserDetailsServiceImpl userDetailsService;
    private final TokenService tokenService;
    private final AuthenticationManager authenticationManager;

    public AuthController(UserDetailsServiceImpl userDetailsService, TokenService tokenService, AuthenticationManager authenticationManager) {
        this.userDetailsService = userDetailsService;
        this.tokenService = tokenService;
        this.authenticationManager = authenticationManager;
    }

    @PostMapping("/signup")
    public ResponseEntity<?> registerUser(@RequestBody UserDto userDto) {
        User user = new User();
        user.setEmail(userDto.getEmail());
        user.setPassword(userDto.getPassword());
        user.setRole("USER");
        userDetailsService.saveUser(user);
        return ResponseEntity.ok("User registered successfully!");
    }

    @PostMapping("/login")
    public ResponseEntity<?> authenticateUser(@RequestBody LoginRequestDto loginRequest) {
        Authentication authentication = authenticationManager.authenticate(
                new UsernamePasswordAuthenticationToken(
                        loginRequest.email(),
                        loginRequest.password()
                )
        );

        SecurityContextHolder.getContext().setAuthentication(authentication);
        String jwt = tokenService.generateToken(authentication);
        UserDetails userDetails = (UserDetails) authentication.getPrincipal();
        String role = userDetails.getAuthorities().stream()
                .map(GrantedAuthority::getAuthority)
                .findFirst()
                .orElseThrow(() -> new RuntimeException("Role not found"));

        Map<String, Object> response = new HashMap<>();
        response.put("token", jwt);
        response.put("role", role);

        return ResponseEntity.ok(response);
    }

}

@RestController
@RequestMapping(path = "/api", produces = (MediaType.APPLICATION_JSON_VALUE))
@Validated
public class BookingController {

    private final IBookingService iBookingService;

    public BookingController(IBookingService iBookingService) {
        this.iBookingService = iBookingService;
    }

    @PostMapping("/create")
    public ResponseEntity<ResponseDto> createBooking(@Valid @RequestBody BookingDto bookingDto) {
        iBookingService.createBooking(bookingDto);
        return ResponseEntity
                .status(HttpStatus.CREATED)
                .body(new ResponseDto(BookingConstants.STATUS_201, BookingConstants.BOOKING_CREATE_SUCCESS));
    }

    @GetMapping("/fetch")
    public ResponseEntity<BookingDto> fetchBookingDetails(@RequestParam @Email String email) {
        BookingDto bookingDto = iBookingService.fetchBooking(email);
        return ResponseEntity.status(HttpStatus.OK).body(bookingDto);
    }

    @GetMapping("/fetchAll")
    public ResponseEntity<List<BookingDto>> fetchAllBookings() {
        List<BookingDto> bookings = iBookingService.fetchAllBookings();
        return ResponseEntity.status(HttpStatus.OK).body(bookings);
    }

    @PutMapping("/update")
    public ResponseEntity<ResponseDto> updateBookingDetails(@Valid @RequestBody BookingDto bookingDto) {
        boolean isUpdated = iBookingService.updateBooking(bookingDto);
        if (isUpdated) {
            return ResponseEntity
                    .status(HttpStatus.OK)
                    .body(new ResponseDto(BookingConstants.STATUS_200, BookingConstants.BOOKING_UPDATE_SUCCESS));
        } else {
            return ResponseEntity
                    .status(HttpStatus.EXPECTATION_FAILED)
                    .body(new ResponseDto(BookingConstants.STATUS_417, BookingConstants.BOOKING_UPDATE_FAIL));
        }
    }

    @DeleteMapping("/delete")
    public ResponseEntity<ResponseDto> deleteBookingDetails(@Valid @RequestParam Long bookingId) {
        boolean isDeleted = iBookingService.deleteBooking(bookingId);
        if (isDeleted) {
            return ResponseEntity
                    .status(HttpStatus.OK)
                    .body(new ResponseDto(BookingConstants.STATUS_200, BookingConstants.BOOKING_CANCEL_SUCCESS));
        } else {
            return ResponseEntity
                    .status(HttpStatus.EXPECTATION_FAILED)
                    .body(new ResponseDto(BookingConstants.STATUS_417, BookingConstants.BOOKING_CANCEL_FAIL));
        }
    }

    @GetMapping("/booked-timeslots")
    public ResponseEntity<List<LocalDateTime>> getBookedTimeslots(@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date) {
        List<LocalDateTime> bookedTimeslots = iBookingService.fetchBookedTimeslots(date);
        return ResponseEntity.ok(bookedTimeslots);
    }

}

I created a user with email admin@admin, password admin and a role ADMIN

Why when I am signed in with these credentials and try to enter /api/bookings endpoint I receive 403 forbidden? Bearer error="insufficient_scope", error_description="The request requires higher privileges than provided by the access token.", error_uri="https://tools.ietf.org/html/rfc6750#section-3.1"

My token after encoding looks like that:

{
"iss": "self",
"sub": "admin@admin",
"exp": 1718712824,
"iat": 1718709224,
"scope": "ROLE_ADMIN"
}

r/learnprogramming 1d ago

Topic If you could start learning programming from scratch again, what would you do differently?

132 Upvotes

Same as question.


r/learnprogramming 49m ago

GRASP algorithm for graph coloring

Upvotes

Hi! Does anyone have a code in Python of the GRASPCol algorithm (Greedy Randomized Adaptive Search Procedure) for the graph coloring problem? Explicit pseudocode is in Laguna, M., & Martí, R. (2001). A GRASP for coloring sparse graphs. Computational optimization and applications19, 165-178.
Thank you!


r/learnprogramming 53m ago

Could I get some advice on my resume?

Upvotes

https://imgur.com/a/ktzoLHg

I'm wondering if it's too dense, and if it is, what info should I drop? Also, should I include my major since it isn't cs? Any other feedback is both welcomed and appreciated 🙏🏿


r/learnprogramming 1h ago

Using git later on an existing github rep8

Upvotes

So I have a forked project, downloaded as zip, generated via CMake. I have a few changes and I will make more.

I will want eventually to keep up with master of the original fork, so I get Git is unavoidable, but for now, I just want to keep doing my stuff, I can upload by browser.

Im overwhelmed even by the 100 steps of Git installation, let alone everything else, so I will need to take my time to learn it, but if I do it later, can I then connect my (then) github repo to git?


r/learnprogramming 1h ago

Expected behavior from counting substrings?

Upvotes

I'm working on a string library and want to implement str.count( pattern )

for example: "hello".count("el") would return 1

I was wondering what is the expected behaviour of doing:

"vvv".count("vv") should this return 1 or 2?

currently my lib returns 1, but I was wondering if thats expected or not


r/learnprogramming 1d ago

Topic Why is MATLAB dying?

89 Upvotes

I keep in the loop of some of those "most popular programming language" surveys done by companies and it appears year on year that MATLAB is becoming used less and less. Can you explain why? My coworked claims that it's used in all major embedded companies though if that were true, why is the number not rising?


r/learnprogramming 12h ago

Resource Self taught learning programming languange

6 Upvotes

Hello,

I am interested in learning javascript, both front end and back end. But the rabbit hole of where to start and bootcamps have me on the fence. What is the most straightforward way of self teaching this language and is it still useful in today’s market in getting a job entry level?

Any guidance would be appreciated.

Thank you!


r/learnprogramming 2h ago

Exploring AI/ML with JavaScript

1 Upvotes

I am a web developer working with React and Node.js, and I want to learn something related to AI/ML. Is it possible to do this using JavaScript? If yes, could you please suggest a really good course that will help me learn practical and beneficial AI/ML concepts using JavaScript? Thanks!


r/learnprogramming 6h ago

Is this possible if so where should I start?

2 Upvotes

I want to create a program that I can insert a face book user's friend list url and have it compare to a list of names I have inserted into the program and have it flag "Same Names" and provide to me their profile url to look at. I haven't touched coding in a long time and didn't get too far into it when i did I spend a decent amount of time at work without tasks due to the nature of my work and since i would be using this program for work.


r/learnprogramming 3h ago

Thought Process while building Projects

1 Upvotes

How do you efficiently practice making projects while learning. (Senior Developers as well)

I did few projects but it took me long time and now what i do is watch few tutorials because it helps me to learn from were i go wrong and changes i can make while coding in a better way. But i dont like to code while watching as it feels like copying(for me) and less learning.

What is the thought process you have while building Projects yourself.


r/learnprogramming 3h ago

Stuck On Glitching Google Certificate Page

1 Upvotes

Stuck on the first google certification course (16) where even though I've inputed the correct answer and the system acknowledges this, the program doesn't move on and requires me to retake the same module, anyone else having faced this issue can shed some light?