instruction stringlengths 34 36.1k |
|---|
We have deployed a restful web service on a application server (Apache). The volume is getting higher and we do want to scale it. We will deploy two more Apache instances on two more machines.
How do I implement a layer which sends request to each of these based on a round robin strategy?
Currently say I have www.myweb... |
While using FLUX in a CRUD application,
according to what I understood, initially the data is returned from an AJAX call and then stored in the STORE. So, all the data that is currently viewed is only from the STORE.
So my question is, if I'm seeing a listing page of all the data and some other user changes that data i... |
I am going to develop a server application to provide the functionality of a book keeping software in tomcat server. I can think of two ways to achieve this.
Creating a single web application - Let's say we have to provide invoice management, user management and report management. All these logic is bound to this sin... |
I'm aware of a few good options:
Big integers (e.g., int64_t, mpz_t, any bignum lib) to represent cents or 10-n cents—say, an integer represents 1/100 of a penny ($1.05 == 10500). This is called a scaled integer.
High level library for arbitrary precision decimal arithmetic such as BigDecimal in Java, Decimal in Pytho... |
I'm trying to identify an object (a cube) in a set of photos. Using Canny/Sobel/Hough I've managed to get the photo down to a set of lines that are pretty accurate; however if I plot these lines on my image there are a lot of duplicates where the angle/distance varies only a tiny amount. Here's a cut down sample:
I th... |
Every class of a model in my application has a create method. The framework gives me the default implementation of create which is “create in the DB”. Sometimes I need to perform some extra actions during create. There are numerous of ways to achieve this: I can override create (and call super thereafter), subsribe to ... |
My understanding is that part of the point of the JVM was that the code could "run anywhere", but CLR code was designed to run only on Windows: so why have a virtual machine?
I know that the CLR runtime takes care of garbage collection, but there are garbage-collected languages that still compile to native code.
The on... |
I currently have two parties set up:
typical HTTP web server
native app distributed to consumers (presumably behind typical home router/firewall configuration)
The app is designed to work on certain small problems, but I want apps configured to work on similar problems to work together. Right now, the only solution I... |
When I learned C++ long ago, it was strongly emphasized to me that part of the point of C++ is that just like loops have "loop-invariants", classes also have invariants associated to the lifetime of the object -- things that should be true for as long the object is alive. Things that should be established by the constr... |
I currently have a requirement to conduct polling in a network where new systems may log into anytime.
The idea is that whoever comes online first goes into mode1 while the second guy goes into mode2, third guy and onwards to into mode3. Simple enough right, but the problem is deciding who came first.
Assume no third ... |
I'm working on drawing application and I want to provide grid with snap to grid functionality. I'm trying to find the right way how to do that (ideally some design pattern), but I'm quite confused about the right class which should be responsible for that.
I have editor class which has an active tool object. Editor is... |
I am always not able to follow Netbeans default coding conventions like the following
Function should be N lines only
Method Length is N Lines (M allowed)
Warning: Do not Access Superglobal $_POST Array Directly
// Using this
$username = filter_input(INPUT_POST, 'username');
// Instead of this
$_POST['username'];
A... |
I am on a project where I call an API and I want to make statistics with the data returned. It returns a big .json object. As that is not possible to flatten, and I am not interested on all the data returned either, I want to parse only certain keys. I have thought of parsing and then creating a well structured json my... |
Take the following class hierarchy:
Client
FacebookClient
PinterestClient
TwitterClient
Each client must define a value for an enum property named ClientType (string property Url in the original version of this question; hence the accepted answer). ClientFactory should then be able to instantiate by client type.
Cl... |
I have a scenario, where I draw multiple graphs in same applications and each graph is an object of graph class.
I want to delete the graph using event handling (button click event) and the event handling occurs in graph class and here I can simply call the destructor to delete this object.
Is there a way to tell the m... |
My team is planning a migration from subversion to git. We support 3 applications... 1 is primarily for internal users, 1 is for corporate "partners" and 1 is for end users. These applications share some code and also communicate with each other using web services and message queuing. They have different release sche... |
I'm diving into the world of functional programming and I keep reading everywhere that functional languages are better for multithreading/multicore programs. I understand how functional languages do a lot of things differently, such as recursion, random numbers etc but I can't seem to figure out if multithreading is fa... |
I have a dataset full of rows that I must initialize into myclass and then process.
I am currently looping through each row in the dataset, initializing a new instance of myclass, then adding that instance to a list with type myclass.
I then loop through the list and conduct a process on each instance (for purpose of t... |
Numerical analysis text books talks about the absorption phenomena (Introduction to Numerical Analysis and Scientific Computing; Nabil Nassif; Dolly Khoueiri Fayyad; CRC Press; 2014) when adding floating point numbers with a big difference in magnitude between them. There is also the concept of Unit In Last Place or ul... |
I am designing a system that uses Event Sourcing, CQRS and microservices. I am lead to understand this isn't an uncommon pattern. A key feature of the service needs to be the ability to rehydrate/restore from a system of record. Microservices will produce commands and queries on a MQ (Kafka). Other microservices will r... |
I'm in the process of experimenting with ways of breaking up a large (and growing project). Currently, we're working with a big Angular application with what will soon be a large number of components.
One idea I'd like to try is breaking each component into a completely separate website/project, as a collection of plug... |
Using javascript or in a native iOS App it is possible to read and modify cookies.
The server generally sets these, but if both the server and the client modifies the values then it becomes a global shared mutable state across systems.
This feels bad.
In the RFC it does not mention user agents modifying cookies other t... |
I'm commenting some code right now, and I'm looking for a word meaning the thing being iterated over. Iterator is an object performing an iteration, but what's the object that the iterator is iterating; the result of one iteration?
|
I'm currently trying to turn some R code (interpreted language) into C code (a compiled language), and I need to explain what is being done and/or why.
Does anybody know of a term/verb for this sort of practice?
|
Consider a situation where a class implements the same basic behavior, methods, et cetera, but multiple different versions of that class could exist for different uses. In my particular case, I have a vector (a geometric vector, not a list) and that vector could apply to any N-dimensional Euclidean space (1 dimensional... |
Given a fairly traditional node class (below), what's the best way to implement equality on a given graph?
If our node looks like this
public abstract class Node{
private final Set<Node> predecessors = new HashSet<>();
private final S<Node> successors = new HashSet<>();
//we do have a visitor scheme
... |
I cannot understand the definition. Here's some code:
Integer iW;
for (iW = 1; iW < 4; iW++)
System.out.println(iW);
int i = iW;
iW += 6;
System.out.println(String.format("iW = %d, i = %d", iW , i));
Outputs this:
1
2
3
iW = 10, i = 4
What is going on, exactly? Integer object iW sure looks like it's changing to me... |
I need to send a photo from one mobile phone to another. Currently, I'm splitting the image up into bytes before sending and then reassembling the image on the second mobile. This works fine, but if the photo is large (and they keep getting larger due to the better cameras on phones), then it takes some time for the ph... |
Domain Driven Design(DDD) has an abstract repository pattern to handle saving and fetching/finding entities in storage (db, external service, doesn't matter). My question is if Repository Pattern has to only bring the objects to system and put it away and it is basically, for example, objects of database drivers like M... |
The task:
I have a database with 4 tables with 200 rows, 800 rows, 50 rows and 30 rows respectively.
Just to simplify it, let's assume the tables are these sets:
A = [Ar1, Ar2, Ar3], B = [Br1, Br2], C = [Cr1, Cr2, Cr3], D = [Dr1, Dr2, Dr3, Dr4], where Ar1 means row1 of table A.
There is also a 5th table "E" with 250 ... |
I have a string that contains numbers in sequence. There are no delimiters between numbers. I have to find missing number in that sequence. For example:
176517661768 is missing the number: 1767
8632456863245786324598632460 is missing the number: 8632458
I have no idea how to even start. As you can see, I don't know th... |
I have base two classes, Operation and Trigger. Each has a number of subclasses which specialise in certain types of operations or triggers. A Trigger can trigger a specific Operation. Whilst an Operation can be triggered by a specific Trigger.
I need to write the code that maps a given Operation to a given Trigger (or... |
I want to design an approval process for my work flow but I wonder if there is an architecrural pattern or desing pattern for this solution.
For example an engineer will create a work. And program manager will approve it. Then general manager will approve it. The steps may be more. Then all users will see the work. Or ... |
This is a pseudo-code from "Artificial Intelligence: A modern approach"
function Table-Driven-Agent(percept) returns action
static: percepts, a sequence, initially empty
table, a table, indexed by the percept sequences, initially fully specified
append percept to the end of percepts
action <-- Lookup(... |
When you sign a SOAP message with a private key, how does the server know your public key in order to verify it?
I am connecting to a Datapower instance that sits in front of our actual Java web service. I keep getting signature not valid errors from the server, so it leads me to believe it has something to do with key... |
Here is a simple programming problem from SPOJ: http://www.spoj.com/problems/PROBTRES/.
Basically, you are asked to output the biggest Collatz cycle for numbers between i and j. (Collatz cycle of a number $n$ is the number of steps to eventually get from $n$ to 1.)
I have been looking for a Haskell way to solve the pro... |
I'm working on a project with has different checklists (questions and answers) associated with an entity (Protocol). There is a business requirement to have these questions be altered in the future and when a new entity is created it would be associated with the current checklist.
Example:
Lets say there is a checklis... |
We want to extend the session duration for our users. I guess it doesn't matter for users who are not authenticated. We can create a PHPSESSID cookie for them and if it expires when they close their browser then fine. But for users who are authenticated we want to extend the session duration so they don't have to sign ... |
Ignoring (with difficulty) Occam's Razor which would seem to put this quickly to rest, what advantage would this have:
typedef struct s_header {
struct s_header *next;
//...
} Header;
over this:
typedef struct header {
struct header *next;
//...
} header;
?
This question is based on an argument I was ... |
Let's consider following scenario:
Person A creates a piece of software and releases the source code under a permissive license, let's say MIT
Person B downloads that piece of software and uses it accoridingly to MIT license.
As an owner and holder of all the right Person A decides to change the license from MIT to ot... |
So Im using the MEAN framework to build my web app. Like all other apps it requires a login & registration.
My Approach so far has been:
Every major function of my app has its own AngularJS controller
I have a data filter controller, which helps to filter data within the app. But my filter controller DOES NOT connect ... |
I have a large codebase with a lot of "anti-pattern" singletons, utility classes with static methods and classes creating their own dependencies using new keyword. It makes a code very difficult to test.
I want to gradually migrate code to dependency injection container (in my case it's Guice, because it is a GWT proje... |
My company has an old GUI application on VxWorks. Now, I was requested to port this application to Windows XP over new H/W platform. The original application calls WindML & Zinc (Tornado's GUI libraries). For successfully porting this application, I can figure out these approaches:
rewrite GUI functions using VC++ on ... |
I find this behaviour in Python quite peculiar and I believe it can lead to many bugs especially if you have a function/method that takes in a list and returns another list after carrying out some operations on the elements in list.
x = []
val = (row for row in x) # create a generator
print(next(val)) # will raise Sto... |
Command Query Separation is a useful principle, though it's not always ideal. Sometimes you need to run a process, which will result in useful data you need to return. My specific case is uploading a file to a server and getting the ID of the file (which is assigned by another system I have no control over).
In simple ... |
I have a program that processes measurements of different types, using different units. For example, kilometers, miles and meters. Or pounds, kilograms and ounces. Each value has to be associated with a unit identifier.
I'm thinking about using urn's, instead of strings, to identify the unit. For example:
urn:mycompany... |
I have following task:
I need to send several instructions after each other to the hardware. Next instruction is never sent before either answer to previous instruction comes (valid answer or error) or timeout happens.
Currently all of those instruction has their own listeners with onReceived(answer) and onError(Error... |
Item 23 of Effective C++ (3rd edition) by Scott Meyers is titled: "Prefer non-member non-friend functions to member functions". The reason Scott suggests is the increase of encapsulation. So, only the functions that need to access the private members are made member functions, the other functions are made free-standing... |
We are developing a system for a customer that does not want to allow installation of packages from outside repositories. The project is in Python and defines its dependencies via setuptools; most of these dependencies are found on PyPI, and others are found on our company's repository. Some of them require system libr... |
I had previously deployed application storage in HTML5 to great success in the deployment stage of a few client projects. I used the app cache feature mostly as a way to allow my clients to remotely install kiosk software in their web browser remotely by setting up a temporary "install url" that they would visit and lo... |
I'm looking for a name or design pattern on an ACL Based permission system (at least, I think it has some features of ACL).
The case
An admin is allowed to create Managers. These managers will be granted several permissions based on what the admin submits when creating the manager (note that the permissions per manager... |
Item 23 of Effective C++ (3rd edition) by Scott Meyers is titled: "Prefer non-member non-friend functions to member functions". I understood that the intention of Scott was that, whenever a function can be implemented in terms of the existing minimal set of member functions, it should be made free-standing.
However, I ... |
Purely out of curiosity, I was posed the question with a hypothetical game corp. that has an online game that they require players to pay a monthly fee for. The specifics was that their service agreement stated that the user only has the rights to the client as long as their subscription is active.
However, said hypot... |
To me, the word "default" means what happens if I do nothing. So I feel that the "default constructor" should refer only to the one that the compiler provides if I do not write any. That makes it clear that "no argument constructor" means one that I have written, just like any method could have no arguments.
I don't se... |
At my Job I'm currently on refactoring a very old php CMS. By now, "code handling" was done by simply copying the whole thing and modify it to fit whatever was needed for this job to be done (actually the CMS implementation itself is rather an example site than a framework for building one).
Luckily, it is pretty prog... |
I am very new to programming and have this humble OOP-related question:
Can we have a module in a OOP-manner written program, that contains 2 or more OOP features? Say, both Encapsulation and polymorphism OR both inheritance and modularity, etc...
|
There's an application, which accepts a user id and password to login. Validation of the id and password is processed by another system. Now after password validation, the application generates a One Time Passcode (OTP) and sends it as an SMS or email to the user.
This OTP expires in 15-30 minutes. Only when the OTP is... |
I am having a hard time trying to figure out the best way to report on and calculate layered time data.
The problem:
A person can sign in multiple times, during this sign in there are multiple statuses a person can be a part of. These statuses can be different per sign in per person. I am trying to figure out the best... |
Scenario: I'm working in an Agile environment. The dev environment has not been configured yet, and I'm told to code a piece of an application.
I code the module and write appropriate unit tests for it as part of the coding task, and test the code offline in my own box.
There is also a testing task that needs to be pe... |
The CPU I am most familiar with is the Z80 which was first released in 1976. The most complicated mathematical single instructions it has are integer ADD, SUB and closely related instructions, such as adding with carry.
As such, it doesn't even have multiplication or division or any on-chip support for floating-point n... |
We have an issue where sessions are ending after a short time, 1440 seconds according to gc_maxlifetime settings which seems consistent with the issue. The PHPSESSID says it will expire when the session ends - I guess when the browser closes? I suppose before then though the GC is cleaning out expired sessions so the P... |
In Python, lists offer an append() method which can be called using standard Python method syntax; for example:
>>> my_list = []
>>> my_list.append('a', 'b', 'c')
>>> my_list
['a', 'b', 'c']
This syntax is intuitive to me, and this pattern is common in list implementations across many OO languages.
Lately, I've been w... |
My question relates to Texas Hold'em Poker. But I believe it will be the same algorithm for any kind of poker game.
So let's consider two hands: AJo and KQo. I can use online calculator and find out that AJo wins in 59.48% cases.
My question is: how can I calculate this probability programmatically?
Of course I can... |
I read every explanation here but still not convinced. I think mergesort is n * n and I know I am wrong but not sure where. Here is what I think:
Suppose we are sorting 8 elements and this is the algorithm (assuming I have the right idea for it):
doSort(int begin, int end, int[] arr) {
if(end != begin) {
in... |
I am working on a paint type application in android. I got toolbar on left contains tools like undoCut, redoCut, box, frame, cutting, coloring, next, previous etc. I wanted to know what is the best way(design pattern) to implement such behavior. How to to perform action against each tool. Enable/Disable tools on some c... |
Sometimes in source codes I see something like:
// TODO: Do we assume searchChar is usually relatively small;
// If so then calling toString() on it is better than reverting to
// the **green implementation** in the else block
(from here)
My guess is that green implementation refers to quickly written code... |
In one case BaseWizardController should implement background functionality of BaseController->BaseConsumerController, in other case it should implement only BaseController.
Any ideas how can I do that?
Update.
I don't mean 'multiple inheritance' in direct sense.
I need some pattern, something similar to Decorator, tha... |
Background:
I work for an NPO which receives large numbers of paper check donations every week. The current process of recording the donations is tedious and done mostly on paper. Because most donations come from regular donors, we assign unique donor IDs, which makes it easier to generate end-of-year contribution repo... |
Python has many strong conventions but I'm unclear on how best to manage exceptions for my module. I know it's generally good practice to define a custom exception for your module. E.g.:
class MyError(Exception):
pass
However, what I'm not clear on is how specific exception classes should get? Should each code pat... |
I currently have an abstract class and multiple classes extending it. My problem is, that there has to be a way to create a variable number of instances of an extending class. The number of instances depends on some results from a prior operation and on the extending class itself.
For now, there is just a method separ... |
I have to design a simple server-client model for the billing system of some fictitious restaurant.
After spending about 10-15 hours on the UML diagram, I haven't gotten that far. The main issue I am struggling is with the client side OO design.
The current two ideas are:
Design A
In this design, I am essentially stuf... |
I have written a struct that represents latitude/longitude coordinates. Their values range from -180 to 180 for longtitudes and 90 to -90 for lattitudes.
If a user of that struct gives me a value outside of that range, I have 2 options:
Throw an exception (arg out of range)
Convert the value to the constraint
Because... |
JSON Web Tokens (JWTs) are an open, industry standard method for representing claims securely between two parties. There are numerous implementations for JWT verification, but it looks like each author is testing his implementation on his own. It would be great if there was a tool or fuzzer to verify a given implementa... |
The server side detect events and store the information to notify the user. When the user opens one of the multiple clients (web, Android, iOS) it sees a indication that there are new notifications. The user can read the notification message.
The clients support multiple languages.
We got stuck searching for a good sol... |
We use GitHub Flow in our project and most of the time, we open a new feature branch from master, do some work there, open a PR, review the code and merge back into master.
However, my current work depends on another issue that is being worked on in feature-branch-A. Is it kosher to create my branch from that other bra... |
I've entered in an argument with a fellow colleague about a piece of code. While he thinks that it is ok, I don't. But I don't have any more arguments than that calling the same method (recursion) in a catch block is not a good practice.
So here is a pseudocode of what we are arguing about:
public String someMethod( So... |
I have a set of type rewriters, each modifies a given C# type in a different way. Examples are:
Add the XYZ attribute to each property of the class
Add an ID property
Add two properties and some corresponding method
As you can see there are implicit dependencies: 1 should definitely run after 2 and 3, otherwise not a... |
Does a web service that is defined by a WSDL; when implemented; need to use the SOAP specification to structure the request and response messages? Can it use an alternative to SOAP? Are there any alternatives to SOAP that are being used?
Vice versa: Do web services that are implemented using SOAP, need to be defined u... |
I was reading about casts in c++ and got confused about how are the expressions actually evaluated. Consider the following code in which var is of type int and after the expression var = (var*10)/10 the memory of var gets overflowed:
#include<iostream.h>
void main()
{
int var = 25000; // signerd int varies from -327... |
When designing the software, must we consider how much this code could be testable? for example, if we used X technology/Class/Interface instead of Y, based on that X can be tested more easily than Y, Is that a good design?
Use Case: I faced a problem when writing the integration test of our software which was built up... |
I have an application (run by a Windows Service) which connects to a TCP server (let's call the service 'Listener' from here on).
[It's important to note that the TCP server is out of my reach, and should be considered as an external component that cannot be changed in regard to the following question]
The TCP Server p... |
Imagine a program similar to this in Python:
import subprocess
class Example():
_cmd_args = (['ls', '-a', '/usr/bin/'], ['ls', '-al', '/usr/local/bin/'])
_default_args = 0
def init(self):
pass
def run_ls_command(self):
p = subprocess.Popen(self.get_command(), stdout=subprocess.PIPE)
... |
I have a dataset sampled with a specific pattern (timestamps). The very first repetition of the pattern is damaged, meaning that the values are nonsense.
To exemplify, my data looks like this:
data = [garbage | pattern | pattern + t | pattern +2*t | ... | pattern + n*t];
Where garbage and pattern could be, for example... |
I'm asking myself how verbose I should be when unit testing projects written in untyped languages like Javascript.
Let's take an example for a strongly typed language (C#)
public bool Foo(MyClass myClass) { /* ... */ }
As C# is strongly typed I can be sure that myClass is either null or an actual instance of MyClass (... |
I am developing a backend where in I will be exposing APIs for my mobile application. Users can register,add products,share the links of products through email/sms/anywhere and others can click on it and buy the product. This is the simple workflow of the mobile application. The app is an image intensive app which will... |
I have a system running in Azure that accepts messages via a REST endpoint. The customer has a certain number of devices that send some data for example temperature and we present this data in a web interface. The part of the system that accepts messages is separate from the website (microservices!) but they access the... |
I wanted to write a readable fraction with html and found it non-trivial and not portable. Why is it not very easy to write mathematical formulas with html and why has it taken so long to include simple mathematical expressions in html? I could think that it should be easy to write a fraction with a straight line betwe... |
Scenario
I have some values of the type : (Name - Email)
From this couples of data, I have to set a ArrayList of "Name" values,something like: |Name1|Name2| --- |NameN| to set a Spinner. (Ordered alphabetically)
When I choose some Name in the spinner, I have to save the Email associated, to send it to other site.
Pro... |
I know this might be a very basic question, but I'm new to XML serialization and spent hours trying to read different pages.
PS: this is a programming language independent question.
|
My aim here is to find out the best possible and feasible solution for my dilemma. I want to import some csv file (may contain around 50~60K records) into database after some manipulation into the files, manipulation includes comparison such as one record already exists into database or not. I already have a .net c# ap... |
Raymond Chen said in 2006 and repeated in 2013:
Do not write in-process shell extensions in managed code
But I am perplex since there even is a library which is exclusively dedicated to writing shell extensions in C# (called SharpShell).
I am actually using this library in my software (for context menus and icon over... |
The general sentiment seems to be that composition is preferable, in most cases, over inheritance, as it leads to less coupling. But for a case like this,
module Publishable
def new?
@content.created_at > freshness_threshold
end
end
class Book
include Publishable
def initialize(content)
@content = con... |
I am writing a Python system where I have a major class(PlayerModel) that has two another classes as members (StateModel and ActionModel). I was wondering, what is the correct way to initialize such composite class?
Currently. I'm creating the members instances separately, and the class's __init__ method looks like thi... |
I need to write a function to detect if a set of strings needs delimiters when concatenated in any order.
For example, the strings ("A","B","C") do not need a delimiter: "ABCBB" -> ["A","B","C","B","B"].
However, the strings ("Pop","corn","Popcorn") do need a delimiter, as the string "Popcorn" is ambiguous: it can eith... |
Quoting https://en.wikipedia.org/wiki/Deadlock#Necessary_conditions :
A deadlock situation can arise if all of the following conditions hold simultaneously in a system:
Mutual exclusion: at least one resource must be held in a non-shareable mode.Only one process can use the resource at any given instant of time.
Hold... |
I am new to database modeling.Here is a problem I was trying to solve:
Information about movies,stars and studios.Movies are shot in studios that own them.A movie is shot in only one studio.Stars are connected to one or more studios but can act in any film that may or may not be owned by the studio.Stars can act in any... |
In postgres, I need to store the hours a merchant is open each week. Essentially, the information you'd see posted on a sign in the merchant's door:
Mondays: Closed
Tuesday-Friday: 9am-1pm, 2pm-6pm
Weekends: 10am-2pm
Some ideas so far:
Break down a week into 30 minute (or even 5 minute) chunks, and use a bit string ... |
I have never used a Continuous Integration system (CI) before. I primarily code in MATLAB, Python or PHP. Neither of these have a build step and I do not see how a CI could be used for my work. A friend on a large project in a large firm told me that language does not matter.
I do not see how CI would be of use to me i... |
I am working with some low-level (by that I mean code that can't use C++ exceptions and/or the standard library) code that makes heavy use of classes.
Basically, every class contains a bool initialize(); method that is called right after instantiation to initialize all its components, underlying objects and such. This ... |
I can see people use boolean flags, especially in Controllers / Presenters, to control the flow of execution. For example,
public void onButtonClicked() {
hasButtonClicked=true
// code here
}
Then later, in an unrelated method, but still of the same Presenter this flag is utilized something along the lines:
p... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.