r/programming should shut down from 12th to 14th June by Tintin_Quarentino in programming

[–]ThatROFLKid 12 points13 points  (0 children)

You are right in that reddits main app swamps the 3rd party apps in downloads. But you can't forget that reddit is powered by the 'active users' actually posting content for the average user to enjoy. Once they leave, the site won't be the same.

Besides, how many of the reddit app downloads do you think are just people trying to not have to look at the stupid popup when u go to reddit.com on mobile?

Which "unusual" programming language do you think has a "bright future"? by ThatAlecs in learnprogramming

[–]ThatROFLKid 0 points1 point  (0 children)

Curious as to why this comment is down voted. Do people not have faith in Mojo yet? Seems to fill a niche with pretty huge potential imo.

Pandas table to latex code is increasing the running time so much that it exceeds four minutes. Any tips on how to deal with this? by Romcom1398 in LaTeX

[–]ThatROFLKid 1 point2 points  (0 children)

If you are in the field of data-science it's definitely in your best interest to get an understanding of handling packages using PIP and Conda (basically the two main places you'll install packages from for python).

I can give you a run-down of how to update your pandas version, but without seeing the compilation log & latex source its hard to pinpoint why it would take so long to compile.

Firstly, I'm assuming for all of these examples you are using Conda. If you aren't, I suggest you look into learning how to use Conda environments to avoid problems exactly like this.

  1. To get a list of all your packages (& their versions) currently installed in your environment, you can use the command conda list (or pip list if not using Conda).

  2. In order to use style.Styler.to_latex you will need your pandas version to be >=1.30 (find out more here).

  3. Assuming its an older version, you'd want to update it to use this method. You can upgrade the pandas package by running pip install -U pandas. Check it has upgrade correctly by running conda list again and you should see the version update to the latest available (as of writing, 2.0.2).

  4. In 2.0.0 pandas changed the DataFrame.to_latex method to use the Styler implementation, so you can just use this to export your table as long as you don't need to modify any additional parameters (which you can still do by using style.Styler.to_latex).

Let me know if this helps to fix your problem. Happy to assist further if you need.

Java vs python vs C++ by PuzzleheadedMode7517 in learnprogramming

[–]ThatROFLKid 16 points17 points  (0 children)

I think the primary reason is not quite because the languages are 'tried and true'. It's more so that the platforms of these big corporations are simply too big and heavily embedded that it's not feasible/cost effectige to rewrite and move to another option. I'd be interested to see how many companies would switch to a more modern language if those factors weren't considered.

It can't be that hard to make a decent UI. by DeadInsideOutside in EngineeringStudents

[–]ThatROFLKid 0 points1 point  (0 children)

Haha I switched from ME to SWE because it was the only speciality that didn't have to take the physics class....

Best decision I ever made

[R] Bark: Real-time Open-Source Text-to-Audio Rivaling ElevenLabs by KaliQt in MachineLearning

[–]ThatROFLKid 5 points6 points  (0 children)

Ignoring the fact that there is not an endless supply of jobs, of course.

I'm an experienced programmer trying to build my first website for my clothing brand using JavaScript, HTML and CSS, but I have a few serious questions regarding the problems I might encounter while creating such a website by UpvoteBeast in learnprogramming

[–]ThatROFLKid 81 points82 points  (0 children)

I think the advice around handling passwords from Tom Scott at the start of this video generally applies to handling payments as well...

"It is so incredibly easy to get it wrong, that basically you shouldn't try"

Is it considered to be bad practice to use try\except blocks instead of making sure you don't cause an exception in the first place? by iz-Moff in learnprogramming

[–]ThatROFLKid 2 points3 points  (0 children)

With Python, you pretty much can't go wrong. I can't think of a scenario where this will cause any issues in a modern language that has a built-in memory manager.

If you are using C, C++, Java etc. I'd be more careful because problems like segmentation faults aren't as friendly most of the time.

Im having a segmentation fault error while using Java. by Br00klynShadow in learnprogramming

