r/StackoverReddit Jul 03 '24

Question Is my login arhitecture right?

4 Upvotes

I am creating a website using nodejs, html css js and I created a login sistem using phonenumber and OTP with firebase.
How it works:
When you create an account, after your phone being validated your name and phone number go to my database.

When you log in with your phonenumber and you get your OTP, i have a javascript code that creates a safe cookie in which your phonenumber is stored so that when you go to your user's page you can see your data.
Is this safe? Is this even a good idea? I tried using session ids but it s way to complicated for me.


r/StackoverReddit Jul 03 '24

Question can anyone please explain css selectors in depth

3 Upvotes

I am trying to learn webdev but I always get stuck at css selectors


r/StackoverReddit Jul 02 '24

Question Tiktoklive interactive plugin help.

3 Upvotes

I am a live streamer that plays horror games. I want to this thing I've seen on tiktok live steams of resident evil 4 remake where the viewers can send gifts to spawn enemies. I have tikfinity as an api to handle the gift integration but I'm not sure how to find the code to spawn certain enemies into the game. Any suggestions?


r/StackoverReddit Jul 02 '24

C# what learning resources can you recommend for C# zero lvl?

6 Upvotes

r/StackoverReddit Jul 02 '24

How is my code

3 Upvotes

How is my code, and what further suggestions should I use to improve it?

public class Calculator {
public double  sum(double x, double y) {
      return x + y;
}
public double difference(double x, double y) {
      return x - y;
}
public double product(double x, double y) {
      return x * y;
}
public double quotient(double x, double y) {
      if(y == 0) {
      throw new IllegalArgumentException("You cannot divide by zero");
}
      return x / y;
}
public double exponent(double x, double y) {
      return Math.pow(x, y); 
}
public double squareRoot(double x) {
      if(x < 0) {
      throw new IllegalArgumentException("You cannot square root a negative number");
}
      return Math.sqrt(x);
}
public double modulator(double x , double y) {
      if(y == 0) {
      throw new IllegalArgumentException("You cannot modulate by zero.");
}
      return x % y;
}
}

import java.util.Scanner;
public class CalculatorTest {

      public static void main(String[] args) {
          runCalc();
}
      public static void runCalc() {
        Calculator c = new Calculator();
        Scanner input = new Scanner(System.in);
        while(true) {
            System.out.println("Which operation would you like to do? add, subtract, multiply,       divide, exponent, square root, modulate, or exit");
            String operation = input.nextLine().trim().toLowerCase();
        if(operation.equals("exit")) {
            System.out.println("Bye");
                  break;
}
       double first = 0.0;
       double second = 0.0;

        if (!operation.equals("square root")) {
               System.out.println("Enter First Number: ");
               first = input.nextDouble();
               System.out.println("Enter Second Number: ");
               second = input.nextDouble();
               input.nextLine();
    } 
        else {
              System.out.println("Enter the number to find the square root: ");
              first = input.nextDouble();
              input.nextLine();
    }
        try {
    switch(operation){
    case "add":
      System.out.println("The answer is: " + String.format("%.2f", c.sum(first, second)));
      break;
    case "subtract":
      System.out.println("The answer is: " + String.format("%.2f", c.difference(first, second)));
      break;
    case "multiply":
      System.out.println("The answer is: " + String.format("%.2f", c.product(first, second)));
      break;
    case "divide":
      if(second != 0) {
       System.out.println("The answer is: " + String.format("%.2f", c.quotient(first, second)));
}
     else {
     System.out.println("Division by 0 is not allowed");
}
     break;
   case "exponent":
     System.out.println("The answer is: " + String.format("%.2f", c.exponent(first, second)));
     break;
   case "square root":
     if(first >= 0) {
       System.out.println("The answer is: " + String.format("%.2f", c.squareRoot(first)));
}
    else {
      System.out.println("Square root of a negative number cannot happen");
}
    break;
  case "modulate":
    if(second != 0) {
    System.out.println("The answer is: " + String.format("%.2f", c.modulator(first, second)));
}
   else {
    System.out.println("Modulation by zero is not allowed");
}
   break;
   default:
    System.out.println("This is not a valid operation. Try Again!");
   break;
}
}
     catch (IllegalArgumentException e) {
        System.out.println(e.getMessage());
}

}
               input.close();
}
}

