/r/programminghelp

Photograph via snooOG

This is a place where you can get help with programming related issues, without judgement.

Ask your embarrassing/noobish programming questions here, and don't get insulted for it.

Rules

Click here to read the rules

Violating any will result in punishment so you should probably go check them out.

Other helpful subreddits

/r/programminghelp

7,377 Subscribers

1

Does anyone know how to program the konami code only using logic gates?

sorry for bad english

before i start explaining; i am not a programmer. i am a producer using vcv rack. i was doing a little project using my gamepad when i got an idea: playing a little sound when the konami code is entered. i started searching for how to do this with logic gates (since it is the closest thing that i have to programing on vcv) but i didnt found anything, and i thought you guys could help me.

1 Comment
2024/12/23
15:30 UTC

1

Multi tenancy with separate databases per customer

I am leading a Multi-Tenancy project, where we adopt the strategy of each customer having their own database, while a central bank stores general customer information, including references to the respective banks.

In the HTTP context, through middleware, I identify the client by hostname and connect to the respective database.

I have questions about how to configure connections to client databases outside the HTTP context, such as in scheduled tasks (cron jobs) or queue consumers. Could anyone who has worked in this multi-tenancy format with separate databases per client share how they resolved the issue of accessing the databases outside the request context?

0 Comments
2024/12/23
13:19 UTC

2

Can any kind soul help me with this?

I was trying to install this: https://github.com/x6ud and https://github.com/x6ud/pose-search
for this, I need an unsplash api to run this program.

in short, something went wrong, something called "saas" had frequent errors, probably because of the versions. I went crazy and gave up on doing that for now.

https://imgur.com/a/sbIfseD.jpg

The reality is that I'm pretty new to this, and I don't know where I get the information to know how to do these things.

I installed node and npm, I got confused several times with the command prompt, and that's it.

0 Comments
2024/12/22
22:35 UTC

2

How can I make a UI like TurboC++ using C++?

I’ve always wanted to work on a project in C++. During my previous semesters in university, I only did beginner-level C++ tasks or used C++ while solving LeetCode questions.

Now, I’m planning to create a "Chat-With-Local-LLM" type of project using C++. I’ll connect it to my locally running LLaMA 3.2 8B model. For a bit of parody, I want to design a UI similar to TurboC++ (strictly keyboard only stuff)

For experienced C++ developers out there:

  1. Which libraries would you recommend for creating a UI like TurboC++?
  2. I’ve completely forgotten how CMake and creating .h files work, so any resources or tips to brush up on those?

Thanks in advance for your suggestions!

0 Comments
2024/12/22
07:41 UTC

1

Broken File Name "��������" Generated by Goofy Code

Filename : ��������

OS: Linux (Winows Subsystem for Linux) /Ubuntu

How tf am I suposed to delete this?
Renaming or deleting attempts always result in some error like: "File /[...]/�������� not found"
Please help me, this project is due tomorrow.

3 Comments
2024/12/19
23:17 UTC

0

Looking for help with Railway.app alternatives

We recently made our saas app hosted on railway.app live. The builds keep failing at times and there seems to be some issue with the payment method added to the account.

Since the app has little to zero traffic(accessible only to beta testers now), been planning to switch from railway and exploring options like setting everything up on vultr/digitalocean or adding on AWS/GCP free tier.

Looking for suggestions.

1 Comment
2024/12/19
19:33 UTC

2

Need advice

Which is the best way learn coding other than courses?. Can a person becomes pro in coding by self learning?. And is youtube best to learn coding?

1 Comment
2024/12/19
08:52 UTC

1

Need help on deciding which SQL, language, and other things for my project

Hello, sorry that this will be long - I am working (completely solo, no support) to develop a sound meter monitoring program for my company, me keeping my job depends on it. I am generally quite tech-savvy, but I am only experienced in Python from my days doing astrophysics research for programming, so I have to research and figure things out (alone) every step of the way.

The plan is to eventually have multiple sound meters measuring at different locations, each connected to a laptop (that can run codes) with internet access, polling live data from the meter, uploading them to an online SQL database, then the user can access this database through a website to:

  1. see the live sound levels;
  2. show/plot historical data on demand.

