instruction stringlengths 34 36.1k |
|---|
Let's say I have the following appointments:
Appointment 1 = 1:00
Appointment 2 = 2:00
Appointment 3 = 3:00
Appointment 4 = 4:00
I need to reschedule all of these one hour later:
Appointment 1 = 2:00
Appointment 2 = 3:00
Appointment 3 = 4:00
Appointment 4 = 5:00
The problem is that I want to do this in one atomic ope... |
If I want to compare two numbers (or other well-ordered entities), I would do so with x < y. If I want to compare three of them, the high-school algebra student will suggest trying x < y < z. The programmer in me will then respond with "no, that's not valid, you have to do x < y && y < z".
Most languages I've come ... |
I would like to hear arguments for or against a plan I am considering. I have a large network of nodes each of which has vector-valued properties. Accessing these properties (read or write) requires a timestamp.
Plan A: pass the timestamp to every method that will access properties (and every method calling those met... |
I was reading about Reactive programming, and came across this article The introduction to Reactive Programming you've been missing with the quote I put in the question title:
Reactive programming is programming with asynchronous data streams.
but this confuses me a bit. For example, the most common example of Reacti... |
I want to write a suite of methods that act as getters when passed zero arguments and as setters when passed a single argument. I have two two reasonable implementations, shown below. Is one better than the other, or is there perhaps an even better way?
class Thing(object):
def __init__(self):
self._size... |
I was wondering, if I have a table that stores, lets say, a user's transactions, then when I need to fetch the user's current balance I would have to go and use SUM() like SELECT SUM(value) FROM transactions. But that seems redundant in the php + MySQL world because a user can refresh the page 3 times in a second if th... |
I came across the following in some sample code:
if (urlStr)
{
NSImage *iconImage = [[NSWorkspace sharedWorkspace] iconForFile:urlStr];
node.nodeIcon = iconImage;
}
else
{
// it's a separator, don't bother with the icon
}
Is this style of using an else statement only for a comment good practice for product... |
I have a library that I use in several applications. It has a method that returns a URL:
class UrlBuilder {
public function url($config) {
$config = do_some_checks($config);
return make_url($config));
}
}
Often an application wants to alter the way the URL is built, and I would like to make that clear from... |
I have a monolith application on a server and I want to break it into multiple microservices.
Because of that for the moment I have to use the same database for all the microservices and each microservice accessing only his own tables.
So my question is how can I reuse the database connection among microservices and st... |
What are practical uses of base64_encode and base64_decode?
At what particular situations are they used? For example, in terms of security?
What is the usage of using this function when sending an image via a URL like this?
echo '<img src="file_viewer.php?file=', base64_encode($dir . '/' . $file), '" alt="', $file, '"... |
I have very limited experience with C++ but I do have plenty of experience with Java and NodeJS.
I've decompiled and tried to make sense of a small C++ compiled file and I've come across something that I do not understand. To me this looks like a value being assigned to an expression which seems weird to me.
What is ac... |
I'm about to push my first project to GitHub (a mini toy lisp interpreter written in C).
I've noticed that the vast majority of open source projects include their license in every source file (at the top). Is that a necessity for open source?
|
We need to customize a desktop application at compile time. Users cannot change the configuration. Only developers and release managers can do it.
The configuration is a little complex. There are more than 10 modules. Each module needs configuration including values, capability flags, etc.
We have 5 configuration group... |
One of the major benefits of the repository pattern is that you can easily switch out implementations for other implementations.
After learning about this pattern I started to make tons of things into repositories like an HttpClient repository for example, this way I can decide which client I want to use. Another examp... |
Let's say I have a sale order with multiple rows of products. Multiple users insert rows so I must check for concurrency. In my db the ID of the order and the number of the row makes my record unique.
In the past I've used one of the following two methods:
Insert a blank record with default value,the max number of row... |
I don't have a formal computer science education, meaning that I did not study computer science topics in a university. However, I work at a programming job and write a reasonable amount of code. Naturally, programming means that I also have to document and comment my code.
The problem I seem to be having is deciding b... |
I am looking for a cache conscious data structure that does not require hashing. This is to avoid HashDoS without needing to use cryptographic PRFs such as SipHash, which are slow (~1 cycle/byte) – I think that one can do better.
So far, I have found HAT-tries, radix tries, and Judy arrays.
HAT-tries still require ha... |
I wonder, if the below idea makes sense for our web application. We show various lists of entities, which typically refer to other entities and so on. In the table view, there are columns showing some properties of the entity itself (like e.name) and also of the linked entities (like e.owner.email).
The classical way i... |
I'm on the way to build a Chrome app, dedicated to fulfill shop/marketplace orders. The orders come from marketplace APIs like Amazon MWS. The data is stored only in the app (with backup). The system need also to work in a quick way if 50.000 or 100.000 orders are stored.
So how to structure the IndexedDB for that?
Eac... |
I am working on a Laravel Project where we are Payment Express. What currently we are doing is that we have Payment Express Class with static function (Not a single property) like given below:
Class PaymentExpress {
public static function first() {
}
public static function second() {
}
}
We are usi... |
I'd like to build a RaspberryPi-based device that can communicate with my Linux laptop over USB (don't think it matters, but I'll be using a custom made USB dongle that has an FTDI chip on it, and my laptop will have the FTDI drivers installed on it).
I'd like to rig my device with a simple control stick and a simple k... |
I don't know about all programming languages, but it's clear that usually the possibility of overloading a method taking into consideration its return type (assuming its arguments are the same number and type) is not supported.
I mean something like this:
int method1 (int num)
{
}
long method1 (int num)
{
}
It... |
I have a series of reference codes that my end users create during the course of the day. These reference codes correspond to a transaction code that is stored in a database. As of now, there are 15 difference transaction codes.
Here's an example:
Tranasction Code - Reference Code
BB01 - 48912388
C949 ... |
How would I write something that fills with the right-most bit (<<< is used to denote this non-existent operator):
1 <<< 7: "11111111" and 0 <<< 7: "00000000"
9 <<< 1: "10011" and 10 <<< 7: "10100000000"
as in the reverse of the Sign-propagating right shift (which fills with the left-most digit):
-256 >> 8: "11111111... |
I have a scenario wherein I need to do certain specific steps in a specific order. For clarity lets take a simple example.
Let's say I have a Student and some Student Properties which I encapsulate in a class StudentDetails.
A simplistic StudentDetails class:
class StudentDetails {
private String name;
private Int... |
Considering a deck of N playing cards with X different rankings and Y different suits (i.e. there are Y cards with X ranking, thus N=X*Y). What is the fastest algorithm to sort them assuming that X, Y, and N will be known at run-time and may be passed as parameters into the algorithm?
Can we beat the performance of qu... |
Currently in a part of my project a domain object like below exists:
public class Address
{
public virtual string HouseName { get; set; }
public virtual string HouseNumber { get; set; }
public virtual string RoadName { get; set; }
public virtual string Postcode { get; set; }
public virtual strin... |
Recently I've been wanting to experiment with NoSQL databases, especially document store ones. After reading, I still don't understand how one might model information that is contained in a relational SQL database (i.e with tables and records) in terms of documents.
For example, a music database might have a table for ... |
When defining bounded contexts of a Domain, what should be a primary guideline:
departments (Sales/Manufacturing/Warehousing), where each department has a common context
(https://softwareengineering.stackexchange.com/a/316829/226099)
work load, for example Sales BC could be broken down to Client Administration, Billin... |
I am using REST API as a presentation layer of a DDD project. In order to secure API calls, I am using token based security.
Security in Web APIs-Basic Authentication and Token based custom Authorization in Web APIs using Action Filters.
If an API user administration context is persisted by a different API or BCs (dep... |
let closure = { (args) -> ReturnT in ... }
vs
func function(args) -> ReturnT { ... }
Why didn't Apple follow the principle of Occam's razor and make closure and function declarations equal? For example, a closure could be defined like this:
let closure = (args) -> ReturnT { ... }
This is how it is implemented in Jav... |
If an application has already an opened WebSocket for live feeds, should I use it over AJAX for the other communications with the server?
Because the connection is already opened, should we use it for requests that are Request/Response and not real time?
I prefer RESTful HTTP requests because I find them more easy to ... |
There is a bad practice in software engineering where a single piece of data is held by value in multiple places.
For example, in an FPS, the location of the player could be held by the AI class, the input class, the main class, and the graphics engine.
Multiple problems can arise from this:
Synchronization issues
Inc... |
I'm using Unity as IoC with C#, but I guess the question really isn't really limited to Unity and C#, but IoC in general.
I try to follow the SOLID-principle, which means that I got very few dependencies between two concrete classes. But when I need to create new instances of a model, what's the best way to do it?
I us... |
I am using Protractor and Jasmine to create end-to-end tests for a webpage. To test this initial page, I have abstracted made some common utility functions to create about 20 test cases for this particular page. An example of this is shown.
describe('User is on the page and', function () {
beforeEach(function () {
... |
I'm integrating an enterprise application with an existing pattern.
The main problem is how to synchronize data between my system and an external system through RPC (HTTP API calls to be precise).
What I have done so far
The first thing I have done is dividing the interface in business methods such that at the beginnin... |
After some googling I found some debates about whether constructor injection or property/field injection is better, but there is yet another alternative that strikes me as more beneficial.
In most programming environments, there is something called "the call context", which is information implicitly passed from caller ... |
case 1:
Sometimes I cannot figure out how to make things to work like in this question,Sending drive names to the combo box. In this case I know how to add items to a combo box as well as about getting drive names but I could not figure how to combine those two in order to work. So I asked the question and since I have... |
So in general when you perform a crossover in GA, you directly flip a random section in the "genome", with the corresponding section in the other parent, and mutate it based on the mutation rate.
Consider the sequences below:
0100 1000 0001 1011
0010 0110 1101 1111
A crossover without any mutation might look like th... |
I am trying to currently get a good grasp on the Observer design pattern, but I am stuck wondering about one specific issue. In the examples I have been able to find of implementation, they are all rather basic in terms of having a specifically designed state.
For instance, the "subject" class that is being observed on... |
Is there a specific data structure, object oriented programming methodology, and/or approach for achieving what programs like LT Spice, Altium Designer, and Cadence Virtuoso use to manage components/nets/nodes on schematics? Specifically in Java?
Above is an example, a sample schematic from LT Spice. There are a bun... |
Question 1
I have a login API endpoint
http://127.0.0.1:8080/api/account/login
It checks if the phone number has been validated. If not it will call
POST http://127.0.0.1:8080/api/account/sendsms country_code=1, phone_number=1234567
How can I prevent abuse to requesting sms? (It'll cost money on my part. I also have... |
OK let's say I have something like this:
public class MyObject {
public static int DefaultValue = 9
private int _value = DefaultValue;
public int Value { get { return _value; } set { _value = value; } }
}
That way, changing the DefaultValue will change Value for all future instances - so having a consta... |
The issue that I have is that I need information from an object that a method returns when it throws an exception. It is a little hard to describe so I have this java pseudo code example. I have a solution, but I don't like it (problems listed below), and was wondering if there was a better one:
public class OuterClass... |
My company wants me to write UI tests that test the business logic (all of the use cases MUST be independently testable) I decided to do it in selenium. I have managed to create a decent product (as of now about 80% of use cases are covered, I have a video recording feature of the test run and a screenshot feature for ... |
I'm skimming through a very popular game's source code at the moment and I came across these variables inside of this class.
public static final BlockPos ORIGIN = new BlockPos(0, 0, 0);
private static final int NUM_X_BITS = 1 + MathHelper.calculateLogBaseTwo(MathHelper.roundUpToPowerOfTwo(30000000));
private static fin... |
I have two Java applications deployed on tomcat. For inter application communication I provide jar file of application (Java API) to other application and it becomes a method call which is fast.
Now I am thinking of creating rest service, can it add some extra time. Of course yes but how much in worst case. Keeping in ... |
I have a Data class that can be placed inside a DataCollection class that can be placed inside a DataCollectionCollection class. Kinda like an egg can placed inside a box that can be placed inside a crate.
The Data class can be "standardized" through a special process. Standardizing it will create a new StandardizedDat... |
If I want my program to be able to run in debug mode, is it a good idea to make it accept a flag such as -D=DEBUG when I run the program? I currently have a DEBUG variable in a .h file but that I can't change after I compile.
#define DEBUG false
I'd like to be able to run my program both in debug mode and "stable" mod... |
I'm trying to create a vector (like in physics) class in Java.
I want to support vector addition, dot product, scalar multiplication, etc.
So, my question is, is it possible to do this with generics? Generics can only take objects as parameters but I'd like to use primitives (double or float).
|
I have built a library that is being used by a few people. They say that library has a few print statements which is wrong because a library should give freedom to users to use the library the way they want and forcing a few print statements is not good that way. Should there be print statements in a library by any ide... |
As i am executing a one pipe example pgm from libc.pdf,I noticed that the parent process first completed then only child process completed.From my knowledged about os the child process must complete before the parent completes.so what happens here
|
Background
Time ago I learnt something about package design, in particular about loose coupling:
The Acyclic Dependencies Principle
The dependency structure between packages must be a Directed Acyclic Graph (DAG). That is, there must be no cycles in the dependency structure.
Robert Cecil Martin aka uncle Bob, Granular... |
I love taking apart applications, software, and websites to see how developers were able to create a feature or how a game handles AI.
Something I'd like to be able to do is view an app's files (code specifically) but I haven't been able to find a solution on Google. I've seen YouTube videos before mention things abou... |
I just learned that static library building skips the linking stage, which explains why my build process succeeds all the time when it's possible I actually haven't implemented a function in my header. In an executable project, the linking stage would alert me if I had done this.
What is the typical workflow for static... |
Say we have a normal pure function such as
function add(a, b) {
return a + b
}
And then we alter it such that it has a side effect
function add(a, b) {
writeToDatabase(Math.random())
return a + b;
}
It's not considered a pure function as far as I know because I often hear people call pure functions "functions w... |
A week ago, I was at LFNW and as I was talking with Larry Hastings after his talk, he said (paraphrased):
There's something in Git that makes the Pull Request workflow possible that isn't there in Mercurial. That's why Pull Requests on BitBucket are not great.
(For context, we were discussing the fact that Python is ... |
At my company, we're building an SDK consisting of a number of assemblies. For example, we deliver an assembly called Company.Platform.Security that contains the implementation of our authorization model.
Now, this assembly contains code that talks to other services over HTTPS. It therefore needs to discover where thos... |
For the company I work at, all of our projects,
including a new one started last year, are written in C89.
We write for vxWorks (a real time embedded operation system).
Our software runs multi-threaded through various spawned "tasks"
We are massively behind schedule, and I am struggling to be productive based on the co... |
Say I have a method that writes a string to a file:
public void write(String content, File out) {
// writes content to out
}
If I want to protect the parameters and ensure that they are not re-assigned a new value within this write method, I can use the final keyword to prevent this:
public void write(final String... |
I'm hoping this question isn't too broad or too prone to opinionated answers, since I could really use some pointers.
I'm trying to come up with a way to persist tabular, spreadsheet-like1, data in a backend. Since the data could very well end up being rather fuzzy (not easily identifiable as being identical, even thou... |
I have a Bash script that processes files read from standard input, one pathname per line, and runs a CPU intensive task on each file. I happened to notice that even with four cores (grep -c ^processor /proc/cpuinfo) only about 25% of the processor was being utilized and that the disk IO rate was way lower than its cap... |
I'm currently trying to understand Yen's k shortest paths algorithm. I based myself on the original paper as well as on the Wikipedia article, but still cannot see why it is correct if k > 2. In fact, I don't even see why it works on the following example:
For instance, let's consider the 3 shortest paths from A to D.... |
I'm uploading to GitHub for the first time and I am facing all sort of doubts about licensing. I did not know that topic was that uncovered in the net! But even it is complex, my situation is so typical that I guess most people using Github knows already about this.
I just want to upload publicly an app which is refere... |
I have a variable which I want to use in only one function. I can write my code like this:
var theAnswerToLife = 42
var multiplyIt = function(x) {
return ++theAnswerToLife * x
}
I have some other functions in that file, which don't use that variable. Therefore, in order to limit access to that variable to only the ... |
For classes with optional fields, is it better to use inheritance or a nullable property? Consider this example:
class Book {
private String name;
}
class BookWithColor extends Book {
private String color;
}
or
class Book {
private String name;
private String color;
//when this is null then it is ... |
I am currently applying some pre-processing to this dataset. Some of the digits are extremely rotated and I would like to know how others managed to get them 'upright'.
I have implemented something on matlab which finds the difference between (most bottom pixel) - (most top pixel) and (most right pixel) - (most left pi... |
If I have function which returns a future, is there any reason to also include a callback where the callback is simply called right before the future completes?
The only advantage I can think of would be to guarantee that some action be performed prior to any tasks pending on the future and also that the action be guar... |
Valgrind does not report a memory leak during my actual usage, only during my scripted test that I scripted with a shell script to test my own shell. I found that I didn't have to use malloc every time I did. For example, strdup could do it for me. Now I wonder if it is possible to formally prove that I really need ma... |
The classic development phases are
requirement elicitation
design
implementation
testing
maintenance
Currently we are having issues with UX joining the mix. My current job lets UX build wireframes as the very first step, and they are treated as SRS. This has led to a lot of incomplete designs, wrong technical assumpt... |
The following code uses a boolean preference active: In the active state, it does an operation which could throw an exception. On this exception, it does fall back to the non-active state.
let active = somePreference;
function getValue(parameter) {
try {
if ( active ) {
return valueStore.query(p... |
Is there a concrete reason to prefer executing callbacks to functions before or after exiting the called function? Example
function doSomethingPossiblyAsync(callback) {
if (errorDetectedImmediately) {
// call callback immediately before doSomethingPossilbyAsync has returned
callback(someError);
}
...
... |
I am trying to automate Business Process which can be characterized as a
pipeline with distinct stages.
Pipeline can be perceived as A->B->C, where A,B,C are distinct Business Steps that work on some common POJO.
For example, lets consider this Business process:
Business needs to identify whether a Book can be sold ... |
I learnt about the check testing framework today that seems good. This far I've scripted tests that uses valgrind so that the tests both display output from the tests and from valgrind. Is there a disadvantage in using many test frameworks like valgrind testing for internal memory management, check testing for unit tes... |
In a method where any positive number returned would signify success, would it be good practice to use negative numbers to define error conditions? Could then use enums to make readable.
|
We are implementing a CAD program (in C++, Qt) where we have interdependant classes :
The smallest brick is the Pattern, it is just a distribution of points. Then we have Layouts which contain Patterns at a given height (z = constant). And finally Stacks, which are a stacking of Layout.
All these entities have a unique... |
I have a class that uses a type, but it doesn't need to know anything about that type. In Swift, I can code this up one of two ways:
protocol Type { }
class Class {
// use Type
}
or
class Class<Type> {
// use Type
}
Right now I'm leaning toward the latter because if the client wants to use an empty protocol... |
I have one BL function and one SQL stored procedure (let's name it: getPersonDetailsById) which returns person details by passing his PersonId.
Now I need to get the same details (data table) but by passing the person's Email because for the same flow I don't have the person Id.
What's the right way to do it:
Option 1
... |
I feel like I should be able to register all my components into the application composition root container no matter what the current state of the environment is, even in the case environment lacks parts of configuration required to proper working of some of its components.
Currently, I sometimes run into code that for... |
Let's say you're building a social web app where an aggregate root (f.e. BlogPost) could be liked and unliked. Now consider a malicious user who wrote a script to perform an endless amount of like and unlike on the same aggregate, maybe he hijacked multiple user accounts to do it in parallel. This would mean the aggreg... |
Background
I have an object that represents a test procedure that I need to run on a product. This object may be used multiple times during run-time, depending on how many times the user elects to run the test. Here is where the design challenge starts. This TestProcedure object contains many members that maintain thei... |
What is the proper way of storing a changelog, similar to git, for data in a database.
Currently, I have it set up so that every line in a table is given a unique string id that is used to determine where an edit occurs. When a user wants to change the value in column juice from Apple to Orange, it logs the date, tim... |
So there are two ways of teaching a neural network as far as I am aware of.
You supply the AI with test data and the correct solution to the problem. After some time the network will be able to get the answers right.
Example: Hand-writing recognition. You supply the network with images and tell it what numbers they re... |
So recently in school we have started programming klm25z boards using ARM Assembly. I was wondering if in most industry jobs, microcontrollers are really programmed in assembly over C. It seems to take at least 2-3 times longer to program in assembly and does not seem to have any significant enhancements in speed, that... |
I'm writing a game in Typescript, and decided going in that I was going to try to adhere to the idea of "interface based programming", where you write code based on an interface, instead of the implementation, of an object.
I wrote up a good number of interfaces, and classes that implement them, then took a step back ... |
I've recently been looking into using JavaScript for templating and I was wondering about the legibility of using this approach.
I understand that JavaScript templating is a very common and much accepted form of templating and I do see the benefits of using this technique.
My question stems more from curiosity as stor... |
I am working on a social networking platform using a database wrapper released under GPL. I'm fairly new to using open source software, so I'm not sure what would require me to release my source code.
From my understanding, if the code is modified and distributed, the modified code must be released. I am planning on ad... |
I am dealing with a pretty extensive data set. After a few joins, the foundation table has something like 40 columns. The next 40 columns will all be calculated. I am trying to keep my Java clean of the business logic because it is fairly verbose, at times difficult to follow, and not necessarily belonging to a single ... |
I've looked up this question many many times but keep seeing different answers, what is the BEST way to save array's? It seems ludicrously infantile that there is no standard or easy way to save arrays like you would save a String or Int... How should this be done? As I understand, putting to much information into Shar... |
I'm trying to draw a UML activity diagram for the functionality of a user retrieving his password when she has forgotten it. It looks like this:
As you can see, this functionality requires two requests at different stages, one for the input of the username, the other for the input of the verification code. So the whol... |
I have set-up a MVC/PAC-like structure for a web application (unsure if it fits any of these design patterns fully). In short it is:
Routing in index.php, which selects the controller and method using the URL http://example.com/controller/method/<params>
Controller's method requests data from 'model(s)' and assigns it... |
I am looking for a system for building state machines with timed/scheduled transitions, and with events that happen periodically during a given state. I can implement it myself, though I feel like this is a common enough requirement that there would be a category of software for it.
I don't need a library recommendatio... |
I am maintaining a large portion of legacy code, written in C. This code was initially written to be comiled against Windows 3 for Workgroups, and later a version for NT was created. This legacy application is still in use today, merrily running along on 3.11 and NT workstations from the early 90's. It works and it doe... |
According to Richardson Maturity Model there are several levels of maturity in REST approach. http://martinfowler.com/articles/richardsonMaturityModel.html
Since DDD uses ubiquitous language, I am wondering what level of maturity is recommended, if a REST API is a presentation layer of my DDD project?
Using ubiquitous ... |
I want to ask if the following workflow is correct!
It is referring to a small private team.
There is a master branch where no one merges there ( except the maintainer ),
a development branch and individual branches for every user. So,every user will push to development branch.
So:
* clone the repo to your local machin... |
I'm building a software and I want to release it under Apache 2.0 license.
Unfortunately, right now, I've no time to put sources codes on public repository like Github or BitBucket. And more, I didn't give the source code to the final users.
Is it conform to Apache 2.0 license?
If the final users request the sources... |
I have created string to linq query library for internal company needs. We will use this library for querying over REST mainly, but it could be used in a lot of other different situations.
The gist of it is this, a user can create a query and put it in a url like this:
www.test.com/api/v1/users?query=$where[#eq(Name,Te... |
I really like this article about leaving the code/camp site in a nicer state than you found it - it seems like a practical approach in the real world to keep on top of code cleanliness.
I also really like feature branches as a way of developing features in isolation so that, if you don't like it, you can easily not mer... |
So this came up in a discussion over lunch about how weird the HTML, CSS and JS triangle of web technology is. HTML is a markup language, one of many. Javascript is a programming language, one of many. However CSS is really weird, it's a style sheet language.
I tried googling around but I really couldn't find a lot of ... |
How can an open source license be compatible with a multi-licensing scheme?
According to a similar question, the author of a library could potentially change its license. But problems arise when the project as already received contributions from the community, because the contributors kind of 'own' the software it self... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.