instruction
stringlengths
34
36.1k
In my computer science capstone project, we have a team of 5 working on various things for an Android app for Pokemon as a multiplayer game (Github). One or two people are working on implementing the "battle engine" for the Pokemon games (Generation I only). This feature has a lot going on. Initially we had a single is...
I have been having quite a time getting this to work reliably for 100s of thousands of terms and potentially millions of pages per source and ETL the resulting data into a database in an automated fashion. I need to run the tasks in Mesos on a repeating schedule. The required languages are Scala/Java. For acquisition...
So for my newest hobby project, I want to create a simple chat application where users can just log in with a nickname (no passwords) and talk to anybody on the network. Off the top of my head, I'm thinking about this design where a frontend Client acquires a User object by registering with a nickname. A Message objec...
I know several frameworks have this functionality built in where you can use their special methods to make DB queries. I also know this is (partially) to ensure that everything is handled correctly to avoid breaking things. So here is the question, if one not using a framework, is there sufficient benefit to using a cl...
Here's the problem: Given an m x n array, get the number of different paths from the top left corner to the bottom right corner, if you can only move down, right, and diagonally down & right. Here's my memoized recursive solution, which is relatively straightforward. It works because the number of paths from position (...
We have a small team currently working on numerous projects. We originally started out as a two person team and jumped in head first without any kind of source control. We currently break numerous best practices and do development on live sites (yuck, I know). We're in the process of fixing this issue incrementally. Th...
In HTTP 1.1, a web server could return a 304 Unmodified response when a If-None-Match header is included in the GET request. For REST API, I've only seen implementations involving server-side caching of the entire response contents where the cache is typically invalidated on subsequent requests to modify the same resou...
I'd like to know or have other ideas --other than my solution-- about how to check if a car on a given position (lat, lng) is getting away (let's say a distance D away) from the path where the car should go over. Another condition for my problem is that there will be queries with different points (positions of the car)...
The question is long, so I will paraphrase it briefly Q: There are n people voting to choose the chair of the committee. Each person can vote for one person that has unique id (it is positive integer and vote will be stored in array). Chair will be the one with the most vote. Design algorithm to determine who is the ch...
I am currently trying to write a unit test of my own. The unit test I am writing is mainly for linear algebra (I know there are great package out there but I want to use my own for my project). My current linear algebra consist of my_vector.hpp/cpp (3d) and my_matrix.h/cpp. So I am currently writing a test_vector.cpp ...
I'm currently working as a senior dev with 3 juniors below me and have introduced a code review process to help manage the quality of code going into production. I feel its very beneficial for all of us to review each others work, however after about 5 weeks of the process I am the only one to make any comments in the ...
I am looking for an efficient algorithm to get unique (non repeated) x amount of integer random numbers that are within the y and z limits. e.g. I want x random integer numbers that are bigger or equal to y, smaller or equal to z and each random number is not repeated. I came up with two solutions but none of them see...
I am reading through Wikipedia's page on UML state machines. I don't understand where it says: A nested state is called a direct substate when it is not contained by any other state; otherwise, it is referred to as a transitively nested substate. I want to understand the difference between a "direct substate" and...
Our current project consists of multiple modules in /modules/. When I work on my current module and i.e. update its README how should I write a commit message for this? Update README Update README in module_XYZ Update README [module_XYZ] module_XYZ | Update README Something else? I think 1. has too less information ...
The title pretty much speaks for itself, but I'll provide the current decision I am facing. I am migrating python code towards the use of generators. The current code looks like this: ... l = returns_a_list(args) log.debug('examining {} entries', len(l)) for e in l: do_stuff(e) ... Outside of the debug log, l fits...
I want my Wire objects to be in connection with Port objects. That is Port has a list of connected wires and method Port.add(wire). Similarly, Wire has list of ports it is connected to and Wire.add(port). class Port Set[Wire] connections method add(wire)joined) class Wire Set[Port] ports method add(port) Sup...
I have tried to implement the Passive View MVP in my WinForms application as much as possible. The Presenter is the only one who uses the Model and the Presenter responds to events that are generated in the View. The View in fact is very 'dumb' as it only fires events and deals with the form controls. Now my question, ...
assume Service S want send data to mobile App in device A in arbitrary time without client interaction. what is best way to keep track of A IP? the only way i can think of is to run a service for keeping track of A public IP (locally on A) if changed -> update S database with new IP. It there better idea?
I'm trying to code a dice game where users log in and then challenge each other. I already made a version of this game without login but only one game could be played at a time. So now, there will be the possibility of several games going on simultaneously between users. In the non-login version I needed 4 tables for e...
In my application I fetch files from the user and process it. Im to limit to a certain scope of file types and each one of these has a different processing approach. How can I design the application in order that when a new type of file is added, I have to change few to no lines in the controller classes. Should I be u...
I have been looking at VC++'s C4267: Compiler Warning (level 3) C4267 'var' : conversion from 'size_t' to 'type', possible loss of data The compiler detected a conversion from size_t to a smaller type. To fix this warning, use size_t instead of type. Alternatively, use an integral type that is at least as large as s...
I'm confused about choosing names for my functions in Python. Sometimes Python built-in functions are imperative such as: print function and string method find. Sometimes they aren't such as: len its name isn't imperative such as calculate_len, for instance, and type isn't find_type. I can understand that print returns...
I suppose that this is a common situation: I test some code, discover a bug, fix it and commit the bug-fix to the repository. Assuming that many people work on this project, should I first create a bug report, assign it to myself, and refer to it in the commit message (e.g. "Fix bug #XYZ. The bug was due to X and Y. Fi...
How do you guys go about entrusting third party packages, libraries, etc. into your projects? In other words, what steps, if any, do you take before incorporating an outside component into your project? Does the sheer number of downloads satisfy your assurance that it is safe? Is it considered safe if you downloaded...
I have read this and this and this: if my question misses the point in those answers, please point it out and we'll get this one deleted. These questions indicate that this may actually be a bad thing under certain circumstances, but I think I understand that difference. QUESTION: If I am using a function from another ...
we have started with microservices recently, but we have some problems with implementing the Security layer. The idea is that the request comes to Gateway, the Gateway looks to authorization header, it validates user, create JWT token and then sends request with info about user to another microservice internally. The m...
Suppose I have some Modules that each are their own component I would now have different Testprojects spanning different modules. UnitB_UnitTest, UnitC_UnitTest, GUI_UnitB_ComponentTest, GUI_UnitB_UnitC_HDD_SystemTest If I concatenate every Modulename involved in a Test with underscore the names will get huge and diff...
The internal framework my company uses has a pretty pivotal Object that has a pattern of being instantiated as a member of a class with a no argument constructor but to be usable you have to call a start method. I understand that constructors are generally minimalist but at the same time why be able to construct an unu...
this question is actually about a complex java project I am doing at university, but it is possible to find a simple case which is really similar to the problem I am facing. In this scenario, we have an app with free version and premium version. A user registers the app for the first time and uses the free version by d...
What I mean here is how do we go from some template T add(T a, T b) ... into the generated code? I've thought of a few ways to achieve this, we store the generic function in an AST as Function_Node and then each time we use it we store in the original function node a copy of itself with all of the types T substituted w...
I have a system where the load is distributed across the nodes in the cluster and once an entity is assigned to particular node, it is taken to completion through that node only(distribution is saved in a table). If the owning node fails, the manager node can reassign it. It is desired that once any node joins the clu...
I'm creating a project which uses SystemJS/JSPM. I'm also using TypeScript. Now TypeScript has the option of compiling JS using SystemJS Modules - which I'm doing and all is good. I've created TS modules and then imported modules from JSPM - at which point TS uses SystemJS to import those modules in Javascript. Where ...
According to this As opposed to the constraints in other kinds of engineering, where the constraints of what you can build are the constraints of physical systems, the constraints imposed in building large software systems are the limitations of our own minds. This sounds interesting on paper, but it also got ...
I am looking for practical and non-synthetic use cases of Python class decorators. So far, the only case which made sense to me is registering a class in a publisher-subscriber system, e.g. plugins or events, something like: @register class MyPlugin(Plugin): pass or @recieves_notifications class Console: def p...
For a test suite I have, each test has a failure rate (from 0 to 1), where 1 means it fails every time and 0 means it never fails, and a duration in ms (this is unbounded). I want a metric (I think either multiplication or division) that will capture the knowledge that tests with a low duration have a high value, and t...
Recently during a code review I came across code, written by a new colleague, which contains a pattern with a smell. I suspect that my colleague's decisions are based on rules proposed by the famous Clean Code book (and perhaps by other similar books as well). It is my understanding that the class constructor is entire...
I'm debating the merits (bikeshedding?) of two different approaches to a simple problem. This setting is numeric, but may not exist, so the options are: Does not exist 0 1 2 3 The programming language in use is C, so there are two obvious ways of encoding this into a byte. Option 1 is to use values 0, 1, 2, 3 and 0x...
I have a doubt with threading data service calls within a foreach loop. Here it goes: Say you need to request data from a service and then process that data, for this example, let's say data request takes 2 seconds and data processing takes another one. If you had to process a list of 10000 elements how would you do it...
In the following c# code example, the instance field [name] is readonly, and therefore is immutable after class construction. public sealed class Example { public readonly string name; public Example(string name) { this.name = name; } public string AllUppercase() { return this....
In a Lisp dialect, I've implemented ANSI-CL-like support for printing objects such that their circular and shared structure is encoded. This is enabled by the special variable *print-circle*. Similarly to ANSI-CL, I have it working when it traverses objects that have custom print methods. But there are tricky corner ca...
In laravel 5 I describe models without specifying fields in model class. Some magic identifies which fields exist in database for this model. use Illuminate\Database\Eloquent\Model; class MyModel extends Model {} When I describe migration for model's table, I specify field type, length and so on. This info exists onl...
I'm a solo hobbyist developer with some code hosted on Bitbucket. I use TortoiseHg client-side for managing my repo. Back in 2013 I developed a feature on a branch but abandoned it before completion. The default branch has seen many commits and structural improvements since that time. Now I'm to a point where that aban...
I am building a proof of concept for data processing web service, that allows users to get data cleaned, homogenized or otherwise manipulated. Often users send different types of data in the same batch. After processing, the data must be distributed to different users individually or in pairs, based on the type of dat...
I have a table Company and User like below... Company Table: CompanyID CompanyName etc... User Table: UserID Email UserType CompanyID etc... First I must tell you that, currently I have two usertypes, Admins (who can do anything) and Users (with some basic privileges) Now, I have a requirement to in...
At the time I'm workin on a project with several Instances of an abstract class. Some functions in the subclasses are the same, some not. This would lead to code like the following. In the Code i use object as parameter, but in the real project it's a defined class and not object. public abstract class BaseClass { ...
As far as I understand the concept, CC is determined by how many nested branched logic the given method have. It can be refactored to checking the opposite of original predicate and calling return. For example: void Foo() { if (predicate0) { if (predicate1) { // some code } } } can be refactore...
I'm interested in whether there is such a thing as a pseudo-compiler that can create a kind of binary or bytecode version of a plaintext script file, which can only be accessed by a proprietary piece of software? I work with a proprietary software client in a Windows environment, and the software has its own script man...
I'm doing use case where users can make reservation of different services such as hotel, car rental etc. If I just want a simple use case, ignore the part that user has to log in and make payment etc. Technically is the answer below acceptable? If not, why? A) ACTOR USE CASE Customer Make Reservation...
First, I need to confess this question come mostly from the still expensive licensing model used by Microsoft for SQL Server Standard. Also because Web edition is now only available through Web Hosting provider. For information: it's 1 license per 2 CPU Core + CAL per user. From a Microsoft sales contact I spoke with ...
I've started down an Autofac rabbit hole that I think I need to pull myself out of. I have a .NET MVC site where a user can list their favorite players per sport (baseball, basketball, etc.) I have a Players controller, and I'm injecting IPlayerService. However, my problem is that the service needs to know which spo...
I get why static local variables are called "static" -- we want them to be allocated in static memory! But what is the reason for calling functions and variables we want restricted to the current file "static"? I don't see the connection; either way, they're allocated in static memory, right?
I'm learning T-SQL. Why the strings are prefixed with N in every example I've seen? What are the pros or cons of using this prefix? Please make it clear that if my column has datatype as nvarchar /vachar then is it mandatory to provide values using 'N' as prefix or it just a system that we are following.
Say we have N persons and M items (when a person has a certain item, she usually only has one piece). For example, person 1 has item A, C, D, and wants item F person 2 has item B, C, and wants E person 3 has item E, and wants G ... You get the idea. So it's basically a supply/demand matching problem, and if we rep...
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...