So far I have written the Python program to request data every second from the sound meter's HTTP, processing and saving them locally in a CSV. The data size is quite small (11MB for 227000 rows) since there are only a few strings/numbers recorded every second. I am looking for advice on the next best courses of action.

As I understand from researching, I need to develop 3 more compenents - the database, backend and website.
- For the database, I was suggested that the Python SQLite package should be sufficient for my purpose, and I can do it in a familiar programming language that I can debug.
- For the backend, I was suggested to use Python web frameworks like Flask or Django; both are also new to me.
- For the website, I have not decided but the suggestion was HTML or CSS or Javascript; none of which I had any experience in, but it should be relatively simple since it only needs to 1) display live metrics, updates every second; 2) plot graphs

So far the questions I have in mind:
For the database:

  1. would I be missing out on essential features for my project down the line compared to using other more advanced languages, like C++?
  2. I know that Python is relatively slower, would performance be a noticeable issue for my use case? Let's assume that the database builds up data overtime, say, up to 1 million rows with 20 columns.
  3. Also the database may need to handle multiple data inputs every second when monitoring, on top of occasionally user query, would that be a problem?

For the website,
4. which language would be the easiest to learn and deploy quickly for an amateur like me? Nothing fancy, as long as it works.

As I have never done anything like this before, I am also open to suggestions to any other glaring issues to my plans and workflow that you guys can spot. Thanks everyone.

5 Comments
2024/12/19
06:16 UTC

1

Multi threading

I have something where I have to check for the location of progressively more objects (it's a game in WinForms (for school, I didn't have a choice) and I check if an object from a list is taking up the same grid space as the player), and that eventually slows the program down to a point where it's seriously impacting the experience.

The collision method (which is just a foreach with every object in a list and checks if x and y are equal to the player) runs in the main timer_tick before the movement, so it eventually checks so many objects' coordinates that it ends up slowing the movement down.

How could I remove the issue? Do I even need multi threading? It's just the first thing I could think off.

I would show the code, but my pos laptop can't connect to the Internet.

Edit: changed it to a dictionary instead of a list. The code is drastically simpler now, but it still isn't much better

4 Comments
2024/12/16
12:46 UTC

1

Have a quick question

Is it possible to create a CS project using logic gates only

0 Comments
2024/12/15
21:12 UTC

2

Printing graphs in C++

I am looking for a way to print a planar graph out just using text. I am honestly not sure how I would go about this. I can print a node and its list of its neighbors just fine from an adjacnency matrix, but actually formatting the text to print a visual representation of the graph is something I cannot figure out. I have looked all over the place and only found people using external libraries or just printing lists of neighbors. Help?

4 Comments
2024/12/15
16:35 UTC

1

SmartASP deployment problem

Good afternoon, May nakapag deploy naba dito gamit SmartASP pero after mo na ma deploy yung ASP .NET core web app mvc is hiningian kanang username and password even though correct naman pagka provide ng username at password is ayaw parin mag login?

0 Comments
2024/12/14
08:46 UTC

0

Help armalite https://peterhigginson.co.uk/ARMlite/ code not working

0 Comments
2024/12/13
12:36 UTC

1

What issues might I still be making with my functions?

0 Comments
2024/12/11
23:59 UTC

4

Can someone help me fix my functions?

Hello! Warning, I am working on a bunch of assignments/projects so I might post quite a bit in here!

I'm a beginner programmer who is not very good with functions. I will try to post an image of what the program's result is meant to look like in the post's comment section. I have the requirements for each function commented above their def lines. I think my main issue is calling the functions but I am not sure how to proceed from here. Can someone help point me in the right direction? Thank you!

https://pastebin.com/5QP7QAad

4 Comments
2024/12/11
05:13 UTC

1

How would you build this?

Hi all,

I'm looking to build a Multi-channel message sequencing product

Essentially allowing you to create email sequences, but also allowing you to message on linkedin and phone call in between etc.

This will be aimed for salespeople, similar to what apollo.io offer, but theres nothing similar in my native country/language

How would you go about building this yourself, or would you get APIs with services like Unipile - is it important to use something like Mailgun for email safety/health?

