instruction
stringlengths
34
36.1k
As part of validation, we perform name similarity check and allow only if the threshold is reached. I got some help from StackOverflow regarding the implementation and finally implemented JaroWinkler algorithm. Recently we observed that it is not reliable for long names and some false names also cross the threshold. I ...
I am trying to understand if C++ types are classes, like in Python for example. Otherwise what datatype is the type itself? E.g. int a = 10 what is int? Is just a token label used by the compiler to decided the space to allocate to the variable?
PROBLEM STATEMENT: Print the items that differ between the following two left and right sorted data sets: A A B C C D D E G F H EOF EOF The proposed solution should print: B E F G H Here is my data-driven implementation of this algorithm in pseudo-code. It appears to produce the de...
I'm developing a JavaScript UI client and my back-end developer refuses to pass me the data in a form that I don't have to transform afterwards. So, I'm currently working on a mapper that contains a lot of knowledge that will only lead to problems later on. In addition, the objects we receive are sometimes very deep an...
I have a class with a Name property, where the name is set by the end-user. In order to ensure compatibility with the rest of the environment, and to avoid rejecting a lot of inputs, some processing of the name is done automatically: public string Name { get { return _Name; } set { if (value == null) ...
We are contracting with a group to create some cloud services for us, and would like to write a requirement for them stating that a particular API call will provide results within X seconds. They are pushing back, saying such a requirement can't be guaranteed because the problem may be in the Internet connection and n...
I have some classes being serialized via frugal (this is an open source extension of Thrift). The primary reason this is relevant is that the serialization process is out of my control and needs to support multiple languages, so I cannot easily modify it. Imagine my classes look like: class response_component: valu...
I have developed an embedded product, which has a dot-matrix LCD, some buttons, bluetooth and WiFi functions. To me, the functions are rather complicated as one of the operating mode can interact or change other modes. And one mode can be actived by different ways, such as by the graphical user interface, Bluetooth or ...
(Apologies if some of my terminology is off, I have not seen much on this subject and am using be best terms I could come up with) Should data model logic live in the database schema? I am making a distinction here between business logic and data model logic. By data model logic I mean things specifically to do with da...
I have recently come across the idea of persistence ignorance, the idea that your domain model should be ignorant of the persistence layer of the application, and that got me thinking. I have been doing my best to keep different parts of the application loosely coupled, wrapping things like the ORM in interfaces so tha...
I'm planning to set up a client side git hook to force a commit to fail if any file in the commit contains the text "donotcommit". Is it possible to hook the execution of "git add", such that I can run a shell script at the time files are added, and permit or deny the add based on the exit status of the shell script.
I am troubled lately about the use of abstract classes. Sometimes an abstract class is created in advance and work as a template of how the derived classes would work. That means, more or less, that they provide some high level functionality but leaves out certain details to be implemented by derived classes. The abst...
I have two files : file1 : contains the value of the variable. file2 : contains collection of steps (subset of collection of file1 ) to follow. Step contains the set of instructions. - > file1.txt x1 = 34 x2 = 33 x3 = 90 ... x12 = 101 x14 = 233 .. x41 = 901 ... ...
I am writing a bot for Matrix using Ruby which allows users to subscribe to RSS feeds and when a new item shows up on the feed it gets sent to the room. The problem I have come up against is how do I get the program to sit and wait for new commands from users while also fetching feeds every 2 minutes? Some solutions I ...
Is it bad practice to use an incrementing primary key to refer to a real world field, such as an id number for an employee? Suppose that 1 is a valid id number for an employee. I am really tempted to use the incrementing primary key as the id number. But I might have ignored some potential problems it might cause. I've...
We are trying to determine the best way to authorise users in a microservice architecture, while ensuring microservices have limited permissions. Our architecture uses a central authorisation service to handle issuing of JWT tokens. We have the following requirements: Users should be limited to perform certain roles. ...
/users?role=admin, where admin is probably some kind of slug vs /users?role=2, where 2 refers to our internal roles dictionary table primary key. Which of the two is prefered?
In the semi-functional Java world, I see development methodologies that make heavy use of dependency injection and mocking frameworks to achieve high levels of unit test coverage. In order to achieve thread safety, behavior is encapsulated in objects which have no state and no side effects (except maybe writing to the ...
Context In my application I use the MVVM pattern. I'll have a ViewModel that can contains information of a student. This viewmodel is used to communicate between my view and model. I use ASP.net core MVC whit vue.js. My project contains out of the following elements: Views (UI) Controller API (responsible for respondi...
I'm currently using the wxPython library to construct a GUI. One interesting aspect of the library I've noticed is that it uses CamelCase notation to write method names, as opposed to the snake_case notation that PEP 8 recommends*. This isn't to much of a surprise however since wxPython is basically a wrapper around th...
I have a finite directed graph (of several weakly connected components). Having two elements I need to check if there is a path from the first one to the second one. The easiest solution is to create the incidence matrix and then using it calculate the connectivity matrix (the further is obvious). But I feel it is not ...
Let's say you have a multiplayer game where different player threads are constantly updating the same game state. How do you best update this state without suffering locking bottlenecks or corrupting the game state? I'm thinking non-blocking data structures like AtomicInteger, AtomicReference, etc. Would that be correc...
After a user invites their contacts from within my app, I want to send the first user a notification "so and so installed the app, you can now connect with them." So when a user invites someone, I send the invitee a link to my landing page, with a unique ID param in the url. Then I know which user got them this far. ...
Modern Windows 10 can run binaries that were compiled on 20 years ago for Windows 95 or NT4, however I imagine that the libraries that the code is calling would have changed massively since then. I know that it is possible to maintain binary compatibility while further developing a library (in C++ for example by not ad...
In Germany we use the expression "Clean Code" (loanword) to describe source code that is well written. Lately I came to translate "Clean Code" literally to german and had an idea that in english there could be several meanings: Clean Code: well written source code Clean Code: a set of rules (code) to keep everything c...
Recently I got a chance to contribute to a project. The project is very vast and contains many independent modules like brand section, store section, user section etc. All these modules contain respective models that contains business logic. Admin has all capabilities like adding a brand to a parent organisation. Creat...
I am developing a bot which I need to start and stop at will. I have 2 buttons in my form, StartButton and StopButton which change the state. The Bot has 4 possible states: starting, started, stopping, and stopped. I am now trying to manage the state transitions. So far I have 4 boolean variables, one for each state. B...
I was reading about composition and I'm wondering if it violates the O in SOLID, and what should be done to fix the situation. In the article the author uses a Fruit and an Apple. At the end the writer admits it would be better as a "is-a" relationship rather than "has-a". Suppose however, you decided to stick with com...
I have been asked to come up with a design for streaming data to the cloud. I have a closed system on a local server. I need to stream recently registered customers or updated customer records on the local DB to a cloud-based CRM and make data available to serve the firm's website. I came up with following design flow:...
We need to organize a way to exchange messages between servers in multiple data centers. Messages are not critical. We just need to be able to send messages from any servers in any data centers to any other servers in any data centers. We are thinking to use Kafka as a message broker for this use case, but we are not s...
I've been given the task to design a system that has a product's price have different amounts of different taxes based on different factors. For example in the US you would get a few - one based on region and another on state and such, while in the EU you get VAT. I'm trying to figure out a non-hardcoded way of differe...
I'm trying to start adding some tests to my code. Please take it easy on me cause i'm still new to this stuffs. As far as i understand dependency inversion, all the dependencies will be place inside a class constructor and they must be an Interface so that we can easily fake it. By following this rule i may end up havi...
What are general guidelines or rules of thumb for when to use a domain-speciifc object vs a plain String or number? Examples: Age class vs Integer? FirstName class vs String? UniqueID vs String PhoneNumber class vs String vs Long? DomainName class vs String? I think most OOP practitioners would definitely say specifi...
I am implementing some kind of web application that has basic social network functionality and browser text game. I do it basically for myself only in order to learn couple of things. (like using websockets and full-stack development) So the architecture I came up with looks like this Generally my web pages consist of...
We have been tasked with implementing a dashboard containing multiple widgets. The dashboard itself and all widgets need to access various secured APIs. Our authorisation protocol is OpenID. Currently, the dashboard requests an access_token with all scopes required by all widgets. Widgets use this shared access_token t...
I've a bunch of classes where one is Abstract class. I draw few derived class from that Abstract base class. For example, class IBase{ public: *register(): bool* *update(): bool* }; class Derived: public IBase{ // implement register () // implement update () }; class Derived2: public IBase{ // implement registe...
Context There is a modular C++ application. Each module provides an interface (an abstract class) which is used by other modules. There are no circular dependencies. The module interaction happens via direct method calls in one way, and via events (a variation of the observer pattern, similar to Qt's signals) in the ot...
I've noticed this correlation, but I'm not sure if it's just coincidence or if others have noticed this as well?
A bit of context: Earlier today I had to update some SQL code that another colleague of mine provided, and since it’s a pretty large script, it’s stored as a separate file (which is then read and executed at runtime). While doing this I accidentally reintroduced two bugs we had a few months back, namely: For whatever ...
I’m working in a project that is building a system to manage data (10-20 million records) collected by a research organization. One of the challenges is that even though the data is superficially similar across the organization (having reasonably similar set of fields), there are currently 20-30 different databases use...
Does i in for loops means iteration or index? How could I know the original meaning? Some programmers say it's iteration, some say it's index. It seems to me more of an index we start from --- we go from zero, to the first in length (which is one, of course), and so forth. But this still doesn't "prove" to me which fro...
I am building a web application crawler that crawls for HTTP requests (GET, PUT, POST, ...). It is designed for one specific purpose; bug bounty hunting. It enables pentesters to insert exploit payloads at specific parts of the HTTP requests. Problem When using the crawler I sometimes run in to the problem of crawling ...
I am building an application where I need to store millions of images and later tag them. The tags attributed to the images could change over time as the tagging system evolves. Images will then be searched for by tags. In terms of storing the files, I have eliminated the option of storing them in a RDBMS; I have tri...
I have this conondrum I have to deal with. We have this already pretty big application which main purpose can be classified into 2 main functions: Core data (deals with a pretty complex data relationships and data analysis). Data presentation/visualization (this is the piece that keeps growing, the reasons to come ne...
Let's assume that I have a piece of functionality in my application which is responsible for adding a deleted marker file .deleted in a directory that is considered to be deleted. What would be that best way to implement this? Static function or an object with a single method that conveys this functionality? Those are ...
I'm fetching a set of tuples from the database, and putting it into a map. The database query is costly. There is no obvious natural ordering of the elements in the map, but insertion order matters nonetheless. Sorting the map would be a heavy operation, so I want to avoid doing that, given that the query result is al...
Imagine a data model of an electric company and the city it powers. The company has several departments that manage at least one neighborhood each in the city. The company database includes information for the homes in each neighborhood, the meters installed at homes, billing history, etc... Any employee in a departmen...
I have an array of unique integers, for example: {1,3,,7,9,31,46,...}, which I want to compress. I have found compression techniques and algorithms for the list of integers, where some integers are repeated but I couldn't find any compression technique for list of unique integers. I would appreciate if anyone could hel...
is a simple abstract factory. I know abstract factory is for selecting a product family. But my question is, can we still use this pattern if ConcreteFactory1 needs to createProductC() but ConcreteFactory2 don't? And if we can't use, how do we solve this problem?
I have a few blogs/websites hosted on my vps. Recently I've decided to move a db on a single central server/vps because all the blogs have the same structure in terms of code and structure of the db. The problem is, how can I effortlessly start using "application_id" in my db? It will denote a website data belongs to....
Whats the difference between tdd and automated tests? I'm confused.
I've been working on a LAMP application(a social network), and am about 4000 lines of code in, and have a working prototype. I learned PHP this way, and thus it isn't programmed very well, and am now realizing I should've used a MVC framework; either my own, or better yet, a pre-made one such as Laravel or CakePHP. If ...
Preface In an application that is separated by layers or distributed by services it is common to have classes that are very closely related data-wise, but which we wish to have loosely coupled. My usual solution (in c#) is to have them implement a common interface. (There are other patterns, but this is what I default ...
At my company, we have adopted full Agile methodologies and related tools. We plan our sprints based on a set of customer requested features by the end of the sprint. Commonly, we do not deliver the features requested by the customer by the end of the sprint and we push to future sprints. This has me concerned becaus...
I'm working on a distributed application and getting deeper into Event-Driven architectures with Microservices. Let's say I have been running two Microservices, CustomerService and AccountService. They both have their own database, and they've been keeping in sync with an event-style messaging with RabbitMQ in between....
If I have an React/Redux single page application that has - say - a customers page that lists businesses that are customers, and from there each customer can be accessed with a URL like this: /customer/1 From there, the page lists contacts at said customer, and the user can drill into individual contacts at that custom...
today, I like to ask you a question towards the capabilities of C++ to realize a specific software architecture. Of course, I have used the search but have not found any directly linked answer. Basically, my goal is to build a program which allows the user for modeling and simulation of arbitrarily composed physical s...
I'm working with a project that our architect has decided to use dependency injection for almost everything. We use an IoC container. One of the main issues that I keep coming across when using this pattern is "How do I pass this bit of data here to a different object that will be used later?" Often, the easiest solu...
I'm working on a site for at-home services. What is the best practice to define a service provider's service area? My initial thought was to define each provider’s service area as a set of zip codes. If the customer requests a service, simply search for providers with matching zip codes - easy enough. I’ve done a bit o...
The current company I'm working for has what I consider to be an unusual set up for their version control system. I'm working with it but I can't help but feel what they are doing is suboptimal and that they'd have much better process if they used what I consider to be a more standard Trunk, Branch, Tag approach. I've ...
So my manager class does 2 things, load items from file and give one item to a thread that asks for it, it also holds the List that will contain all the items. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Bot.Core.MainEnt...
I've been working on different genetic algorithm selection methods recently. At the moment I have a RawFitnessSelction class, a RouletteWheelSelection class and a TournamentSelection class. I've been asked to use a factory/abstract factory pattern to choose the different selection methods. I think I'm going to go with ...
I am using tape for unit testing in Node JS. I wanted to ask one thing about better coding while writing unit testing. When using different inputs to a single method, is it a better idea to use all cases inside one test function or different cases of single method in different test function? test('getXYZ: get XYZ from ...
I found a module (single file) contained within a large project (100s of files) on github that was of use to me. Licence is MIT. I created some PRs but the author didn't seem to have the time to accept them. I asked for permission to set up a new project using his module and they were happy for me to do so. I copied th...
I'm currently in a university course that requires students to work in groups on a semester-long project. In my group's case, we've been tasked with making a location-tracking system. There are two primary components to the system: the backend (which houses the datastore, exposes endpoints, et cetera), and the mobile a...
In C++, is it bad practice create blocks of code inside some function, such as the following: bool f() { { double test = 0; test = // some other variable outside this function, for example. if (test == // some value) return true; } ...
I have a rather large class that contains a number of related member variables. These member variables can be grouped into related sections. We've noticed that the pattern of use of the class is to make a copy of an existing instance, change only a few of the member variables, and then do work with the resulting instan...
I'm reading Robert Sedgewick's Algorithms book and I often see the term API client. Please take a look at this exercise: Write an iterable Stack client that has a static method copy() that takes a stack of strings as argument and returns a copy of the stack. Note : This ability is a prime example of the value of h...
We're wondering what the best practise for registering types in a IoC-Container is. What would be arguments for and against the following principles: Principle 1: Only one Assembly my.project.DependencyInjection Seperate assembly for dependency injection One class (f.e. UnityConfig.cs) where all types of the whole sol...
I'm currently dealing with a GraphQL project with poor architecture. I read about where to put AuthZ checks and they refer to the "business layer" as to be called from a GraphQL resolver. Up till now, I thought GraphQL belongs in the Data Access Layer (or at least, JUST BEFORE the DAL), but it now looks like it belongs...
I was recently hired in a company and I have been asked to help writing an API that was left unfinished. I do not have much experience yet so I am never too sure what are good coding practices. This API will be used later to create an web interface showing information about the application developed by the company. Bot...
We're trying to build a solution where we have a requirement to check password compliance of a user with respect to all the systems that he has to. For example, if system 1 mandates that password should have 4 alphabets and system 2 has a requirement of 5 alphabets, if the user happens to have access to both systems 1 ...
I'm designing the data model of a payment database. One of the domain requirement is to keep track of how the customer paid and, if applicable, what was used i.e.: Visa, Amex, etc. In the past I have used PaymentMethod to describe Cash, Credit Card, or Check. But I'd like to use the most appropriate name for the corre...
I have a Class that "controls" the current application state, ApplicationStateManager. I have an Enum that lists the possible states for the application enum ApplicationState { Idle, Starting, Started, Stopping, Stopped } ApplicationStateManager contains members such as: public static ApplicationS...
I have to write API validation functions where the rules can get hairy and have many outputs depending on the branch taken. These validation functions end up being a nesting of lots of IF conditions here and there (I try to stick to simple condition IF for simplicity), where I have lots of comments to help what's happe...
In the following code sample, the processes are assigned to different contexts. And each App object will be bound to only one context. Though all the processes run the same code, only those belonging to the context will execute the methods of App. In order to implement this goal, as shown in the code, I have to add if ...
I will have a database of products where each record will have a number associated with it, let's say, the number of "sales". I will periodically update the database so each "sales" field for each record will be updated. I need to sort these records based on the "sales" columns, descending. I need to track the "ranking...
I am new to git and I would like to set up a so-called "integration manager workflow" as defined per Git official website with the following diagram As far as I understand, to do such thing I need to use the following command : git --bare init to make the directory my "blessed repository" and then set up read/write p...
Since I'm better with visual representations, I basically want to get this done: I did some searching and could only find this Git: Branch or Fork? And this one A decent git branching model for products that should accompany the version of another, third-party product (and pros and cons of one proposal) But while a s...
I've tried posting this question on StackOverflow but they told me to try it here since it's not so specific. I'd like to know the name of the algorithm or technique of following implementation. I wonder if this thing present in standard libraries of other languages (my implementation is in Javascript). Consider a func...
I am looking for the best pattern to apply in my problem. I have an interface that defines my service class functionality interface NegotiationInterface { abstract public function resetNegotiation(Negotiation $negotiantion); } A main class implements it public class NegotiationService implements NegotiationInterf...
Following Ordering menu items fed from multiple modules the question was raised to me, who is responsible for ordering and alignment of menu items in a modular application. The previous link suggests that the module who offers the menu item is responsible for saying where it will be located ("at index n", "after module...
I want to create a mobile quiz app where users can sign up and compete against each other. For the signup I am just using username/password combination. I want to ask you what are good ways to store the this data. I was thinking of simply saving the username and password in firebase database. Is that a good way? But t...
I have a route in a RESTful API where I need to pass a single username (email address) but not password. The route is designed to have GET method, so my options are either query parameters or a custom HTTP headers. I read that sending usernames via query parameters is not a good practice, but could not find any relate...
I have two applications, first is like starting point and the main app is second one. Whenever i have to do something, i have to login to the App1, provide some details to it, then App1 builds a Session(sort of a custom session, embeds lots of serialized data) and then re-direct the session to App2. Once I am done with...
I was looking at the Apache license, and under "4. Redistribution" I have to meet a few conditions in order to "reproduce and distribute." What if I simply just want to copy and paste some code into my website/app? Is that considered "reproduce and distribute?" Would I still have to do all those things listed under "4....
I am currently working on adding more customization to an entity component system library, although the problem is a little more general than that. In essence, I currently have hard coded containers for almost everything I do. I use a flat map* for storing components (for those unfamiliar with ECS, just consider it as ...
I want to figure out if its better to inherit a base class or interface or write the code up for entities. To better paint the picture assume the scenario below: Scenario: There are 30 entities All entities have 2 common fields (createdDate, modifiedDate) 10 of the entities also have a extra field called serverStatus ...
I have a bit of a mental block when trying to model my scenario whilst practicing DDD. The problem appears to be around 2 entities you would consider to be aggregate roots. I feel these aggregate roots would be an aggregate root in their own respective bounded context. Essentially, I have complex rules to apply in thi...
In java/android we can call code written in the c/c++ language for execution speed advantage. I have heard of Ahead Of Time compilation which (as far as i know) compiles the entire application to native code during its installation. I want to perform some mathematical operations like compression, encryption (not images...
My website is running on Azure and I deploy via the Deployment slots feature. When code gets pushed to my production branch, my "staging" site gets the code, I check to make sure it's ok, then I do the "swap" with production site. All is well. Now, I need to create a 2nd production website, where the only difference is...
I've read this page about design patterns, and how you should treat them when writing your code. From my understanding, as the title in the link states: Patterns are not building blocks. If I understand correctly, this means not to use a design pattern until it makes sense to do so, correct? Don't start off saying yo...
When I program in Java, I make all nullability explicit; that is, an instance of Foo is assumed to be non-null, and if I want it to be null, I use a @Nullable annotation (or better, Optional<Foo>). But C# doesn't natively support annotations, and Nullable<> is only for value types. But what if I did something like this...
Say, a gateway server keeps IPs to a main server and a database in a config file. This makes it easier to change the IPs without having to recompile. Does it really matter if this file gets committed? What conditions would apply to guard an IP address from public knowledge in this scenario? NOTE: The access to the data...
I'm building an app with a Client table that lists clients and it's PK by an auto-incrementing ID field. I need an immutable unique identifier for each client that will be used in business logic. For example client will upload a single file to an AWS S3 bucket, I want to use this ID as part of the file naming conventio...
I have licensed my software under GPLv3 and made it available on Github as an open source repository. Am I allowed(under GPLv3) to distribute binary releases of the application so it is easier to use ? I know I am obliged to make the source code available to the end user. Can this issue be solved if I linked if I link ...
I had a debate with a friend and I'm looking for a way to resolve it and decide which approach is better for maintenance and whether there's some consensus about a best practice regarding it: If an application shows some data on the UI (for example order ids that are added dynamically by the user) and there's a button ...
I'am new in Microservices, and this is the scenario. Background: I have an Web Application that requires store and retrieve files and let's say that i need to storage documents (PDFs, Word Documents, Excel,etc). My idea is to create an API in .NET core that allows you to create store files and provide an ID so that wh...
Let L be an ordered set of positive integers (for example, the set of all primes). Here, #L = infinity, and N is a positive number serving as an upper limit. Goal is to list the following set M: M = {all multiplicative non-linear combinations of L | each multiplicative combination < N} For example, if L = {a,b,c, ...,...
As far as I know Lua uses closures to encapsulate local variables, well I've got a function call in a worker thread which passes reference to a callback function, and the async call will be handled by the main thread, means callback will also execute on the main thread. My question is, because I don't know if accesses ...