instruction stringlengths 34 36.1k |
|---|
From wikipedia:
Servant is used for providing some behavior to a group of classes.
Instead of defining that behavior in each class - or when we cannot
factor out this behavior in the common parent class - it is defined
once in the Servant.
Please take a look at MoveServant and Movable example in the wiki page. ... |
I am working on a web app that must deal with very large impulses of simultaneous users, who need to be authorized, to request identical content. In its current state, it's totally crippling to even a 32-core AWS instance.
(Note that we're using Nginx as a reverse proxy)
The response cannot be simply cached since, in t... |
this is a fundamental question about MVC (in particular using AngularJS) and I've found similar questions here, but not the exact same problem:
Could the view call a function of the model, or should it only call functions of the controller?
Here's the example:
In my Model there's a function to delete items of a collect... |
I'm programming a game (turned base, in a grid) for which I implemented an AI using the minimax algorithm (with alpha-beta prunning). It's all fine and working, but the AI is too good and I can't win against it.
So now I want to introduce difficulties to the game (something like easy, normal and hard). The AI as it is ... |
I have recently started reading Heads First Design Pattern Book as well as coding on my final year project. In my project I am having Tanks which extends Entity. A Entity can be anything in the game which is positionable on the game map. Entity is an abstract class.
I have a move() method in my Entity class which will ... |
I'm a bit of an amateur when it comes to web development, but I need to do something a little more sophisticated than usual at work and I'm not sure how best to proceed.
The setup is as follows. I have a web server set up which takes some input from the user, gathers a reasonably large amount of data from various web ... |
Currently I am working on a project which has two sub system: a web application and a web API (consumed by android app) and both being developed as separate project since the API system need to deploy on different server but will access same database. After gathering requirements and producing Use cases, I have designe... |
I am working on a giveaway algorithm to select a customer based on what they purchased:
If they purchase item 1, they gain 1 point.
If they purchase item 2, they gain 2 points.
If they purchase item 3, they gain 3 points.
Each purchase in the database has an item_id, which I can use to figure out which item they have... |
<?= $vars['title'] ?>
For example, if we were writing a library from scratch, and we had File, FileHandle, DirHandle, and FileSystem classes, would each of these go inside a package/namespace called file? Or one named filesystem? Or os or fs? And if one of the former two, would it be a problem that we had file::File? ... |
First, yes This question is very similar to Arrays vs Objects in view template but my question sort of expands on this...
When deciding on whether to use an object or array to pass data to your view. Which would be a better approach when you're looking for a view that you can re-use for both....
Data passed through a... |
I know that since I own the code rights I can change the license in a newer version. But does it mean that while it's under GPL I have to comply with it myself? Or can I do whatever I want with it? Like not disclosing the source or stating changes I committed after.
|
I am implementing an interface I on a class A.
Class A implements I.
I have an Iterator T that is supposed to return an object which implements I everytime I call next.
My iterator goes as follows (of course omitting other stuff):
public class T<I> implements Iterator<I> {
@Override
public I next() {
... |
I need a advice on creating an architecture where I want API layer in between UI layer and business layer. UI layer should only consume REST services for displaying data.
Reason for doing this is that we need to expose same service for others clients like iPad, Android etc.
Now my questions are:
Do we need dependency... |
We are building a multitenant webservice with PHP and MongoDB. There is a need for communication between service employees and clients, communication can be established in many different ways. Some of them are: SMS, MMS, Email and, possibly, an internal chat system.
The question is, how to properly implement the databa... |
Imagine a modern PC game for example. I'm using this example because typically the executable file is fairly large, and especially in modern games the resource files are also pretty big.
Patching a resource file is fairly simple because depending on the file format it could just be a case of replacing one contiguously ... |
I've read many articles concerning microservices architecture and I was wondering when to use AMQP or REST.
I've read that loose coupling between services is a good thing and AMQP seems to be a good choice in that case. But if we use AMQP, this means that we do not need REST endpoints anymore (but it means that we lose... |
I have been following one of the capabilities Microsoft introduced for the Universal Windows Platform (UWP), namely app services. An app can now provide a service in the form of a background task that can be called by other apps to perform some task. It's something like a webservice on device.
Let's say a developer cr... |
We hear a lot about graph databases such as Neo4J and a little less about semantic platforms such as OWLIM and similar triple (or quad) stores.
I understand the latter is associated with embedded OWL support but what does that mean in value terms? What is the unique value of an RDF triple/quad store with OWL tooling th... |
In academic meaning, it seems to me that
algorithm design is studied in a high/abstract level of computation (computability, complexity), although software engineering is also studied in high/abstract level in academia.
software engineering is about the process of creating a software program for solving a problem. Th... |
How does one best write tests for a multi-threaded producer-consumer C program?
I know GDB can be used to debug threads, but I believe GDB also stops the thread currently being debugged while other threads continue running.
I want to test proper mutex lucking/unlocking and blocking by my threads. I've looked around a l... |
I am working on my final year project and making a multi player game. It's a tank battle game.
In the client basically we will have 2 types of Tank. One will be controllable by the keyboard and other will be the one's which are enemy tank's and not controllable. Enemy tank's position will change depending on when it g... |
I write a lot of front-end tests, and the tests fail really often. To be honest, they're hard for me to write. I feel like I have to do a lot of work keeping track of the state of the page. It seems like every function I write is the opposite of a pure function. There are so many side-effects. I get stale reference exc... |
I have an application that is divided into two main parts:
A web crawler written in Python
A REST API written in Golang
They share a MySQL database, which is mainly populated/updated by the web crawler, and then read from by the REST API.
I wanted to use an ORM on each side to make interacting with the database easie... |
Is using mocks in the following way a bad idea:
writing tests where mocks expect certain calls from the subject under test
Or even just writing mocks that return values to the subject under test if/when requested
Reason for my doubts: It ties down the SUT to an implementation, since the tests would need to change wh... |
I'm trying to understand the inherent tradeoff between roles and permissions when it comes to access control (authorization).
Let's start with a given: in our system, a Permission will be a fine-grained unit of access ("Edit resource X", "Access the dashboard page", etc.). A Role will be a collection of 1+ Permissions.... |
I've got a group of scripts to run and I'd like to batch them all together. Rather than write a .cmd/.bat file to run the lot it feels to me like there ought to be something similar to a playlist (e.g. .pls ?) file and 'script player' that could run each script in order and have different options on what to do if a scr... |
I want to write small library to guide a child process for a specific needs (not trying to reinvent bicycle here).
My needs includes reading from child stdout and stderr. I want to implement this as streams. If I would use simple std::streambuf descendant that reads directly from pipe on underflow - then my stdout and ... |
I have a Web API, and I'm thinking if it's a good idea to always wrap the result with a my own result model which will always contain specific structure like:
{
Data:(of type T generic),
Messages:[
{Key:"Key1",Messages:["Msg1","Msg2","Msg3"]},
{Key:"Key2",Messages:["Msg1","Msg2","Msg3"]},
],
MetaData:[
... |
I am currently working on a software using C# .NET and WPF with the MVVM pattern.
Though the software is almost done, I have been discussing our architecture for a long time and I would like to get your opinions/advices on the convention/good practices side.
The current architecture is as follows:
Project/
DataConte... |
We have an old system to manage inventory adjustments that is going to be remade. There are different type of reasons to make an adjustment, and each type requires different data to be filled. Some only require the product and quantity, others require a document ID, others require two products per adjustment, and so on... |
I'm learning about dependency injection and while I can see the appeal of it when writing functional libraries, I fail to see how it solves anything when you'll also be the one using the libraries.
It makes testing the library much simpler, because there isn't much to test.
But you will eventually have to test your inj... |
We have a big table with a lot of data and a select query which takes 3 seconds to run.
However we are a highly concurrent environment and each second we get 100 new records in our database.
So let's say we have this query, and before that query starts, we have 1000 items which satisfy those query. The query takes 3 se... |
I use Mapbox to display some moving markers over a map with several polygons drew over it (feature layers).
I have serveral markers (~1000) and multiple feature layers (polygons ~200) that represent different regions. The markers are moving (once per second with a constant velocity) and I have to know at any moment on ... |
Let's say I have the following entities.
Product, Option, and OptionValue
Product can be created without any options.
Option must include at least one OptionValue
OptionValue can be created without associations.
In this case, can product be an aggregate root?
I was thinking 'Yes', but then..I can't delete Option obj... |
I find tests a lot trickier and harder to write than the actual code they are testing. It's not unusual for me to spend more time writing the test than the code it is testing.
Is that normal or am I doing something wrong?
The questions “Is unit testing or test-driven development worthwhile?”, “We are spending more time... |
I'm a web developer and I've been asked to write a desktop app. The languages and libraries that I'm most familiar with are standard web tools (Javascript, Angular, Bootstrap). I'd like to use these same tools.
Lately there's been considerable interest in using web tools for Desktop, and frameworks have appeared that m... |
I'm hoping someone who's given this some thought can help me understand. Most style-checking tools seem to distinguish between warnings and errors.
To me, the point of a lint error is that a style issue ought to be fixed.
In the cases where the tool isn't smart enough to see that an exception can be made, many tools h... |
I would like to develop a web browser based interface that can be accessed locally and remotely for a C# console application. I would love this to be a light weight, self hosted app if possible (as long as that means it can be accessed over the web).
I am confused about the differences of
Web API
OWIN
Katana
I starte... |
I'm developing a application in Python and I've found various packages on pypi which appear to be what I need.
However, how do I know I can trust these lesser known packages - it only has a couple hundred downloads a month? Should I look at the tests/the source code? Perhaps write my own tests for these packages?
Any a... |
With regard to a child process in Node.js that is created like so:
var cp = require('child_process');
var n = cp.fork('child.js');
When forking a child_process with Node.js is it proper to kill the child process when it's done with it's work?
At the moment my guess is that if you don't kill the process that it stays ... |
I have a medium-sized python program (~5000 lines of code), which I've built up over time, with no particular plan as I went ahead. The architecture I've ended up with consists of 5-6 large Singleton objects, each of which handle a certain aspect of my program, such as database comms, a web-server, data gathering clien... |
I've an already existing project in C#. Now I should implement a plugin system. For this plugin system I've to implement a programming api/sdk. I dont want, that plugins have access to the assemblies that are used by my existing programm. This is the reason why I'll write a programming api that limit/specifcy the acces... |
I would love to know how the 3-Tier architecture differs from MVC (Model, View Controller) in ASP.Net as it seems to me that the same architecture applies.
In 3-tier we have User Services Layer, BusinessLayer and DataAccessLayer, on the other hand we have Model, View, and Controller. This seems same architecture to me.... |
I have been working with some fairly large text files containing about two million lines of text. I don't know the length of the content or the lines in advance, just the number of lines. I have been considering two problems that probably have a similar solution:
How do I change or add to the nth line, without my com... |
We're starting a new MVC 5 project that will ultimately consist of 4 websites depending on the kind of user:
One internal, for company employees.
One for agents, independent contractors that work for the company.
One for external salespeople.
One for customers, which could be any one from their homes.
The internal w... |
I believe this question has been discussed to death.
I was reading up on REST and it says that it has to be stateless.
Yes i do understand there are application states and resource states.
Taking for example a normal web service,
Say if i were to log in from PC A and perform some transactions without logging out.
I ... |
I want to launch a service that could support integration by third-parties. Unfortunately it’s way out of hand to build an entire API by now. Here’s my question: Would there be any possible solution by providing cookie access to third-parties in the browser by the logged in user? For example, “like a picture” in the na... |
I'm working on a web framework that makes surveys. It has an expression manager which lets admin users run code on the client as Javascript. There could be a potential XSS problem when there's more than one admin, as is the case for universities. So, instead of compiling expressions to Javascript, what about compiling ... |
I’m building a mobile app marketplace and I came to the point of integrating a payment tool. I'm using Mangopay, which has a nice workflow for making payments in a marketplace using its REST api. The question is: is it correct to implement all the workflow and the interactions in the mobile app, or should I implement i... |
Before writing this question, I'd like to state that I use Linux on a daily basis, which is why I'm creating this post to extend my knowledge of the other main operating systems I'm concerned about, Mac OS and Windows.
I'm developing a NodeJS application that needs to read a configuration in order to understand what to... |
Is the following an acceptable breach of the 'Nested types should not be visible' (Microsoft .NET code analysis CA1034) rule?
I have a have a class, let's call it 'TandAOLL', this is tree and an array of linked lists all in one, this is a QuadTree implementation which allows for grouping of points.
Inside this class I ... |
I want to create a multi-page application using angularjs, because i want to make use of a lot of angularjs functionality, like two way binding, form validation, AJAX handling, etc. But I read from some blogs that angularjs is best suited for SPA only. Is that right?
Can I use it in my multi-page application?
If I can... |
Code
public interface IVehicle {
string VehicleMake { get; }
int MonthsSincePurchase { get; }
bool IsApprovedUsed { get; }
...
}
public class WarrantyPopUpHandler {
virtual bool ShouldShowPopup(IVehicle vehicle /* What should I pass in?*/) {
return false;
}
}
public class VolvoWarrantyPopupHa... |
Pseudo-Code
interface IPagingInfo
{
int CurrentPageNo { get; }
int RowsPerPage { get; }
...
}
interface ResultsRetriver
{
ResultRows GetResults(IPagingInfo pagingInfo);
}
class ANewResultsRetriver : ResultsRetriver
{
ResultRows GetResults(IPagingInfo pagingInfo)
{
// TODO: Retrieve an... |
I'm looking for a good tool or technique to search a Java code base and find every method that says it returns a collection (List, Set, Map, etc.) but sometimes returns null. This would be a cool IntelliJ IDEA inspection and could work without annotating @NotNull.
|
Say I have a SSN field in a form. I want SSN to be in format of xxx-xx-xxx.
I may just have a SSN formatter checking whether the input are all digits and adding dashes when necessary.
Another option is to have both SSN formatter and validator. SSN formatter doesn't check type or range, so it accepts asdfghjkl and fo... |
How does a commercial library vendor manage to stick to the same ABI over years of development (or is this a bad assumption on my part)?
I would have thought that over time a lot of functions and class interfaces would be completely rewritten. Do they just have the foresight to know what footprint to use from the get-g... |
So I understand that one must not use
using namespace std;
in header files. Well for my assignment we have to overload the >> operator. I got my program to run and all, but I had to include the
using namespace std;
Is it okay to do it this way? I attempted to overload the operator without including that command in ... |
Sometimes I find it useful to have a single class with multiple instances (configured differently via their properties), rather than multiple classes (inheritance).
??? Pattern
Single class (Fruit)
Different fruit are instances of Fruit, with properties configured correctly.
Behavior implemented as blocks.
class Fru... |
So our scrum team was talking this morning about some mega screw ups that one team continues to make but could apply in any situation and how we could bring transparency and accountability for the entire department. We have around 80 people including documentation, QA, development, product management, technical operati... |
I've been searching on the internet about using interval ajax polling for live web pages and I've been using it along with SignalR. Now I always read an article online about using ajax polling for live web pages that there could be an impact on your server or maybe there's a downside effect when using ajax polling if y... |
Let's say library A, B and C are all custom math libraries. They may or may not use the same data types. The libraries have methods that accept data type inputs like ProcessAsync(DataTypeA) or ClusterByFeature(IDataTypeB, Func<IDataTypeB, double>).
These libraries will be developed for modularity. E.g. Future graduate ... |
If there is Employees repository and I have to get Employee that has a greatest salary - where to put filtering that represents business rule for that?
I can get all Employees and filter them out in Domain Model, but that does not seem as efficient as SQL Query in repository. What patterns come into play?
|
I'm using CMake for several years now and found that - in the cases where I'm struggling with CMake - I'm still not completely sure about the concept behind CMake (not taking into account CTest, CPack or CDash also shipped with CMake).
When I started I came across Bill Hoffman's presentation on Google Tech Talks and on... |
I have a list of points, with floating point coordinates, of which I've computed the square of the Euclidean distance between these points. I have not computed the actual Euclidean distance between these points because computing a square root is an expensive operation. So, I have a list of floating point squares {a², b... |
I would like your feedback regarding some best practices on design relationship between objects, specially when a singleton object is involved.
Let's imagine I need to simulate a Shop with Customers.
There is only one Shop in my application and a Customer belong only to that Shop.
When the Shop closes I need to notify... |
I'm using JavaScript but the question can be generalized to all the languages.
In a nutshell - I'm checking if a browser connecting to my site is a microwave and cater for that accordingly.
What would be the best way to structure my code?
Best way is in "most readable", "most maintainable" (insert your own metric here)... |
I'm porting the ESRI geometry-api-java library to C#. They have placed the library under the Apache License. They also mention it in the README.md.
They have a small bit of licensing info in the header of each source file. Do I have to replace that header with my own Apache 2.0 License disclaimer? Or do I just leave th... |
I'm currently designing voucher system to be implemented in our company e-commerce application.
I'm currently have voucher table in database which contains following information :
Unique voucher code
Voucher remaining count -> How many times this voucher can be used in purchase transaction
Other columns
Currently, ... |
I've a series of labels and icons inside the screen. A label is on the right of corresponding icon.
I must perform a sort of declutter: when two or more labels overlap each other (or a label with an icon), the label must be moved in free space. This for every label. I must move all overlapping labels in order that at t... |
In functional programming, how do I do an equality comparison of all items in an array?
I have an array of items that I want to compare, for example for equality. Is it possible to use a fold (also known as reduce) operation for this?
This code won't work, because after the first iteration, memo is a boolean:
[a, b, c... |
Our project utilizes a static database (no writes). With many users we don't actually have a problem per se reading it. If a database "locks" per read request by any user, then would it not be more efficient (though perhaps unnoticeable) to have multiple databases that each user connects to individually?
We are databas... |
I am documenting an existing system using UML 2, and a few of the classes are too big to comfortably fit into a single class box.
So far, I've resorted to breaking up the class into multiple boxes with the same header, with (cont'd) annotation added. This is supposed to represent a single Foo class with four public mem... |
If you have multiple instances of a classifier with the same name, do they simply combine, or is that not allowed?
For example, are these two equivalent?
+-----+ +-----+ +-----+
| Bar | | Bar | | Bar |
+-----+ +-----+ vs. +-----+
| +a | | +b | | +a |
+-----+ +-----+ | +b |
... |
I have a group of invoices to send to a back end.
The requirement is to be able to send everything with a button, so I can do the following:
Send everything as form fields name like form1_detail_text
where form1 would be the id of the invoice, detail the part, and text the kind of field.
I can put every invoice separa... |
I have a system that allows certain functionality to be implemented different ways, but requires that the functionality of each implementing class be wrapped in another layer. For example, each implementor has a doFoo method that interacts with an API. The implementor classes can be loaded at runtime (they are, essenti... |
I know the term "scripting languages" is just a subset of programming languages, but I want to refer to programming languages such as Python and Ruby among others.
First of all, why don't we need a compiler for these languages? For example, IDEs like Visual Studio or Eclipse have their own compiler in order to transl... |
I have questions regarding software development process,
Let's assume we have three teams
Business analysts
Implementation team
Quality assurance team
I think that Business analysts inputs is BRD (Business requirements) from the client,
My question is regarding the implementation team input (the engineers who a... |
I am following a course of Algorithms and Data Structures.
Today, my professor said the complexity of the following algorithm is 2^n.
I waited till the lesson was over, approached him and told him I actually believed it was an O(n) algorithm, and I did the computation to prove it, and wanted to show them to it, but he... |
How could one compare the shape of abstract syntax trees of similar source code programs (C, C++, Go, or anything compiled with GCC...)?
I guess that plagiarism detection on source code would use such techniques, but I have no idea of how would that be called...
For example, unification could be used to compare AST, bu... |
I have a Screen Window system, a Screen (IScreen as interface), which holds a window, either WindowA or WindowB. System can switch window by calling stateChanged:
class IScreen{
public:
virtual void stateChanged(int state)=0;
};
class Window{};
class WindowA : public Window{
public:
WindowA(IScreen* screen){
... |
Lets say you have a user-interface with a tree view, and you click on already selected item. Should the click-event be handled normally or ignored (since the item is already selected)? Lets also assume that performing normal click-handling involves lots of lengthy calculations, but in overall takes less than 200 ms.
In... |
I'm really glad that EcmaScript 6 has promises built into the language, but the syntax will still be quite wordy:
new Promise(f).then(r => {
...
}).then(r2 =>
...
}).catch(...
I'm just wondering if there are any languages that have syntactic sugar for promises, so the result looks more like conventional imperative pr... |
I want to design an online book reader system as a programming exercise. I wrote down the following requirements:
Searching a book by title.
Bookmarking a book.
Mark a book as favorite.
Give rating.
Manage users.
The constraints are that only one user can read a particular book at a time.
I follow Clean architecture.... |
I've been working for quite a while now on a service that generates optimal routes for a given set of addresses and vehicles (Vehicle routing problem / traveling salesman problem).
Now it's all working fine, but the bottleneck is getting the distance/time between two addresses used for calculation. Currently we use web... |
I'm currently developing an application that has quite a few dependencies.
Now I want to release the code as open-source under the WTFPL (Do What the Fuck You Want to Public License).
Of course this only applies to my code, not that of any dependency. How would I go about this?
I pull in my dependencies via an automati... |
Let say I've a fixed length number, e.g. 6 digit: 837493, I want to apply some process (with a salt), and generate a new number of another 6 digits,
e.g.
number = 837493
another = hash(number + salt) // another is also a 6 digit number, e.g. 948375
Are there such algorithm exists?
|
In JavaScript, one should declare all variables at the beginning of the function to mitigate the risk of mistakes related to the fact that the scope of variables is a function. The following code illustrates this non-intuitive scope by actually printing "Hello, World" to the console:
var demo = function () {
if (fa... |
The usual instinct is to remove any code duplication that you see in the code. However, I found myself in a situation where the duplication is illusory.
To describe the situation in more details: I am developing a web application, and most views are basically the same - they display a list of items which the user can s... |
Given a workload with many long running CPU/IO intensive operations (e.g. producing multi-GB text files from database reads and business rules), what is the best way to balance .net application load across a group of Windows Server 2012 R2 VMs?
Ideally, the approach would allow for adding/removing/patching nodes as ne... |
Where you would envision an out-of the-box ASP.NET MVC 5 web application on top of an MSSQL database, I have now been placed in a situation where I'm supposed to use custom external token endpoints and use bearer tokens to make authenticated API calls.
I'm, de facto, attempting to create a(n as) databaseless (as possib... |
In my current job they are defining a new corporate architecture for java development. It is something like this:
ProjectView: JSF view layer. Uses delegates on the ProjectClient layer.
ProjectClient: Defines Delegates and Facades. It does de lookup for the EJBs the business layer.
ProjectBusiness: Implements the Fa... |
Dilemma
I've been reading a lot of best practice books about object oriented practices, and almost every book I've read had a part where they say that enums are a code smell. I think they've missed the part where they explain when enums are valid.
As such, I am looking for guidelines and/or use-cases where enums are N... |
I've been given most of the hiring responsibilities and will be conducting the in-person interviews. I'm also going through the resumes for worthy candidates. The plan is to have the HR department do the phone screening though. They'll ask the normal HR questions and then any questions I give them and then report back ... |
If I include, say, a GPLv3 repository in in my repository using git subtree, would that count as distribution? Am I now required to license my repository as GPLv3 as well?
I don't intend to modify or interact with the GPL code, but I would like to have it in my repository for convenience and as a reference.
|
I have my own home server and port 80/443 is blocked from my ISP provider. I want to create a Qt gui application that saves my data on my server using REST (using port 8080 or something) using nginx/node. The user would log in using a username/password. What would be another alternative to secure the data being exch... |
I have a n by n maze, like this:
[0, 1, 0, 0, 0, 1]
[1, 1, 0, 1, 1, 0]
[1, 0, 0, 1, 0, 1]
[0, 1, 1, 0, 0, 1]
[0, 0, 0, 1, 0, 1]
[1, 0, 1, 0, 1, 1]
Only 0-fields are passable, and one can only move directly up, down, left, or right.
I want to find the longest possible cycle-free path from a given point.
I am aware that... |
I'm very fastidious about code. When I remove functionality from a file I remove the cooresponding #includes. I've hit several errors where I would remove a #include from a header, and another file that #included the header I was editing depended on that #include.
Depending on the error given by the compiler it can was... |
According to Gödel's incompleteness theorem, not every problem can be solved using algorithms. How do we know if a problem can be solved using algorithm?
How do we know that NP problems are algorithmically solvable?
|
I am learning OpenGL and the tutorials (1, 2) I'm reading teach me that to scale/rotate/translate an object you have to know matrix multiplication. Why? Instead of 3x3 matrix you can use 6 floats: scale_x, scale_y, sin_a, cos_a, mov_x and mov_y. They would result in...
Less GPU and CPU usage (matrix multiplication tak... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.