Anyone that's got any experience in similar, please let me know your thoughts!

0 Comments
2024/12/10
20:00 UTC

1

Need help expanding the scope of a class instance to span across multiple files.

So i'm making a drawing program, and i have a brush class named brushClass in clas.h, with an instance called brushInstance in main.cpp. I need to make a function that can access the data stored in brushInstance that is in func.h. Is it possible to expand the scope of brushInstance such that func.h can access and change data that brushInstance contains?

1 Comment
2024/12/10
16:57 UTC

1

Input for string name is skipped, can’t seem to figure out why. Any help/advice would be much appreciated.

std::cin >> temp;

if (!temp) {
    std::cout << "no temperature input" << '\n';
}

if (temp <= 0 || temp >= 30) {
    std::cout << "the temperature is good." << '\n';
}
else {
    std::cout << "the temperature is bad." << '\n';
}

std::cout << "Enter your name: ";
std::getline(std::cin, name);

if (name.empty()) {
    std::cout << "You didn't enter anything." << '\n';

}
if (name.length() > 12) {
    std::cout << "Your name can't be over 12 characters long." << '\n';
}
else {
    std::cout << "Welcome " << name << "!" << '\n';
}

return 0;

}

8 Comments
2024/12/09
23:11 UTC

0

Help needed about technology and solution?

Regards .i seek help for an automations process that will be based mainly on PDF files that are mainly narrative and financial. My question is how could I automate the process of reviewing those files sure after converting them to data and add logic and commands to cross check certain fields among the same single file and conclude.i know that IA could help but I need note technical feedback and technology. Your feedback is appreciated

2 Comments
2024/12/09
11:48 UTC

4

I wont land a project on upwork and i am going broke

I am good with data scraping/mining and manipulation python ive been learning programming on and off for 2 years i cnanot buy connects on upwork as in my country they are really expensive. Is there any other way i could land my first clientm

1 Comment
2024/12/09
05:59 UTC

1

Where to go after the start?

Right now, and for a while I have known basic programming, things such as python and C++, while coding with the raspberry pi and arduino. However I know that I am not as adavanced as most programmers. I often have vague ideas about what a cashe is or a firewall, but I have now idea how it works. Nor do I understand anything that is deeper code, such as the diffrences, beetween firmware and AI(like the subleties, im not that dumb lol). But where do I start, where do I go forward. I realize that i could keep just learning new languages, but how do I go deeper?

5 Comments
2024/12/09
02:28 UTC

0

Need help, working of post fix and pre fix operators

int a = 10;
int c = a++ + a++;
int a = 10;
int c = ++a + ++a;

Can anyone explain why the value of C is 21 in first case and 24 in second,

In first case, first value of A is 10 then it becomes 11 after the addition operator and then it becomes 12, So C = 10 + 11 = 21 The compiler also outputs 21

By using the same ideology in second case value of C = 11 + 12 = 23 but the compiler outputs 24

I only showed the second snippet to my friend and he said the the prefix/postfix operation manipulate the memory so, as after two ++ operation the value of A becomes 12 and the addition operator get 12 as value for both Left and right operands so C = 12 +12 = 24

But now shouldn't the first case output 22 as c = 11 + 11 = 22?

2 Comments
2024/12/08
10:29 UTC

1

Reshaping issues in NN optimisation

Hi, I do apologise for how atrocious the code will look. I'm new to Python and haven't coded in a few years, trying to complete an assignment. I've checked online and read up on Stack Overflow on the best way to approach this, but maybe I'm just doing something wrong.

I have a code block for extracted weights and biases and the gradient code block (part of a BSGN-QN optimisation) that is taking this function. I've attached the BSGN-QN block as well.

