instruction stringlengths 34 36.1k |
|---|
I am new to Git, and am trying to figure out how use a git repository when a project's files are spread across different drives.
For example: The project requires html files on one drive. The CSS and JavaScript files are stored on a different drive. I don't have the option to keep them together.
Is there a good way t... |
For general-purpose programming there are literally hundreds of programming languages. But for interacting/querying the databases, why is SQL pretty much the only used language?
|
In the following code example, we have an class for immutable objects that represents a room. North, South, East, and West represent exits into other rooms.
public sealed class Room
{
public Room(string name, Room northExit, Room southExit, Room eastExit, Room westExit)
{
this.Name = name;
this.... |
Admittedly, this is a homework problem but I have tried to figure it out on my own. Just want to make sure I get it correct. So far, the only design pattern I believe to be correct would be the Adapter design pattern. I could implement an Adapter class to publicly inherit from class C and privately from class D and ins... |
I'm not really sure what/if there is a gold-standard on how much a unit test should be broken down. Another thing is sometimes I question whether I am wasting my time on a specific test. I am new to unit testing/TDD. So for example, say I have some simple code like this:
public class IntegerStats
{
public int MaxVa... |
In the past couple of months I've worked with both Apache Spark and Druid for some projects. As I've gone through the process of learning how to use these tools, I've spent some time reading through their documentation and peaking into their inner workings (the under-the-hood code rather than the API level code).
In b... |
I am new to programming in the Windows environment. The language I use is C. More specifically, I try to manipulate COM-ports on Windows manually (without special libraries, only WinAPI functions).
My question concerns the presence lots of typedef's in windows.h. What purpose do they serve?
Is it OK to mix bool, BOOL, ... |
is the following code snippet:
String[] str = {"Abc","Ghi","Def","Mno"};
Object[] obj = str;
String[] p = (String[]) obj;
same as :
String[] str = {"Abc","Ghi","Def","Mno"};
Object[] obj = str;
String str1 = (String) obj[0];
String str2 = (String... |
In Bash, to increase an integer value stored in a variable, we need to explicitly use arithmetic expansion.
i=1
i=$((i+1))
Otherwise
i=1
i=i+1
will not evaluate the expression i+1, but assign the expression as a string to the variable.
This is very unnatural compared to other programming languages, where an expre... |
The Setup
This is a membership-based site. Each account is capable of:
Making posts (unlimited, no restriction on frequency)
Liking, sharing and commenting (on) the other posts
The goal is to provide the smallest possible resolution for account stats. Instead of bundling likes into groups of 15-minute intervals (or s... |
How would a computer represent -6886707 using 24 bits?
I need someway to verify this: 100101101110101011001101.
First I converted 6886707 to binary, which is 11010010001010100110011. Then I put one zero at the left in order to have 24 bits, then I switched the zeros into ones, and ones into zeros, and added 1.
|
Let's take French and Japanese adjectives as simple examples.
French adjectives have gender (masculine or feminine) and number (singular or plural), whereas Japanese nouns have neither. However, Japanese adjectives belong to particular groups, called i-group or na-group. So, we could theoretically model this as simply ... |
I have a vector<int> num, I want to get the size of longest subarray with the sum less than or equal to k.
My approach:
O(n^2). Repeat for every element in the array.
Can we do better?'
Note: I don't need the actual longest subarray, only its size. So the return value is int.
|
I'm working on a project that generates massive amount of data and store that data in a SQL database. I'm talking about like 1 thousand records per second. Next I've to push that data to a database. If I do the data generation and database push sequentially, it'll slow down the data generation which is not acceptable. ... |
I'm wanting to create a class that stores words in a set so that I can see if a word belongs to that set or not. I'm not wanting to build ever set every time I instantiate the class, so I'm using what I think is dependency injection. The following is a basic structure of the class. I'm a student learning about programm... |
Imagine there is an interface IPriceProvider which supposed to serve 2 needs: historical and latest. So I think we have 2 options here.
First:
PriceInfo GetLatestPrice(string symbol);
PriceInfo GetHistoricalPrice(string symbol, DateTime pointInTime);
Second:
PriceInfo GetPrice(string symbol, DateTime pointInTime);
In... |
Let's say, for sake of an arbitrary example, that I want to store information about twinned towns. I want to be able to access the data about the twinning by having the names of both towns as keys, but assuming that neither is the 'initial' key. So I'd access the data property like this: twinning_data['derby', 'montrea... |
I'm designing an application where I have users and admins (further down in the future, I can have different sub-ranks, where each one can have access to some area of the application).
Currently, I have a single "User" class with a "type" integer attribute, which is checked when accessing restricted areas.
This feels... |
As I read in Software Architecture in Practice by Len Bass, Paul Clements and Rick Kazman about availability voting tactic, the definition of voting tactic in fault recovery is:
Processes running on redundant processors each take equivalent input and compute a simple output value that is sent to a voter. If the voter ... |
So I wanted to know the differences between these two. I know software interrupts are sometimes referred to as exceptions, which makes the differences between the two somewhat confusing. Asking this entire question from a program level perspective; wouldn't an exception just be an illegal action whereas a software int... |
I have been developing a blogging site, where people can post an article or blog and others can comments on them. The site is coded in Angular.js, ASP.NET and SQL is being used a data store.
For each article there can be 'n' number of comments and anyone who is registered in the site can put any number of comments in f... |
I am creating interface in Java for custom error handler.
Want to pass an argument error object but I need it to be child of Exception class.
Is it okay to use my defined class name in an interface ?
Won't it make it less of an interface in terms of not being dependent
on any implementation ?
I try to do something like... |
I understand that save for breaking out of loops nested in loops; the goto statement is evaded and reviled as a bug prone style of programming, to never be used.
Alt Text: "Neal Stephenson thinks it's cute to name his labels 'dengo' " See the original comic at: http://xkcd.com/292/
Because I learned this early; I don... |
I'm currently trying to build my first solution following DDD principles.
Until recently everything was more or less clear, but now I have a task to import configuration data for my application and I am not sure what would be a best place to fit such a functionality...
I have a sales analysis application, and at some m... |
In the spirit of divide and conquer, I've gotten into the habit of using helper methods almost everywhere, including for the simplest of tasks.
As a really simple example, let's say I have a sort of library program written in Java 8 that deals with books, and it has the public method filterByAuthor that takes a list o... |
I'd like to introduce test-driven development practices in an established legacy product. As with most legacy products, we could use quality improvement via safe gradual refactoring/code coverage and TDD for both new features and defects could go a long way.
However, there are a few challenges: in some cases writing te... |
I have a project which uses a rolling window to count events from incoming XML files and rules based on the values of the window. For example if 10 events of X happen in an hour - trigger an alert.
Now further requirements have surfaced where we need to pinpoint the data that caused the alarm to trigger, ie. What 10 XM... |
I have a system that handles various transactions from hundreds of clients a minute. Each transaction is limited to a subset of functionality, and thus for each type of transaction (circa 25 of those) I have a separate database table (this avoids lock waits for all the clients connecting). These clients are connecting ... |
to make this question easier to visualize, let's call this the "chicken mesh problem".
Suppose you have a rooster and a number (suppose it is 30) of baby chickens.
Goal: Allow the rooster to uniquely ID each and single one of the baby chickens,and RELAY messages (indirectly, hence the word "RELAY") to a specific baby ... |
We are working on a project using Google App Engine + Google Cloud Datastore. The language used is Python.
At some points of our API, we check if some arg is passed in request, and we make some query on database if arg isn't null.
Example:
result = None
if request.name != '':
result = ndb.Key('Users', request.name... |
Shared Access Signature is a delegated access mechanism available for Azure resources and account. Based on the documentation here - https://azure.microsoft.com/en-in/documentation/articles/storage-dotnet-shared-access-signature-part-1/, it is clear SAS is never linked to a user principal. Thus making it vulnerable to ... |
Today I had a dicussion with a colleague.
I tend to believe that a value in a property should be a meaningful part of the state of an object at any given time. This automatically almost always makes the constructor fully responsible for the initial assignment of all the properties in a class. Other methods may subseque... |
Each component has multiple possible states and any number of them can be active at a time. Some combinations of states have a value associated with it. At any given point, it wants to be able to get the best value for the currently active states of the component. The problem is when there isn't a value associated with... |
Several teams at my company practice a code review workflow I've never seen before. I am trying to understand the thinking behind it, with the idea that there's value in making the whole company consistent. (I contribute to multiple codebases and have been tripped up by the differences in the past.)
Code author submit... |
So I am going to use ReactJS for the front-end for a web application
The application is mostly CRUD stuff but with some ajax UI etc.
For the back-end I am using Laravel
Right now I have both the front-end code and the back-end code in the same repository which works for me so far, but I get the feeling that I have two ... |
From Programming Languages: Principles and Paradigms
By Maurizio Gabbrielli, Simone Martini
The bound mechanism for type variables is fairly sophisticated and
flexible. In particular, a type variable can appear in its own bound.
We restrict ourselves to a single example of this case, and we refer
the reader to th... |
Today I had a discussion with a colleague.
It is my understanding that a class has the responsibility to ensure that its objects have a valid state when interacted with from outside the class. The reason for this rule is that the class does not know who its users are and that it should predictably fail when it is inter... |
Let's say I have a method called setDate. I also have another method called isValidDate to see if a string is a valid date string.
For convenience, setDate uses isValidDate internally as a mean of validation, so the developer doesn't have to do the validation manually. But isValidDate is used in other methods as well. ... |
I have a RPG kit in the Unity Store and I wanted to add some protection for the consumers for when they want to save pretty much any information. From the gear the character is wearing to inventory, bombs, keys, locations where objects were moved etc. I already have all that working it is just I was using the Unity C... |
I'm writing a python app that instructs a database to perform various processing instructions on partitioned tables. The processing can take long enough that there might be a timeout, so I surround my calls to the database with try:... except: blocks like:
while True:
try:
process_one(table, logger, cursor)... |
I want to read data in a format like the following using Java.
[scenario]
id=my_first_scenario
next_scenario=null
name=_"My First Scenario."
map_data="{~add-ons/my_first_campaign/maps/my_first_map.map}"
turns=30
[side]
side=1
controller=human
team_name="good"
... |
According to Wikipedia, the 90 / 10 rule of program optimization states that “90% of a program execution time is spent in executing 10% of the code” (see the second paragraph here).
I really don't understand this. What exactly does this mean? How can 90% of the execution time be spent only executing 10% of the code? Wh... |
I'm reading the book JavaScript: The Good Parts.
On page 113 it recommends function expressions instead of function statements, because statements are subject to hoisting:
The statement:
function foo( ) {}
means about the same thing as:
var foo = function foo( ) {};
Throughout this book, I have been using the second... |
In general, what should be the best way to repopulate a form when submission fails due to invalid inputs.
Here, invalid would mean something did not pass the check or some validation methods server side. So upon failure the form is reloaded and user would like to see his data repopulated.
How do we do this in general... |
Problem
I am currently investigating a solution to allow fast upload (and retrieval) of data that can be implemented via NoSQL/SQL or a file system on a Centos server with 64 core cpu with 529GB of ram.
The case is as follows:
The users have a need to keep a track of data uploaded onto a server, then at some point retr... |
I am actually modifying a package under the GPLv3 License which according to a page requires to:
Include a copy of the license and copyright notice with the code.
However such package/code don't have the license nor the copyright notice on each file. Can I modify significantly the code of such package?
|
What does these UML diagram arrows mean in Iterator pattern that are drawn from ConcreteAggregate to ConcreteIterator and backwards. I have looked thorough the legend (notations) of UML diagrams, but I guess that was more confusing than explaining.
As much as I understand the arrows mean that ConcreteAggregate is depen... |
Consider that the Facade has inside it lots of sub-components but it done not pass messages from one sub-component to the other but also has some business logic in it. Is it still Facade pattern?
|
Recently a co-worker has taken to checking boolean values in the following manner:
if boolVar.boolValue {
...
}
These variable are generally declared explicitly as boolean types either using:
var boolVar: Bool!
or
var boolVar = false
I am under the understanding that if a variable is declared as a boolean then i... |
I am building a stream processing architecture and was wondering what to do with metadata about the stream. For instance, every message of data coming from a source has the same attribution, as it passes along from source to processing, enriching and eventually to a sink that attribution data does not change but is re... |
Just watched a video about continous delivery and there it was suggested to trigger a build and execute unit test on each commit.
For our team of 10 developers and a build time of at least 10 minues I wonder how this will work as in 1 hour, all developers might deliver something ==> we might end up having multiple ongo... |
TL;DR:
I have bad, no .. horrible, horrendous code that kind of works but is a mess and is not easily maintainable.
I want to redesign it and repackage it to where objects are well defined and messages that pass between the objects are well-defined, and the whole architecture makes sense and is easily maintainable.
Th... |
Many places in stackexchange state that you should not unit test implementations, only the public interface of a class. But what if the public interface is a method that doesn't return any value, for example a public SendMailNotifications() method with certain logic that has some internal logic (private methods) and se... |
How'd I go about copying a function in memory to a different location and be able to run it from the new location in C++?
I thought maybe memcmp would work, but I'm not sure how I'd go about running it after it copied to the new location.
|
The problem goes like this:
There are n piles of wooden planks and m machines, let xi be the number of planks in i-th pile. The machines produce different parts for chairs; each machine requires a different amount of planks, let's denote it by yj for j-th machine. To create a chair, you need one of each part.
You ar... |
So, as part of my final year project, I'm writing a web crawler in Java to gather website data that I will then process. One of the attributes I need to gather is "number of popups". I know a pop-up blocker can display the number of popups blocked on a given website, and this information would be sufficient.
Alternati... |
So here's the problem. I have a massive C# project in Visual Studio. It has a big GUI that manages a large number of classes.
In one of the form windows, there is a bunch of textboxes. The user fills in the data and then clicks a button and then my class is created to do whatever.
How do I work on and quickly run this ... |
In code there are private and public declarations. Why shouldn't I make everything private or make everything public?
|
This question is followup to this question.
Is there any benefit in avoiding the 'this' operator when implementing pure methods? That is, are there any advantages to making all dependencies explicit via argument lists, versus allowing implicit dependencies by referencing instance data via the 'this' operator within the... |
The Python 3.1.5 docs refer to the % style formatting as "Old String Formatting Operations" and provide this warning that it may be removed:
Note: The formatting operations described here are obsolete and may go away in future versions of Python. Use the new String Formatting in new code.
The replacement section appe... |
I'm working on a boilerplate component that's supposed to generate a working sort-of "getting started" project structure. Think of it, in a web app context, of a component that will generate a Controller, a View and the routes configuration so that once you call it, you can immediately go to the browser, type the route... |
So currently where I work we try to mimic our production environment as close as possible to our production environment. Our micro-services (APIs, listeners, data stores) are organized in the fashion that if it performs a responsibility (down to the data model) different than something else it deserves its own containe... |
arr[2^30][100000]
for (int i = 0; i < 2^28; i++) {
value = a*b+c;//only a example. In all, value is an integer.
arr[value][arr[value].length++] = i;
}
My code like above. Random access a 2D array 2^28 times to save the position. But this code is too slow for my algorithm.
Does there are any method to speed i... |
In my naive opinion it should be O(n) in worst case since Tree could get spindly and unbalanced.
|
I have a list of domain name that contains wildcard ('*' character)
Example:
*.google.com
*.domain.com
...
It contains nearly 1 million domains.
The data will be stored on a mongodb or redis database.
Given a domain name, such as "abc.domain.com", I need an algorithm that will check the data for a match.
For example,... |
What is best practice when writing acceptance tests for a form l without knowing the exact layout of the HTML file?
Would it be for example to test that the page contains, let's say an element with div[@id=form_field_name], and "force" the developer to use that id? Is there a better way to approach this?
I'm using Rob... |
First of all I know nothing I can do that 100% prevents illegal copying of my software. I'd like to just make it reasonably hard for a competent person to do, and almost impossible for an unknowledgeable person to do.
I have a contract job coming up to develop a web app using the WAMP stack, commissioned by a company's... |
In my experience, many of the projects I have read in the past didn't have relationship definitions in the database, instead they only defined them in the source code. So I'm wondering what are the advantages/disadvantages of defining relations between tables in the database and in source code? And the broader question... |
In the last several years I keep hearing the term multi-tenancy being thrown around, and each time I Google its meaning it leaves me confused:
(Wikipedia) : The term "software multitenancy" refers to a software architecture in which a single instance of software runs on a server and serves multiple tenants. A tenant i... |
Is the building process such as waterfall or agile used to implement a system, linked to the way an enterprise system is rolled out in an organisation?
As an example: A system is developed using an incremental approach and is implemented into the organisation as each increment is finalized.
or
A system is developed us... |
I make some changes in console application that was released under the MIT license but i don't understand much about the license. Is it required to credit the original author in it and do i need to credit myself for changes?
|
As getters in C# may be relatively costly, I wonder if they will be called every time or if the compiler will do any optimizations.
Let's have a look on this:
List<A> CurrentList{ get; }
void DoSomethingWithList()
{
if(CurrentList.Count > 42)
{
foreach(A processingA in CurrentList)
{
... |
Java service classes...
I have two service classes one for 'store'(save) data, another service for 'load' to display content.
It was implemented , now new requirement - depends on user input for load (for ex version) if it is not latest one do some logic to upgrade(based on some xslt transfomation) and save(store) the ... |
How do you keep track of maven dependency versions?
Let's say you are using version 1.0.5 of an library.
<dependency>
<groupId>groupIdName</groupId>
<artifactId>artecfact-id</artifactId>
<version>1.0.5</version>
</dependency>
But some people find a very bad security bug in version 1.0.5 and they release ve... |
Context
Our group builds and is responsible for maintaining multiple apps for a larger institution. We are in the process of breaking up our monoliths into reusable microservices (hooray!). When we got up to notifications (primarily email notifications) we got stuck. Our users consume multiple applications, and each se... |
Today we have vendors selling cloud based enterprise systems which an organization can lease and also configure and customize to fit the organisations needs. Even if there is work in performing configuration and customization, the implementations can still be done quicker than if the system was to be built in house lik... |
Encapsulation is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. Client code is expected to inherit from system-supplied classes and then substituted for the system's classes in its algorithms.
Inheritance is when an object or class is based on another objec... |
The title of my question is general because I feel like this problem is of a general nature, but to set the stage I'm going to provide a specific example.
We use a homegrown workflow engine that is driven by database tables. Within those tables lurks a directed graph that represents the workflow. The graph contains S... |
The following code examples provide context to my question.
The Room class is initialized with a delegate. In the first implementation of the Room class, there are no guards against delegates that throw exceptions. Such exceptions will bubble up to the North property, where the delegate is evaluated (note: the Main() m... |
I had a job interview recently and I was supposed to do an exercise where one part of the coding was using the ExecutorCompletionService. Well, there were other ways, but this would have been the easiest.
My problem : I did not know about this. After I found out about this, I could look it up easily (tutorials, example... |
Note: I get that refactoring is something you do along the way, you don't treat it as it's own "thing", or it's own specific task. I am talking about refactoring along the way, however I am not sure how much time I might end up spending refactoring or rewriting instead of solely implementing new features.
I've been ask... |
I am implementing a finite state machine in Python 2.7, and I am considering using an English word that I don't commonly see in code: "stimulus". I have a transition function that accepts some kind of input and the current state to decide which state to transition to:
def transition(self, stimulus):
# each state c... |
Recently I worked with a Restful API server and encountered a problem with handling database error.
The basic approach is every time a SQL exception occurred, the server will return "500" to client and client will have no idea what is wrong inside the server. It's fine for server errors. But sometimes, the errors are ... |
I have a website that's running on a production server, backed by mongodb. Every hour or so, some new data becomes available that I want to add to the db, inserting new documents, and updating old ones.
I get the new data on a development server, and update the dev server's copy of the db. If everything looks good, I ... |
I know requiring javascript on a webpage has been a hot topic the last couple years.
I'm wondering if someone wanted to use custom elements but still allow the website to be usable without javascript how would they do that?
Would they have to add a <noscript> with regular elements? or is there some way for browsers to... |
I have a seemingly standard task of sending push notifications to Apple devices from a server written in Java. I have never done that in the past, so I went to tutorials and Apple documentation.
1) The APN Provider API claims that THE protocol to send push notifications from the server is HTTP/2. I failed to find any t... |
The following program starts with hundreds of permutations and shrinks them down to a small result set. Furthermore, I am only looking for the first valid result. What techniques can I use to make this more efficient?
#!/usr/bin/python3
from itertools import permutations, zip_longest
def get_result():
checked = [... |
I'm about to write a Java library. Basically, this library provides something like this to its user:
interface Foo {
void doA();
boolean aWorked();
void doB(int value);
}
The user is not supposed to implement this interface (obviously). Thus, user code will look something like this:
Foo f = Library::SomeFactory(... |
These days I have seen couple of sites (including Youtube) that stream videos through Ajax calls (XHR) in few MBs or even less than MB. For an example of what I said see the highlighted lines in the image below.
I want to know:
What this technique is called in programming terminology?
How it works?
|
In the relational database world, we would tend to store unique pieces of data uniquely (e.g., in a single table, for example). However, now, with object stores (e.g., Firebase) it seems like storing the same piece of data in multiple places might be the best-practice? Is this true?
For example, I want to have users st... |
I have a StringValidator. A StringValidator is either a Regex or a string pattern using '*' wildcards. I want the StringValidator.StringIsValid() to perform one action or a different one, depending on which overloaded constructor was used. I can think of several ways to do this, but I have no idea of the best way.
Note... |
I'm using a third party product that has a class I can extend to provide a new way for that product to get data (the product is Sitecore but I don't think it's super relevant to the question).
They have a DataProvider class that I can extend:
public class Sitecore.DataProvider {
public ItemDefinition GetItemDefinit... |
Let's say you have three development branches going at once (dev 1, dev 2, dev 3), each branch working on different features for a given software product.
If I understand continuous integration correctly, these development lines would each need to constantly check code back in to a shared main line (once it has passed ... |
While creating server.js file we need to provide routes information as
var Login = require('./routes/login.js');
app.use('/login', Login);
Now, suppose the node project is a REST services project. so this type of entries could extend to lots of lines , meaning for every route we need to provide the above given 2 line... |
Given finder : List of map, key : String, Val : String.
On receiving super map : a map which is super set of one or more map in a finder, find map from finder list which has contains maximum elements from super map.
For instance
Map { Name = Adam, Qualification = Engg, Job = Manager , Country = US, City = Seattle}
l... |
I was wondering what the best practice is regarding databases for integration tests on the build server. If there is a best practice.
Currently, our build will create a new database from scratch for every build. Integration tests are then performed against this.
However, as the project has a long history, and continues... |
I have a large number of classes with an abstract base class (A) that contains behaviour that must be supported by all the sub classes say [B..I].
In my code, I end up with a collection of objects that is created based on input from an external system. These objects belong to subclasses described above and they go thr... |
I was going over some old code and found the following peculiar naming convention at a template method implementation.
// TEMPLATE METHOD
// Checks condition and fail fast if condition is met.
// Otherwise call the hook method (to be implemented by subclasses).
@Override
public boolean accept(String text) {
if (con... |
I am working with a big set of data right now and I wrote a program that calculates a result based on some inputs. I have 10 inputs, each of them has about 20 different possible values. I am not sure what technique to use to find the combination of these inputs that will produce the biggest result.
Here is a made up ex... |
If I have a complex attendance project to track the employees attendance and leaving, and according to that they get overtime money through a workflow.
The schedule is something like that :
6 weeks clickable on the top and the dates of the month in the right hand side.
I save the overall calculation but sometimes so... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.