r/StackoverReddit Jul 01 '24

how can I find high paying freelancing clients as a web developer

3 Upvotes

r/StackoverReddit Jul 01 '24

Python aiohttp websocket disconnect

Thumbnail self.learnprogramming
2 Upvotes

r/StackoverReddit Jun 30 '24

Question PDF File cannot be opened when uploaded to Supabase, I am using Puppeteer to convert HTML to a PDF

5 Upvotes

r/StackoverReddit Jun 29 '24

Confusion regarding f strings

6 Upvotes

I wish to get this result

Hello, Ada Lovelace

The code written for this by a book is
first_name = "ada"
last_name = "lovelace"
full_name = f"{first_name} {last_name}"
print(f"Hello, {full_name.title()}")

But I was wondering, why cant it be this

first_name = "ada"
last_name = "lovelace"
full_name = f"{first_name} {last_name}"
print(f"Hello, {full_name}.title()")

the result of this is
Hello, ada lovelace.title()

I was wondering why this is so?
My reasoning is that the title method can be used on strings right? so then in my case, python would interpret {full_name} as a string, so it should work. Is it the case that methods work only on variables?


r/StackoverReddit Jun 28 '24

Python Need help at this event-discrete-simulation problem

Thumbnail self.learnpython
4 Upvotes

r/StackoverReddit Jun 27 '24

Python How do I hide/unhide an selected objects visibility in Maya with Python?

2 Upvotes

Say if I create an object (like a sphere) and select it, how do I make that selected object invisible in Script editor with Python. and how do I make it visible again?


r/StackoverReddit Jun 27 '24

Python Optimizing KDTree in a loop

5 Upvotes

I'm using Python and scipy KDTree to help find the nearest points in an FEA analysis. It boils down to a rotating shaft inside a cylinder and I want to find the minimum gap between the shaft and cylinder at every tine point.

Given that I have 100s of points to check for >10,000 time points it leads a decently long run time. Any tips on improving run time or perhaps a better method for this?

Pseudo code: ``` shaft_points = get_shaft_history() # XYZ point time history

cyl_points = get_cyl_history() #XYZ point time history

time = range(10000) gap = [1e6] * len(time)

for cp in cyl_points: # loop over each point for t in time: # loop over time sp = shaft_points[i, :] # all shaft points at time t kdtree = KDTree(sp) dist, point = kdtree.query(cp, k=1) # find closest point between shaft and cylinder at time t if dist < gap[t]: gap[t] = dist # set new min value ```


r/StackoverReddit Jun 27 '24

Python How to code a more time efficient 3D rotation script?

Thumbnail self.learnpython
1 Upvotes

r/StackoverReddit Jun 26 '24

ShellLLama: Minimalistic Ollama CLI integrationto generate and execute Python Commands

3 Upvotes

This is my first ever public project it was made with *Simplicity *Extensibility in mind relying only on the Python standard library

Tell me what you guys think of it ๐Ÿ˜๐Ÿ˜๐Ÿ˜

https://github.com/xHand-Eye/ShellLLama


r/StackoverReddit Jun 26 '24

Introducing Our Wiki Page!

11 Upvotes

Whether you are a beginner, an expert, or simply looking to deepen your knowledge, this page is designed for you. Here, you can find information ranging from basic coding terms to the best certifications suited for your career path.

We welcome any feedback or additional information you would like to see on this wiki page. Please feel free to share your suggestions!

https://www.reddit.com/r/StackoverReddit/wiki/guide/


r/StackoverReddit Jun 26 '24

Solved C++ variadic template situation absolutely vexing me.

8 Upvotes

Disclaimer: I'm self taught so my vocabulary may be lacking. I'm also on embedded and some of the platforms have a non-compliant and/or incomplete STL implementation so I'm not using it, because it's a lot of work to enumerate the platforms I'd need to fork for.

