r/CodingHelp • • 46m ago

[How to] Is it possible to set up a localhost server that allows WebRTC services outside your own network?

1 Upvotes

For a personal project, I needed to create a video call and screen sharing service, but to avoid paying for a server, I was wondering if it’s actually possible to run the server on localhost and have the other person connect through a Cloudflare tunnel. Do you know if this is possible? How feasible is it, and what problems might arise?


r/CodingHelp • • 1d ago

[PHP] Whats the most efficient way to pull messeges in PHP?

3 Upvotes

I run a small chat site for students at my school (about 140 users). It's built with plain JavaScript on the frontend and PHP on the backend, on shared hosting.
https://hbhub.noahgajnielsen.dk

Right now each open tab polls the server about once per second:

GET /chat/?poll=1&listV=eecc4cd414d8f9c9&requestsV=ef46db3751d8e999
GET /chat/?poll=1&listV=...&requestsV=...&nav=messages%3D1%26after%3D2633

listV and requestsV are hashes of the chat list and friend requests. The server compares them and only sends data back when something has changed. after is the ID of the newest message the client already has.

This works, but:

  • Every open tab makes ~3,600 requests per hour, even when nothing happens
  • Messages can still show up with up to ~1 second of delay
  • Many users leave the tab open all days

What I've considered:

  • WebSockets: my host doesn't seem to allow long-running processes (e.g. Ratchet or a Node server)
  • Server-Sent Events from PHP: I'm unsure whether a PHP script holding a connection open per user will exhaust PHP-FPM workers
  • Long polling: same worker concern

Question: On shared hosting without long-running processes, what's the most efficient way to push new chat messages to the browser? Is SSE from PHP practical for ~100 concurrent users, or should I keep polling and back off (for example, slow down when document.hidden is true)?


r/CodingHelp • • 4d ago

[Javascript] How do you customize artillery load tests and create a more realistic simulation?

Thumbnail reddit.com
2 Upvotes

r/CodingHelp • • 6d ago

