instruction stringlengths 34 36.1k |
|---|
I write embedded firmware using C++. A common job for firmware is to "handle" different types of "messages" (e.g., in a communication protocol). The "C" way of doing this would be a really big switch statement like so:
void handleMessage(const AbstractMessage& msg)
{
switch (msg.id())
{
case Message1::kId... |
Problem statement:
You are given an array of strings. Each element (string) of array is of size 2. You are supposed to find the length of shortest possible string such that every element of the array is a subsequence in that string. And we also have to return the number of such strings possible of that length.
Example ... |
I've been working as a test automation engineer for almost two years now. As expected, most of my job involves ensuring that the automation (primarily written in Python) is operational and reliable. However, I often find myself performing numerous tasks such as creating and maintaining test cases and test plans, debugg... |
When talking about having a rich domain model successfully, in real applications, it needs to, somehow, access some abstraction of complex functionality (instead of being a row state calculator the way we see in most examples).
But, is there any problem in using abstract classes with polymorphic properties to do this, ... |
I have lots of code like the following. An "Entity" type that has some numerical properties. To be able to reuse the arithmetic I write the arithmetic functions against an interface. I use extension methods, which are easy to use. I use similar extension methods to convert the numerical values into formatted text to di... |
In C programming, I have a set of information, and I have to ways of providing it to user:
construct a data structure and provide it as an object.
write a function to read them out and return them.
I used 2 for part of my project - some of my users expect to have those values available at compile-time, so function-li... |
Stack: ASP.NET Core + Razor + SQLite
TLDR: How do I rely solely on Facebook Login for authorization?
I am building an app with sole integration to Facebook for my Facebook group. Essentially it is a "bidding" platform where ultimately the buyer & seller will communicate directly outside my app.
From my initial planning... |
In the Netflix series Suits, Season 1, Episode 8 (Identity Crisis), the legal team, with the help of a hacker, is tasked with proving that a business magnate embezzled funds, splitting them and opening several different accounts across different overseas banks (i.e. to launder the funds via structuring). They know the... |
I'm interested in integrating with an external system which uses webhooks to notify clients of events. The system is very similar to Stripe - the REST endpoints have rate limits to avoid undue polling load and instead relies on clients/users receiving webhooks to keep track of state. In the rest of this post, I'll writ... |
In a multitenancy application where you create a new postgres database for each tenant, what's the best way to handle database connections on runtime?
Do you open and close connection on every request or do you leave a connection open once opened, if yes, won't you exceed the number of open connections and how do you c... |
I have a C-Style API with methods that return pointers to native objects, e.g.
EXPORT hs::Pose3d* getJointEndPose(dh::Joint* joint);
And in C#,
[DllImport("Solver.dll")]
public static extern IntPtr getJointEndPose(IntPtr j);
To make the API a little nicer, I would like to distinguish between the types that the IntPtr... |
After reading
What is a" feature envy" code and why is it considered a code smell?"
I know the following code is suffering from "feature envy":
public class Garden{
public float width;
public float height;
}
public class Owner{
Garden garden;
public float getAddLawnCost(){
... |
I've a issue that hasn't been answered for long. Say, using a class C as the member of class B that is the member of class A (or even deeper nested). When I design some classes I often design such nested classed. I know that it often makes trouble, for example, if you forget to initialze a member of such class, the cod... |
As the title says, Im thinking if it's a good practise to have classes that have Open and Close methods in the sense that they can be reused without a new instance being created again.
Also, if I want to use Dependency Injection with the class and use it with IoC, then I dont think I can pass for example a "filePath" a... |
I'm working on a website that, for all intents and purposes, functions as a Choose Your Own Adventure book rendered as a single page app (SPA). Starting at the left, this is the user experience:
Each (virtual) page is rendered from an HTML-like templating language, making the user experience dynamic; for example, the ... |
My application has to maintain a stateful object and update it periodically based on events received. I get an initial HTTP request to create this stateful object. After that the object has to be updated asynchronously(using RabbitMQ in my case).
On my initial HTTP request I create a domain object. I thought I'd just c... |
I am preparing to create my first .NET MAUI Blazor hybrid app. It is a relatively new technology so there aren't a ton of resources to look at, but of the ones I have found, they are all structured like so:
With standard .NET MAUI apps, most people use the MVVM design pattern from what I can tell. Those look like the ... |
For most apps I've built which deal with CRUD operations, I end up two very similar UI pages: one for the creation of the object, one for updating it.
An example would be StackExchange's UI for creating a question and the UI for editing a question (but very similar, but slightly different).
How can we minimize duplicat... |
For example, for a mobile frontend, you need to get all the data for rendering at once. The interface is divided into blocks, in which there can be both blocks with a catalog (categories) and other types, for example, banners with additional information, and they are all mixed on one page. Each block has a position num... |
One of the main guidelines I keep seeing for successfully building a microservice application is to use a separate database for each microservice. In diagrams these are usually depicted as physically separate databases.
My question is, could a single Postgres process that manages several separate databases be an accep... |
I have been told that Rust is both safer and faster than C++. If that is true, how can that be even possible? I mean, a safer language means that more code is written inside the compiler, right? More code means more instructions for the processor to process.
In this case, I'm thinking about arrays. In C and C++, you ca... |
I was reading the infrastructure persistence layer design documentation, and this quote has me confused:
This'll probably be my biggest feedback. I'm really not a fan of repositories, mainly because they hide the important details of the underlying persistence mechanism. It's why I go for MediatR for commands, too. I ... |
I'm making a piece of software that is able to recognize Magic the Gathering Cards from a picture or the actual camera.
The codebase scans for rectangular shapes (cards) in an image and calculates 64bit perceptual hashes for them, which get compared to a precompiled database of approximately 40.000 hashes for all the m... |
Currently I have an existing API for my AI Engine, and a python wrapper to interact with the API. So this wrapper acts like a helper class to help format and automate some of the process that is needed to call the API.
There are 2 ways to interact with the API
User (using Jupyter Notebook - python) => Python Wrapper =... |
I work on a SaaS system which is generally a single-tenant environment. Customers (whom the SaaS instances are for) would like a way to subscribe to events, such as updates of certain data entities. For the most part, it seems like a general Pub/Sub architecture, where our system publishes the message, and the customer... |
At the moment I design a RESTful API for a resource that is normally created by a cron job from existing data.
Since the cron job runs only every 10 minutes it is possible that GET: /user/{id}/resource returns a 404 Not Found.
In that case the client needs to create the resource with a POST request with an empty body I... |
I'm learning JavaScript and just came across "use strict". It sounds like to me it should always be in play but me being a beginner I was wondering if there are scenarios/environments when we should not use "use strict" (besides super old code that doesn't support it obviously).
|
I'm building an HTTP API database adapter that has an authentication component. Users can authenticate using password, federated login such as OAUTH, and JWT.
My initial design is something like the following:
pub enum AuthType {
Password,
Federated,
JWT,
}
pub struct Adapter {
pub client: reqwest::Cl... |
I know there have been many post about diamond problem, one of it: Why do you reduce multiple inheritance to the diamond problem?. But I'm not asking what it is or what is the solution of the problem. Also I'm not asking why multiple inheritance is bad. What I don't understand is, why is it a "problem"? Consider:
struc... |
I am currently reading Code Complete. And I was confused when the author in one case uses the term "detailed design", and in the other "design for construction". What is their difference? Or is it one and the same?
As I understand it, when developing architectural developments, it will be necessary to "apply processes"... |
AFAIK, APIs are a means by which two computers communicate with each other.
What exactly is REST API?
My confusion arises from this figure where a docker cli which is on the same host as the docker daemon requires REST API to communicate with each other. Isn't that weird? Why'd you need REST API to communicate in a sa... |
Say I have a simple layered .NET application, with three layers:
API
Adapters
Application
The application layer needs to use some typed http clients to communicate with external APIs. This means that the typed http clients cannot be put in the Infrastructure layer, unless interfaces are provided in the application (... |
I'm making a console application that returns a lot of information directly to the console. I do this with a custom logger. Actually my logger implementation is just a frontend to print (with some extras).
The application is quite complex and I made it in DDD style, but one thing doesn't work for me - almost every busi... |
When retreiving data with an api and saving it in a DTO, some values are nullable: null on initial class initialization but VS also warns you for this. For example, an employee:
public class EmployeeModel
{
public Guid Id { get; set; }
public int EmployeeNumber { get; set; }
public string? FirstName { get; ... |
I would like to represent tree structures in YAML. Each node of the tree is composed of a (key,value) pair. The key must be a string.
A structure like this would be perfect:
node1:
child_A:
child_AA:
child_AB: 1.2
child_B:
node2:
...except that I sometimes have nodes that have value... |
I often see /-/ in API design, what is it used for?
Is there any related documentation?
I have tried to find it in the following documents, but did not find any relevant information:
https://cloud.google.com/apis/design
https://google.aip.dev/general
https://learn.microsoft.com/en-us/azure/architecture/best-practices/... |
Currently my code base has 3 deployments, development : where devs unit test and develop features, testing : where testers run end user verification for the features and production : the deployment available to clients. The issue we're facing is that all 3 routinely go out of sync. One solution is to allow only develop... |
Can a use case use both extend and include?
For example like the "Take Advanced Knowledge Quest" use case in the picture below.
|
Say I am trying instantiate an instance of a Table. Table here denotes a restaurant table used for eating. Say I have 3 different table types
enum TableTypes {
SMALL,
MED,
LARGE
}
I have some questions on the best way for the following
Should I have 3 separate lists that hold available instances of 3 tabl... |
Let's take an example of Order.
An order can have the state new, canceled, shipped, or processing.
The new order can be processed.
The new order can be canceled.
The processing order can be shipped.
The processing order can be canceled.
The canceled order cannot be processed, shipped, or new.
The shipped order cannot ... |
I have a huge amount of files (mostly documents like pdf ~80-90%, but also images, videos, webpages, audio etc.), somewhere around 3.8 millions of files which occupies ~7.8Tb of hard drive space on a 10Tb hdd.
I have tested a lot of software from the internet (Windows and Linux) for removing duplicate files but it's ju... |
My company, which specializes in logistics and transportation, delegated the majority of the backend microservices to our team. All of the microservices (which our team inherited from "past generations") appear to have inconsistent input field validation. Mobile number format validation is a good example. There would u... |
I'm working with a RESTful API where a POST operation is used to create a user. A required field, which could be an email or a unique user nickname, is unique across the system. The response to this POST contains a unique id for the user, which is a deterministic hash calculated from this unique field. Therefore, the s... |
I've been reading a bit through Clean Code and I came across the Single Responsibility Principle. The principle states that every class should have only one responsibility.
An example taken from chatGPT gives me this:
#include <iostream>
#include <vector>
#include <string>
class Product {
public:
Product(std::stri... |
Looking for a good reason to avoid this solution.
Problem
Multiple microservices/SAAS, each storing the same data that needs to be synced (example is customer contact details).
1st is an OAuth microservice.
2nd is a CRM that supports Pub/Sub pattern.
3rd new microservice
possibly a 4th like marketing automation (Hubs... |
I'm not sure how to manage configuration settings in a C#/.NET environment. For simplicity lets say I have 3 assemblies: My MainApplication is the project being started and containing the business logic. It references a separate Configuration library, which reads numerous configuration values from a config.xml file tha... |
In the context of an object-oriented language, such as Dart, I have an abstract entity which has a single property called id (which is incrementally uniquely generated to make sure there are no-clashes).
Then, classes which extend Entity can add other properties on top of the Uid, which however are not final (i.e they ... |
Something like this
cmp $0, %eax
jl exit
jumps to the exit: label if the content of register eax is less than 0.
So it's kind of jl applies the < operator to the operands of cmp, but in reverse order, i.e. content-of-eax < 0.
Why is it like this, historically speaking?
Digital computers were born in the left-to-right ... |
Do RESTful endpoints eliminate the need to SQL triggers?
Triggers are supposed to execute after a certain event. Would moving to RESTful api endpoints conceptually eliminate the need for SQL triggers?
The reason being, effects triggered from an event can be managed purely by well constructed RESTful endpoints. This inc... |
I'm aiming to create a simple event-driven system where each microservice operates with its own database. The idea is to share database changes across microservices through events. To ensure proper event ordering, I'm considering a strategy where I use the unique ID of a database row as the event key. This way, events ... |
I've seen in several REST API guidelines recommendations to use filtering in form of, e.g.:
/products?filter=name eq 'Milk' or price lt 2.55
(example from: https://github.com/microsoft/api-guidelines/blob/vNext/Guidelines.md#971-filter-operations )
I tried to find a library that will help me to parse this kind of reque... |
I have a small open source package and I'm trying to automate parts of the release life cycle. I am very confused about how to automate version bumps. Here's the relevant information about my version bump procedure.
I'm working in Python. I define the version hardcoded as the __version__ attribute in __init__.py in th... |
From my understanding, in declarative programming, programmer only need to define the end result, but not how to compute it. But for execute that said function, the function must be pre-defined by the language, that instruct the machine to compute, step by step, for user to use in the first place - hence it implementat... |
I have a discussion with a colleague regarding how to model a command that immediately gets an answer to it's HTTP POST request back. In this specific case we do an API call to a 3rd party IDP API that we don't control, we'll do a HTTP post and get a response.
There are two statements from him regarding this:
Event St... |
I'm currently working on a Spring Boot application where I need to create an endpoint similar to the one mentioned in the Confluent Cloud documentation (link).
The cURL example provided in the documentation is as follows:
curl -X POST -H "Content-Type: application/json" -H \
"Authorization: Basic <BASE64-encoded-key-... |
I'm working with an API that uses OpenAPI for its schema documentation. However, there are certain fields in the request body that shouldn't be visible to all consumers, for example, internalProperty: bool. These properties are crucial for some internal functionalities but aren't documented in the public-facing schema.... |
I'm a novice in UML component diagrams.
How would I draw the following situation?
I have an << item >> called "DataAquisition". This item consists of a << unit >> called "driver". The driver requires an interface to the device, which is connected to the physical device. This is modeled by passing the interface through ... |
I write BFF (Backend For Frontend) and it's domain is to provide user info and microservices integration.
The User domain model looks like below:
public class User
{
public required Guid Id { get; set; }
public required string Name { get; set; }
public required AvatarUrl AvatarUrl { get; set; }
}
The domai... |
I recently finished an interview with a company as a web developer. I'm the first and only developer that is about to be hired in this company.
They have a web application that was created by a software company, and they have received the source code of the app.
Years went by, and now they want to refactor their web ap... |
I'm very new in DDD and I was following one of the videos of GohperCon to structure of my Golang App using DDD with Hexagonal Architecture. At the lowest (deepest) layer is the storage that can be Memory, JSON, SQL ...
I'm planning to use MySQL and I structured my storage directory as follow:
app
|
+- storage
|
+... |
According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I should declare the most abstract type as possible. However, in some cases I remember, especially for UI related codes, I can't declare the most abstract type because those UI object usually require to run some child... |
If I give a real example, I want to create a desktop software that includes:
electron js app that communicates with react js using IPC channels.
I need to communicate with software that only has a Python module. so I created a TCP server/client communication for this purpose.
I have a printer with C++ SDK. so I also c... |
I am working on a tool that scrubs Do-Not-Call (DNC) phone records from a skip-traced CSV file.
I have this PhoneModel for child phone entries for each row. It consist of the following fields:
isDNC
score (How accurate is the phone number for that record)
phoneType (Landline, Mobile, ...)
phoneNumber
date (last update... |
I'm reviewing some lecture slides and had a question on the following slide :
Assumptions (8 clocks to transfer data) Up to 3 outstanding load requests.
The slide is illustrating that the number of useful math instructions that can run is limited primarily by the memory bus bandwidth. Of course the "8 clocks to tra... |
I could not find anything regarding this question except some lecture notes about game design and a book which describes something similar but not quite the same.
General Description
The approach is as follows.
There are two kinds of state in an application: Core State and Derived State. The Core State is any state tha... |
When writing code on a desktop pc as well as on a laptop or other computer, is there a general recommended strategy for being able to keep the same environments set up on both machines?
I use Git heavily for keeping the code sync'd, VsCode has settings sync, Pip and NPM etc for packages, but there are other aspects of ... |
Suppose I need to find the last selected index of options according to last selected contents, eg: options : A,B,C,D,E ,last selected option: C, so the last selected index is 2.
There is a special case : If last selected option does not exist in current options (including case that no options), last selected index is 0... |
As an embedded firmware developer, I often write classes to represent/act as drivers for hardware on a microcontroller. These driver classes will usually contain pointers to hardware registers and other state variables.
Often, these drivers inherit from some generic interface. For example, assume I have the following... |
This question is inspired by comments on this recent question. In that question I asked about a version tagging workflow. A few commenters suggested it was a little strange that I'm tagging and releasing every new feature that is merged into main. It sounds like it is more typically to collect up a few new features and... |
Summary
I saw a solution to a problem described as having O(c) Time complexity where c is the number of unique items in n.
I don't understand why we can say the complexity is O(c) despite looping through all items.
Example
func foo(items: [Int]) {
var uniqueItems: Set<Int> = // ...
for i in items {
if ... |
I've been reading this Wikipedia article Composition over inheritance. It gives a code example of inheritance first, and then a code example of composition. In case of inheritance there are data that are present in form of the model field. When any of the methods draw, collide or update need to do their function, they ... |
According to When is a number a magic number?, I know magic number should not exists, so I know the following code about creating a Label from some UI framework and set the color RGB needs to be improved:
Magic number version:
Label* label=Label::create("someText");
label->setRGBColor(32,128,192);
to refactor it, eve... |
I'm working on an embedded C++ project that involves logging certain types of statistical data (like successful accesses, failed attempts, and other events) to the flash memory (just incrementing these values). Due to the nature of the system, power can be lost at any moment, making it important that all data is writte... |
At my org we extensively use @Value.Immutable annotation to generate Immutable classes (usually with builders) for our internal data transfer objects (DTOs). In our codebase I've seen both interfaces and abstract classes being used for such DTO definitions.
For example for a DeviceData DTO we could have an interface as... |
Consider a processing system which ingests objects from an external source and performs extensive processing. One example could be objects detected by a computer vision system which are then fed into a security alert system that looks for particular movement behaviors, and abnormal positioning.
The external object prov... |
I have three seperate fields and all three are unrelated to each other but part of the same collection (Tables for SQL folks).
Now, what I'm getting stuck at is, should I allow end-users to make one big PUT request to update the data in those fields or should I have the end-user send multiple PUT request.
One thing to ... |
Many times while writing MVVM apps in C# I've come across this sort of problem where I need to expose the model in a view model so that I can get it in another view model and do something with it.
Currently I have a model with a mutable list of nested models. The models are just data + serialization logic.
public inter... |
Powerful reflection capabilities make implementing nice architectural design patterns such as MVC and Dependency Injection very simple in languages like Java and Kotlin. In particular, reflective tags and annotations make it possible for a DI framework to "feel out" the layout of the program, "catch" controllers and vi... |
I'm working on a system and we need to do some refactoring on the upload service, that handles all files and images uploads to the system. Nothing fancy, but I it got me thinking about the folder structure we are using, and how others do, if there is any benefits doing one way or another.
For example, the folder struct... |
I was just reading a StackOverflow question here, about extracting the version number from a node package.json file. And the simple
'read in the json and access the property in your build tool'
got huge number of
'no no no you risk exposing all your dependency versions to the client'
-type responses.
But I'm a bit ... |
I have an android app in which I am trying to follow the MVVM arcitecture.
I have a Room database, abstracted by a Repository class that has methods like getAllData() which I use in my *ViewModel classes.
Now I want to quiery the data in the database, namely getAllData(), then filter, group and transform the data in di... |
Given a graph layout like the following image, where the layers/rows (y coordinate) and ordering of nodes within each layer have already been computed, what algorithm can I use to make it look "nicer"?
Just to clarify, all I am wanting to change is the X coordinate of each node. The y coordinate (the layer) should rem... |
I want to make my own pooling library.
By design, I want each poolable class to have a reference of the pool it came from, so ideally whenever the user wants to make a class poolable they'd have to inherit from some Poolable base class.
But that seems to immediately have major drawbacks in OOP design. If the user wants... |
How can I do conditional mapping in Domain Driven Design?
Let's say my application is structured like this:
- Core
- Domain
- Application
- Presentation
- DTOs
- API
I have an aggregate root called Post which also has a list subscribers to that post.
Here's the deal: Only the moderators are allowed to retrieve... |
I’m looking for some advice on best practices for Visual Studio workflows.
I maintain several C# libraries which I use in various projects I develop. I also make them available publicly, as packages on NuGet and as source code on GitHub.
Because I am often tinkering and tweaking my common libraries as I use them, I typ... |
In relation to another question I had, I have been researching Simulated Annealing.
The general example used with this algorithm is the traveling salesman example. I have been testing the code described here : https://jamesmccaffrey.wordpress.com/2021/12/01/the-traveling-salesman-problem-using-simulated-annealing-in-cs... |
My first introduction to object-oriented UML statecharts was the book "Practical Statecharts in C/C++" by Miro Samek. He proposes a framework in which the state machine is a single class and each state is a method within the class. Once you have developed a state machine, it is easy to inherit/extend its behavior sim... |
Can NIC handle(send/receive) multiple packets at once?
For example, 2 asynchronous tasks request 2 different things from a database. Are those 2 requests sent simultaneously by NIC? Also, are the responses interpreted simultaneously by NIC?
|
I am looking to enhance my skills in back-end technologies and would need your help in setting up a scalable microservices architecture.
Here's my project.
I have N sensors that send me data (Pressure, temperature, pollution, etc.) every second.
I would like to create a web interface that displays the latest known valu... |
I'm trying to solve the following problems here:
In the X world, companies have a hierarchical structure to form a large binary tree network (can be assumed to be a perfect binary tree). Thus every company has two sub companies as their children with the root as company X. The total number of companies in the structur... |
I built an app in the way that one context is closed in one package. However, as code grows there are more situations in which the code is duplicated. As I understand the package should contain everything that is needed for the given feature within its context. On the other hand, the dependencies between packages make ... |
In the Scrum framework, the Product Owner is the person responsible for preparing the backlog, refining it, and prioritizing it. He/she is expected to be a domain expert and somebody with enough technical knowledge to make meaningful decisions on what to prioritize first (with the involvement of the dev team, of course... |
Main execution thread creates asynchronous job (started and executed by different process) that works on same data that the main thread. For example we create some database entries, that we want to process asynchronously later, but choose not to do it in main thread. This creates a situation when main execution thread ... |
I have Projects table. Projects can have costs, so I have a Costs table. A cost can be because of a product or beacuse of a service. So I have 4 main tables:
Projects (IDProject, Description...)
Costs(IDCost, price, quantity, IDProject...)
Products (IDProduct, IDProvider, Reference, Description...)
Services (IDService... |
I have a rich client with quite complex domain logic and I want to keep the domain and presentation layer separated. How would you advice to intergrate the domain logic with the UI in this case.
I implemented in the domain objects and services in following fashion
public class ProductOrder
{
public double SomePara... |
A bit of architecture here, I want to determine if there is any concern(s) about it.
The interesting part, in diagram below, is the communication between the Local Service and the browser that a user is running. The browser makes requests to the remote service API, but would also do requests to a Local Service (using ... |
So I am designing some microservices that communicate via messaging and event queues.
However, if I update a message class, for example remove a field, this will break several participating microservices and require a redeployment. I can see microservices can be deployed independently, but not if there is a central cha... |
I'm writing a compiler in Rust. I've reached the point where I have an AST and am ready to do symbol resolution, type-checking, etc. But, I'm unsure of how to represent an AST as containing "unresolved" symbols and "resolved" symbols.
Background
To achieve separation of concerns, I'm first passing over the AST to resol... |
I am an inexperienced developer fresh out of college. I was handed a Windows Forms Application to work on.
The application previously relied on system time. They wanted me to make it so that we could adjust the time within the application. No problem at all for me, I just added in some number selectors for up to +/- 23... |
Question
I'm working on a C#/.NET Core project, and I'm looking for guidance on organizing interfaces, especially when it comes to using NSubstitute, Moq or other libraries for mocking, because there I need an interface. I've explored different approaches and would like to gather insights from the community.
Inside De... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.