instruction stringlengths 34 36.1k |
|---|
I have a couple of async method that is basically a yes and no reply
isUsernameAvalible() isOnline() isImage() yada yada... you probably get the point by now.
As a demonstration... try to think of this as a more generic async promise handling (not that it has anything to do with image manipulation) and it could be work... |
I have created an app using Cordova, that I want to release on the Google play store. My app uses other peoples plugins that have a variety of licences, including Apache licence and MIT. I believe that I need to reference their work at some point. how do you recommend I do this? eg in an 'about' popup in app? or does i... |
I'm using Unity in C# for dependency injection, but the question should be applicable for any language and framework that is using dependency injection.
I'm trying to follow the SOLID-principle and therefore I got a lot of abstractions. But now I'm wondering if there's a best practice for how many injections one class ... |
When developing backend - serverside code - for websites or web services and using a GPL or CDDL library, such as https://tyrus.java.net/. I would just "use" the functionality of the library. No modifications would be made to the tyrus libraries.
Do I have to release the code of the whole project or any part of the p... |
I found this answer on StackOverflow very clear to explain the difference beween the Logic Programming paradigm and the Functional Programming paradigm:
The thing that makes logical append different [from the functional one] is you can use it to compute the list that results from appending one list onto another, but y... |
The software product I work on has several services and user interfaces. There are separate setup files for each unit of the product for installation. We make customer specific changes and bug fixes every day. We need to store a seperate version for each customer.
Recently, we made the mistake of installing the wrong v... |
Is it against best-practices to use a POST request to read data? Are there any exceptions to this? e.g. Authentication requests where you have to POST data to perform a read action.
I have an API call that requires a lot of parameters and it's basically a Read action. I can't use GET request because it may hit the URI ... |
I am currently developing a new web application based on a rich JavaScript client which communicates with multiple REST web services on my server. That application is intended to be used in at least two country with different languages, so we need to localize it.
My question is where should I manage the localization : ... |
I have a library /Web/ such as follows
/Web/
Builder/
Builder.php
Exceptions/
ExceptionHandler.php
JSONSerializer/
CategoryJSONSerializer.php
ProjectJSONSerializer.php
....
Module/
Category/
Controller/
Category.php
... |
A while back I got into a discussion with a classmate about whether our application should use multiple JFrames, or windows. I'm a linux-user, and said yes. He's a windows-user, and said no. When asking around in the team it seemed like all linux users wanted multiple windows, and windows users seemed to be scared of t... |
So, I'm working on a project that takes a very complex entity from a third party framework and converts it into the native object that defines that entity. This entity has several one-to-many relationships, and a few of those have some one-to-many relationships. I've often been told nested loops are the worst, just abs... |
In the below code.
<!DOCTYPE html>
<html ng-app="app10" ng-cloak>
<head>
<title>Custom directives</title>
<style>
[ng\:cloak], [ng-cloak], .ng-cloak{
display: none;
}
</style>
</head>
<body>
<div ng-controller="mainCtrl as o">
... |
I've been studying creational design patterns for the past week or so because I have a common use case that keeps coming up, and I can't figure out which pattern fits the bill.
Here is a simplified scenario: I have different types of notifications -- e.g. email, SMS (text message), etc. -- and I don't want the client... |
Trying to understand onion architecture. As I understand it, there is different opinions about the names of the layers.
In this post I refer to the layers as: infrastructure -> api -> domain -> core.
The core concept is, as I understood it, that the outer layers can know about the inner layers, but that the inner can n... |
In an attempt to solidify my understanding of the command pattern, I decided to write a calculator application that utilised it.
After making some progress, I realised that my choice of application may not have been the ideal choice.
I have the following components:
View.xml
This is the user interface of the calcula... |
I need to be able to convert a version string to an integer. I've decided I will follow semantic versioning so version strings will be of the type x.y.z.
Initially I thought a simple algorithm like int = x * 10^6 + y * 10^3 + z would be sufficient and it most probably will be since I've never seen software with a three... |
Controller:
function indexAction()
{
if ($condition)
$this->renumPosition($id); //LINE #1
}
//Redirect only - function's sole purpose is to call another function
function renumPosition($id)
{
$this->repository->renumPosition($id);
}
Repository:
function renumPosition($id)
{
//SQL, DQL, ORM code... |
I like the Swift way of trying to eliminate unintended consequences wherever possible. Whenever there is a change to the language that deprecates something I have been doing for years, it forces me to rethink what I consider to be best practice. The elimination of ++,-- was the most recent time this happened.
One area ... |
I need to implement a producer-consumer pattern for reading, processing and saving electrical values. I have to implement this in C# .NET 4.6.1.
I try to describe this in great detail, so that there hopefully is no misunderstanding about the goal I want to achieve. I have an idea how to do it, but it may not be the bes... |
I'm an intermediate Python dev and just starting out with Haskell. It seems like Python's classes can be used in a way that is similar to how Haskell's typeclasses are used. It seems like typeclasses are just a way to implement operator overloading. Like this:
# main.py
class MyClass:
def __init__(self, num, name):... |
I want to develop an app where users can upload an share images. I am planning to integrate a disclaimer which says that it is prohibited to upload images which contain crime, sex, insults etc. Furthermore I want to implement a "report a user" button where multiple reported users get blocked. But most of the people do ... |
You are writing a boolean expression that might look like this:
team.Category == "A Team" && team?.Manager?.IsVietnamVet
public class Manager
{
public bool IsVietnamVet { get; set; }
}
public class Team
{
public string Category { get; set; }
public Manager Manager { get; set; }
}
...and you get an error:... |
I have a program that translates a DSL to C++, which uses a Visitor pattern on the intermediate representation.
I quite often need to replace the currently processed node with one of a different type (e.g. replacing the "unresolved type" with the type definition).
What is a good pattern to do that?
I've tried:
storing... |
It is caused by the naive programming paradigm: focus on just a single object, do something with it, and if you have to work with many objects, you loop, iterate and traverse, repeating the operation on each object you come across. This is usually o.k. for rather small collections in memory.
It is wrong in an environme... |
I have read that there are languages other than C++ that can also compile standard C++ source code too (Objective C++ can do this). Which other languages for Windows and Mac OS are there, that support this too? In contrast to Objective C++, are there also languages available which allow to derive a native class from a ... |
When building a service that uses both a back-end REST API, and (a) front-end application(s), is it proper to build into that API the ability to dispatch email?
Take Twitter for example; for those who don't know, they function with a back-end REST API and a front-end static website that consumes JSON resources.
I don't... |
Some languages (Javascript, Python) have the notion that a function is an object:
//Javascript
var fn = console.log;
This means that functions can be treated like any other object (first-class functions), e.g. passed in as an argument to another function:
var invoker = function(toInvoke) {
toInvoke();
};
invoker(f... |
Currently writing a JSON Importer and creating some POJOs based on the data. I also have a requirement to write an JSON Exporter which take the information in the POJOs and exports a JSON doc.
To me I would like to reuse the the same code if possible. Does such a thing exist where you can reverse the function/method? i... |
I read an article on BBC. One of the examples they said was that people with surname 'Null' are having problems with entering their details in some websites.
No explanation is given about the error they are facing.
But as far as I know the string 'Null' and the actual Null value is completely different (from a databa... |
I am developping an Android application that is using NDK in order to access to data from the Linux kernel. As you may know, this is done using IPC (Inter Process Communication) through Android's bound services.
While writing the documentation related to this application, I am supposed to describe the application's arc... |
Is it good practice to define private constant strings that have the same name as their values? Take the following code for example.
public class Example {
private static final String FIRST_KEY = "firstKey";
private static final String SECOND_KEY = "secondKey";
private static final String THIRD_KEY = "thir... |
I think the question in general is best summed up as, should Laravel's App::make() be considered a dependency? On the one hand it can instantiate any number of different implementations, so maybe it is not a hard dependency. On the other hand, should a class really be responsible for calling App::make() to instantiate ... |
Does UML provide its own data types for the attributes in the class diagram?
If so, what data types does UML provide?
If UML provides its own data type and the target language has an equivalent type with a different name, which one do I pick for the class diagram?
My UML book uses the lower case camel syntax for attri... |
(that can change its value over the course of the program)
Or is 'instance of something' strictly related to classes and objects? If so, how would you define the concept of 'variable' when it comes to C++?
|
I am currently designing a JSON RESTful API which should have a boolean endpoint such as /item/vote which can either be false meaning that a user has not voted for a specific item or true meaning that he has voted.
I am currently struggling to select one out of multiple possible designs:
HTTP status codes
PUT /item/vo... |
I have function that has three parameters, called key, value and attribute.
Parameter attribute may be empty or have within two arguments. Code of function below is shortened (deprived of arguments validation)
public function Set_ContentUsage($Key, $Value, $Attribute=NULL)
{
$this -> ContentUsage = array();
$At... |
Quite often there are situations where a bug exists in code, or a feature is requested, where it is expected that the fix/implementation will add less value to the business than the cost of any of: implementation, in particular validating that no side-effects are introduced pre-release and implementing any re-work requ... |
I have an amount class which provides the minus method among others. The result of this operation is of course another amount.
The question is how can I handle the three cases according to the signum of this amount polymorphically?
Currently, I am just switching on the signum of the contained value in the amount but I ... |
Some Explanation
I'm somewhat new to python and to programming (I've been at it for a little over a year). I just recently discovered python properties, and I've been using them to limit the mutability of my classes' attributes. It helps me or maybe other people who might use my code from misusing it. And because of th... |
Okies, totally newbie question here. I can read the code, mimic the code and understand the basics to be deadly. But, I never really took the time to understand what ANSI C really meant. I just look and code. Been doing it since I was 15 years old and I'm 33 now.
It's been awhile since I touched C, but getting back int... |
I had an assignment on dynamic programming due last night, but I had to turn it in unfinished because i could not understand how to solve the last problem:
The state wants to monitor traffic on a highway n miles long. It costs ci to install a monitoring device on mile i of the highway. The maximum distance between mon... |
When responding to an HTTP request for a commonly used file on my web server, for example index.html, rather than reading the file each time, I list those popular resources in an array and read them when the server starts, so for all requests those files dont have to be read.
I think this might increase the efficiency ... |
While I was reading a research paper on concurrency named Software and the Concurrency Revolution (html version). I came across following lines:
Unfortunately, although locks work, they pose serious problems for
modern software development. A fundamental problem with locks is that
they are not composable. You can’... |
Say I have a bunch of JavaScript functions similar to:
message = [“000”, “111”, “222”, “333”];
function F0(){
alert (message[0]);
}
function F1(){
alert (message[1]);
}
function F2(){
alert (message[2]);
}
function F3(){
alert (message[3]);
}
Is there a way to make some kind of template for this se... |
I'm relatively new to C++, so I'm not sure how I should best handle small dependencies (e.g., a scripting language, or a JSON/YAML/XML Parser).
Should I create separate projects and link them as static library, or are there downsides of just putting the .h/.cpp files into my main project?
The latter seems a lot easier ... |
Is there some design pattern for handling situation where class hierarchy constructors parameters force the most bottom classes to have too many parameters?
Ideally this would be in C++, if language matters. Consider following generic example:
class dependency1;
class dependency2;
class dependency3;
class ClassA
{
pu... |
I am making a tic-tac-toe game in C#. I have a string variable for each square. I want to make it so the user inputs the square name i.e. (topMiddle). Then I declare the input playerInput. I want to use str.Replace(' ', 'x'); but instead of str I would use the name of the box i.e.(topMiddle). How would I retrieve that ... |
I am making a weather app that involves temperatures. You can change between Kelvin, Celsius, and Fahrenheit just for fun.
However, temperature figures get used all over the place in different ways. Does it make sense to have a Temperature class that stores the number as well as its units, and has various methods for i... |
We are looking to do a full rewrite of our backend E-commerce platform and as a consequence of this the front end will also need to be rewritten. The front end is a monster of javascript that is to put it bluntly: out of control.
The plan is to break up our backend monolithic system to a series of microservices gradua... |
I'm writing a research essay over distributed cloud-based systems, and one of the topics that I'm trying to touch on is potential solutions to high database utilization in a single-database multi-tenant architecture. I've been searching the web for some ideas, but for the most part I'm coming up empty handed.
For examp... |
Assuming declarations are expressions consider such code:
if ((var x = foo()) and (var y = x)) or (var z = bar()) then
println(z);
end
The reference to x is OK, because at this point x has to be set, but the reference to z (in println) is not. It can be valid or not.
I would like to compute those two "states" of var... |
I want to define own data type, say a Digit, which would have definite type of values ( 0 to 9 ) and I'm struggling with defining this in a way it's practical. What's the best way (design pattern) to do this?
I'm doing this in Scala, which might provide some advantages, but I'm also interested in general approach.
If i... |
I noticed in scrum meetings, that developers often give realistic estimations on stories. However, even rather simple stories need a lot efforts for configuration, setting up third party components, testing and final build, and the system has accumulated quite some technical debt, so the estimates often appear too high... |
I have a class Car which has 2 properties: int price and boolean inStock. It also holds a List of abstract class State (empty class). There are 2 states which can be applied on the car and each is represented by its own class: class Upgrade extends State and class Shipping extends State.
A Car can hold any number of ea... |
I have the following class:
internal class LeaveRequest : ServiceBase
{
private const string InvalidRequestMessage = "Specified Request does not exist";
private const string InvalidApproverMessage = "You are not an approver for the specified user";
private const string RequestWrongStatusMessage = "The req... |
I do a lot of programming work for other people's businesses. I am currently working on a project for my local Scouts group that I have worked with before.
The problem is I have built them their server and I administer it for them but the problem is they need to make sure it's secure. Which is fine, and then I raised t... |
I'm currently writing a browser based game where events occur in real time - as an example of this, take Farmville, where a crop only grows after a particular length of time.
Running a method every second is a bad idea, and so the better setup would just be that when the server is asked for data it works out how long h... |
In layered architecture does it matter where static methods go? Or is it the architect deciding this? For example can the DAL be static to cache records and perform smart data retrieval at the application level? How about the service layer; can it be non-static?
I ask this because I have seen examples from good archite... |
Eve Online, a game I used to play, had an interesting "permissions" system for account interactions with other apps.
The permissions encompassed dozens of individual permissions, each under a category (which may or may not have been relevant to the resulting hash)
The interesting thing is that the entire permission sta... |
I have two questions about keeping timers running (like growing crops in Farmville) when users are not online:
Am I right in thinking that I should just calculate what would have happened when the state is requested, rather than actually running something every minute for example?
How should I keep the client in sync ... |
If you're working on a client side mobile application, for a smoother UX, optimistic rendering is encouraged. This is where the application makes UI updates based on user requests that get sent to the server without waiting for the response assuming the response will be successful.
What this also means is that the requ... |
For example:
URL blogFeedUrl = new URL("http://manishmaharzan.com.np/getJSON/json.json");
HttpURLConnection connection = (HttpURLConnection) blogFeedUrl.openConnection();
connection.connect();
InputStream inputStream = connection.getInputStream();
Reader reader = new InputStreamReader(inputStream);
int contentLength = ... |
Suppose that you're trying to fork a software package, which mentions in its manifest that it is distributed under the "MIT" license:
[..]
License: MIT
Copyright: JC Holder
License-file: LICENSE
[..]
However, upon inspection of the license file, you find this (followed by the Expat license... |
In Robert Martin's Clean Code, I encountered the following method on p. 195:
private void parseSchemaElement(String element) throws ArgsException {
char elementId = element.charAt(0);
String elementTail = element.substring(1);
validateSchemaElementId(elementId);
if (elementTail.length() == 0) marshalers... |
Rightly or wrongly, I'm currently of the belief that I should always try to make my code as robust as possible, even if this means adding in redundant code / checks that I know won't be of any use right now, but they might be x amount of years down the line.
For example, I'm currently working on a mobile application th... |
I'd like to know whether it's possible (and how) to detect whether a user is actively in a web app (aka in the browser tab) and not on another website. If also like to relay the information to a web based portal and to have this work with all (or at least Chrome) browsers and on iOS and Android.
This would be used in a... |
I went through a PHP/JS tutorial on user registration with secure hashing (no salt though) using sha. What I didn't understand is why the hash was generated on the client. Also, I don't understand the hashing in general.
This is how I think it works:
User creates an account and password and sends plain text to the ser... |
Have two images with the same dimensions.
I want to create a file that contains information on what pixels are different between the two images. The file should also tell me the value of the new pixel (integer).
An example of such file is
230,8528
291,920
550,1500
Which tells me that the pixel at index 230 changed to ... |
I need some clear explanation and maybe an example of how frameworks like JavaFX, Tkinter etc. work.
Lets take Python's Tkinter. When I bind a button's action I just do
def callback():
print "clicked!"
b = Button(text="click me", command=callback)
Somehow I give the callback function as a parameter to the Butto... |
Is there an expression in programming that something will 'exercise bugs'?
I have seen this written before but I don't know what it means.
|
I'me developing an iOS chat application and working on the db design for the contacts feature. There are 2 kinds of contacts-
Unsaved Contacts - Contacts with who you've conversed with, but not saved as a contact
Saved contacts - Contacts saved by the user. These are synced with the server as well. Saved contacts can ... |
Using Object Oriented Programming we have the power to create a class inside a class (a nested class), but I have never created a nested class in my 4 years of coding experience.
What are nested classes good for?
I know that a class can be marked as private if it is nested and that we can access all private members of ... |
I have to design a system where I need to make some processing (which might take say 10 mins).
After some amount of time (say 30 mins), I need to come back and check the status of this processing and possibly stop any further processing.
There would be multiple such processes fired and running sequentially or in paral... |
I am writing a library for OVH api calls, and I am wondering how to make it friendly for unit tests.
I have a class APIClient. The constructor of this class initializes the object with all parameters, but then immediately tries to perform authentication. There is also the send method for sending generic authenticated A... |
Quick background: I am working on developing an interface that will be implemented by myself and other developers. This interface will allow users to "plugin" new functional code into a system for new use. This new code will be called from an already running server/application. (TLDR: I need to develop the ability f... |
I'm coding an Optical Character Recognition specifically for the Internet meme images. This is a school project and it should be coded in C.
I'm currently having trouble with the method/algorithms I will use to code my OCR. Indeed, almost all meme images have the same font which is Impact (never mind for the others whi... |
I got following exercise:
An algorithm takes 0.5 ms for input size 100. How large a problem can be solved in 1 min if the running time is the following:
linear
O (N log N)
...
So the algorithm can process 100 items in 0.5 ms therefore 100*(2*1000*60) = 12 000 000 items processed for linear time.
Now how to solve 1... |
I'm designing a RESTful web service using WebApi and was wondering what HTTP responses and response bodies to return when updating / creating objects.
For example I can use the POST method to send some JSON to the web service and then create an object. Is it best practice to then set the HTTP status to created (201) or... |
class ConnectionUtil{
public static void main(String args[]){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
....
....
}
In the code I have manually written the driver details and connection detai... |
I am trying to log a JSON error message to Google's Cloud Logging platform. Unfortunately, the maximum size message you can log is 8000 bytes and some of the JSON documents I want to log are larger than this. Rather than just chop the JSON string off I would prefer to iteratively remove the largest 'field' (and repla... |
I am wondering about best practices here.
MVC (Model - View - Controller) patterns involve separating components of your program that model the data, manipulate those models, and display those results to the user (usually through the UI) in some way.
What about a function that takes the model data and inserts it into a... |
I'm having trouble cleaning up my code, and was wondering if there was any sort of pattern that I'm not aware of that can help me in this situation.
I need to process a list of objects in various methods, somewhere in those methods, an object in the list can fail for a specific reason, and the reasons can vary. I need ... |
I'm trying to create a parent class with a constructor that takes a single int as a parameter. I also need to derive a child class that creates two instances of the parent class using a constructor that takes two ints. I know I use the "super" keyword to use the constructor from the parent class, but how can I use th... |
Let's consider the following class diagram
I would like to express the following rule in OCL
if cond = true then
bderived = b
else
bderived.x = b.x + 10
bderived.y = b.y + 10
endif
My best guess to express the above using OCL is the following:
context A::bderived : B
derive: if cond = true then b
else... |
User32.dll exposes a RegisterHotKey function, to register, well, hotkeys:
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool RegisterHotKey(IntPtr hWnd, IntPtr id, uint fsModifiers, uint vk);
Using this API, we can register hotkeys like Ctrl+R or whatever m... |
I have written a compression codec that I am releasing under the AGPL.
I would like to link it with FFmpeg, a video streaming application. FFmpeg is
licensed under the LGPL, but since it supports some GPL v2 codecs, it can also be licensed under GPLv2. But not GPLv3.
So, in order to link my codec with FFmpeg, I will re... |
Im Just getting started with actor pattern. Coming from UnitOfWork pattern.
Lets say i want to create Actor Pattern for a Employee Management System to mark they are present or absent.
The Problem Im facing is
Should I Create a class Say EmployeesActor instantiate it and use it as a single actor to manage all the emplo... |
Question:
Are there any techniques for communicating with methods of other components but still keep a "pure" Observer pattern ?
If yes are they indicated/regularly-used or am I just overcomplicating stuff?
A practical example
Suppose I have an architecture with the following characteristics:
System is a Word Proces... |
As far as I know, .cpp usually contains far more codes than .h, mainly because .cpp contain implementation details of functions instead of just one line of class member/method definition.
Here comes to my mind is a quite weird idea: is it good practice to write or migrate some contents or codes from .cpp to .h, in orde... |
I'm thinking about how to debug better without using Getters/Setters. If it helps, I program using xcode.
Many answers in Stack Exchange have argued against Getters/Setters for lack of encapsulation (read: When are Getters and Setters Justified), but my reasoning for now is that I use them for easier debugging; setting... |
Recently I started playing with node.js.
Now, every node tutorial out there states that you should start with
npm init
and then, say you want some standard server framework, say you choose express:
npm install express
but then you'll want many more things you are used to from worlds like ASP.NET.
I talk about templat... |
I am working on Qt/QML/C++ based Client-Server software system with custom protocol. Now, in both projects inside QtCreator I have same header and implementation files inside both projects.
What is the best way to eliminate duplicated files, or, if I put custom communication protocol inside library, is this the right p... |
I am designing a class whose object is instaniated with a user idn which creates a pdf with that user specific details. It should log something depending on success or failure which can be determined only by caller as the success or failure depends on if it was not just created but dispatched which is done by the calle... |
I have a question about how to name a class in java. Could a class name be arbitrary or have to obey some rules? For example, I want to define linked lists in a class, does the class name have to be "ListNode" in order to ensure it is a recursive data type?
|
I've been set a challenge that I'm trying to get my head around, but am struggling with the best (or 'correct') way to implement it. The challenge is to create a simple console app written in Go that calculates the sum of squares of n numbers. However, I must do so without using a for loop and only the standard library... |
Intro
The following assumes C# as a reference language, or any other statically typed language. This is not a question specific to Unity's API, but it is used as an example.
In Unity's API, most people come across the Raycast function. This has an argument, of type int called layerMask. This is an integer, that works a... |
Ref: https://docs.oracle.com/javase/tutorial/java/generics/bounded.html,
We have the method: public <U extends Number> void inspect(U u)
Why can't this be: public void inspect(Number n) ?
It achieves the same thing, whats the point of using the generics here?
|
Suppose we have a domain in which we can generalise some operation by passing in a function, like the Select \ map functions. Now suppose that the function we pass in has some domain specific name, and fixed parameter types. Let's call it a BazFunction
We can approach defining a BazFunction in two ways:
As a delegate... |
Suppose I have a class called MyClass, with a member variable 'var'.
And the following scenario:
echo '<pre>';
$x=new MyClass;
$y=new MyClass;
$x->var=$y;
echo 'Checking for $x->var===$y :'.($x->var===$y).PHP_EOL; // outputs 1
$xs=serialize($x);
$ys=serialize($y);
$xsu=unserialize($xs);
$ysu=unserialize($ys);
ech... |
David West in his book Object Thinking (chapter 10, section 1, sub-section 2) proposed that in an ideal OO environment, every objects should be capable of presenting themselves upon request; be it to humans (as GUI), non-native components (as JSON and/or XML), or any other interested parties:
Object thinking says that... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.