r/CodingHelp • u/CouchResident • 2d ago
r/CodingHelp • u/TuxedoKitty2023 • 3d ago
[Random] Does this happen a lot? need some advice.
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 • u/an1lsalan • 3d ago
[How to] Ideas Need advice/tips for my game server hosting panel
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 • u/OperationVisual6523 • 3d ago
[C++] I need help with my code (Cpp Markov Chain, PickRandomWord part)
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 • u/leapd-ai • 3d ago
[Python] how to save money on cache with api routing
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 • u/pc_magas • 4d ago
[C] In my case I think `frame_bytes` should be the same as mmapped buffer.
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 • u/XIA_Biologicals_WVSU • 4d ago
[Java] This is a little program that I created with the help of AI
reddit.comThis 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 • u/Due_Experience9255 • 4d ago
[Random] website not working cause i deleted a buncha stuff
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 • u/ADFormer • 4d ago
Unreal Blueprints/C++ Not even sure how to properly describe this, but how do I guess "normalize" an integer?
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 • u/AddendumWeird8789 • 4d ago
[How to] Can’t get past DataDome + imperva
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 • u/Emre_ben • 6d ago
[Lua] I tried first time modding Project Zomboid
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 • u/FR3SH_AUT1ZM • 7d ago
[Request Coders] I need advice from experienced coders. Regarding etiquette and best practices. (Preferably those that work in the industry.)
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 • u/xxxrottentothecore • 8d ago
[How to] How to read this code that I decided from a QR?
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 • u/Affectionate-Finger5 • 8d ago
[How to] Pull Airpods case and Buds battery information in real time from iphone.
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 • u/ItchyForever1398 • 9d ago
[Python] Turn off camera and mic with a single button
Hello, i am fairly new to coding. I was trying to write a script that would basically mute my mic, turn off my camera and minimize the screen when im on a call on discord or google meet at the press of a button. Is this something that is possible? I am not able to figure out how to get to the turning off of camera and mic part. anyone here that could gyide me or like lemme know if what im trying to do is not a possibility, would be greatly appreciated.
r/CodingHelp • u/Extension_Fig_2168 • 10d ago
[Python] Need assistance with a Python Code that keeps on crashing
galleryr/CodingHelp • u/Catamituz • 12d ago
[C++] WHAT am i doing wrong theres like 500+ lines of code and millions of errors (C++ code drone aeronamics) ⬇️⬇️I put the code below


