instruction stringlengths 34 36.1k |
|---|
I have a C# cmdlet(1) that uses "ConfigurationManager.AppSettings" to get database connection strings necessary for some stored procedures used in the cmdlet(1). If another application instantiates an instance of the cmdlet(1) class object, then calls a method on the class that use a stored procedure an error is thrown... |
I host my own webserver through Java. The problem is I can only access it through a web browser by using an ip address. Can I spoof a url? For example, I type in 192.168.2.111 into the address bar, I want this to switch to a url.
|
I would like to know if I am correctly eager loading nested resources in my API.
In my app, companies can have many technologies, and tools. The relationship is stored in the join tables companies_technologies and companies_tools.
At an endpoint /companies, I would like to return all the companies and their technologie... |
The problem: 50 different commands which are typed into a command line for a program, lets say for telling a robot what to do. Some of the commands have user determined values such as travel north 5 (5 units of predetermined kind). Others are simple commands, scan area, that have no user determined input.
In my courses... |
I'm working on developing a simple game and am using the switch statement quite frequently. Is it possible to reference the specific case in question instead of typing out the constant value? For instance:
switch(String upgrade)
{
case(Bullet_Power_1):
remainingUpgrades.Remove("Bullet_Power_1");
... |
Input data: a grid of cells of different colors.
Problem: how do I cover this grid with a minimal number of non-overlapping rectangles so each rectangle contains the cells of one color only?
|
Delegates and delegation exist to enable passing specific messages to an observer, regardless of that observer's type. In a coordinator-type architecture, where coordinators manage and run the flow of an application (instead of say the UI layer, à la iOS & UIKit), delegation serves as the primary means of communication... |
Lets say I have a Widget class. I also have TextWidget, ComboWidget, ChoiceWidget classes that inherited from Widget class.
I create this widgets based on the situation. After creating the widget, I just show some data on widget and get one from the user. After that the widget gets destroyed. My current code is somethi... |
I am trying to devise a versioning system for a product that we are building. We have three environments: DEV, TEST and PROD.
One system is that eg. if we have a (small) change in DEV, we increment the version to 5.1.2 from 5.1.1, have this version number propagate to TEST and PROD as well. Then for the next (small) ch... |
Is it possible to create a Javascript file that act as "click counter"?
What I want to do is that I put that Javascript file in my domain
mydomain.com/js/clickcounter.js
And anyone can include it to start counting clicks..
Example for THEIRdomain.com/index.html
<script src="mydomain.com/js/clickcounter.js"></script> ... |
I am trying to implement a tree data structure that callers of my code edit for me to operate on. The idea is that the caller can hold a reference to nodes from the tree and modify their data (both attributes and children), which triggers an event that prompts my code to update a visual render of the tree.
The problem ... |
We are currently working on a micro-service based system. The idea behind it is to split our monolithic system to small domains (micro-service per domain).
All services will be used by our internal applications, but we have plans to expose it to public.
One of the services would be identity management service, which wo... |
I'm a long-time Java developer who's trying to make up his own mind about TDD.
I've used JUnit since I first discovered it in 1998. I use it regularly, but I don't subscribe to "write the test first". My coverage will range from 60-90%; I'm not compulsive about driving it to 100% in every case.
I read Extreme Program... |
I'm using a large and complex library including R and C++ code, available online via a subversion repository. Trying to figure out how it works I took a bunch of notes in the source code itself, in the form of comments. Years later, the repo has been updated, so now I have to choose among:
Updating and starting from ... |
Unfortunately, I am not even sure of the keywords to use for this question, so if this has already been asked please point me the right way.
Given a set of vectors:
[3, 5, 3]
[10, 23, 5]
[123, 53, 97]
(here, 'vector' means one dimensional sets of numeric values).
I'd like to know a way of finding the closest match for... |
Synopsis:
I am working on a level editor for a game written using Unity, the game is actually a new engine for an old game. This is a +20 years old game and its data structures are by today standards, hard to deal with in an environment such as Unity. Hence why I'm writing a level editor to ease the pain.
Basically the... |
Is it good practice to use a free website as package identifier if I do not have a real website? EG com.weebly.vikarjramun.myapp.myactivity Just wondering...
|
It seems to be the view and controllers are rigidly defined, but the model is highly nebulous. For instance, views go in views folder, controllers have the word controller in their name and have controller annotation, but models...?
What is the standard or de facto or at least the recommended way of implementing the mo... |
We are about designing microservices application around REST API. The application is aimed to search, Create, Update and retrieve document from many heterogeneous repositories.
I'm wondering if I have to model the services around operations (each operation GET, PUT, POST, PATCH, ... as service) or around the repositori... |
Evans introduces in his book "Domain Driven Design" in Chapter 6 "Aggregates" the concept of Aggregates. He further defines rules to translate that concept into an implementation (Evans 2009, pp. 128-129):
The root ENTITY can hand references to the internal ENTITIES to other objects, but those objects can use them onl... |
I bet I'm not the only one here that has had problems with something like this: you want to check something in a language that has the == operator for checking equality and instead you do something like: if (a=5) which always returns true, given that the language uses = for assignation (which the most common thing by f... |
I'm lead on a team with a half-dozen senior engineers. I very much believe it would benefit us greatly to do code reviews for all the standard reasons. Not necessarily every change but at least a steady stream of background reviews. So people at least see other's changes and start talking about them.
Is there a good wa... |
I have applied a custom heuristic to my A* search. It is admissible, but it is not consistent (monotonic). As such, I am not guaranteed to find the shortest path.
I had assumed I could use a hybrid approach that calculates both the euclidian distance heuristic and my custom heuristic and choses the tightest consistent ... |
In a textbook I've been looking through for a class, it is stated, a statement can be empty (the null statement). The null statement is defined as just a semicolon.
It does absolutely nothing at execution time. The null statement is rarely used.
As a moderately experienced programmer, I find it interesting that they sa... |
Which way is better?
-- Option 1-------------
if ( condition1 )
{
statement1
}
else
{
exit program
}
if ( condition2 )
{
statement2
}
else
{
exit program
}
----Option 2------
if ( condition1 )
{
statement 1
if ( condition2 )
{
statement2
}
else
... |
I'm working on a Spring-based REST api that has v1 and v2 variants:
/api/v1/dates
/api/v2/dates
Correspondingly, there are v1 and v2 packages in the code base:
com.company.api.v1
com.company.api.v2
Is it a good practice to postfix class names with version number like below:
DatesControllerV1.java (in v1 package)
Dat... |
I have an asychronous file transfer using boost::asio.
Multiple files can be transfered at the 'same time'. Same time as in - file packet for file 1, next packet for file 3, next for file 2, ... No threaded file-transfer in the same socket.
Currently I'm sending each time a 10KB packet/message/string, including a small... |
Let's say you have a signature like so:
public void MyFooBar(IExtraSuperLongTypeName param1, TypeA param2 ISomeotherReallyLongTypeName param3, TypeB param4, TypeC param5)
Formatting in on one line is ugly and hard to read. A style that resharper uses
to format this is to push the parameters down like so
public void My... |
I am developing an Angular SPA and I am currently in the design phase. I have created a sample architecture which I am planing to use in my SPA but I would get some feedback because I want the architecture to be scalable and maintainable. I have tested this architecture out and it works so far.
My Current Architecture:... |
For some time now, I have searched and read a lot about memory alignment, how it works and how to use it. The most relevant article I have found so far is this one.
But even with that I still have some questions about it:
Except in embedded system, we often have huge chunks of memory in our computers that make memory ... |
We're actually naming our test packages just like their to-test counterparts. So we end up with this structure:
src/main/java
com.hello.world
helloWorld.java
src/test/java
com.hello.world
helloWorldTest.java
I always felt like this is not pretty smart since you can't distinguish between "test"... |
We plan to refactor our company system into a micro-service based system. This micro-services will be used by our own internal company applications and by 3rd party partners if needed. One for booking, one for products etc.
We are unsure how to handle roles and scopes. The idea is to create 3 basic user roles such as A... |
I taught a course years ago, and then I used some JDBC exercises using what I now know is the Active Record Pattern.
I would like to modernize the exercise by changing the Active Record Pattern so classes don't do their own persistence. But I would not like to use any persistence or ORM framework for teaching purposes... |
A lot of ORM sites and SQL tutorials mention these relationships as if they are obvious or to be taken for granted, but I don't fully understand why the distinctions need to be made.
Consider two tables A and B, both with id fields, and linkage(s) between these two tables.
My understanding is that:
One-to-one relation... |
I would like to use command / handler approach where I register few handlers in global.asax in my MVC app and send commands from MVC controllers to those handlers.
public class CommandProcessor
{
private static readonly ConcurrentDictionary<Type, Type> ListOfHandlers = new ConcurrentDictionary<Type, Type>();
p... |
I'm working on a smallish voting webapp. Similar to strawpoll but only authenticated users are allowed to make polls, while everyone is allowed to vote.
User:
id
email/password_hash/name/...some other data...
Poll:
id
user_id REFERENCES User.id - notes which user created the poll
title
PollOptions:
id
text
poll_id... |
I was wondering if are all tasks executed by the CPU (fetching, reading, writing, etc.)? Everything is controlled, manipulated or executed by the CPU?
|
I've been working with javascript for the past 4 years. I'm very confident about my problem solving skills and I can see that my code quality is improving. I try to stay up to date with the community and I'm currently working with ES2015 and React.js. However, I feel like I can't grasp programming design patterns at al... |
We are developing a series of tools for our internal usage (only). We are writing the documentation in parallel with the development progress.
Is it important to provide different documentation formats? For the moment we generate the documentation only in HTML
|
If we have Table A that has a one to one relationship with Table B, does it ever make sense to keep them apart? Or does it never hurt to combine them into a single table? Do either of these scenarios (two tables vs one combined table) impact anything with respect to its normal form (1NF, 2NF, 3NF, etc)?
|
I'm currently in the process of writing a program in R to perform analysis of data from a mass spectrometry experiment. Well, that's the idea. I'm fairly new to R, and didn't actually perform the mass spec experiment myself, so I'm encountering a few problems.
Essentially, I have a set of m/z (mass/charge ratio) value... |
Can using single-character variable names as parameters in a function okay?
For example, look at the code below:
public static int factorial (int x) {
if (x == 0) {
return 1;
}
return (x * factorial (x - 1));
}
In this case, is using variable name "x" okay as the parameter for the function? In wh... |
So I have a "Bars" table in my database and a "Add a Bar" form which allows a bar owner or manager to add his/her business listing to my website database. I also have a "Beers" table in my database and I want the owner/manager of the bar, when entering his/her bar info, to be able to pick how ever many beers from my da... |
I'm a junior developer learning programming in Python. I found that some of functions I write uses too many parameter, like
def f(a,b,c,d,e,g,h):
What would one recommend to avoid such a situations? I heard about classes but have not yet learned them thus far. Is it wise to make function to work like this:
def f(param... |
We're looking into adding authentication to a range of APIs that we are about to develop. The solution is entirely fluid as it currently stands, but the basic premise is that there is one API layer that the customer interfaces with, and several APIs behind that that this initial layer delegates to.
Part of the proposed... |
I am currently working on project that is make a online judging system like codeforces. In this system user can submit code and the system will compile, execute, and generate output on a specific input set, and match the output with system result then give verdict.
There is a two part of that system. Front end is in P... |
Suppose I have some project of which I own the code. It has a library which is licensed under Apache 2.0 (but that shouldn't influence this). So I can choose if I want to release the code using GPL, Apache 2.0 (or similar) or make it a closed source project.
As there is quite some code, I want to build the documentatio... |
This is a general software design question. My program is written in Java, but I suppose my question applies to any object-oriented programming language. The best way for me to explain my situation is with an example.
In applications like LibreOffice and MS Office, the user chooses a program option when launching the ... |
Let's say I have something called "Actuators". Each "Actuator" may have capabilities associated with it. Should I reuse it wherever it fits, or should I create entirely separate kinds of actuators for each kind of target?
I have block targets, I have item targets, I have entity targets and I have command targets.
An ac... |
In an off-hand comment on this question about storing PHP objects in a MySQL database I mentioned that it is probably not a good idea to do so.
My reasoning is that MySQL is explicitly a relational DBMS, and that it doesn't make sense to force it to be something else, as it will not be optimize for that.
I would assu... |
Say I have a function whose input is an array of fruit objects, and returns a list of *cloned) apples from that list, with each cloned apple mutated with an additional property visible on it. Would a good name be extractApplesAndSetVisibility, or is there a better name?
|
Why is it that :
System.out.println(+'A') //gives output as 65
System.out.println('A') //gives output as A
Also
System.out.println(8+4+'A'+"PRIME"+4+4+'A');
gives output as 77PRIME44A
Why is it that 8+4 before the String "Prime" are being added, while 4+4 after "Prime" are being printed as it is ?
I also ha... |
I've recently bumped into string methods and mainly
str()
method caught my interest because, it makes string out of every type of data?
integers, booleans and so on. And if you want, they can be easily stored in variables like new strings:
my_string = str(45161516)
that variable will automatically hold that number as... |
I've got a simple example of using a fluent interface to attach events in JavaScript
function attach(fn){
let handler,to;
handler = fn;
attach.to = function (el) {
to = document.getElementById(el);
return attach;
}
attach.on = function (type) {
to.addEventListener(type,fn);
return attach;
}
... |
Trying this again but with a slightly different approach. My previous thread was here Can anyone explain this one-to-one, one-to-many, many-to-one, many-to-many concept with respect to ORMs? but honestly I think it confused me more than it helped, especially when there seemed to be conflicting views even among the answ... |
I've forked a Github repo and added an upstream remote as described here. I expect to make some backward-compatible bug fixes for which I'd like to submit upstream pull requests, as well as some major non-backward-compatible changes. This question is about how to manage both of those things in one repo, or whether th... |
Is there a possible test to check if a PDF file contains text or it is created by scanning paper sheets ?
text : plain text that, for example, I can copy & paste while I am reading the PDF. Not searchable / hidden text. Created for example from a wordprocessor.
not text : PDF from scanners, containing only JPG or TIFF... |
As an example, in Python I have a lowest_prime_factor function which does it exactly what it says it does. Then, in another function, I need to call this function and store it. In another language where variables and functions can share names then I would simply do lowest_prime_factor = lowest_prime_factor(n). In Pytho... |
Say I wrote a program containing 3 methods. Each method was 100 lines. Method 1 was main(), and Method 2 was called by main().
I then duplicated the program into an identical second program. After duplicating it, I added 4900 lines to Method 3.
Method 3 is never called by either program.
Program 1 has a file size of 3.... |
which is the more efficient approach to print the reverse of an array of integers in Java:
First Approach:
int length=array.length;
for(int j=length-1;j>=0;j--)
{
System.out.print(arr[j]);
}
Second Approach:
List<Integer> listInteger = Arrays.asList(array);
Collections.reverse(listInteger);
int length=listInteger.s... |
We have an existing implementation where all users belong to an organisation will depend on the organisation subscription, so if the subscription has ended all users belong to this organisation will not be able to access our web application. They won't be able to login due to expired subscription.
Sample DB Schema for ... |
If class A has many of class B and class B has many of class A, should we place a diamond on both sides of the line between them?
Like in the picture below, or is it fine to just indicate the amount in both directions and have the diamond only on one side?
|
Suppose that I have a project written in JS via such frameworks like Node.js and Express. It also uses Mocha as a test framework and Gulp as a build system.
I wonder what is the best way to expose installation, testing and deployment to users.
I mean, users typically have to do the following stuff:
Install Node.js and... |
I have an open-source project which requires me to create mathematical models to compute some things. I have to analyze some data to decide which model works well and determine the range of errors produced by the model.
I want to document this analysis, but I don't want to put it directly in the code because:
It can b... |
I have a function, let's call it test. This function has arguments, but I don't know how many arguments it has. It returns always a Boolean.
I have another function, let's call it calibrator. This calibrator function gets the possible alternatives of the test arguments in a 2d array. Every argument can have many altern... |
I am trying to write a simple live sine wave generator from scratch in Qt.
I try not to use any external APIs like ASIO or VST. And I want to generate new audio while playing. (As opposed to the Qt example, it just repeats some samples)
Qt only gives you a QIODevice that you write data to at a fixed sample rate.
(If th... |
I'm programming on a c project and use code from another author. I change the main functionality to a new, complete other one. The most of the new code is my own but some files are untouched and others are modified.
Every file of the other author begins like this:
/*
* Copyright (C) 2005 - authors name <authors_name@ho... |
Let's consider these four functions:
# Racket
(define (square x) (* x x))
(define (sqr a) (* a a))
# Javascript
function square(x) {
return x * x
}
function sqr(y) {
return y * y
}
All functions square the given number but in different languages or with different naming. Output of calling any of them is always ... |
Any libraries, API, or tips are welcome. I am trying to draw Landsat 8 images using Canvas utility of Javascript on my browser. The grayscale reflectance values for Landsat 8 bands are from minimum -32768 and maximum +32767(int16). The Canvas utility offers RGBA for range 0-255. If I scale (-32768, 32767) range to (0,2... |
I started to rewrite very monstrous (and old) web application. It runs on PHP 5.3, the design is completely mad - Models and Viewers, no controllers etc. I have been able to refactor the code to work with PHP 7, bend the autoloader to start using Composer and I want to start refactoring the core.
What I basically need ... |
I'm creating A Map like Travian on Xamarin forms
My map is something like 5000*5000
The way I want to do that is to load part of the map (21*21) of the big map where the current village is the center of the 21*21 map but show a 7*7 map to user(Again current village center of it)
So when user scrolls the map, can see t... |
In traditional Rail app, we need to deal with controller/model/action and has a view that generate HTML output. Now
There are many JS framework like backbone/react that allow us to code client side that consume API very easily.
And our webapp might also provide APIs for public to use.
I am thinking, instead of codin... |
I have two existing tables called VehiclePlants and VehicleModels.
Right now, the VehicleModels are linked to a possible multiple of VehiclePlants
The customer wants this changed to be just a one-to-one relationship.
My question:
When I add this column VehiclePlantId to the VehicleModels, knowing that this has to be ch... |
It looks like there's a problem with our deploy process where old versions of our service are being deployed to certain clusters, but it's hard to tell exactly what's wrong, since all we have as data points are occasionally failing tests which suggest bugs that were fixed in previous builds.
In order to keep an eye on... |
With in the introduction of anonymous types in C# we got the var keyword.
Now people use var everywhere instead of the correct type. The reasons I've heard given for this are:
It makes refactoring easier
It's shorter
it improves readability
A common example might be
var result = client.GetResult(query);
is better th... |
I have created one utility module which converts one file format to another one. File i.e. test.abc will be converted to i.e. test.pqr and internal format of files are totally different. This module involves nearly 5 different file formats.
Internally, it uses one native tool and I do not have any control over it. It ... |
I've started to learn about approaches to integration testing in big enterprise applications (java based, spring, and everything :) ).
So I saw two main approaches:
Running parts of spring context substituting real data parts with in-memory implementation. A drawback of such an approach I guess is that its very hard t... |
I was watching this video about the CAP theorem, where the author explains well the trade-offs of distributed systems. However I disagree with the CAP theorem in the following aspect. Given the picture below:
Whenever there is a partition, in other words, whenever a slave loses its connection to the master, this slave... |
My team is using SVN to store a lot more than just source code - we are storing all kinds of files. A process I'm working on designing is used to generate diff reports whenever a certain Excel spreadsheet is updated and acknowledged by a subset of the team. (This spreadsheet is automatically generated by a separate pro... |
Trying to understand strings better in C#
Are these assertions correct?
string is immutable
string is reference type but behaves like value type
For these code samples...
string x = "one"
(creates string instance holding "one" in memory)
x = "two"
(destroys "one" instance and creates new string instance holdi... |
My understanding is that the system below can accomplish consistency, availability and partition tolerance. So I must be misinterpreting some aspect of the CAP theorem. How come?
Let's say I have a distributed system with 100 redundant nodes: 50 in a datacenter in the US and 50 in a datacenter in Europe. These two data... |
I have 3 billion strings. I want to make a frequency map so I can discard strings that occur fewer than 100 times or more than 100,000 times. What kind of data structure(s) should I use? I'm thinking some kind of bloom filter.
|
Looking at DB tables created by a different developer I have noticed that whenever a table had a forein_key_id field/column, it was always an INDEX/KEY.
I am not sure if it was manually created, or automatically by some 3rd party software. However, I myself usually created keys using different principles. i.e. Just ... |
I understand that CSS only supports multi-line comments like such
/* foobar */
Why is there not support for single line comments.
// foobar
They are just as common in programming and seems particularly useful for a language like CSS where each rule is on it's own line.
If there was no particular historical reason for... |
My code takes 2 dates and finds the age of those dates in days. In my daysBetweenDates method the instructor uses an assert statement:
assert not dateIsBefore(year2, month2, day2, year1, month1, day1)
My question is, why do you have to use 'assert not' in this example and in the signature why is year2, month2, day2 fi... |
Say I have a program where a user is presented with a treeview of multiple directories and must check desired file/directories that they would like to later be copied.
That aside once the user has selected the files how can I go about creating a separate executable after a button is clicked that will perform the copy o... |
I was reading on the TypeScript site and saw that the TypeScript compiler is itself written in TypeScript. "The TypeScript compiler is implemented in TypeScript and can be used in any JavaScript host." I don't understand how this can work, wouldn't that create a circular dependency? Chicken-and-egg-scenario? was the f... |
In C, * is called the indirection operator or the dereference operator. I understand how it works when it is used in a statement. It makes sense to write *p or * p, considering that it is a unary operator.
However, sometimes in a declaration, a * is used.
void move(int *units) { ... }
or
int *p = &x;
It seems strange... |
I have a sorted list , lets say 1, 6 , 10 ,15 ,16 , 18, 30, 50.
How do I find first three items which are in the less than interval of n, say 3.
For example in the above list, 15, 16 and 18 is the answer. Is it possible to get to this in better than O(n) ?
|
I am new to the token concept of Authorization.
I am developing angular app which calls the Web API built with asp.net core. I am currently using JWT(JSON web Token) to authorize the users. These tokens are issued after login and sent in authorization headers on every request. The tokens last for 30 minutes. Now the pr... |
I have few classes which used System.out.println (which should be avoided) and now I am trying to move those into a logger.
We already have been using logger in some other modules. But the module I'm working haven't used it anywhere. So, I thought to create a new common class & put a new entry in logback.xml file for t... |
I am developing an application that has a lot of options like local database CRUD operations, file IO, web APIs calling, notifications, user preference settings, services, widgets etc.
At start it seemed no problem to work with classes, now reaching 50% app completion, I see 20+ classes in my app (all code documented/f... |
I'm discovering craftsmanship and trying to learn it, and I decided first to understand how to work with the SOLID principles.
I'm actually facing some troubles while dealing with the Open/Closed principle.
How I'm working
In fact, I'm usually building applications like the following:
Presentation layer with Angular
B... |
We have a more or less "typical" ReST API that allows clients to interact with a bunch of resources, let's say Maps and Devices. An authenticated client can get a list of maps, it can download a map, upload a map and do similar things with devices.
Currently the resources have URIs that are modeled something like this:... |
I have a hard time understanding when the Single Responsibility Principle is correctly used. Consider the following code:
// --------------------------------------------------------------------------------------------------
void CTCPClient::Try_Send_Data(const char *Outgoing_Message)
// --------------------------------... |
I am developing an online medical website (similar to a HIS) whose users are hospitals specifically hospital administrators, doctors, and other staff authorized by the hospital to use the system. There are many hospitals that would use the website.
There is a feature in my website where the authorized user is able to ... |
Uncle Bob's chapter on names in Clean Code recommends that you avoid encodings in names, mainly regarding Hungarian notation. He also specifically mentions removing the I prefix from interfaces, but doesn't show examples of this.
Let's assume the following:
Interface usage is mainly to achieve testability through depe... |
Citing JUnits homepage: "JUnit is a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks."
According to a the answer of this question: Library vs. framework vs API?, a framework is "a collection of patterns and libraries to help with building an application... |
I use perf to profile my application. To make interpretation of the resulting call graph easier, I partitioned my core loops using label functions like maptable_appendRange that can be easily searched for in the call graph. Unfortunately, these functions are mostly inlined by the optimizer and therefore do not show up ... |
Suppose I have 3 domain events, Event1 Event2 and Event3. When command arrives at my Service Layer, I can rise 2 commands at the same time - e.g. Event1 and Event2. One Class has event listener for both events, but it should basically wait until both events are received to start processing it. Otherwise I need to execu... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.