instruction
stringlengths
34
36.1k
I face an issue where I want to inject Entity Frameworks DbContext into a service class, in a WPF application. The problem is that the service classes are instantiated and contained by the view models. That could mean a rather long life time for DbContext, if injected directly into the service. The solution I have com...
On our product there are many config files (we have many processes) For "logicical" configuration, we store all configuration in a document based database and then distribute the configuration to different component upon configuration change. But, We also store configuration on app.config files, and sometimes, these ...
I'm working on a webapp that is supposed to be "database-driven". Now, the stuff we do is a bit evolved (a little configurator) and I hesitate to re-read the DB on every callback, because I fear data might become inconsistent (several linked tables are involved) and possibly a lot of checking would have to be added to...
I'm fairly new to web development and I have a bit of a weird question. I'm currently working on a personal project that may or may not eventually become a real, commercialized product. In my database, I have a "user" table that stores the user's information, including their username, encrypted password, first name, la...
I am doing some code review for a project and they have generated a name based UUID using SHA256 as the hashing algorithm. I found a some Java code that created a Name-based (hashing) UUIDs using SHA-256 in Java The Java code takes the first 16 bytes from the SHA256 and sets the UUID type to 5 and sets the RFC 4122 var...
Consider that you've got a POJO that you intend to serialize and send through a socket. You can use whatever serialization strategy you wish (JSON, XML, protobuf, ..., etc) to serialize the actual POJO into a byte[], then you send it through the socket. The byte[] arrives on the other end, but in this receiving context...
I'm expirementing with creating a website as a IT Ticketing system. This website has a top nav and a side nav. I want the content area to change depending on the link clicked. I've managed to get the concept down using just php through isset($_GET['page']) and conditional statements which activates the include command ...
As of iOS 6, Apple thought Unwind Segues would be added to their layout/views. What this means is, when you're on the 7th view of a stack, you can pop back to any other one. For those of you pure OO fans (like myself), I cringed a little. I cringed even more when I learned these also work with pop-ups. Why would a mod...
First, as I know, Entity in DDD is almost same with Value Object except Entity has identity. Every article I have read say same thing that entity id has ORM mapping with any ORM tool. But I don’t want to use ORM mapping in Entity. Instead, I would like to do database operation with Repository Interfaces without mapping...
I am developing a hobby project where I try to use DI to get testable code. Until now, I found that it improved both the readability, usability, and testability of the code. However, now I have a situtation where I find that the usability suffers a lot and I think there is some key part of DI that I am missing. In the ...
I have this project with MVVM and clean architecture well implemented but I've decided to split it into modules. Right now I have: apimodule apimodule: with the retrofit dependencies app: with the data, domain and presentation layers. I want to modularize it even more: Create a domain module with the domain models, u...
I have recently encountered multiple articles with title Everytime a mock returns a mock a fairy dies And I ran into exact same situation while using factory class in my code. I am writing a sample Java code here to explain in detail what I mean. @RequiredArgsConstructor class Battle{ private final GunFactory; pub...
I'm just not sure as to why JIT (Just-in-time) and AOT (Ahead-of-time) are often presented in contradiction to another. If we do not care about about portability, it feels to me that a program could very well be AOT compiled and then, at runtime the JIT could be used to re-optimized the hot parts. What are some known...
I have displayProjectTable that gets state from reducer projectData and populates itself. Currently displayProjectTable has a local state that stores focusedRowID. My problem is that I want other components to have the ability to modify the focusedRowID and it's content. Some examples: -A component tells displayProjec...
I have been using a pattern in a lot of places (mainly C#) that I would like to know the name of. Here is an example of it in C#: public enum ThingType { A, B, C } public interface IThing { ThingType Type { get; } } public class ThingA : IThing { public ThingType Type => ThingType.A; } public...
I would like to run tasks in parallel. At this time, I am using a very simple worker pool using a single concurrent queue shared by all the threads. Every task has a non unique "tag" (an integer in my case). I would like tasks having the same tag not to run in parallel. At this time, I have implemented it by having a R...
I'm using a listener pattern where a class A listens for events from various classes B, C, D with the help of a listener interface I Essentially the structure looks like: interface I { void generalCallback(); } class A implements I { @Override public void generalCallback() { /// Do some stuff ...
Let's say I have a booking system where I want to fire an aws lambda function to send an email or message to users, 10 minutes before their booking starts. I have looked online and found few solutions. AWS Lambda + CloudWatch + DynamoDB: Someone suggested adding the job to dynamodb and setting the TTL to when I want t...
This is (again) a question of methodology... Suppose we are testing a service that returns Articles given ids, i.e. List<Article> getArticles(List<Integer> ids);. In addition, the corresponding location will be null if the id is invalid. Firstly fill the database by the SQL: INSERT INTO articles VALUES (2001, "aaa"), ...
What is the best way to send messages from a Contact Us page in a website as a notification email to an administrator ? So far, this is what I did but I feel like this is not really the proper way. I created a gmail account that will serve as an email sender From the contact us page, I fetched the values from the text...
I don't know if this is the right place to post this sort of question, so feel free to move it. Lets say that Vendor X is selling a certain software package. There are also other competitors, including Vendor Y, selling similar software packages. My company is leaning toward purchasing the software package from Vendor ...
The goal within my framework is to provide facades or front-facing functions/APIs so that people can easily interact with my system, as such, in most cases, that goes super well by having static functions that people can just call and have everything sent to them, but I have an issue when it comes to these static funct...
I'm currently working with a very large system and have been asked to add an additional parameter to a method that's called from over 200 different places directly. The method signature looks something like this: public static bool SendMessageAndLog(long id, long userId, string message, string cc="", params Attachment[...
This is not about the specification of semver itself (which is crystal clear), but rather about the best approach to implement it within a development pipeline when building libraries. TL;DR: who/what sets the version and deploys the artifacts, and when? We're planning to opensource some of our internal Maven-based G...
Oh, abbreviations in code, the bane of every developer. Consensus seems to be against them, because readability might be affected. But the examples given are often extreme: like "repr" for "represent". I call that extreme, because it is shortening a word not in need of shortening, into something that has a very ambiguo...
I'm wondering what's the best approach, and its advantages, when specifying parameters for the Web Service methods. Best to explain it through examples. In my (SOAP) WebService, used by a Xamarin mobile app, I have a WebMethod SubmitForm(int, TransactionData, List<Answer>), where: int is the ID of the Project and speci...
We maintain a technical project whose specifications are in a document of few hundred pages. It's a text document (Word), not a Wiki or a Web-based stuff. The document contains lots of tables with values (strings, numerical, parameter names) . Some tables are huge (hundreds of data), other are quite small. I'm looking ...
I'm trying to figure out the best way to "partially" use the validates_uniqueness_of validator for a particular case of problem. Let's say I have a Book class with multiple comments, with the Comment class having a belongs_to :book. Now let's say I have certain comments which I consider notable, such as "most quotable"...
I'm trying to find a source of information to explain how to sort a list of items considering their multiple attributes and units. All I can find on the internet is code example on sorting Javascript lists and SQL queries. The key is that it must compare Price, Probability and Color at the same time, for example. A hig...
General question how can I design an interface that can support both // v1beta1.Deployment type Deployment struct { metav1.TypeMeta metav1.ObjectMeta Spec v1beta1.DeploymentSpec Status v1beta1.DeploymentStat } type DeploymentInterface interface { Create(*v1beta1.Deployment) (*v1beta1.Deployment, err...
I'm curious if there is a pattern or at least a better way to code this situation. For example, say you're writing a rest api for a reporting workflow. You have a User class and a Job class. Each User has a Job, and each Job a JobType. Some actions will be the same for the user but have additional logic based on their ...
I am making a C++ glfw wrapper for myself to use. I want to have classes like Monitor, Window, Context that would be wrappers for glfw objects like GLFWMonitor* or GLFWWindow*. The problem is that if I want to have a method create_window() in the Window class, it must have access to the underlying raw glfw pointer in M...
I am working on building a API and SDK for a web service. My question is what is the correct practice for logging. Should the SDK do logging for the API methods? All the SDKs I have seen do not do this so I am just wondering is that the recommended best practice?
I'm struggling a bit for a preferred way to organize a sequence of asynchronous tasks that can be applied in parallel. Say, you are parsing data from many files. In my case I'm using javascript and promises, but this could be most any language. (Hence the weird tags as "javascript" and "language-agnostic". Option A:...
Given that I want to write a Given/When/Then scenario When I write a Given/When/Then scenario Then my Given and When are generally the same thing I've been trying to practice writing user stories in Given/When/Then but I often end up with something like above; the Given and When are identical. I find that high level s...
I'm currently writing a small language of my own, and have been considering the difference between the C++ style, where the access modifier applies to a block of members, and the C#/Java style, where the access modifier is specified separately for every member. I'm not going to ask which is better; I realize that's ver...
I know that in some contexts, best practice would be DDD, CQRS and EventSourcing, but in my case this would be too complicated of two reasons: My team is beginners, and we want them to be productive as early as possible The application is really simple, but obviously the complexity may grow in time This question is a...
I am trying to determine which is the best arquitecture to my application, I am planning to use python, mysql, angular and flask as an intermediate between python and angular. I have all the shots of basketball matches of different seasons whith the correspondant player, team, position, etc; and I want to plot them in ...
My team is building a tenanted primary service, with shared microservices used by that primary to separate common business tasks. We're building a new microservice that is responsible for running a series of business rules against a primary object in our system. Think of it like the Order in a shopping cart, and maybe ...
Suppose I'm writing C or C++ code which deals with... ok, let's make it citizens in a state. In this state, citizens have numeric id's (not strings - numbers); and for reasons of performance, or compatibility with other software, it is assumed there can be less than 2^32 citizens. Now, in my code, I have a bunch of fun...
I want to build a REST API but I have some holes when it comes to the security part. I would like to get my head around how to authenticate the calls to the API. Therefore, this is my first draft for how the process should be: User account is created Token is automatically generated and stored in db, associated to tha...
Example 1: Let me assume that I have a base class A. Class B extends Class A (Class B is a derived class). Can I conclude, Class B doesn't obey single responsibility principle since it uses the concept of inheritance? I.e certain changes happen to Class A will require changes to Class B as well? Hence the responsibili...
I am curious about these three questions when building a push-based(write fanout) feed system: How does it handle the unsubscribe logic? To me, it seems to me that we have two choices: delete or keep the history data from one’s inbox. If we choose to keep it, does it mean that when processing the timeline read reques...
The only way I know of is to copy the whole heap by allocating copies of all objects on a new heap and dropping the old one, like couchbase db does for example. Presumably you could also do the same on a subset of the heap to copy less data around each time. Google isn't helping me much, since it only talks about heap ...
I was playing one of my favorite games from Supercell, and I imagine it’s a rather complicated game, and it stems across the two main mobile platforms. My question is, do the developers write the game logic twice? I’ve never developed games on iOS or Android applications, so my knowledge on this is limited. Do companie...
I am trying to create a good pattern for my application. I want to reduce as much as possible the duplicate code and I want to use generics as much as possible. I have created a pattern for this but I want to know is there anything wrong with the code or if is there any other better pattern already made for this. Base...
I run on a daily basis a set of VBA-rich Excel files. Most of them include MS Office application cross-talk, but also employ third-party applications and MySQL. Due to the fact of running those files in a specific order and at a specific time of day I set up an xlsm-based scheduler to run those files and control output...
I want to code a little program that takes in head tracking data and moves a 3D object accordingly on the screen. To achieve this I found a software called opentrack that has a C++ API. The problem is that any game dev environments I know / have a way to access use C# as the language. I'm very confortable with C# and u...
I am creating a rest template to consume REST API secured by OAuth 2.0. The provider has implemented an expiry for the access token for 5 mins. So Using the rest template, I will be calling the database and sending records via Rest Template. The records may vary from 10k to 1 million, so I wanted to create a fault pr...
I'm working on an application which needs to open a database file. There are 2 "versions" of this database: one of them is more general data storage, and the other contains "less" information. That being said, database table structures are different, so I need to issue different queries to get "same" information from e...
In Java string classes are final, we know that we can't inherit a final class and not able to write on this, then how did we enter a value on a string even its a final class?
N.B. Several months after initially asking this question (and not coming up with any satisfactory answers) I am now learning to use HTML Custom Elements / WebComponents. It seems the same question comes up again: I know I can turn everything in my HTML into a Custom Element... so what do / what don't I turn into a Cus...
We are creating a new page on our website which will require overall ~5000 LOC. Now the problems here are: How to get so many lines reviewed? When to merge these changes to master for release? How we currently solve these problems: We create a temporary Release branch in which everyone will merge their features relat...
I have to code a gui like this: It's an homepage with a left menu and a changing right part, on button1 click form1 must be displayed, on button2 click form2 a so on. Each form has its own button "ok" that would call a controller function which will save data entered by the user in a database (but it is not relevant)....
Summary Instead of calling WebApi straight from a Web Forms User Control, I have created JS class which contains functions returning jQuery AJAX requests. The control would instantiate the class and call these functions, which would allow me to separate the code that calls the API from my control. Is this the best appr...
Problem I am working on an application for my personal use. Basically what I require is a 24 hr running cloud application that will get alerted about the new articles posted on provided website links and fetch about heading or specific content from those articles. The info is processed and put together after which post...
I know that "mvn clean install" cleans everything that has already been built by maven and rebuilds everything as specified by pom.xml. However, if things have already been installed, and I just run "mvn install", does it reinstall things that already been installed? In other words, does it install things twice or does...
We(in my company) use to save the JWT token in the cookie. The web application is on Spring boot + JSP application. So the flow is, in a successful login service send a JWT token, that token has been saved in the cookie and all the subsequent request to the service the token has been retrieved from the cookie. The curr...
I've run into a common annoyance where I'll have an event that sends a parameter, but some consumers of the event don't need the parameter at all. So I wrap it in another function that decouples the signature from the actual method call. This adds one more level of thought that a reader needs to parse before understand...
I'm currently refactoring an older legacy application and use React to rebuild some of the former functionality. This application has a form which has +10 different input fields. The aim is to kind of built a wizard that leads the user through fields, instead of bombarding them with +10 fields at once. Now, I've thoug...
If I obtain a release build of a github project from a Maven repository, how can I securely verify that it's the authentic build? DETAILS That was my X question. My Y question follows. Maven's Guide to uploading artifacts to the Central Repository says: To improve the quality of the Central Repository, we require you ...
I have recently decided upon a micro service design to merge two Spring Boot applications. I basically have 2 applications that deliver two entirely different front ends, but share user accounts. My current structure is (in no particular order): Application 1 Application 2 Gateway service Discovery service The gat...
I am trying to imagine how Google Chrome automatically updates but have some questions: Is this against Apple's terms of service? I feel like I've seen somewhere that Chrome for MacOS isn't in the Apple Store because of this. Not sure. How is it swapping out its runtime? Is it possible to autoupdate on iOS/iPad? Basi...
We're Scrum teams building microservices. Our GitHub repositories are single-branch, each of us integrates his/her code into master several times a day, with no feature branches. Our Jenkins pipelines compile the code, run automatic tests, supply the code to other services for static code scans, and deploy our software...
I am new to Golang and I've seen it is very common to check for errors all the time. I am trying to find a way to not have my code polluted with "if error { log... }" or "if error { exit }". What do you think of a function like: fun exitIfError(error err) { if error != nil { exit(1) } } That body of the functi...
I have an external process in my program. To interact with it i have a configuration file i can edit. The external process then reads this file periodically and updates its state accordingly. Now what is a good name for this file, as represented in code? ExternalProcessApplicationConfigurationFile feels 'static' since ...
Consider a SimpleCalculator class which contains four methods (Add, Subtract, Multiply, Divide). I need to create another class ScientificCalculator which needs above methods plus other methods like Sin, tan, cos, log, etc. Should I reuse the functionality by inheriting from SimpleCalculator or should I think of some o...
I have a MySQL database with a column Body MEDIUMTEXT. Until now I used to only store the contents into it. There was no update option for the users of the application. Now, I wanted to add an update option to the content(To make it easy, just think it like a stack exchange editing a post scenario). I know about not o...
I have mainly three groups of CSV files (each file is divided into several small files): First group of CSV files have 600+ GB in total (MAYBE 200+ GB if in int, cause CSV calculates by char right?), each file has same size of lines, the whole data should be gather line by line together. The application should read som...
I am working with C++ in a Linux/ Unix environment. I am trying to learn the physical design of large scale projects. In one of my projects, I am using an SDK from a camera manufacturer. They released a new version of this SDK and one of the applications I had built based on the previous version stopped working because...
For teaching purpose, I would like to create a simple implementation of State Pattern using PHP 7.4. So, I've tried to create a simple "document state machine" starting with Draft, sending to review and, after three "votes", can be published: <?php namespace StatePatternPHP; interface DocumentManagement { public ...
My language is C#. I have a set of seven classes that all ultimately derive from a single class. The image of the class diagram is posted below. I will frequently need to iterate through collections where the members are all the seven classes intermixed. An example collection might look like this: Collection: A, D, C, ...
I have been coding some octave .oct files lately (C++), and for my purposes speed is of the essence. It seems to me that creating C++ objects (in general) can take some time. I was wondering if there is some way to circumvent this? Maybe to somehow create a statically allocated object the first time the function is ca...
I am confused about the Open/Closed principle. The principle says "open for extension, closed for modification". My thinking is that if there is a class and if you need to add any new functionality to that class, you can add that functionality by creating a new derived class which is inherited from the base class. So y...
I'm trying to apply Clean Architecture to a mobile Android App, but I still have some doubts about how to manage API calls. Currently, the classes are structured like this: View -> ViewModel -> UseCase -> Repository -> DataSource It's all well and good when the API calls are about fetching some data from/sending some d...
I'm writing a python function to replace all the non-alphanumeric characters in the keys of this dictionary with underscores. To make sure it's working as expected as I don't have a ton of experience in the language, I created a sample dictionary with a few different samples to make sure it worked well enough. Is thi...
I am writing a program for Windows, which uses two databases. One is very big (dozens of tables and thousands of records) and comes from another program, but I only download data from it. Second is "mine" and only used by my program (dozen of tables and hundreds of records). I have a repository to keep track of changes...
I am building a blog system's comment api, and decided to provide the REST api like: post: /blogs/{blogId}/comments/ put: /blogs/{blogId}/comments/{commentId} These api accept the same parameter: public class CommentEditParam { private String content; // identify the reply to user's id private Long replyT...
Consider two services (bounded contexts by DDD): Sales Billing Sales is responsible for creating orders and Billing for handling payments. Sales tracks orders and Billing holds payments: Sales DB Billing DB +----------+-------+ +------------+----------+-------+ | order_id | paid | | payment...
Task Description I need a way to wrap different types of progress bars in a way that an algorithm can update the progress without knowing about the exact implementation. The progress implementation may allow the user to request to cancel the operation and the algorithm can query if it should stop at points where it can...
A superclass should never be aware of its subclasses. Or so I thought. I have a Filter class, which wraps a function and some of its kwargs. Some other kwargs are callable eg specific_filter=Filter(some_funct,day='sunday') you can then use the Filter object like so resulting_object=specific_filter(some_object) or r...
Apply is a fitting name for a member function of a function-type class that applies the function to the given arguments: class Addition { int apply(int a, int b) { return a + b; } } But what about the opposite, when the class that a function is applied to has a method that applies a given function to itsel...
I have a Github project for a Django web-app that one team uses. Other teams are interested in also using it and they'll need separate instances of it (it's a stock tracking database so they need to not see each other's stock). It's also likely that they'll be small modifications that different teams will need. For the...
Are streams of binary data considered a form of bit banging? Does this definition change if the array is buffered? I am referring software which handles binary data on a general purpose CPU; for example, Java's Input/OutputStream, C++'s istream/ostream, and C's character arrays. I'm aware of that working on individual ...
My company works in the field of public infrastructure in Europe, specifically as a software provider and operator. All of our development work is currently outhoused, to two main suppliers relevant for this question. Our company background is in the (semi) public sector, so some development methods take a little longe...
I need to generate a large Excel file (something around 50 megs) and send response to another API which will provide it to the front end for a download option. My question is if it will be better to save generated Excel file and provide a path as a response to the API for the front end (something similar what web mail ...
In most of the examples for Abstract Syntax Trees (AST), I see no function or classes. I am wondering, if the functions and classes are represented in the AST? If no, where should the functions, classes and templates be stored? What is the possible data structure representation for the code? I was thinking about struc...
I am currently designing a system that lets users connect their Cloud Storage such as Google Drive, Dropbox etc and also to their physical filesystem (personal laptop/ ftp server etc.) and then can just open a single webpage page where he can find all the files in each of the storages and can download them. My system h...
Compared with HTML (Hypertext Markup Language), TLV (Tag-Length-Value) also can be used for a data representation. If TLV is designed smart enough, it can represent hierarchies and trees with no problem. Unlike XML or HTML which are human readable, TLV is not. Because it is showing the tags with numbers than text. On t...
In Form-based application (WPF/MVVM/SQLServer), consider the form that handles the classical actions that you can perform on any entity. Create Read Update Delete The problem, in general terms, is simple to tell. which class of the viewmodel competes the call of any of the above actions? What is clear: * the ultimat...
I work with Spring applications. Recently I have found this article about the Anemic Domain Model. They recommend putting logic in Entity classes. It solves a problem that Martin Fowler described in his article. We can move logic from our service layer to the domain layer. It sounds good. But can we do the same with ou...
I have an application. It needs to send emails. We've all been there, done that, got the t-shirt. I've got an IEmailMessage interface: public interface IEmailMessage { string From { get; } string To { get; } string Subject { get; } string Body { get; } bool IsBodyHtml { get; } } with a readonly...
The initial task was to find very quickly, free time for resources, let say - hotel rooms, services availability. I came with following model: Let say we have 24h in 1 day, and 365(366) days in a year. 1) We have a sequence of bits timetable=0001011....000, length(timetable) = 24*365 = 8760 0 is busy 1 is free. So if...
I have an C# MVC Application which is basically a large application form. We are using a large ViewModel to store all the information the user enters as they pass through multiple steps in the application. My problem is that certain steps are loading/saved dynamically through AJAX. I need to store some of the database...
I have several POCO´s (simple classes holding data) that I have need to flush from memory from time to time whenever a collection grows too large. Most often I want to upload the data to a REST service, but if it fails I want to save the data to disk. In the best of worlds, the code should be able to handle any data ty...
I have proposed a REST API called 'getSessionState' which basically a backend API that retrieves some state info from a redis server and return to the clients. Because the state data is kept in a Redis server, whenever a user calls the function I will extend the expiry of the redis data structure by a bit in order to ...
This is an existing C# .NET WinForms project. I assume it was not developed with unit tests in mind from the very beginning. It uses a Model-View-Controller architecture, and the backend is a content repository (a kind of heirarchical database) which I am not too familiar with, since I have only touched the front end. ...
It's mind bending experiencing reading code like : "Aggregation".Equals(evt.Id)) I was unsuccessful in trying to talk the person out of this style, maybe I'm wrong? Or maybe I wasn't articulate enough, hence the post here.
Is it a standard practice to develop a HTML project using partial views. Consider a project where the design team will develop the HTMLs based on the requirement & then the backend team will work on that. For example: index.html: <html> <head> //reference to jQuery </head> <body> <div class="main"> //all...
my_dict = { 1: 11, 2: 12, 3: 13 } If I want to work on the list of keys from my_dict there appear to be (at least) three ways to do this in Python >3.5 (i.e. on or after PEP 448) List Comprehension: [key for key in my_dict] [1, 2, 3] Unpacking: [*my_dict] [1, 2, 3] Constructing a list from the view of the ke...