instruction
stringlengths
34
19.9k
Im running a service that crawls many websites daily. The crawlers are run as jobs processed by a bunch of independent background worker processes, that picks up the jobs as they get enqueued. Now currently I'm doing throttling "in-process" meaning that the threads will do a random sleep between each request. However h...
I'm searching for the correct type of diagram in which I can see all dependencies between the functions, classes and files of my Python program (multiple files). It's for cleaning purposes. So my question is: Which diagram should I use? I though about Class Diagram, but there are no dependencies between functions (whi...
I'm looking into 32/64bit signed integers and their algebraic properties. I am quite sure that the the three operators +, - and * fulfill the distributive and associative property (integer division does not because of the information loss) even though we have some kind of information loss due to wrapping of positive <-...
I wrote a Chess engine in Java and I am porting it over to C++. I am new to C++. The idea: I have a Board object which holds a 2-dimensionnal array of Piece objects. Queen, Rook, Bishop, etc are subclasses of Piece. They all have a method getPossibleMoves(). Therefore they need to have a reference to the board to be ab...
I am building a library class that provides functionality for mathematical operations on BigDecimals (and a few on BigIntegers). Now, BigIntegers are quite easy to master and pleasant to use. BigDecimals can be tricky, but in the end, it finally pays off. I want my class to provide results accurate up to a specified le...
Ok, in my database I have a table Event and a table Room. Each Room can have many Event. Room table roomID-roomName 1 - cafe102 ... Event table eventID- Time -type -roomID 1 - 11:20 - 1 - 1 2 - 15:20 - 1 - 1 ... So I want to crate a Class structure that mimics the DB structure. public class Event{...
Disclaimer: I am not against third-party controls because I believe it's for productivity I have used Telerik asp.net controls, especially the RadGrid because it makes it easier to do CRUD. They have fantastic controls. I thought I would do the same for asp.net mvc but looking at the code involved scares me. I saw an...
I'm working on a web application that is publicly accessible. (Really) Long story short, we have two sets of tables in the database with relatively the same names and relatively the same data. The first set of tables are used by our web site, which I will call Set A. The second set of tables are used by an Oracle Forms...
I need to compare to double variables like this if (distance <= radius) both distance and radius are doubles and I remember in class how to use epsilon comparisons for checking equality but how would I do it for <= or >?
I know that this is a debated practice, but let's suppose that this is the best option for me. I am wondering about what is the actual technique to do this. The approach that I see is this: 1) Make a friend class that of the class who's method I want to test. 2) In the friend class, create a public method(s) that call ...
We've been working on a networked online game project which will run in near future and looking for a satisfying solution for our distributed game database. We didn't take networking costs into account so far. We have following constraints: 1) We planned to use MySql but we can review alternatives if offered solution...
I created an email queue where I put the requests for emails to be sent. If the SMTP server is unavailable, the requests are not lost. When the SMTP server gets back online, the background service will pick up the requests to send the emails and process accordingly. Question: I now have a requirement to deliver text me...
http://highscalability.com/blog/2010/11/9/facebook-uses-non-stored-procedures-to-update-social-graphs.html talks about how Facebook moved logic out of the database into the application in order to improve ease of development (scaling better across employees instead of across databases). Are there any studies/articles/b...
I am creating a closed source application whose task is to launch other open source applications (similar to start menu of windows). So i have included various opensource applications under licences like : GNU-GPL LGPL MIT license Apple Public Source License Version 2.0 Apache creative commons CeCILL I have not modif...
Situation: I need distinct results from two tables, that both have duplicates. I would like to know if I should combine UNION and DISTINCT. Example 1 - Only use distinct SELECT DistinctValue FROM Table1 UNION SELECT DistinctValue FROM Table2 Example 2 - Combine distinct and union SELECT DISTINCT DistinctValue FROM Tab...
I need to ask a question that have been bugging me for some time now: If I have a single core and one OS thread, this thread will get 100% of the CPU time and all is good. If I have a single core and two or more OS threads, they will share the CPU time using time slices. So, is the time slices always the same amout of ...
Let's say I have a question pool to generate exams out of it. Each question contains a difficulty from 1 (hard) to 99 (easy). The questions are available in a hash / array (adapt to your favorite languages naming, I'm going with hash as it is a ruby implementation) in the following format: questions = { :55 => [<#Que...
It is useful to have the interpreter derive the type of a variable automatically. This on its own is similar to the auto keyword in C++11. However, in Python variables can change their type after being declared for the first time. This potentially can cause a lot of errors. I haven't seen any reasonable use case for th...
I am working on a self-study project but I cannot come up with a reliable answer. Here is the deal: I start with 500cm sticks. I have orders from customers who want smaller sticks. I am willing to cut my 500cm stick into as many as 7 pieces. How can I determine which combination of customer orders to use for each sti...
I'm slowly working to finish my degree, and this semester is Compilers 101. We're using the Dragon Book. Shortly into the course and we're talking about lexical analysis and how it can be implemented via deterministic finite automata (hereafter, DFA). Set up your various lexer states, define transitions between them, e...
I always preach never to force push anything, because that adds ambiguity to the repository server. In this specific example, we collaborate with a customer and they "skip a step" and force push instead of appropriately pulling and merging. This takes the ambiguity of what code is good, what code is bad, out of their w...
Usually, when I write software, I use unit tests for each function to test if it is working without any problems. However, recently I have found myself writing some software that are not really amenable to unit testing. For example, writing code for an operating system, where standard libraries are not available. Anoth...
Which programming language first came up with the finally block? I ask purely out of curiosity. It is a very useful piece of syntactic sugar, and whoever first created it surely has a very impressive grasp of solutions to programming problems. (Note: it is deceptively difficult to find an answer to this question...)
I am aware of that is a difficult question and depends on the game mechanics and game type being applied. So, many answers can be given. For the sake of simplicity, it would be better to consider a typical online MMO game in order to make easy to find a satisfying answer. This is the question partly related to my prev...
The function foo, has a nested function; bar. Calling foo with a second set of arguments feeds them into bar if bar is returned at the end of foo. How does this work and what is it called? Are there any uses for it over simply having a single set of arguments that calls the function normally? def foo(arg1): print(a...
I'm a developer in the IT department of a large oil company. I received a spec document, basically in plain English, about business rules that need to be implemented in a new application. The rules are really difficult to translate into code, since I don't know all of the inner workings of the business. Is it acceptabl...
I have to set up remote debugging for a multi threaded application running on a embedded device. C++ is the language. I've gotten so far and got the remote debugging working for a simple application, but when applying the same procedures on the multi threaded giant just don't work (the application starts behaving unpre...
I'm currently embarking on a MongoDB project (a simple user login system), and I notice that there is an option for authentication. Here is the server string, with the userinfo shown as optional information. mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db From the MongoDB Manual: Before gaining ac...
A tutorial (for Javascript) I'm doing suggests we write a function like this one: function sayHello() { //Some comments explaining the next line window.alert("Hello"); } Other than obfuscation are there benefits to writing something like this in real life? If so, what are the benefits?
All right, I know this sounds complicated, but all relationships are, lemme clarify. Well, I have three entities in my database which are tied to each other in a string of relationships, the app is for restaurants, and the tables are as follows: Customers Id Name Email Packages Id Name ImageUrl Price Description Pro...
I'm making an Rails app that in theory should scrub new posts from the users facebook and twitter accounts and put them in a timeline for an analyst to analyze and determine if they are good or bad posts, if the user posted "bad content" the analyst marks it as so and warns the user. I've made the authentication with o...
I'm developing the web Java application and come across the following issue: I'm using jUnit 4.5. Suppose that I have a method which aggregates data from a database for the rendering their to a markup. Is it make a sense to testing an sql query in the way that I simple write a series of sql-queries and compare expected...
We have a system (ms stack, .net, sql) that receives data from thousands of remote devices (several independent readings/min). We currently save all the data to a db as it arrives and a second service reads and processes the data - using the database to 'buffer' the input. We want the second process to be scaleable as ...
Firstm I'm using PostgreSQL 9.3. I'm solving the problem which is to retrieve a data from a separated databases and to render it into a web page. The web project is on the Java (JSF 1.2). Presently that particular feature's implemented by using dblink query, which retrieves a tables from a separated databases and FULL ...
I have the following two object variables Date a; Date b=null; Definitely both 'a' and 'b' are not referring to any objects. Now if I invoke following statement System.out.println(a.toString()); There will be a compile time error, whereas if I invoke the following statement System.out.println(b.toString()); There wi...
I'm learning MVVM pattern with C#, WPF and .NET Framework 4.5.1. I'm using MVVM Light framework to do it and now I have a doubt. Reading the book Windows 8 MVVM Patterns Revealed I see that the author uses Event Aggregator Pattern. I'm not sure if I need it, because in the following ViewModel I would have to raise the ...
Legacy SOAP service here at work use a token authentication. The flow is: As first step I call the startSession method passing username (say myUser) and password (say myPWD) as parameter. At this point username/password are checked against a DB table: +------------+-----------+---------+ | username | password | ...
I'm not sure how to ask this. I know this is simplistic, but I understand (I think): REST is an architecture, not required, simply a way to build REST is a style and a community standard for transfer of data REST uses verbs and nouns, mostly the latter, GET, POST, PUT, DELETE... As I read I only see the architectur...
When designing an own programming language, when does it make sense to write a converter that takes the source code and converts it to C or C++ code so that I can use an existing compiler like gcc to end up with machine code? Are there projects that use this approach?
When writing a class which has ("satisfies") 1 or more interfaces, should I note somehow (e.g. in an XML comment, or with an attribute) that a particular method was added for one of the interfaces? For example, the IComparable interface requires an int CompareTo(Object) method. I know I don't need to do anything other ...
I'm writing some test code for a feature which processes PDF files. The basic idea behind the tests is that I point them towards some PDFs I've selected specially, they process them and I check that the output is what I expect. My question is: where should I be storing these large-ish PDFs? Should I check them into v...
Is there a conceivable design pattern for any object-oriented program? I ask this because recently I saw an implementation of a Door class with a Lock. It was part of a test and the answer said that the code is following the Null Object pattern: class Lock { public: virtual void close() = 0; virtual void open()...
I have been writing SQL for over 10 years now. I am extremely proficient at it and have experience working in SQL Server, Oracle, MySQL, PostgreSQL, etc. While there are multiple standards out there, they seem to be more suggestions than standards. When you start talking about column types and stored procedures, there'...
Edit: I've found the original publication. It seems to me that the original does not have a l′(i). But I could be wrong because the definition of rpr(i) is so obscure to me. I'm not sure how it makes use of it when rpr(i) is negative and what happens when no such reoccurrence is found. I'm trying to implement Boyer-Moo...
I have a significant quantity of external resources that I need to load. It takes about 5 minutes to fully load (about 16 gigs of data). These are basically third party image patterns that I have to deserialize. I then use these in my application to process images. They all get used and they get used often. Ideally...
Is there an accepted way to store variable sized classes in memory mapped files, or is this always considered bad practice? Essentially I want to store a collection of image patterns files that are third party classes in MMF. Once they are loaded, they are read only. They are guaranteed to be less than a given size,...
I'm looking for an algorithm that gives me the n nodes that are the farthest away from each other. Can this be accomplished relatively efficiently? To clarify my question: I think of the problem as a variant of the opposite of the travelling salesman problem. We have this graph: The distance matrix looks like this: ...
I'm writing some macros which declare template types and I'm a bit stumped for terminology. To illustrate, take the following example: // template class declaration template <typename A, typename B> // what is this called? class A; My question is: What is the name of the line above class A?
I'm working in a software development team as software developer. I've been working on the same project for three years now. The software is a 32-bit desktop based C# application in .NET 4. Our target platform in Windows 7 (we had to support Windows XP till last year). The software communicates with various custom hard...
class Employee{ String name; int id; //No explicit constructors } Now I can invoke the following statement: Employee e1 = new Employee(); With the above code, the compiler will provide the definition for the constructor Employee(). If I define a single explicit constructor as follows: class Employee{ ...
Here is my problem: I stared to create an e-commerce web site info collector. So I created a parser for each site. The parser class is stateless. I have got methods like: getItemPrice(WebElement page) getItemTitel(WebElement page) getItemDescription(WebElement page) etc.. While creating a JUnit tests for that the conv...
I find myself confusing to understand the concept of private cloud. If a company has an offshore data-center, and now if the company wants to move into a private cloud, what does the company has to do? If I am correct, in order to use the term cloud, there should be virtualization. If there is no virtualization, there...
I am writing a game in C++, and something I have noticed is that I have many resource files which need to be loaded after a particular point in initialization. For example, OpenGL textures and VAOs can't be created until there's a current OpenGL context. Once loaded, they will never be modified, so it is most convenien...
Let's suppose I have a list of derived objects from some base: class Circle : public Shape; class Rectangle : public Shape; There is object, which has vector of Shape * as member variable: class Screen { std::vector<Shape *> shapes_; } But now I need to persist this in database (PostgreSQL to be precise). Only wa...
This problem arose whilst writing a simple 3D vector class. The class contained methods (Java, so no operator overloading) for addition, subtraction, multiplication, and division. These methods performed this operation between the instance they were called on, and another vector or single value. When it came to writing...
I have some doubt on Heap and stack memory in java.. whether those are memory space or algorithm(procedure) of storing data at run time. Here is the class class HeapStack { String str = "test"; // heap memory int a = 10;// heap memory private void Test(){ int a = 10;// stack memory St...
In java 1.8 they have wonderful new "default interface methods". In 1.6 how close can we come? The goal: use code to keep clients from being able to tell that a class is not a java interface. If we preserve the right to refactor the class name into a Java Interface we don't need to create a Java interface now. We j...
I've received a task to build a shipping estimative that suggests the best accomodation of goods on as few boxes as possible: There is a finite set of known retangular box sizes There are many arbitrary retangular item to be packed inside boxes The fewer boxes should be used the best. Because shipping two boxes 1x1x1 ...
TL;DR - I'm looking for guidance with my database design. I am concerned that my existing design is inefficient and won't be able to handle large numbers of employees. This is going to be long, so please bear with me. I am in the process of creating a JEE application for staffing demand, supply and usage kind of web ...
I inherited a project that I've been maintaining for approximately a year now. The project primarily revolves around performing various financial calculations for the end user. It's roughly 100,000 lines of spaghetti code held together with duct tape and gumption. I've been slowly going through and refactoring the code...
I have code reviewed a piece of Python code, but to me it looks really ugly, hacky and complex for something that can be achieved very easily. The code looks something similar to the following: _extra.py (this is supposed to be a private module because of the underscore): import dependency class Extra(dependency.Cls):...
This software is allowed to use under GPL or you need to obtain Commercial License to use it in non-GPL project. The above is mentioned on an open source project. It does not mention GPLv3 or GPLv2 explicitly. Does that mean I can use it as GPLv2/3 as per my convenience (as we can with LGPL) I'm an open source newbi...
Purity One of the interesting concepts in Haskell is the purity. However, I am wondering what the pragmatic reasons behind this is - let me explain a bit more before you reject my question. My main point is that we are going to have side-effect no matter how we might encapsulate these in a language. So, even if a progr...
Many modern languages provide rich exception handling features, but Apple's Swift programming language does not provide an exception handling mechanism. Steeped in exceptions as I am, I'm having trouble wrapping my mind around what this means. Swift has assertions, and of course return values; but I'm having trouble pi...
I was recently thinking about the following. According to the open / close principle, once a piece of code X has been implemented and tested, it should not be modified any more. X can still be replaced by another piece of code implementing the same interface (maybe with a better implementation), or new functions and me...
I am not a very experienced programmer. So I ask. The field in question is the "Amount" field. I store an amount only in a couple levels of the derived class. The code is a slice of the POCO classes that are making up my data model, the datalayer is Entity framework, code first. I mention that because the reason I did...
I have multiple patterns that I want to expand. Expansion should expand number and letter ranges between curly braces. Numbers need to support padding. I want to have it expand into a List(Of String) for ease of iteration. Patterns may include multiple sets of curly braces and they can be in any position. Here are some...
Let us say I have an open source project on github. Now I wish to include tools required to develop the project so others can easily contribute. It is hard for me to tell when these tools should be included in the project for others to use and when they are a personal preference and part of my private development envir...
Our web application sends a one-time use generated token, in the form of an URL, to clients who forget their passwords. This works except for the case where the client is sitting behind another server (i.e. the spam server) that scans their email for URLS and does a GET on the URL. I'm assuming the server is checking f...
I have heard a prominent language designer remark that no language today enforces real object privacy, and we are still unsure whether it is possible in practice to design a language that does. Without trying to read this particular person's mind, this piqued my interest. There are, I think, two distinct concepts at wo...
Many say that we cannot override a static methods. But we can override a static method. The question is, when we override a static method why it does not result in polymorphism ?
I am writing a C API for retrieving data from a hardware device. The data will be returned as a string with approximately 30 bytes of text per item. The problem is there may any number of items. Could just 10 or there could be 10,000. So the returned data could range from 10 x 30 = 300 to 10,000 x 30 = 300,000 byte...
I'm currently trying to get my head around a few patterns (especially the ones mentioned in the title above) that are made to address different problems and are being used in different parts of the application, however they seem to heavily overlap in functionality once they are implemented. Let's take for example the f...
I am working on an application that get packets that don't belong to the pc,so i use promiscuous mode on my NIC,i need to read the packet and and handle it. Because i don't have any connection formed and the packets can use either TCP or UDP(only one of them) i thought of using RAW socket in order to read the data. If ...
I'm designing a "view" handling system for a game. The goal is to be able to have different "views" that can be shown in sequence or stacked on-top of each other. For example, the initial splash screen is one View and the main menu that follows the splash screen is also a View which is rendered when the splash screen t...
I wish to know if there are any known algorithms for dispensing a list of files for a specified maximum directory size (disc size for example), while attempting to keep output directories size close to each other.
A project I'm involved in has suffered a change in scope, and before I set about trying to cook up some homegrown solution, I'm wondering if there is something out there -- some framework, for example -- that will spare me from having to design and debug my own code. Let me try to explain the details as simply as possi...
I am writing a class that wraps (the parts of) an external API I am using. Let's take the GitHub API as an example. My imaginary GitHub class now has a fetchUser() and fetchRepository() method. When GitHub decides to host their API at github-api.com I only have to change it once. Nice. But what's the name of this - ver...
I am learning socket programming. I have a Java application as my server, and C# for the client. Just sending string lines from one to another. Below I have code snippets showing how I am currently doing it. Anyway, being new to this, there are two points that are still bugging me: If you send a very large string, it i...
On a job application, part of the job description is "...needs to know HTML and CSS as some .NET is required...". What does this mean? I thought HTML is a programming language, CSS is a way to format HTML, and .NET is just a runtime framework that is not something you really "know". Can someone please explain what th...
I have been doing a lot of reading about polymorphism, inheritance and typing (specifically how it applies to Java). I have seen some interesting examples, but not much explanation as to why. I.e.: Person p = new Student(); I am assuming we have a Person class and a Student class which extends the Person class. My...
I'm an experienced software engineer, and have experience in a range of languages from PHP, Ruby, C#, Java - the last few years I've primarily worked in Java. I'm now learning Scala, and it's my first real foray into functional programming. I understand that my methods should not have side affects, and that I should fa...
I'm currently trying to learn UML but I have trouble with this one. Lets say you have a container with cards, a container with players, and that player has also cards. How would you draw this in a class diagram (application model). How would you set the composition and multiplicity? Thanks in advance. I was thinking ab...
A project I'm working on currently depends on several SDKs and APIs that perform identical tasks, but for different external products. For example, in an Internet of Things world we have a common interface of TurnOn, TurnOff, GetStatus, etc. Having all of these dependencies in the meat and potatoes of my project is g...
I am programming for a embedded system. When this system boots up it reads from a configuration file some data and execute rules to put the system state according to the configuration read. This configuration is dependent on the environment/requeriments of each customer and can be managed via management interfaces (as ...
I'm new to C++, coming from Java. In Java, all variables (except for primitives) are essentially pointers. They hold the address of whatever they're 'holding'. So any Java data structure stores it's data by reference. You can also store by value, i.e. save and return a copy of any item you store, but that would take ex...
The purpose/s of this question is to discover what are some of the most reliable methods of achieving communication between existing offline software and a web application. (Example) Scenario: A person has written a piece of software that primarily runs "offline" on a cluster/network of local servers (accessible physi...
I'm learning about Domain Driven Design and struggling with the question if a particular object should be handled as entity or value object. All possible surname prefixes are kept in a database table. (The data is used in a combo box). Since there are records kept of all these prefixes, should Prefix be seen as an enti...
I am currently programming a Stratego game in JavaScript, simply because I wanted to learn to use JavaScript while spending some time to keep my programming skills up to par. (My current work assignments involve no programming.) This info is not entirely relevant though. :-) The thing is, right now my AI works pretty w...
Let us have case class Money(amount: BigDecimal, currency: Currency) case class Currency(code: String, alpha3: String) Money is a value object and Currency is an entity. When transforming Money to JSON I would replace currency with its code. However reverse operation requires repository access (which is implemented u...
What generic name is given to classes that encapsulate a collection of esoteric functions which together perform some larger cohesive but entirely self-contained task useful to the wider application, by producing a computed result given a number of input parameters? An example might be a class that calculates the short...
If someone forks your repository and commits some changes, what is the accepted way to proceed if you'd like to ask them whether it's alright to pull those changes in? Can you issue a pull request on the forker's behalf and count on GitHub to alert them somehow? If not -- I notice GitHub doesn't support sending users m...
Having a bit of a debate about the starting project structure (using Maven/Eclipse) for a big Java application. Option 1: entities (i.e. the whole database using Hibernate classes-first) services (i.e. sets of read/write operations on the entities) app (perhaps split up more further down the line) Option 2: area1-enti...
I have a class the implements A which will run a certain method of class B. There is a requirement that this A should never crash when running this operation (which is not possible, right?). To reduce the chance of crashing I'm catching Throwable around the operation, like so: public void method(B b) { try { ...
I'm not a Fortran developer myself, but I'm about to use it a little and found myself wondering why, if it is much older than C but equally as performant as C, was it never used to develop any operating system before C and UNIX came along? A substitute answer, if the above is invalid, might be which operating systems w...
I am beginning to refactor a large, very old, messy project. One of the biggest issues is the lack of a central location on the filesystem for simple things like images, icons, documents, csv, etc. The number of assets is on the scale of thousands, so I am looking for ways streamline management. Should I be looking in...
During a code review today, a colleague of mine said something interesting: prototype is only useful when you need inheritance - and when's inheritance ever a good idea? I thought about this and I realised that I usually use inheritance to get around code that was badly designed in the first place. Modern OO style pr...
Lets suppose there's a database schema defined like this: Person.mail_address_key ----- Address.address_key Person.billing_address_key ----- Address.address_key A Person has a mailing address and a billing address. As a denormalization technique, we create a separate Address table. Most of the time the mail_address_...
I am currently creating a website which will allow people to buy consumer products (deodorant, shampoo, toothpastes, etc…) from a store. Those products tend to change price and other details twice per year or more. And I want to show past purchases’ prices and other details to the client. And I wanted to know what the...
My understanding is that in C++11, when you return a local variable from a function by value, the compiler is allowed to treat that variable as an r-value reference and 'move' it out of the function to return it (if RVO/NRVO doesn't happen instead, of course). My question is, can't this break existing code? Consider th...