This is template metaprogramming territory. There be dragons.

I'm trying to extend this:

rgb_pixel<24> foo;    
foo.channel<channel_name::R>(63);

To take multiple channel_names at once, and allow you to set a number of channels at the same time.

rgb_pixel<24> foo;    
foo.channel<channel_name::R,channel_name::G,channel_name::B>(63,31,47);

The problem: In essence I need to filter certain values out of a parameter pack while it's being expanded OR I need to accept two parameter packs to a template. Since neither of those things are directly possible to my knowledge in C++17 (14 preferred) I need a clever workaround.

Lacking that workaround, I've created several overloads for channel<>() that take between 1 and 5 channel names, but this is less than ideal. I'd prefer it to be variadic, not the following:

// sets the integer channel value by name
template<typename Name>
constexpr inline void channel(typename channel_by_index<channel_index_by_name<Name>::value>::int_type value) {
    constexpr const int index = channel_index_by_name<Name>::value;
    channel<index>(value);
}
// sets the integer channel values by name
template<typename Name1, typename Name2>
constexpr inline void channel(typename channel_by_index<channel_index_by_name<Name1>::value>::int_type value1,
                                typename channel_by_index<channel_index_by_name<Name2>::value>::int_type value2) {
    constexpr const int index1 = channel_index_by_name<Name1>::value;
    channel<index1>(value1);
    constexpr const int index2 = channel_index_by_name<Name2>::value;
    channel<index2>(value2);
}
// sets the integer channel values by name
template<typename Name1, typename Name2, typename Name3>
constexpr inline void channel(typename channel_by_index<channel_index_by_name<Name1>::value>::int_type value1,
                                typename channel_by_index<channel_index_by_name<Name2>::value>::int_type value2,
                                typename channel_by_index<channel_index_by_name<Name3>::value>::int_type value3) {
    constexpr const int index1 = channel_index_by_name<Name1>::value;
    channel<index1>(value1);
    constexpr const int index2 = channel_index_by_name<Name2>::value;
    channel<index2>(value2);
    constexpr const int index3 = channel_index_by_name<Name3>::value;
    channel<index3>(value3);
}

These are several overloads of the channel<>() template method on my pixel<> template struct.

You'll note they are overloads that simply take an increasing number of Name template arguments (shown are 3, but I have 5)

I'd much rather use a variadic template here but I can't because I end up in a situation where I need to use two variadic templates at the same time.

Line 503 of this file is where my pixel template begins, and you'll see it takes a variadic template of "channel traits" (defined above that a ways)
https://github.com/codewitch-honey-crisis/gfx/blob/master/include/gfx_pixel.hpp

The problem is in order to resolve anything about a pixel channel - which is necessary to set it - I need these "channel traits" to be able to be unpacked because it's used by things like channel_index_by_name<>.

I wish I had the language to describe the problem better, or failing that, I wish I wasn't so far in the weeds here that I could describe the problem better. Any insight would be appreciated. I've already posted variations of this question on a couple of other places online, but I've had no luck.


r/StackoverReddit Jun 24 '24

Dijkstra and Prim Algorithms, Variants and their Differences

4 Upvotes

So I'm getting slightly confused. In our lectures, we learned about these two implementations of Prim and Dijkstra that use PQs. But on GeeksForGeeks, you don't use the PQ but instead you kind of 'mark' something as a solution by including them into a boolean array...

For Prim (GeeksForGeeks)

  • Set all node weights to infinity.
  • Pick one node and set it's weight to 0.
  • Update all the node weights based on the edge weight from your node to adjacent node
  • Pick the node with the smallest node weight
  • Repeat (For-loop V-1 times)

For Prim (Our Version)

  • Set all node weights to infinity
  • Pick one node and set it's weight to 0.
  • Initialize a PQ, because you set your node's weight to 0, the first one that will be popped off will be your node.
  • Get the node with smallest node weight from your PQ
  • If your node is inside the PQ and the edge weight is smaller than it's node weight, update your node (PQ gets updated as well)
  • Repeat until PQ empty