def extract_w_b(params, dim, n_outputs, hidden_layer_s=2):
    first_weights_size = dim * hidden_layer_s
    second_weights_size = hidden_layer_s * n_outputs
    frm = 0; to = frm + first_weights_size; layer_1_weights = params[frm:to].reshape(dim,hidden_layer_s)
    frm = to; to = frm + second_weights_size; layer_2_weights = params[frm:to].reshape(hidden_layer_s,n_outputs)
    
    first_bias_size = hidden_layer_s
    second_bias_size = n_outputs
    frm = to; to = frm + first_bias_size; layer_1_bias = params[frm:to]
    frm = to; to = frm + second_bias_size; layer_2_bias = params[frm:to]
  
    weight_1 = layer_1_weights
    weight_2 = layer_2_weights
    bias_1 = layer_1_bias
    bias_2 = layer_2_bias
    
    return weight_1, weight_2, bias_1, bias_2


def w_gradient_func(x, y, ddim, hiddenlayer_s, n_outputs):
    def grad_func(params):
        w1, w2, b1, b2 = extract_w_b(params, ddim, n_outputs, hiddenlayer_s)
        #w2, b2 = w1, b1
        z1 = x.dot(w1) + b1
        a1 = np.maximum(z1, 0)
        y_pred = a1.dot(w2) + b2
        n = x.shape[0]
        delta_o = (-2 / n) * (y - y_pred)
        grad_w2 = a1.T.dot(delta_o)
        grad_b2 = np.sum(delta_o, axis=0)
        delta_h = (delta_o.dot(w2.T)) * (z1 > 0)
        grad_w1 = x.T.dot(delta_h)
        grad_b1 = np.sum(delta_h, axis=0)
        grad = np.concatenate([grad_w1.ravel(), grad_w2.ravel(), grad_b1, grad_b2])
        return grad
    return grad_func


def bfgs_qn(func, grad, x0, tol = 1e-6, max_iter = 100):
    n = len(x0)
    x = np.array(x0, dtype=float)
    h = np.eye(n)
    history = [func(x)]
    
    for i in range(max_iter):
        grad_x = grad(x)
        p = -h.dot(grad_x)
        line_func = lambda alpha: func(x + alpha * p)
        alpha = goldensec_search(line_func, u=0, v=1)
        s = alpha * p
        new_x = x + s
        
        if np.linalg.norm(grad(new_x)) < tol:
            break
        
        y = grad(new_x) - grad_x
        rho = 1.0 / (y.dot(s))
        h = (np.eye(n) - rho * np.outer(s,y)).dot(h).dot(np.eye(n) - rho * np.outer(y,s)) + rho * np.outer(s,s)
        x = new_x
        history.append(func(x))
        
    return x, history

Here is where BFGS-QN gets called, so it can taken in the main.py:

def optimise_bfgsqn(func, grad, x0, tol=1e-6, max_iter=100):
    params_o, history = bfgs_qn(
        func, grad, x0, tol, max_iter
    )
    return params_o, history

