instruction stringlengths 34 36.1k |
|---|
I'm creating a class representation of a mathematical tuple (or simply, an ordered set of numbers). Being a list-like object that could benefit from an iterator representation, I have decided to give it one. By following this tutorial, I have found little difficulty in creating the iterator class.
What I do not underst... |
I have a situation where let's say I have a folder called logs which has N folders.
Each folder contains events for a specific event type and each folder has N .log files where each file has multiple lines of JSON.
Example:
event1.1.log
{"id":1, "name": "ABCD"}
{"id":2, "name": "EFGH"}
{"id":5, "name": "IJKL"}
{"id":7,... |
I'm trying to create a REST API that allows the user to:
create a resource if it doesn't exist.
update a resource if it exists.
with the same request.
Given an example: I have a company that has many employees. I know that the way that usually an employee is inserted is using something like do a post request to /empl... |
DataModel contains a Proof that contains all the information of its integrity along with the method with which the Proof should be verified.
In this case I designed a JWS type of proof that can be generated by using a ProofGenerator object that contains the private key to calculate the Proof. However each time a DataMo... |
We are creating a SPA, and thus the frontend is more than just a view for backend generated pages.
Now to create an "entry" you normally press create, and then fill in the data for that entry in the resulting page. (as admin you can view and edit in the same page that others can view).
to help generation we created a "... |
Let me try to clarify my question with an example. Assume a library of some sort which has a built in logging system and it is published as Library.Core. As the maintainer you want to add a wrapper around your logging system to add support for Microsoft.Extensions.Logging. You create a working implementation and publis... |
Is a "wrong" to return anything else besides this in a constructor?
Take this TypeScript Queue sample:
class Queue {
private buffer: string;
constructor(buffer: string = "") {
this.buffer = buffer;
}
push(n: string): Queue {
return new Queue(this.get() + n);
}
get(): string {... |
I am reading up on system design concepts, specifically DataBase replication and partitioning. I understand that partitioning is used to improve throughput, and/or when the amount of data is high i.e. basically to improve scalability. But at what point do I need partitioning?
Eg. If I have a single table in my OLTP DB ... |
We have to make a bunch of HTTP calls from Java/Spring-Boot application which will be mix of in-sequence and parallel.
Level 1 : We make 3 parallel calls to Services 1 , 2 and 3
Level 2: After service 1 response is received (which is a list), we make parallel calls to service 4 and 5 for each item in list
Level 3 : Aft... |
I know the lifetime of the controller class is transient by default, but I think it's better to be singleton. should explain to me why creators choose transient instead of singleton or scope lifetime?
Thanks a lot
|
I'm in a dilema where I'm translation a full mobile app where the translations are going to be a key value pair but I'm not sure how to name the key.
Should I name the keys describing what the text is, like (key: ok, text: Ok), or should I name the key from where it is on the screen/context, like (key: screenXButton, t... |
I need a good approach to declare a lot of variables over a context. For exmaple in kubeflow, I need declare a pipeline with a lot components in order to do that, I use the following code:
component_1_op = comp.load_component(
'path/to/component/1')
...
component_n_op = comp.load_component(
'path/to/component/n... |
I have method with the following prototype :
R[] = method(k,n)
which :
n = ordinal value 0 <n <10^9
k = math function depend on n value : i.e n^6
R = array of computed values
For example :
n = 10^8
k = n ^2
so then :
n [index]= 1,2,3,...,10^8
R [index]= 1,4,9,..,..
I dont want to do the common solution : iterate an... |
I am trying to implement a basic bytecode VM, which I plan to target with a compiler. How can I implement the ability to call external C functions using the bytecode, i.e., call arbitrary functions in runtime. For example, my future compiler should be able to produce programs that call printf(), malloc(), etc. My guess... |
So the current setup is a typical event sourced system built on AWS: Lambdas exposed with API Gateway to get the orders (commands), the domain (aggregates) apply some validations after loading the aggregate, publish all events in the event store (DynamoDB).
Where things get interesting! How to react to these events! So... |
I'm currently brushing up and learning about a bunch of techniques to hopefully begin implementing in my own workflow; one of which is IoC (and DI in particular).
I'm hoping someone could clear up my confusion I have reading two articles about the subject:
In this post, the author seems to demonstrate that you can use ... |
So, I have an entity called Consultation that is being used as a member variable of the class VideoCallViewModel that goes like this:
struct Consultation: Equatable {
enum Status: Int, CaseIterable {
case pending = 100
case dropped = 150
case ready = 200
case created = 300
ca... |
I have to manage multilingual information in JSON documents in a MongoDB/Mongoose context. But I'm in a dilemma regarding best the format to use with a view to performance metrics:
I'm currently considering two formats (data is left empty):
// English translation in top level, and all of the others language are
// kept... |
When using collaborative applications like issue trackers, planning tools, etc. it can be very frustrating to have to keep hitting refresh to make sure you're viewing the same state as your colleagues. Therefore I want to build my applications so that when one user changes something, it shows up on everyone's screens. ... |
When an entity is changed, I want to raise an event to notify potential consumers about the state changes. My question is, should I have
an xxxChanged event for each attribute, or
a single EntityChanged event that identifies which attributes changed?
Having more specific events seems better to me, as consumers can s... |
I'm creating an application using the jigsaw modules system. The app will just perform some tasks in multithreaded environment. In my mind the app architecture (modules) looks like that:
Work (the task implementations and management plus some related
stuff)
UI (graphical/text based representation of data present in Wo... |
DevOps of our customer require that our application creates database objects and Kafka topics automatically on application start, if they are missing. Moreover, they want the application to automatically upgrade the database model, if it has changed (e.g. by using Liquibase).
My response is: Do not want us to do that i... |
I am developing a simulator of a bank software system, where each operation (deposit, withdraw, transfer, ...) is just a string.
I have 5 main classes :
Bank where bank accounts are stored.
CommandValidator that takes a command (string) then decides whether it is valid or not (through its validate(string) method) accor... |
How does changing the video quality works behind the scene? Suppose I am watching a video on youtube (I will use YT as an example in this question) and suddenly my internet speed becomes slow, in that case YT automatically (or sometimes I as a user) change the quality to some lower resolution. But the video does not st... |
I have an UI module that will expose only one class - UserInterface. The class will be responsible for collecting user input and providing output (command line UI style). From logical way of thinking, I'd never need more than one instance of the UserInterface class.
Should I enforce only one instance using design like ... |
The average utility class: A stateless class that provides some functionality by exposing static methods. Its default constructor is private to avoid instantiation. When ever the average utility class is used, a hard dependency is created.
So, referencing the utility class is the way to invoke a desired method. But cou... |
I have a Python application using SQLAlchemy. It uses around 15 database tables.
For example, I have an image table that lists image files manipulated by the application. Most operations involving that image have side-effects both on the filesystem and on the database.
To keep this easy to test and de-couple the logic ... |
For the last several years, I've been checking all dependencies of my team's nodejs project into source control. At first, we stored the archives of all dependencies using yarn v1's offline mirror, now we store zips using yarn v2's cache feature.
The reason I felt like it was a good idea to do this is package security... |
There are 2 independently functioning web applications. Web-app1: (Flutter+Django+Postgres). Web-app2: (Angular+Spring+Postgres). Each of the web-apps has its own user database and are functioning independently. It is now decided to integrate the 2 apps such that Web-app2(Spring) will no more have it's regular users in... |
I am trying to model APIs for
Create shipments
Fetch Available shipments (based on region preferences)
Accept shipments (allows logged in user to accept multiple shipments on first come first serve basis )
Allocate shipments (allows logged in user to allocate multiple shipments to driver, shipments must be accepted fi... |
This question is vaguely Internet of Things (IoT) related - but it's about the intra-net (no external internet connection in this scenario - we are air-gapped). Let's say I have a new smart household appliance. This smart appliance can connect to my wi-fi and has a built-in HTTP server that you can contact with your ... |
I am a junior developer and my typical senior developer just got fired and while they try to replace him I shall ask you.
I have an API that returns some internal data of ours in increments of 200 per call. There are about 40,000 pieces of data that I need to grab each week or 200 calls that need to be made to this API... |
In particular I am wondering if it is acceptable to have an instance variable that can be calculated by other instance variables (i.e. during the creation of the object)?
On one hand I see the data dependency and information redundancy as a possible issue. However on the other hand performance will suffer if the value ... |
For fun, I'm developing a multi-player card game. I plan to run it on a single cheap VPS, so deployment would have to kill the process and re-start it with the new code. There is no Load Balancer. I'm okay with deployment causing a few minute outage, but not losing game state. I want to use websockets or real sockets, ... |
I am working on a small project and I tried to represent the following two requirements in my diagram:
An album may be performed by either a singer or a band (not both).
My plan to implement this requirement is to create a producer class that combine both singers and bands to guarantee that only one of them has perfor... |
I have read that objects contain the actions it can perform as functions and its attributes as variables. But i am getting confused with objects that don't seem to perform any actions such as an integer, quadtree and set.
I know that we can represent these "non-real objects" as abstract data types. But this is differen... |
I'm going through a beginner programming learning guides and the teacher brings up the try catch block paradigm.
The code you put in the try block is run and if an error happens the code in the catch block is run. Your application should recover from it.
try {
// do something that might throw an error
}
catch (exce... |
I want to learn firestore and to this end I created small project which replicates instagram. Not all functionalities of course, just the very basics - photo sharing, comments and the possibility to report a comment or a photo.
This is how my current collections look like:
users -> user_id -> [username, email]
followin... |
i want to set up basic login page in xamarin.forms. There is no username/password, just a simple pin
so far i have 3 pages to do this
Sign-up Pin page
Sign-up Confirm Pin Page (re-enter pin to confirm)
Sign-in Pin Page
Main app page
my project flow as follows:
1st time user, will be prompt to "Sign-up Pin Page", tha... |
I have a background as a full stack web developer, but didn't code professionally speaking for about 8 years, now focusing on technical and/or functional analysis. In the meanwhile, many things changed of course, and I'm now trying to "refresh" my understanding of how modern web can be rendered, so that I can still at ... |
I'm aware that it's generally considered bad style to write tests that have to run in a particular order. Let's say I'm testing an account-management API, and have the following two integration tests: test_create_account, and test_log_in. What I understand to be the correct style for this would be something to the effe... |
I understand their own characteristics but a lot of articles focus on comparing the two methods but never talked about they serve different purposes within SOA.
Eg. Example of ticket system and identity management.
When creating a ticket I can assign to a person from a list, which the list gets from identity managemen... |
Consider the following java code:
public class Foo {
private Bar bar;
....
public Bar xxxBar() {
if (this.bar == null) {
//resolve bar
this.bar = resolvedBar;
}
return this.bar;
}
...
}
The idea of xxxBar method is to do resolving only once and ... |
So I have been down the rabbit hole of finding that HTML forms don't support DELETE requests, and then looking into mimicking the the behaviour with a Javascript fetch request (but it is not straightforward to implement in Javascript). The way I see it, with or without Javascript, there are 3 options available:
Have a... |
Problem description
I have an IoT app that provides a server backend and browser UI client for interfacing with proprietary control systems. Some deployments of this application will require that the server is not publicly accessible on the internet; instead, the hardware will often be part of a network managed by the ... |
I'm quite unexperienced in the sysadmin area. Now I'm facing the responsability of managing two (remote) servers. I'm working in an informal organization.
So I have passwords for the OS's users, database users and so on.
I want to be able to store the access information securely in case someone else has to take my plac... |
Let's say I want to make a class for a car. A car has an engine, transmission, steering, radio, ... Each of these parts have its own internal state, so in C++ it makes sense to use composition like this:
class Car {
public:
Engine engine;
Transmission transmission;
Steering steering;
Radio radio;
};
On the... |
This is somewhat similar to this question but I could not find a solution there.
I have a project that I've worked on over the past 4 years. I started without any Python knowledge and learned as I went along, so there is a lot of legacy code and weird things that work but could break easily. I'm redoing this project wi... |
I was reading this article, and the author uses HTTP long polling to design a chat application.
I was wondering how does this compare with a dedicated Message Broker services like Apache Kafka, or RabbitMQ. I'm trying to understand system design, and I am confused about HTTP Long Polling.
Is it something can work with... |
Microsoft suggests to inject ILazyLoader service inside entities in order to enable lazy loading manually in EF:
https://docs.microsoft.com/en-us/ef/core/querying/related-data/lazy#lazy-loading-without-proxies
So this is a little weird to me to do such thing, as it obviously contradicts separation of concerns in layers... |
I'm trying to design a system to buy mangoes (not really mangoes, but it's a good proxy). One mango is the same as the other. These are very high-in-demand mangoes; quite possible many people at once will try to get a mango and there is a fixed amount of inventory.
Users will reserve a mango first, securing it for them... |
For example, I create an API endpoint that provides the next available label for creating some items, so I call it like this:
GET /api/v1/get-next-label/
Is it ok to return just:
LBL-000001
Or is it better practice / or there is an argument to return something like:
{
"label": "LBL-00001"
}
|
I have a use case for which a user can perform a multiselection. I am writing the use case description and wonder: Should the selection action be documented as a trigger of the use case, or in the main success scenario?
Below are the variants I am considering. I think the last one is probably best, but I'm not sure if ... |
It often happens that we have a set of structured data. Let's say our data is about charitable organizations. I could turn it into a list/set of objects/structs:
struct Charity {
let name: String
let yearFounded: Int
let volunteerCount: Int
}
I could also think about it as a table (possibly using the Python P... |
I'm working on implementing a language server and corresponding Visual Studio Code extension for a small scripting language. The language server is implemented in Rust, so I can generate binaries that the VS Code extension can execute to support several editor features. I am trying to decide how to handle distributing ... |
I'm in a scenario where, when a certain command is applied on an aggregate, I have to
change the state of the aggregate itself
if ALL related aggregates are in the same state, then notify the world outside
here is an example (in pseudocode)
finishRace(raceId, carId)
cars = repository.findCarsByRaceId(raceId)
... |
I want to warn devs in my team to rebuild the docker containers after installing or updating npm packages.
This is because whenever we edit packages in the environment the only way we've found to test them is to clean the entire build and rebuild everything to re-install everything the way it would be installed in the ... |
I'm modeling a general RPG-game-style quest system where player choices lead to certain effects. The below examples have been simplified for the sake of clarity. This is a web-based context, which I suspect is relevant for the question at hand.
In short: How do I inject dependencies into a wide variety of implementatio... |
I am building a REST Api from scratch so i am overthinking and revisiting various approaches and best practices.
I have a Materials repository that serve all the sub-domains of our logic.
Also i have a Sales and Inventory sub domains that both relate to the Materials.
I found this question that evolves exactly around w... |
Say I wanted to build my own CMS system and store data in MongoDB. I would like to have a Collection called BlogArticle. Each article can have a different structure, but will be put together by the same building blocks.
So for example, Blog Article No. 1 might look like this:
1. Title: "2 Great Videos of Cats"
2. Video... |
If a function is being used to process incoming results, I believe an SRP violation exists if it contains all the logic:
def process_response(response):
'''Process the results of the web request'''
# logic to parse response
# logic to format response
# logic to write response
This function is doing a lot,... |
thinking about the design of an IoT project where the devices don't have a standard application layer but rather a thin custom application layer utilizing TCP sockets. What I mean by this is that the device wakes up every 15 minutes or so opens a socket on the server and sends data in, waits for any incoming data and ... |
I'm currently studying dependency injection and I'm having some issues with the so called 'flexibility' advantage of using dependency injection.
The flexibility advantage is mentioned in post Criticism and disadvantages of dependency injection, where it is mentioned that dependency injection enables
"switching implemen... |
I wanted to implement a method insertCard in Python which interacts with only a specific type of object called a Card.
The Card should always have a cardId and may have additional payload or fields that the user can specify.
In Java, I would do:
class Card {
int cardId;
}
class PlayingCard extends Card {
int c... |
I have a C++ class (Class D) that is a decorator of another class (Class B). Class D inherits from B and also requires an instance of B to construct that it keeps track of. Class D overrides all methods in B and instead calls the same functions on it's own instance of B. My worry is in maintaining this. If someone edit... |
So I have a design/architectural question. I want to develop a pattern in a programming language that is able to allow a app command-line shell to send commands to a running application to create objects that a developer maybe working on while the application is running.
For example:
CLI> createObjCmd someClass arg1 ar... |
I'm developing an application that will show some weather information based on the user's location. Since the weather forecast is just a very small feature of the app that complements the main ones, I do not want to spend too much money on the 3rd party weather API which charges per per API call
The app will make a req... |
I have some code where I believe the SLA (single level of abstraction) principle is broken in a way that the low-level code (if-statements) is outside and the high level code is nested inside the cases. A simplified version of the code is:
public void GenerateReport(int effort, bool delayed)
{
if (effort < 5)
{... |
I'm the only software engineer for a small company and I want to make my deployment process more robust because I can't work away from my dedicated workstation with my current process. I only make proprietary, internal software for Windows that is used by employees using Visual Studio.
My current process is:
Code
Test... |
Consider this simple example:
We have the apartments table below:
ID
Address
0
555 Maple St
1
123 Oak St
2
999 Pine St
We also have the tenants table below:
ID
Name
0
Bob Foo
1
Jane Bar
If I want to map tenants to apartments (assuming that one tenant could rent multiple apartments for this... |
I've worked on a few codebases without a great automated test suite, where changes that concern the whole platform have to be thoroughly tested by developers and there would be a high risk that a degradation is introduced with each release. How do you prevent this from happening?
The less than perfect answers from my e... |
Companies spend a lot of money on tooling for on-prem. But then they often want to move to the cloud for its obvious benefits, but feel limited in their ability to do so since they already invested so much in on-prem tooling. Can companies use already-purchased on-prem tooling in the cloud if they want to move to the c... |
So I am developing my own DBMS as a resume project, but I am so deep now on this that I am even considering in the future to release it as an open source project and receive feedback from the community. My DBMS has to be customizable, and with that I mean that you can literally write your own code to change features o... |
I am looking for advice on database design for a web app I am building.
Part of the website needs to display content from a SQL database dynamically depending on the component's context. To be more specific, I need the component to display a subset of columns from the item_info table, depending on the value in another ... |
I've been reading quite a lot on the concept of Inversion of Control (IoC) and Dependency Injection (DI), and I've seen that DI often relies on an IoC container, which among other roles has to
Register: The container must know which dependency to instantiate when it encounters a particular type. This process is called ... |
In our application (ASP.NET core) we have events that require computations and which results need to be persisted in a database (the objects are projects that need recalculations when a property changes, and then the financial results need to stored). These actions need to take place asynchronously in the background.
... |
I am currently working solo on a very small simple python microservice. I started building this app, mostly by habit, in a virtual environment. As I started to get closer to the point where deployment considerations needed to be made, I started to realize that all of the dependencies I'd need to include in the containe... |
A few hours ago I turned in my entrance exam, and i am very curious about this last problem.
Given a cluster of stars each x, y, z range between -1000 to 1000. No four stars are coplanar.
Find the minimum volume of a cylinder that covers all stars, the cylinder can be in any direction.
At least 1 base of the cylinder ... |
Assume a Person has a Phone and a Phone has Contacts. Assume in the real world the Contacts of a Phone are sorted by their first name.
When I phone.add(Contact c), the phone sorts its contacts. Then this contact has its first name changed. How can phone know about it and sort its contacts?
public class Phone {
List... |
I am looking for advice on database design for a web app I am building.
In the web app (Angular, REST API, Oracle SQL database), I am constructing a web form dynamically. I chose dynamic form construction, because I will need to display many similar, but different forms (around 30), and the questions asked on the form ... |
I've been working in a rather large codebase filled to the brim with small classes such as
class Person
{
public string name;
public int age;
public int height;
}
As a mainly front-end experience developer I'm finding a hard way to determine the best practice when returning multiple values from methods. Fo... |
I am implementing anonymous functions (lambdas) in a scripting language that supports hot reloading. The language currently supports passing user defined functions (pointers) to plugin functions which can store the function pointers to be called later (event handlers). With lambda support I can dynamically create the ... |
I've come across some apparently-conflicting patterns of behaviour. I'd like to understand why they each exist. I'll call them "conventions" for the sake of simplicity, though I'm not sure the term is a great fit for all of them.
Convention 1: we do not commit generated artefacts (especially binaries) to source contr... |
I develop my current project with a very strict approach to TDD and try to make it as close to Kent Beck's TDD By Example book. So right now I've got code coverage of 93%, with 1290 unit test cases, 58 integration tests, and 25 UI tests. However, the tests durations on the CI are too long IMHO:
Unit tests: 15 minutes
... |
I recently wrote a small PowerShell script to clean a Visual Studio solution. It's used by a small team of 5 persons on a regular basis. I built it in PowershellISE (GUI client) and it works great, but some time later I ran it from Cmd and then after completion I was to my big surprise not in the same directory as prev... |
Consider the following GUI screen:
When user selects a person from PersonListView, EditPersonView should show person's first name and last name and allow the user edit. So, I end up with the following UML class Diagram where each Java package represents the layer of the class.
My question is in SelectedPerson and if ... |
I am in the process of carrying out a software architecture for my client, in fact
THE HISTORY OF THE REQUIREMENT :
MY PARTNER SEND cvs files via MFT to MY CLIENT , many times a day .
MY CLIENT has a listener ( cron job in linux and batch ) , when a file is received in a folder , the client consumes it and store it in ... |
There's a question that struggles me for a long time already and so far I couldn't find or figure out a good answer. Hopefully, you will help me with that, folks.
Before the story, a little background: in test automation, there's one very popular pattern called Page Object Model. Briefly speaking, it's about mapping al... |
I've been suggested an authorization flow between three parties that seems not secure to me, and I would like to know if I'm assuming correctly.
Let's say Party A has many customers (one of them let's call it Customer X) with data in Party A.
Party A is allowing Customer X to get data from their API. In order to do tha... |
My company uses Major.Minor.Patch.Build for our version numbers. When a new release is started, the Major.Minor.Patch part is set. Then as work is done, the build number goes up until a build is deemed good enough. When that happens, then that Major.Minor.Patch.Build is released to Testing. If it passes Testing, th... |
I'd need some feedback on how to approach the design of a function that highlights parts of a time series chart. The chart shows the response time of an application, in particular the 90th percentile, over time. Each bar on the chart is one minute. I want to see anomalies, determined based on thresholds I define.
I exp... |
I'm working on a application which uses event-sourcing and CQRS to define it's domain model.
Background
We have implemented projections to aggregate stream of all domain events into a read models used by the application. But I think our current implementation is quirky and finicky as we tinker with it frequently. So I ... |
Our company is an aggregator of multiple payment services fragmented on the web. So instead of businesses integrating multiple services one by one, they will only need to integrate to our API, and we will connect to every one of the products for them. We connect by writing individual scripts for every one of these serv... |
To my understanding, C does not have the concept of objects, then how can Python be implemented in C to support something that C can not? How is the concept of "Object" modeled in C? What is internally used?
Edit : Reading through the comments, I am interested in this specific implementation of Python which "uses" C to... |
I have an existing microservice that talks to a Natural Language Processing (NLP) product and fetches around 50 fields.
I need to create domain objects in Java now from these fields.
I read about builder pattern and read Effective Java. I understand builder pattern and using fluent approach is a good way to build objec... |
If an I/O device is reading the main memory (directly) then is it possible for the CPU to access the cache?
I think it's possible for the CPU to access the cache in case of a hit. But in case of a miss there could be two scenarios.
Either the CPU pauses the DMA and fetches blocks from the main memory (haven't heard of... |
I have an entity that contain the status of data (WaitingForData, ReadyForData, DataUsed).
class Batch
{
int Status { get; }
DateTime StartTime { get; }
string Code { get; }
void SetCode(string code)
{
Code=code;
if (StartTime not null) { Status = ReadyForData; }
}
void SetDat... |
Imagine a "clean architecture" in which you have two use cases. One of them is CreateCustomerHandler, and the other SignUpCustomerByGoogleAuthHandler. So, the SignUpCustomerByGoogleAuthHandler has to reuse the CreateCustomerHandler to eventually create a Customer.
Is it legit to inject CreateCustomerHandler to SignUpC... |
I'm trying to delineate the responsibilities between client & server. I have the server parse a file, and then send back the uncategorized accounting transactions. The URL looks something like:
POST /api/accounts/:account_id/transaction_file // used for the upload
GET /api/accounts/:account_id/uncategorized // gets al... |
I have a web application that has a lot of multi-action items that are done that require an email notification. Although not the biggest deal, we currently have it set so that it sends an email to the other user when things like a comment or a "status" has changed.
Let's say our one user adds a comment and then changes... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.