/**
* Multi-rotor drone aerodynamics simulation
* Models forces, moments, propeller dynamics, and 6-DOF rigid body motion
* with simplified atmospheric and induced velocity effects.
*
* Intended for educational / numerical experimentation use.
*/
#include <iostream>
#include <vector>
#include <array>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <stdexcept>
#include <algorithm>
#include <numeric>
#include <random>
#include <chrono>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
// ---------------------------------------------------------------------------
// Constants & utility
// ---------------------------------------------------------------------------
constexpr double g = 9.80665; // m/s²
constexpr double rho0 = 1.225; // kg/m³ sea-level density
constexpr double R_earth = 6371000.0; // m
constexpr double T0 = 288.15; // K
constexpr double L = 0.0065; // K/m temperature lapse
constexpr double R_specific = 287.05; // J/(kg·K)
inline double deg2rad(double d) { return d * M_PI / 180.0; }
inline double rad2deg(double r) { return r * 180.0 / M_PI; }
inline double clamp(double v, double lo, double hi) {
return std::max(lo, std::min(v, hi));
}
// ---------------------------------------------------------------------------
// 3-D vector (lightweight)
// ---------------------------------------------------------------------------
struct Vec3 {
double x = 0.0, y = 0.0, z = 0.0;
Vec3() = default;
Vec3(double x_, double y_, double z_) : x(x_), y(y_), z(z_) {}
Vec3 operator+(const Vec3& o) const { return {x + o.x, y + o.y, z + o.z}; }
Vec3 operator-(const Vec3& o) const { return {x - o.x, y - o.y, z - o.z}; }
Vec3 operator*(double s) const { return {x * s, y * s, z * s}; }
Vec3 operator/(double s) const { return {x / s, y / s, z / s}; }
Vec3& operator+=(const Vec3& o) { x += o.x; y += o.y; z += o.z; return *this; }
Vec3& operator-=(const Vec3& o) { x -= o.x; y -= o.y; z -= o.z; return *this; }
Vec3& operator*=(double s) { x *= s; y *= s; z *= s; return *this; }
double norm() const { return std::sqrt(x*x + y*y + z*z); }
double norm2() const { return x*x + y*y + z*z; }
Vec3 normalized() const {
double n = norm();
return n > 1e-12 ? (*this)/n : Vec3{0,0,0};
}
double dot(const Vec3& o) const { return x*o.x + y*o.y + z*o.z; }
Vec3 cross(const Vec3& o) const {
return {y*o.z - z*o.y, z*o.x - x*o.z, x*o.y - y*o.x};
}
};
inline Vec3 operator*(double s, const Vec3& v) { return v * s; }
std::ostream& operator<<(std::ostream& os, const Vec3& v) {
os << std::fixed << std::setprecision(4)
<< "(" << v.x << ", " << v.y << ", " << v.z << ")";
return os;
}
// ---------------------------------------------------------------------------
// Atmosphere model (ISA troposphere approximation)
// ---------------------------------------------------------------------------
struct Atmosphere {
static double density(double altitude) {
// altitude in meters above MSL
if (altitude < 0.0) altitude = 0.0;
double T = T0 - L * altitude;
double p = 101325.0 * std::pow(T / T0, g / (R_specific * L));
return p / (R_specific * T);
}
static double temperature(double altitude) {
return T0 - L * std::max(0.0, altitude);
}
static double speedOfSound(double altitude) {
return std::sqrt(1.4 * R_specific * temperature(altitude));
}
};
// ---------------------------------------------------------------------------
// Propeller / rotor model (blade-element momentum theory simplified)
// ---------------------------------------------------------------------------
struct Rotor {
double radius; // m
double chord; // m (mean)
int numBlades;
double pitch; // rad (collective)
double rpm; // revolutions per minute
double Ct_coeff; // empirical thrust coefficient scale
double Cq_coeff; // torque coefficient scale
Vec3 position; // body-frame position relative to CoM
Vec3 axis; // unit vector of rotation axis (body frame)
bool clockwise; // rotation direction
Rotor(double r, double c, int n, double p, const Vec3& pos, const Vec3& ax, bool cw)
: radius(r), chord(c), numBlades(n), pitch(p), rpm(0.0),
Ct_coeff(0.12), Cq_coeff(0.008),
position(pos), axis(ax.normalized()), clockwise(cw) {}
// Angular velocity in rad/s
double omega() const { return rpm * 2.0 * M_PI / 60.0; }
// Disk area
double area() const { return M_PI * radius * radius; }
// Advance ratio / induced velocity estimation (very simplified)
double inducedVelocity(double v_axial, double rho) const {
// Momentum theory: T = 2 * rho * A * vi * (v + vi)
// Solve quadratic for vi given thrust estimate
double T_est = thrust(rho, v_axial); // circular dependency resolved iteratively later
double a = 2.0 * rho * area();
double disc = v_axial*v_axial + 2.0*T_est / a;
return 0.5 * (-v_axial + std::sqrt(std::max(0.0, disc)));
}
// Thrust (body axis direction)
double thrust(double rho, double v_axial) const {
double Om = omega();
double tip_speed = Om * radius;
// Simplified: Ct ≈ k * (pitch - alpha0) * (1 - something*mu)
double Ct = Ct_coeff * pitch * (1.0 - 0.15 * std::abs(v_axial) / (tip_speed + 1e-6));
Ct = clamp(Ct, 0.0, 0.25);
return Ct * rho * area() * tip_speed * tip_speed;
}
// Torque about rotor axis
double torque(double rho, double v_axial) const {
double Om = omega();
double tip_speed = Om * radius;
double Cq = Cq_coeff * pitch * (1.0 + 0.3 * std::abs(v_axial)/(tip_speed+1e-6));
Cq = clamp(Cq, 0.0, 0.03);
return Cq * rho * area() * radius * tip_speed * tip_speed;
}
// Force & moment contribution in body frame
void forcesAndMoments(double rho, const Vec3& bodyVel, const Vec3& bodyOmega,
Vec3& F_out, Vec3& M_out) const {
// Relative axial velocity (projection of velocity onto rotor axis)
Vec3 relVel = bodyVel + bodyOmega.cross(position);
double v_ax = relVel.dot(axis);
double T = thrust(rho, v_ax);
double Q = torque(rho, v_ax);
// Thrust force along axis
Vec3 F = axis * T;
// Reaction torque opposite to rotation
double sign = clockwise ? 1.0 : -1.0;
Vec3 M_torque = axis * (Q * sign);
// Moment due to force offset from CoM
Vec3 M_force = position.cross(F);
F_out = F;
M_out = M_torque + M_force;
}
};
// ---------------------------------------------------------------------------
// Rigid-body 6-DOF state
// ---------------------------------------------------------------------------
struct State {
Vec3 pos; // inertial position (NED-ish: x North, y East, z Down)
Vec3 vel; // inertial velocity
Vec3 euler; // roll, pitch, yaw (rad)
Vec3 omega; // body angular rates (p,q,r)
State() = default;
};
// Direction cosine matrix (body to inertial) from Euler angles (ZYX)
struct DCM {
std::array<std::array<double,3>,3> m;
static DCM fromEuler(const Vec3& e) {
double cphi = std::cos(e.x), sphi = std::sin(e.x);
double cth = std::cos(e.y), sth = std::sin(e.y);
double cpsi = std::cos(e.z), spsi = std::sin(e.z);
DCM d;
// ZYX rotation
d.m[0][0] = cth*cpsi;
d.m[0][1] = cth*spsi;
d.m[0][2] = -sth;
d.m[1][0] = sphi*sth*cpsi - cphi*spsi;
d.m[1][1] = sphi*sth*spsi + cphi*cpsi;
d.m[1][2] = sphi*cth;
d.m[2][0] = cphi*sth*cpsi + sphi*spsi;
d.m[2][1] = cphi*sth*spsi - sphi*cpsi;
d.m[2][2] = cphi*cth;
return d;
}
Vec3 transform(const Vec3& v) const {
return {
m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z,
m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z,
m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z
};
}
Vec3 inverseTransform(const Vec3& v) const {
// transpose because orthonormal
return {
m[0][0]*v.x + m[1][0]*v.y + m[2][0]*v.z,
m[0][1]*v.x + m[1][1]*v.y + m[2][1]*v.z,
m[0][2]*v.x + m[1][2]*v.y + m[2][2]*v.z
};
}
};
// ---------------------------------------------------------------------------
// Drone configuration
// ---------------------------------------------------------------------------
struct Drone {
double mass;
Vec3 inertia; // principal moments (Ixx, Iyy, Izz)
std::vector<Rotor> rotors;
double Cd_body; // body drag coefficient
double refArea; // reference area for body drag
double armLength;
Drone(double m, const Vec3& I, double arm)
: mass(m), inertia(I), Cd_body(0.8), refArea(0.05), armLength(arm)
{
// X configuration, 4 rotors
// Front-right, rear-left clockwise; others counter-clockwise
double a = arm * std::cos(M_PI/4.0);
rotors.emplace_back(0.12, 0.025, 2, deg2rad(12.0),
Vec3{ a, a, 0.02}, Vec3{0,0,-1}, true); // FR
rotors.emplace_back(0.12, 0.025, 2, deg2rad(12.0),
Vec3{-a, a, 0.02}, Vec3{0,0,-1}, false); // FL
rotors.emplace_back(0.12, 0.025, 2, deg2rad(12.0),
Vec3{-a, -a, 0.02}, Vec3{0,0,-1}, true); // RL
rotors.emplace_back(0.12, 0.025, 2, deg2rad(12.0),
Vec3{ a, -a, 0.02}, Vec3{0,0,-1}, false); // RR
}
void setRPMs(const std::array<double,4>& rpms) {
for (size_t i = 0; i < 4; ++i) rotors[i].rpm = rpms[i];
}
// Compute total force & moment in body frame
void computeForcesMoments(const State& s, double rho,
Vec3& F_body, Vec3& M_body) const {
F_body = {0,0,0};
M_body = {0,0,0};
// Rotor contributions
for (const auto& r : rotors) {
Vec3 Fr, Mr;
r.forcesAndMoments(rho, s.vel, s.omega, Fr, Mr); // NOTE: using inertial vel!
F_body += Fr;
M_body += Mr;
}
// Body aerodynamic drag (simple quadratic, opposite to velocity)
// Transform inertial velocity to body frame
DCM dcm = DCM::fromEuler(s.euler);
Vec3 vel_body = dcm.inverseTransform(s.vel);
double v = vel_body.norm();
if (v > 1e-3) {
Vec3 drag_dir = vel_body.normalized() * (-1.0);
double q = 0.5 * rho * v * v;
F_body += drag_dir * (q * Cd_body * refArea);
}
// Gravity in body frame
Vec3 g_inertial{0, 0, g}; // NED: +z down
Vec3 g_body = dcm.inverseTransform(g_inertial);
F_body += g_body * mass;
}
};
// ---------------------------------------------------------------------------
// Numerical integration (RK4)
// ---------------------------------------------------------------------------
struct Derivatives {
Vec3 dpos;
Vec3 dvel;
Vec3 deuler;
Vec3 domega;
};
Derivatives computeDerivatives(const Drone& drone, const State& s, double rho) {
Derivatives d;
// Position derivative = velocity
d.dpos = s.vel;
// Force & moment
Vec3 Fb, Mb;
drone.computeForcesMoments(s, rho, Fb, Mb);
// Acceleration in inertial frame
DCM dcm = DCM::fromEuler(s.euler);
Vec3 F_inertial = dcm.transform(Fb);
d.dvel = F_inertial / drone.mass;
// Euler angle rates (kinematic equations)
double phi = s.euler.x, th = s.euler.y;
double p = s.omega.x, q = s.omega.y, r = s.omega.z;
d.deuler.x = p + std::sin(phi)*std::tan(th)*q + std::cos(phi)*std::tan(th)*r;
d.deuler.y = std::cos(phi)*q - std::sin(phi)*r;
d.deuler.z = (std::sin(phi)/std::cos(th))*q + (std::cos(phi)/std::cos(th))*r;
// Angular acceleration (Euler equations for principal axes)
// I * domega = M - omega × (I omega)
Vec3 Iomega{drone.inertia.x * p, drone.inertia.y * q, drone.inertia.z * r};
Vec3 gyro = s.omega.cross(Iomega);
d.domega.x = (Mb.x - gyro.x) / drone.inertia.x;
d.domega.y = (Mb.y - gyro.y) / drone.inertia.y;
d.domega.z = (Mb.z - gyro.z) / drone.inertia.z;
return d;
}
State rk4Step(const Drone& drone, const State& s, double dt, double rho) {
auto addScaled = [](const State& a, const Derivatives& d, double k) {
State r = a;
r.pos += d.dpos * k;
r.vel += d.dvel * k;
r.euler += d.deuler * k;
r.omega += d.domega * k;
return r;
};
Derivatives k1 = computeDerivatives(drone, s, rho);
State s2 = addScaled(s, k1, dt*0.5);
Derivatives k2 = computeDerivatives(drone, s2, rho);
State s3 = addScaled(s, k2, dt*0.5);
Derivatives k3 = computeDerivatives(drone, s3, rho);
State s4 = addScaled(s, k3, dt);
Derivatives k4 = computeDerivatives(drone, s4, rho);
State next = s;
next.pos += (k1.dpos + 2.0*k2.dpos + 2.0*k3.dpos + k4.dpos) * (dt/6.0);
next.vel += (k1.dvel + 2.0*k2.dvel + 2.0*k3.dvel + k4.dvel) * (dt/6.0);
next.euler += (k1.deuler + 2.0*k2.deuler + 2.0*k3.deuler + k4.deuler) * (dt/6.0);
next.omega += (k1.domega + 2.0*k2.domega + 2.0*k3.domega + k4.domega) * (dt/6.0);
// Keep yaw in [-pi, pi]
while (next.euler.z > M_PI) next.euler.z -= 2.0*M_PI;
while (next.euler.z < -M_PI) next.euler.z += 2.0*M_PI;
return next;
}
// ---------------------------------------------------------------------------
// Simple attitude / altitude controller (PID-ish)
// ---------------------------------------------------------------------------
struct Controller {
double targetAlt = 5.0;
double targetYaw = 0.0;
double hoverRPM = 4500.0;
// gains
double Kp_alt = 800.0, Kd_alt = 400.0;
double Kp_att = 120.0, Kd_att = 40.0;
double Kp_yaw = 60.0, Kd_yaw = 25.0;
std::array<double,4> update(const State& s, double dt) {
// Altitude error (NED: z positive down → altitude = -pos.z)
double alt = -s.pos.z;
double alt_err = targetAlt - alt;
double vz = -s.vel.z; // climb rate positive up
double thrust_cmd = hoverRPM + Kp_alt * alt_err - Kd_alt * vz;
// Attitude: simple PD on roll/pitch, yaw rate damping
double roll_err = 0.0 - s.euler.x;
double pitch_err = 0.0 - s.euler.y;
double yaw_err = targetYaw - s.euler.z;
// wrap yaw error
while (yaw_err > M_PI) yaw_err -= 2*M_PI;
while (yaw_err < -M_PI) yaw_err += 2*M_PI;
double droll = Kp_att * roll_err - Kd_att * s.omega.x;
double dpitch = Kp_att * pitch_err - Kd_att * s.omega.y;
double dyaw = Kp_yaw * yaw_err - Kd_yaw * s.omega.z;
// Mixer (X configuration)
// FR, FL, RL, RR
std::array<double,4> rpm;
rpm[0] = thrust_cmd - droll + dpitch - dyaw; // FR
rpm[1] = thrust_cmd + droll + dpitch + dyaw; // FL
rpm[2] = thrust_cmd + droll - dpitch - dyaw; // RL
rpm[3] = thrust_cmd - droll - dpitch + dyaw; // RR
for (auto& r : rpm) r = clamp(r, 1000.0, 9000.0);
return rpm;
}
};
// ---------------------------------------------------------------------------
// Main simulation
// ---------------------------------------------------------------------------
int main() {
std::cout << "=== Drone Aerodynamics Simulation ===\n\n";
// Create a 1.2 kg quadrotor with ~0.25 m arm
Drone drone(1.2, Vec3{0.015, 0.015, 0.025}, 0.25);
State state;
state.pos = {0.0, 0.0, -0.1}; // start almost on ground
state.vel = {0,0,0};
state.euler = {0.05, -0.03, 0.1}; // small initial attitude error
state.omega = {0,0,0};
Controller ctrl;
ctrl.targetAlt = 8.0;
ctrl.hoverRPM = 4800.0; // approximate hover
const double dt = 0.002; // 500 Hz
const double t_end = 12.0;
double t = 0.0;
std::ofstream log("drone_log.csv");
log << "t,x,y,z,vx,vy,vz,roll,pitch,yaw,p,q,r,rpm0,rpm1,rpm2,rpm3,rho\n";
std::cout << std::fixed << std::setprecision(3);
std::cout << "Time Alt Roll Pitch Yaw |V| RPMs\n";
std::cout << "----------------------------------------------------------\n";
int step = 0;
while (t < t_end) {
double rho = Atmosphere::density(-state.pos.z); // altitude = -z
auto rpms = ctrl.update(state, dt);
drone.setRPMs(rpms);
state = rk4Step(drone, state, dt, rho);
// Ground collision (simple)
if (state.pos.z > 0.0) {
state.pos.z = 0.0;
state.vel.z = std::min(0.0, state.vel.z);
// crude friction
state.vel.x *= 0.8;
state.vel.y *= 0.8;
state.omega *= 0.5;
}
if (step % 250 == 0) { // print every 0.5 s
double alt = -state.pos.z;
double spd = state.vel.norm();
std::cout << std::setw(5) << t
<< " " << std::setw(6) << alt
<< " " << std::setw(6) << rad2deg(state.euler.x)
<< " " << std::setw(6) << rad2deg(state.euler.y)
<< " " << std::setw(6) << rad2deg(state.euler.z)
<< " " << std::setw(5) << spd
<< " [" << int(rpms[0]) << "," << int(rpms[1])
<< "," << int(rpms[2]) << "," << int(rpms[3]) << "]\n";
}
log << t << ","
<< state.pos.x << "," << state.pos.y << "," << state.pos.z << ","
<< state.vel.x << "," << state.vel.y << "," << state.vel.z << ","
<< state.euler.x << "," << state.euler.y << "," << state.euler.z << ","
<< state.omega.x << "," << state.omega.y << "," << state.omega.z << ","
<< rpms[0] << "," << rpms[1] << "," << rpms[2] << "," << rpms[3] << ","
<< rho << "\n";
t += dt;
++step;
}
log.close();
std::cout << "\nSimulation finished. Log written to drone_log.csv\n";
std::cout << "Final altitude : " << -state.pos.z << " m\n";
std::cout << "Final attitude : roll=" << rad2deg(state.euler.x)
<< "° pitch=" << rad2deg(state.euler.y)
<< "° yaw=" << rad2deg(state.euler.z) << "°\n";
return 0;
}
r/CodingHelp • u/piengepool • 13d ago
[Java] Swing help. Image gets distorted when partially outside window.
I have a JPanel class that draws an image on screen with camera panning. The camera is zoomed in. The image being drawn is a 16x16 Minecraft dirt.
When the image is entirely inside the window, it looks fine. When partially outside the window, it distorts and makes the image narrower to fit it inside the window. Eventually it snaps to the next pixel.
Does anyone know why this happens and how to fix it?
I'm using:
MacBook Air M1
Java 25
IntelliJ
The entire class is below.
public class CameraPanel extends JPanel{
public static void main(String[] args) throws IOException{
JFrame frame = new JFrame("Camera");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new CameraPanel());
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private double cameraX, cameraY;
private double zoom = 10.0;
private Point lastMousePosition;
private BufferedImage image = ImageIO.read(new File("src/test/resources/dirt.png"));
public CameraPanel() throws IOException{
addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
lastMousePosition = e.getPoint();
}
public void mouseReleased(MouseEvent e){
lastMousePosition = null;
}
});
addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e){
if(lastMousePosition == null){
return;
}
cameraX += e.getX() - lastMousePosition.x;
cameraY += e.getY() - lastMousePosition.y;
lastMousePosition = e.getPoint();
repaint();
}
});
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(
RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR
);
AffineTransform transform = new AffineTransform();
transform.translate(cameraX, cameraY);
transform.scale(zoom, zoom);
g2.drawImage(image, transform, null);
}
}r/CodingHelp • u/BlueMountain8080 • 13d ago
[Java] Coding Interview Question for Software Developer
I was asked in a recent interview, "What software do you use for API's?" I froze like a deer in headlights! Nothing came to mind. And I knew that the person asking the question had been a lead dev for 8 years. My answer was, "I use Intelli J."
Thankfully, there wasn't a follow-up question!
What could I have said that would have been a better answer? What are some software platforms to integrate API's from one software to another?
Thanks in advance!
r/CodingHelp • u/colnelali • 14d ago
[Python] How do I extract mathematical language accurately from a pdf using python
Tried alot, can't get to any solution. Special characters or diamond question marks appear etc but the accurate and understandable text doesn't. I'm looking for a library or a method which can address this, extract complex characters e.g. set notations or special characters in maths and fractions etc etc
if anybody can help,
thanks alot
APPRECIATE THAT
r/CodingHelp • u/Ashamed-Job-5491 • 14d ago
[Python] I built Last Signal: an offline-first forensic CLI that investigates why AI agents fail
I've been working on a problem that I think will become increasingly relevant as autonomous AI agents become more common.
What happens when an AI agent doesn't actually make progress, but keeps executing anyway?
Imagine this:
An agent calls a tool.
The tool fails.
The agent retries.
It fails again.
The agent enters an unproductive retry cycle.
Eventually, the process crashes.
You have execution logs, timestamps, tool calls, and error messages. But reconstructing the complete failure sequence and determining what actually went wrong can be surprisingly tedious.
Existing monitoring solutions can tell you that something failed. Raw logs tell you what happened. But identifying recurring failure patterns and distinguishing explicit evidence from inferred causes requires additional investigation.
So I built Last Signal, an open-source, offline-first digital forensics CLI for failed AI-agent executions.
What does it do?
Last Signal supervises agent processes and reconstructs their execution traces to perform evidence-grounded digital autopsies.
It currently detects four failure patterns:
Repeated Tool Failure: Identifies repeated operational failures associated with a tool.
Unproductive Retry Loop: Detects retries without a subsequent recorded success.
Terminal Tool Failure: Identifies a tool failure immediately preceding process termination.
Unrecovered Execution Failure: Detects fatal execution failures without a recorded recovery path.
The interesting part is how the analysis works.
Instead of asking an LLM to guess why an agent failed, Last Signal applies deterministic rules first.
Optional local AI through Ollama can then interpret the findings and suggest recovery strategies.
Deterministic ground truth first. AI interpretation second.
Technical details
Python 3.10+
Typer and Rich
JSONL execution traces
Deterministic failure-detection engine
Ollama for optional local AI analysis
GitHub-flavored Markdown autopsy reports
The forensic core works without cloud AI services, and deterministic analysis can run without Ollama.
Installation
pip install last-signalPublished on PyPI: v0.1.0
Links
Documentation: https://lastsignaldocs-five.vercel.app/
Looking for contributors
The current implementation is Python-based. One of my next goals is developing a native TypeScript module so the same forensic capabilities can eventually reach the JavaScript ecosystem.
I'm particularly interested in collaborating with developers experienced in TypeScript, Node.js, and backend infrastructure.
If that sounds interesting, contributions and architectural discussions are welcome on GitHub.
I'd genuinely appreciate technical feedback, especially around the failure-detection rules, trace reconstruction, and how agent observability could be improved.
What failure patterns have you encountered when building autonomous AI agents that existing logging and monitoring tools made difficult to diagnose?
r/CodingHelp • u/DovahkinnPlays • 18d ago
[Help with getting started] need help with getting started with coding
i want to get started with coding and you know its about the journey not the destination so frick vibe coding, but i want to make a 3d game, i suck at coding but i want to learn, ive been looking for engines but they all seem to sketch or annoying, i was tempted on using source since i got into source modding for a bit but i discovered it aint open source, so what engine do i use and what tutorials (only experience i have with games in scratch and 3d is a raycasting game i made in scratch)
r/CodingHelp • u/Zealousideal_Cap2653 • 19d ago
Which one? I am interested in game developing and want to become a game dev.
Hi coders. I am 18. I will be going to university next year. I am interested in game developing, i want to make indie games and roblox games. The problem is that I am completely beginner to coding. which language should I learn first ?
r/CodingHelp • u/handsome-guy-here • 19d ago
[C] what is/are the best resources for learning web assembly?
yes, i already know C, although im at least aware that there are some special functions when applying it to web assembly
i'm going to school in a bit so i won't be able to read/answer your comments just yet sry