I had to wrap the gradient function because I had issues trying to parse it elsewhere (I've truly messed this up I think).

I get the error below when I run my main.py:

ValueError: Dot product shape mismatch, (123, 123) vs (1, 2)

  File "", line 127, in grad_func
    delta_h = (delta_o.dot(w2.T)) * (z1 > 0)
  File "", line 158, in bfgs_qn
    grad_x = grad(x)
  File "", line 177, in optimise_bfgsqn
    params_o, history = bfgs_qn(
  File "", line 43, in <module>
    params_refined, history = novel.optimise_bfgsqn(
ValueError: Dot product shape mismatch, (123, 123) vs (1, 2)

Please let me know if there's a blog I'm missing or just made a huge mess of the whole thing :/

Thank you

0 Comments
2024/12/07
17:37 UTC

3

Question, Projects using thinkpad

I heard that old thinkpads are favorable by programmers and it’s better than raspberrypi. What’s the next step?! I couldn’t find guides in YouTube on how to use it for projects, can anyone enlighten me?!!

5 Comments
2024/12/06
21:42 UTC

1

POST method not working

Can someone please tell me wtf is wrong with the code?? Why does every time I press submit it redirects me to the same page. I tried everything to fix it and nothing is working, I tried using REQUEST and GET instead but it still didn't work. please help me I need this to work, the project is due in 2 days

btw only step 9 is printed

<?php
include "db.php";
session_start();

echo "Session set? Role: " . (isset($_SESSION['role']) ? $_SESSION['role'] : 'No role set') . ", email: " . (isset($_SESSION['email']) ? $_SESSION['email'] : 'No email set') . "<br>";
error_reporting(E_ALL);
ini_set('display_errors', 1);

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    echo "Step 2: POST data received.<br>";
    echo "<pre>";
    print_r($_POST);
    echo "</pre>";

    $role = $_POST['role'];
    $email = mysqli_real_escape_string($conn, $_POST['email']);
    $password = $_POST['pass'];

    echo "Role: $role, Email: $email<br>";

    if ($role == "student") {
        echo "Step 3: Student role selected.<br>";
        $query = "SELECT * FROM info_student WHERE email = '$email'";
        $result = mysqli_query($conn, $query);

        if ($result) {
            $row = mysqli_fetch_assoc($result);

            if ($row && password_verify($password, $row['pass'])) {
                echo "Step 5: Password verified.<br>";
                $_SESSION['role'] = 'student';
                $_SESSION['email'] = $row['email'];
                $_SESSION['student_name'] = $row['name'];
                $_SESSION['student_password'] = $row['pass'];
                header("Location: index.php");
                exit();
            } else {
                echo "Error: Incorrect password or email not registered.<br>";
            }
        } else {
            echo "Error: " . mysqli_error($conn);
        }
    } elseif ($role == "instructor") {
        echo "Step 6: Admin role selected.<br>";
        $query = "SELECT * FROM admin WHERE email = '$email'";
        $result = mysqli_query($conn, $query);

        if ($result) {
            $row = mysqli_fetch_assoc($result);

            if ($row && password_verify($password, $row['pass'])) {
                echo "Step 8: Password verified.<br>";
                $_SESSION['role'] = 'admin';
                $_SESSION['admin_email'] = $row['email'];
                $_SESSION['admin_name'] = $row['name'];
                $_SESSION['admin_password'] = $row['pass'];
                header("Location: index.php");
                exit();
            } else {
                echo "Error: Incorrect password or email not registered.<br>";
            }
        } else {
            echo "Error: " . mysqli_error($conn);
        }
    } else {
        echo "Error: Invalid role.<br>";
    }
}

echo "Step 9: Script completed.<br>";

mysqli_close($conn);
?>

<!DOCTYPE html>
<html lang="ar">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
    <link rel="stylesheet" href="style.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<script>
    function setRole(role) {
        document.getElementById('role-input').value = role;
        document.querySelectorAll('.role-buttons button').forEach(button => {
            button.classList.remove('active');
        });
        document.getElementById(role).classList.add('active');
    }
</script>

<div class="container">
    <h2 class="text-center my-4">Welcome</h2>
    <div class="role-buttons">
        <button type="button" id="student" class="active btn btn-primary" onclick="setRole('student')">Student</button>
        <button type="button" id="admin" class="btn btn-secondary" onclick="setRole('instructor')">Instructor</button>
    </div>
    <form method="POST" action="login.php" onsubmit="console.log('Form submitted');">
        <input type="hidden" id="role-input" name="role" value="student"> 
        <div class="mb-3">
            <label for="email" class="form-label">Email</label>
            <input type="email" class="form-control" id="email" name="email" placeholder="Enter your email" required>
        </div>
        <div class="mb-3">
            <label for="pass" class="form-label">Password</label>
            <input type="password" class="form-control" id="pass" name="pass" placeholder="Enter your password" required>
        </div>
        <button type="submit" class="btn btn-success">Login</button>
    </form>
    <div class="mt-3">
        <p>Don't have an account? <a href="register.php">Register here</a></p>
    </div>
    <?php if (isset($error)): ?>
        <div class="alert alert-danger mt-3"><?php echo $error; ?></div>
    <?php endif; ?>
</div>
</body>
</html>
1 Comment
2024/12/05
17:45 UTC

1

Cross-posted: Assistance with Updating AAC Software Developed by User's Father

I am working with a person who had an augmentative speech program written by his father. This program, “New Speech,” has been used for over a decade, with some updates along the way, and is the person’s primary mode of communication. It is currently being used on an old MacBook Pro, that needs to be updated. A few issues have been identified with getting New Speech to function on a new MacBook Pro.

·         First, the information we have is mostly complete, however- as his father was the initial developer and maintained this software, since his passing there is some information we do not have which contributes to the issues.

·         NewSpeech was initially developed by his father, and is father contracted another developer to upgrade the code using LiveCode.

·         We tried to bring NewSpeech as it currently operates on his older MacBook onto a newer MacBook, and received an error message. From what I can tell (as someone without programming experience), the issue is that NewSpeech is configured for 32-bit and not 64-bit, so will not operate on newer MacBooks.

 

I am seeking assistance in updating this software so that it can function on a newer MacBook. The person strongly prefers Mac computers, so we would like to consider this option first, but they are open to exploring Windows if it is impossible to use NewSpeech on a newer Mac.

 

The family has provided us with all files that his father stored about NewSpeech, I suspect there is information within these files but I am honestly not sure where to start.

 

We appreciate any thoughts the community may have!

0 Comments
2024/12/05
15:16 UTC

0

Weird error just randomly popped up in Python.

It's usually running fine, it just started getting this error and won't let me pass. using OpenAI API btw if that helps.

response = assist.ask_question_memory(current_text)
                        print(response)
                        speech = response.split('#')[0]
                        done = assist.TTS(speech)
                        skip_hot_word_check = True if "?" in response else False
                        if len(response.split('#')) > 1:
                            command = response.split('#')[1]
                            tools.parse_command(command)
                        recorder.start()

Error:

speech = response.split('#')[0]

^^^^^^^^^^^^^^

AttributeError: 'NoneType' object has no attribute 'split'

Please help, can't find any solutions online.

2 Comments
2024/12/04
20:34 UTC

1

Need help, tkinter configuring widgets

I have a method that does not work when being called. The program just stops working and nothing happens.

def change_statistics(self):

"""Updates widgets in frame"""

q = 1

new_player_list = player_list[:] # player_list[:] is a list of player objects.

new_percentage_list = percentage_list[:] # percentage_list[:] is a list of float numbers where each number represent the percentage attribute of a player object.

while len(new_percentage_list) != 0:

for player in new_player_list:

if player.percentage == max(new_percentage_list):

player.position = q

self.children[f"position_{q}"].configure(text = f"{player.position}")

self.children[f"name_{q}"].configure(text = player.name)

self.children[f"number_of_w_{q}"].configure(text = f"{player.number_of_w}")

self.children[f"number_of_games_{q}"].configure(text = f"{player.number_of_games}")

self.children[f"percentage_{q}"].configure(text = f"{player.percentage}")

new_player_list.remove(player)

new_percentage_list.remove(player.percentage)

q += 1

break

I have tried using `self.update_idletasks()` before break and the only difference it makes is that the method will work for the first loop in the while loop, but then it stops working.

1 Comment
2024/12/04
15:12 UTC

1

redefination of main error in c in leet code

I am a beginner to leet code was trying to solve the two sum question.

#include<stdio.h>

int main(){

int nums[4];

int target;

int i;

int c;

printf("Enter target");

scanf("%d",&target);

for (i=0;i<4;i++){

printf("Enter intergers in array");

scanf("%d",&nums[i]);

}

for (i=0;i<4;i++){

if (nums[i] < target){

c= nums[i];

c = c + nums[i+1];

if (c == target){

printf("target found");

printf("%d,%d",i,i+1);

break;

}

}

}

}

i wrote this code which i think is correct and i also tested it in an online c compiler where it seems to work just fine but when i try to run to code in the leetcode it shows compile error

Line 34: Char 5: error: redefinition of ‘main’ [solution.c]
34 | int main(int argc, char *argv[]) {
| ^~~~

can yall help me

1 Comment
2024/12/03
13:59 UTC

2

Help with CSRF and XSS Protection

builder.Services.AddControllersWithViews(options =>
{
    options.Filters.Add(new Microsoft.AspNetCore.Mvc.AutoValidateAntiforgeryTokenAttribute());
});

If I have this code in my Program.cs-file. Will all my Controller-methods automatically be protected from CSRF and XSS attacks by default. Or do I have to add:

[ValidateAntiForgeryToken] 

... infront of all my methods?

3 Comments
2024/12/03
09:50 UTC

Back To Top