[C#] How would I get randomiser to stop giving duplicate questions?

Thumbnail reddit.com
3 Upvotes

r/CodingHelp • • 7d ago

[C++] Part two of my Markov Chain Project

3 Upvotes

Hey there! So i figured how to do the lottery system for my markov chain but im getting stuck on how to initialize it. what im trying to do is im trying to get the first two words and get them to predict the third word coming. But i dont know how to do it so far and this is what i have. I just kinda threw stuff at the wall till it stuck but yeah this is what i have so far. Thanks

I cant figure out the stupid code format on reddit for mobile, sorry in advanced.

void MarkovChain::initializeChains(const vector<string>& words) { //(void)words; // fill me in

map<list<string>, map<string, int>> token;
map<string, int> ngram;

for (const auto& word : words) {
    list<string> key(words.begin(), words.end());
    token[key][word]++;
}

}


r/CodingHelp • • 8d ago

[Python] [WinError 4551] An Application Control policy has blocked this file.

Thumbnail reddit.com
1 Upvotes

r/CodingHelp • • 9d ago

[Random] Ethical dilemma about a very specific case of coding using AI. In search of opinions and points of view.

3 Upvotes

Hi everyone.

I’m an artist. I draw, I play and produce music, I edit videos, I know sound engineering, I animate sometimes, and I’m learning cinema in the university course I’m attending.
Of course I have this somewhat visceral intollerance against generative AI, and as a consequence I’m not really fond of AI in general, even tho I recognise its potential benefits.

I’m also NOT a developer, and I don’t know how to write in any language except, if a language it is considered among this community, a tiny bit of html, despite my digital literacy that I can say goes very well above average.

Recently I’ve been having many ideas of some programs that do not exist and that might come helpful to me, but, as I said, I’m not a developer and it would take me a lot of time to even start learning to code. This puts me in this bit of an edgy situation where I either wait a long time until I’m confident in developing, or I pay someone to make softwares for my personal use, or I ask an AI to write the code for me.

For the programs I have in mind, of which I won’t describe the features planned, I would create every visual asset by myself.

The question is: in your opinion, should I ask an AI to write the code for me, while I direct the software design choices and do the artistic side alone by myself, or should I rather opt for one of the other two choices?


r/CodingHelp • • 10d ago

[How to] A practical site for company interns to learn technical tasks fast

2 Upvotes

I’m a Computer Science student and I created Intern.dev for interns who are already working in a company and need to learn a technical task quickly.

Instead of long courses or copying everything from AI, the site gives a hands-on guide. Every path includes the explanation of what you should do, the libraries you need, and a copy-paste project. All based around the same Task Management API.

FastAPI – Create the API

Docker & CI/CD – Containerise and automate the API

Authentication – Add users, JWT and roles

API Testing – Cover passing and failing test cases

A simple chatbot is included. It only helps with the basic tasks. It does not replace reading the path and adjusting the code yourself.

Preview:

https://intern-dev-7-clean.vercel.app/docs

This is a temporary link. I will move the site to a proper domain soon


r/CodingHelp • • 11d ago

Which one? How to import only part of Google Sheet

Thumbnail reddit.com
1 Upvotes

r/CodingHelp • • 14d ago

[Java] been learning on mooc.fi, is so far on part 2 of Java 1, is there a better way for this?

Thumbnail reddit.com
1 Upvotes

r/CodingHelp • • 15d ago

[Random] Does this happen a lot? need some advice.

3 Upvotes

So I’ve been coding for about seven or eight years. In 2023 I took a break from making websites for people.

They say when you stop making websites after a while, you tend to forget certain things

I tried to code a few weeks ago. Normally, I’d remember the elements and the names of everything

Is it really true when you stop coding for a while you have to look up what the language means again?

I never wanted to be that type of person, but I know everyone learns differently. Is this really how it is?

Sorry for the stupid question. I just wanna make sure I’m not the only one who dealt with this

It’s kind of like a good friend of mine knows how to draw and they haven’t drew anything in three years.

They took a long break. They don’t seem to forget a lot of things, though regarding drawing.


r/CodingHelp • • 15d ago

[How to] Ideas Need advice/tips for my game server hosting panel

2 Upvotes

Servus,

Ive been working on a new game server hosting panel. The goal is something that’s easier to set up and nicer to use day to day than what’s out there right now.

Ive used Pterodactyl, Pelican and AMP. They’re cool projects, no doubt, and I respect the work behind them. But I kept running into the same problems: setup takes too many steps, the UI gets confusing for non-technical users, and simple tasks like installing mods, managing backups or switching versions take more clicks than they should.

Before I go further, I’d like to hear from the people who actually run these servers:

  • What annoys you about the panel you use now?
  • What feature do you keep wishing existed**?**
  • What would make you switch panels? Or what would stop you from switching?
  • Which games do you host? I wanted to start the project with Minecraft and Hytale at first (because thats what i play the most) but an "Egg-System" like Pterodactyl would be cool too (or maybe backwards compatible with them maybe (?))

No link, no sign-up, nothing to sell. This project will be open-source. I’m trying to build the right thing before I build too much of the wrong thing. Brutal honesty is welcome.

Thanks in advance.


r/CodingHelp • • 15d ago

[C++] I need help with my code (Cpp Markov Chain, PickRandomWord part)

4 Upvotes

Its in c++ and the code im trying to make is for a markov chain. Its an assignment my teacher has given for extra credit and im trying to do it. Im kinda lost, i sent my professor an email and so far she hasn't responded at all.

So i figured to come here on reddit and hopefully figure out where im going wrong. So far i only have one of the three required components for the markov chain and i don't really want to use chat or gem to see whats wrong. So yeah if anyone's up for it, please help? That'd greatly be appreciated.

Heres my code on the bottom:

Here, for anyone who wants to see their code in code blocks:

map<string, int> ticket;
map<string, int>::iterator itr;
map<string, int> winning_tickt;

int totalTickets = 0;

for (const auto& word : wordsAndCounts) {
    totalTickets += word.second;
}

if (totalTickets == 0) {
    throw runtime_error("Couldn't select a random word");
}

winning_tickt["Winning_ticket"] = rand() % totalTickets;

for (int i = 0; i < totalTickets; i++) {
    ticket["Ticket" + i] = i;
}

// First idea:
// while (ticket != winning_tickt) {
//     for (itr = ticket.begin(); itr != ticket.end(); itr++) {
//         if (ticket == winning_tickt) {
//             cout << "Found it!";
//         }
//     }
// }

// Second idea:
while (ticket != winning_tickt) {
    for (itr = ticket.begin(); itr != ticket.end(); itr++) {
        if (ticket == winning_tickt) {
            return ticket["winner"];
        }
    }
}

Alright to put it short, im trying to make the pickrandomword part, made two maps, one for all the tickets and one for the winning ticket. I have an iterator so it traverse each ticket and find the winning ticket or is equal to the winning ticket. I have totaltickets set to zero so i can use the for loop to add counts of all the tickets to my totaltickets since the perimeter is a const variable. I was hoping for the 2nd for loop to be the way i traverse each ticket while the winning ticket hasnt been for yet! And im trying to think of what to do once the winn I ng ticket has been found but im getting stumped. So yeah. Please..help.


r/CodingHelp • • 15d ago

[Python] how to save money on cache with api routing

1 Upvotes

I see so many cost saving promise that promote API routing between models. I initially thought that is valuable. Then ran few experiments, it turns out any time that you route the request to a new model, you could save a bit, but many times the cache for each individual models expire and you would pay for new cache write again and agin - which overall wipe out the API routing cost saving benefit.

I wonder if anyone has similar experience. How you have solved this? Is clause planning to add shared cache feature?


r/CodingHelp • • 15d ago

[C] In my case I think `frame_bytes` should be the same as mmapped buffer.

1 Upvotes

I initialize my linux framebuffer like this:

#include "framebuffer_init.h"
#include <sys/ioctl.h>
#include <stdint.h>      // uint32_t, uint64_t
#include <stddef.h>      // size_t
#include <stdio.h>       // perror()
#include <unistd.h>      // close()
#include <sys/ioctl.h>   // ioctl()
#include <sys/mman.h>    // mmap(), munmap(), PROT_*, MAP_*
#include <linux/fb.h>    // fb_var_screeninfo, fb_fix_screeninfo, FBIOGET_*
#include <fcntl.h>       // open(), O_RDWR (if opening framebuffer here)


int framebuffer_init(
    int fb,
    uint32_t *width,
    uint32_t *height,
    uint32_t *pitch,
    uint32_t *bpp,
    uint64_t *size,
    void **map
){


    struct fb_var_screeninfo vinfo;
    struct fb_fix_screeninfo finfo;


    if (ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0 ||
        ioctl(fb, FBIOGET_FSCREENINFO, &finfo) < 0) {
        perror("framebuffer ioctl");
        return 0;
    }


    *width  = vinfo.xres;
    *height = vinfo.yres;
    *bpp    = vinfo.bits_per_pixel;
    *pitch  = finfo.line_length;   // bytes per row (was never set)


    // Total mapped size: use the virtual height in case of double buffering
    *size = (uint64_t)finfo.line_length * vinfo.yres_virtual;
    
    *map = mmap(NULL,*size,PROT_READ | PROT_WRITE,MAP_SHARED,fb,0);


    if (*map == MAP_FAILED) {
        perror("framebuffer mmap");
        *map = NULL;
        return 0;
    }


    return 1;
}


void framebuffer_cleanup(
    int *fb_fd,
    void **map,
    uint64_t size
) {
   // Implementation ommited for reduced post verbocity
}

Then I my main:

#define _GNU_SOURCE

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/fb.h>

#include <cairo.h>

#include "framebuffer_init.h"
#include "cairo_render.h"

int main(void)
{
    int fb = open("/dev/fb0", O_RDWR | O_CLOEXEC);
    if (fb < 0) {
        perror("open framebuffer");
        return 1;
    }

    uint32_t width = 0, height = 0, pitch = 0, bpp = 0;
    uint64_t size = 0;
    void *map = NULL;

    if (!framebuffer_init(fb, &width, &height, &pitch, &bpp, &size, &map)) {
        fprintf(stderr, "Framebuffer initialization failed\n");
        framebuffer_cleanup(&fb, &map, size);
        return 1;
    }

    cairo_format_t fmt = (bpp == 32) ? CAIRO_FORMAT_RGB24
                                     : CAIRO_FORMAT_RGB16_565;

    // Back buffer in normal RAM, with exactly the same layout as the framebuffer
    size_t frame_bytes = (size_t)pitch * height;
    uint8_t *backbuf = calloc(1, frame_bytes);
    
    if (!backbuf) {
        fprintf(stderr, "Back buffer allocation failed\n");
        framebuffer_cleanup(&fb, &map, size);
        return 1;
    }

    cairo_surface_t *back = cairo_image_surface_create_for_data(backbuf, fmt, width, height, pitch);

    if (cairo_surface_status(back) != CAIRO_STATUS_SUCCESS) {
        fprintf(stderr, "Back buffer surface creation failed: %s\n",
                cairo_status_to_string(cairo_surface_status(back)));
        cairo_surface_destroy(back);
        free(backbuf);
        framebuffer_cleanup(&fb, &map, size);
        return 1;
    }

    cairo_t *cr = cairo_create(back);

    const struct timespec frame_delay = { 0, 16 * 1000 * 1000 }; // ~60 FPS

    while (true) {
        draw_with_cairo(cr);
        cairo_surface_flush(back);

        // Wait for vblank; if unsupported, fall back to a fixed delay
        uint32_t dummy = 0;
        if (ioctl(fb, FBIO_WAITFORVSYNC, &dummy) < 0) {
            nanosleep(&frame_delay, NULL);
        }

        // Single copy of the whole frame
        memcpy(map, backbuf, frame_bytes);
    }

    // Cleanup (reached if you add an exit condition to the loop)
    cairo_destroy(cr);
    cairo_surface_destroy(back);
    free(backbuf);
    framebuffer_cleanup(&fb, &map, size);

    return 0;
}

I initialise the backbuff like this:

    size_t frame_bytes = (size_t)pitch * height;
    uint8_t *backbuf = calloc(1, frame_bytes);

Whereas I use this function for drawing using cairo:

void draw_with_cairo  (cairo_t *cr) {

    // Background
    cairo_set_source_rgb(cr, 0.05, 0.08, 0.16);
    cairo_paint(cr);

    // Rectangle
    cairo_set_source_rgb(cr, 0.1, 0.6, 0.9);
    cairo_rectangle(cr, 100, 100, 400, 200);
    cairo_fill(cr);

    // Circle
    cairo_set_source_rgb(cr, 1.0, 0.3, 0.2);
    cairo_arc(cr, 600, 300, 100, 0, 2 * 3.14159265);
    cairo_fill(cr);

    // Text
    cairo_select_font_face(cr, "Sans",
        CAIRO_FONT_SLANT_NORMAL,
        CAIRO_FONT_WEIGHT_BOLD);

    cairo_set_font_size(cr, 48);
    cairo_set_source_rgb(cr, 1, 1, 1);
    cairo_move_to(cr, 100, 450);
    cairo_show_text(cr, "Cairo + DRM/KMS");
}

I feel like that this calculation:

    size_t frame_bytes = (size_t)pitch * height;

Is unnecessery since backbuff should have the same size as mmaped framebuff. The reasin why is because I memcpy the backbuff into actual buffer:

        memcpy(map, backbuf, frame_bytes);

Upon drawing loop. Cairo initialization and drawing happen through these functions:



#include "cairo_render.h"

cairo_t* init_cairo(void *map, uint32_t width,uint32_t height,uint32_t pitch, cairo_surface_t **surface ){
   *surface =cairo_image_surface_create_for_data(map,CAIRO_FORMAT_ARGB32,width,height,pitch);
   return cairo_create(*surface);
}

void draw_with_cairo  (cairo_t *cr) {

    // Background
    cairo_set_source_rgb(cr, 0.05, 0.08, 0.16);
    cairo_paint(cr);

    // Rectangle
    cairo_set_source_rgb(cr, 0.1, 0.6, 0.9);
    cairo_rectangle(cr, 100, 100, 400, 200);
    cairo_fill(cr);

    // Circle
    cairo_set_source_rgb(cr, 1.0, 0.3, 0.2);
    cairo_arc(cr, 600, 300, 100, 0, 2 * 3.14159265);
    cairo_fill(cr);

    // Text
    cairo_select_font_face(cr, "Sans",
        CAIRO_FONT_SLANT_NORMAL,
        CAIRO_FONT_WEIGHT_BOLD);

    cairo_set_font_size(cr, 48);
    cairo_set_source_rgb(cr, 1, 1, 1);
    cairo_move_to(cr, 100, 450);
    cairo_show_text(cr, "Cairo + DRM/KMS");
}


r/CodingHelp • • 16d ago

[Java] This is a little program that I created with the help of AI

Thumbnail reddit.com
0 Upvotes
This is a little program that I created with the help of AI. I only used AI when I became stuck on certain parts of the program. The program allows the user to input a file directly into the IDE, whcich allows the terminal to output what is in the file; it also allows the user to select a file to read, and finally allows the user to select a place to save a file and enter text to be saved into a file. 

r/CodingHelp • • 16d ago

[Random] website not working cause i deleted a buncha stuff

0 Upvotes

ok so idk where to go for this so if there is another thread i should be on lmk just please spare me idk nothing about anything please dont be mean pleaseplaspeplasepleasepleas

i wanted to look at facebook marketplace without logging in so i inspected the log in pop up and just kept deleting random code until it went away. but now the scroll feature or any button on any facebook url wont work. man that shit says 612 errors 7 warnings

i tried to press the "restore defaults and reload" button, and i tried to restart my computer, I use brave and i dont think there is a button that lets it restart, i even go on another brave profile and it dont work on there '

and idk what to do i want to look at toys on fb marketplace so bad idk what to do if you can help please le me know or if there is somewhere else i should ask pleas let me kno thank you


r/CodingHelp • • 16d ago

Unreal Blueprints/C++ Not even sure how to properly describe this, but how do I guess "normalize" an integer?

6 Upvotes

Hi been working on a game for a few years now and managed to stumble my way through this so far.... I've gotten stuck on the stupidest stuff.... but I have been stuck on this one for a while and worst part is I don't even know how to word this in Google to get an answer as its... a strange but either potentially simple or completely impossible thing I'm not sure XD

But what I'm trying to do is max out an integer at 255, so a 256 bit would become 1, a 512 becomes 2, 1024 becomes 4, and so on... There shouldn't be a scenario where it has to wrap over again so the max we should be having to deal with is 32,768 becoming 128 (if it even gets to that at all)

best solution I've got right now is to iterate over each bit with a for loop, "and" the integer with one of those base numbers and if that bit is detected then subtracting the desired bit from the undesired one and subtracting *that* from the original int (so like [int] - (512-2) for example) but I feel this operation is far too costly given this is already packed within 3 other (albeit equally small) loops so I was hoping there might be a much cheaper solution to this

Edit: Solved! Thx!


r/CodingHelp • • 16d ago

[How to] Can’t get past DataDome + imperva

2 Upvotes

Im vibecoding my project and im having a little trouble scraping one website in particular. Seems like they are using DataDome + Imperva.

Claude code and ChatGPT are not being able to get past it.

Any one knows how to do it?

Thanks


r/CodingHelp • • 17d ago

[Lua] I tried first time modding Project Zomboid

2 Upvotes

But can not get into vehicle. I used classic vehicle template and add a custom mesh. I can not drive. Was it so big for animation complete?


r/CodingHelp • • 19d ago

[Request Coders] I need advice from experienced coders. Regarding etiquette and best practices. (Preferably those that work in the industry.)

4 Upvotes

So first question is, what exactly is vibe coding? I currently am new (a month experience.) when I'm writing code, my comprehension seems to be great but I use AI to double check my work and give feedback. Example being I used AI while making a weather and news app, I'd write the code, and if I got an error I'd check over it and if my eyes weren't catching a typo or I didn't understand I'd copy it and let chatgpt look over it and correct me. I'm making sure to understand what the code actually does. I told someone I'm learning via vibe coding and told him that and his response was that's not vibe coding then just described vibe coding as using AI to code... I'm confused.

Second question. With all of the resources out there with existing code, if I use it instead of hand coding is that wrong? I want to build my portfolio and eventually get some small back end developer job/internship quickly but I want to do it right. So any advice even if it's shit talking I'll appreciate.


r/CodingHelp • • 20d ago

[How to] How to read this code that I decided from a QR?

2 Upvotes

I recently got scammed and I'm trying to get as much information from the scammer to strengthen my filled complaints.

This is what I got after decoding the QR code the scammer sent me but I have no idea how to read it

00020101021127810012com.p2pqrpay0111OWNBPHM2XXX020899964403041620241008000020290514+63-96090477455204601653036085802PH5915Da .. Br. . Le.. 6006Manila630422D0

*the dots are supposed to be asterisks but I dunno why I can't type them that way


r/CodingHelp • • 20d ago

[How to] Pull Airpods case and Buds battery information in real time from iphone.

3 Upvotes

So im creating a app and i need to be able to pull the airpods battery data. howevery searching online says that it can only be done with a mac but i need it to work on a iphone. any suggestions would be greatly appreciated.


r/CodingHelp • • 22d ago

[Python] Need assistance with a Python Code that keeps on crashing

Thumbnail gallery
4 Upvotes