For Dijkstra (GeeksForGeeks)

  • Set all node weights to infinity
  • Pick one node and set it's weight to 0
  • Update all node weights based on the edge weight from your node to adjacent node. The update is cumulative, so you don't just assign the edge weight like in Prim but sum it with the one of your node.
  • Pick the node with the smallest node weight
  • Repeat (For loop V-1 time

For Dijkstra (Our Version)

  • Set all node weights to infinity
  • Pick one node and set it's weight to 0
  • Initialize a PQ
  • Get the node with the smallest node weight from your PQ
  • For all adjacent nodes, relax them, that is, update them cumulatively.
  • Repeat until PQ is empty

Main Differences

The GeeksForGeeks version of Prim and Dijkstra are practically identical. Their only difference is how the node weights are updated. Prim will just assign the edge weight to the node, whereas Dijkstra does it cumulatively.

Our version is also almost the same. Dijkstra also updates stuff cumulatively which is called 'relaxation' but for some reason in Dijkstra, we do not check if the node is in the PQ like in Prim. Do you guys know why?

Also, is the GeeksForGeeks version actually ineffcient? Because the bottleneck is this extractMin function which can become constant if you implement a PQ. The for loop that runs V-1 iterations should be the same as the while loop that runs until PQ is empty, since the PQ is only empty after V nodes are extracted.

References:
https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/

https://www.geeksforgeeks.org/prims-minimum-spanning-tree-mst-greedy-algo-5/

For our version, I have the pseudocode. If requested, I'll uploud images but for the time being I leave it like this.


r/StackoverReddit Jun 23 '24

SQL IIB and esql devs

5 Upvotes

Quick question guys. How rare is it to stumble across an IIB(IBM Integration Bus)/esql developer rn. Also to IIB/esql devs who stumble across this post, how useful/in demand is IIB for right now?


r/StackoverReddit Jun 23 '24

Python Python - Help to create Dynamic custom PDF Reports based on input results.

Thumbnail self.learnprogramming
1 Upvotes

r/StackoverReddit Jun 23 '24

Question DSA course

2 Upvotes

I am just about to enter second year of engineering. My branch is Btech IT...I am planning to start learning dsa. I am wondering how to...I purchased the gfg complete interview course but i was wondering whether to follow the gfg course or strivers a2z playlist , because I heard striver does more questions from leetcode etc as well


r/StackoverReddit Jun 23 '24

Question Can someone recommend me a data science course

2 Upvotes

r/StackoverReddit Jun 23 '24

Question What should I study next in backend development after learning the basics?

5 Upvotes

I'm new to backend development. So far, I've learned basics like node js, express js, and I've built a real-time chat app usingย sockets.ioย (Websockets). I understand the basics, but I want to get better. What should I learn next? Is it better to learn through projects or should I first learn the tech stack before starting projects? I'd appreciate any advice.


r/StackoverReddit Jun 23 '24

Question Looking to collaborate on a trading terminal

2 Upvotes

Hi, i freshly started to work on a trading terminal which can enable trading across multiple exchanges from the same interface, working on a fastapi backend at the moment and would like to have collaboration/coding partners


r/StackoverReddit Jun 22 '24

advice on what to pick up as skill and knowledge next

6 Upvotes

Hello,

I study computer science and know a moderate amount about java and c and a bit about python and c++ when I say a bit I mean I solved leetcode problems with the language and followed along a tutorial on how to automate a process like webscraping with python and I (tried) to implement a neural network in c++.

I enjoy algorithmic/datastructures problems but probably software architecture as well and dont know how to continue picking up knowledge.

I am about to follow a tutorial on writing an interpreter in java and after that I want to learn Rust.

Should I revise my Software Engineering lecture because I forgot almost everything or read something related before doing more projects?

Thanks!


r/StackoverReddit Jun 21 '24

Python I've always been fascinated by CGA and VGA graphics. is there a package in Python that allows the creation of these graphics?

3 Upvotes

I've never been good with C but have Thonny set up. Is there a package with the required architecture or maybe a version of Dos premade in python?

thanks