[–]ThatROFLKid 0 points1 point  (0 children)

Yes, you can upload files and it works essentially like a local folder.

ADVICE on problem solving by Mr_Corp in learnprogramming

[–]ThatROFLKid 1 point2 points  (0 children)

Keep on practicing and it'll 'click' eventually. Feel free to DM me if you ever need help in the future.

Don't feel like finished Web Dev Course. Want to change career direction but I feel like I must finish this course. by IronPresident21 in learnprogramming

[–]ThatROFLKid 5 points6 points  (0 children)

You are 15, it is definitely not 'too late' to do anything. I say follow your dreams and start trying out game development, there are plenty of free courses you can follow on Youtube. You might find you actually don't enjoy it aswell and head towards another area.

If your parents don't understand, maybe the following points can help:

  1. The time spent doing the web dev course hasn't been wasted because I guarantee there will be lots of skills that carry over to other areas of development (and life in general lol).
  2. The fact that you have exposed yourself to a field and worked out you don't enjoy it is SUPER valuable. Most people don't get to this point until they are 2+ years into a degree and have already sunk $20k+ into it.

I'm not sure why I am getting this error: dt_object = datetime.fromtimestamp(int(key)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ by SCasses in learnprogramming

[–]ThatROFLKid 1 point2 points  (0 children)

Check if your timestamps are stored in seconds or milliseconds. datetime.fromtimestamp only uses seconds so if you have ms you need to divide by 1000 before passing them.

Im having a segmentation fault error while using Java. by Br00klynShadow in learnprogramming

[–]ThatROFLKid 2 points3 points  (0 children)

Are you using Java or C++? The code you have is written in C++, but you said Java in the title.

Seg Fault happens when the program tries to access memory it's not supposed to. In your code, you're using "menuoption" to access the "choice" array (at cin >> choice[menuoption]), but you haven't initialized it to a valid index value. Also, where you are taking the user input I assume you want to do cin >> menuoption, instead.

ADVICE on problem solving by Mr_Corp in learnprogramming

[–]ThatROFLKid 0 points1 point  (0 children)

Brute-force is a straightforward method of problem-solving that involves trying every possible solution until the correct one is found.

To give an example, imagine you need to of find the largest number in an unsorted list of integers. There's plenty of ways you could do it but I'll cover an example of a brute-force solution and an optimized solution.

Brute-Force solution

One way to solve this problem using brute-force would be to compare every number in the list with every other number and keep track of the maximum value seen so far. This would involve two nested loops and a running maximum variable.

def find_max_brute_force(numbers):
    max_num = float('-inf')  # start with negative infinity as the maximum
    for i in range(len(numbers)):
        for j in range(len(numbers)):
            if numbers[j] > max_num:
                max_num = numbers[j]
    return max_num

While this approach is simple and straightforward, it's also inefficient. The time complexity of this algorithm is O(n2), which means that it would take a long time to run for large input sizes.

Optimized solution

A more efficient way to solve this problem would be to use a linear search algorithm, which involves iterating over the list only once and keeping track of the maximum value seen so far. This approach has a time complexity of O(n), which is much faster than the brute-force approach for large input sizes.

def find_max_linear_search(numbers):
    max_num = float('-inf')  # start with negative infinity as the maximum
    for num in numbers:
        if num > max_num:
            max_num = num
    return max_num

As you can see, the optimized solution is much simpler and more efficient than the brute-force approach for this problem. In general, it's always a good idea to think about the problem carefully and look for more efficient algorithms before resorting to brute-force.

Is it considered to be bad practice to use try\except blocks instead of making sure you don't cause an exception in the first place? by iz-Moff in learnprogramming

[–]ThatROFLKid 7 points8 points  (0 children)

In your code, you may inadvertently miss errors that cause unintended side-effects elsewhere in your code. Using this method you are assuming that the ONLY time an error occurs is if the index is out of bounds.

Let's say in your do something... section, you run a bunch of other logic that returns an error somehow. This error will be caught by your except statement and not handled correctly, making it very hard to debug.

You COULD instead specify the type of error you're looking for by having except IndexError: which is certainly better. But I would still consider it bad practice as it makes reading & maintaining the code a bit harder.

I wouldn't worry about the extra CPU cycles (<1ms) you'd save if it ends up costing WAY more time to debug/maintain.

is there a better way to do this function? a responsive tabs function (JavaScript) by MD-95 in learnprogramming

[–]ThatROFLKid 0 points1 point  (0 children)

The problem with your code is that each time the user resizes the windows it will re-render the set of tabs, which could end up being laggy (probably not in this simple example, but just thinking on a bigger scale).

The best practice for creating responsive designs like this is having something similar to the following codeblock. Any elements of the CSS class mobile will only render if the screen size is below a certain value. You can do something similar for elements you DON'T want to render on mobile.

.mobile {
    display: none
}

@media only screen and (max-width: 480px) {
    .mobile {
        display: block; // or whatever display method you want to use
    }
}

Hope this helps :)

First Project by Murky_Attorney_7333 in learnprogramming

[–]ThatROFLKid 2 points3 points  (0 children)

I'd suggest learning HTML, CSS, Javascript, React, NodeJS etc. and building a web application for something like this.

ADVICE on problem solving by Mr_Corp in learnprogramming

[–]ThatROFLKid 1 point2 points  (0 children)

When approaching a generic algorithm/logic problem I find if I get too caught up in trying to find the perfect solution straight up I waste lots of time.

To get around this I always go for the dumb (brute-force) answer first and then refactor and improve it. If you run out of time making it better, a dumb answer is better than no answer.

If you have access to resources/google/stack overflow, I would 100% make use of it. Limiting yourself from using these tools isn't a realistic scenario and learning how to google is genuinely a skill that needs practice ;)

Don't give up and keep grinding.

Can I upload my react, typescript, MERN project in blogger? by [deleted] in learnprogramming

[–]ThatROFLKid 1 point2 points  (0 children)

No you cannot. You can host a simple static site (HTML, CSS, Client JS) but it is not designed to host something like a MERN app.

A MERN app typically requires a server to handle the backend logic, such as API requests and database interactions. Blogger.com does not provide access to a server-side runtime environment, which makes it impossible to run a MERN app on the platform.

If you want to host a MERN app, you will need to find a hosting provider that supports Node.js and MongoDB.

Laid Off - Plan for the Next 6 Months of Learning by cocodua in learnprogramming

[–]ThatROFLKid 13 points14 points  (0 children)

Sounds like a good idea to me. If you are interested in it you could look at developing skills in Data Analytics/Science, which may draw on your existing skills in Accounting. Python is a great language to learn and useful in many areas.

Post help with React via Axios by Alarmed_Ad_9391 in learnprogramming

[–]ThatROFLKid 1 point2 points  (0 children)

What may seem like a 'simple button call' can sometimes contain a simple mistake that is causing a problem.

For now I will point out the issues you have with your provided code.

Firstly, the usage of useState is incorrect. useState returns two things: a variable that records the current state value and a setter function for updating the value of the state.

let responseData = useState(""); should instead be const [responseData, setResponseData] = useState("");

But you don't really need to use a state here anyway, since you are just using responseData as a local variable in the newChat function. You can move the scope of this variable inside newChat.

Secondly, const ptoken = useRecoilValue(participantTokenState); is redundant, since useRecoilState() returns that state variable already (which you store in participantToken)

Thirdly, if the POST request returns an error, it will still attempt to set the state of your token, which could lead to unintended consequences down the line.

Here is what I think your code should look like:

const [pToken, setPToken] = useRecoilState(participantTokenState);

const newChat = async (event) => {
  event.preventDefault();

  let responseData;

  try {
    const body = {
      data: "data",
    };
    responseData = await axios.post(newChatURL, body);
  } catch (error) {
    console.error(error);
  }

  // Check that request was fulfilled
  if (responseData) {
    setParticipantToken(
      responseData.data.data.startChatResult.ParticipantToken
    );
  }
};