instruction
stringlengths
34
19.9k
I am writing up a user registration application in PHP as part of my learning process. I have written up the general rules my code should follow. Please let me know what you guys think of it. Have a form with the email address and password. Generate 2 random tokens to be appended to the URL to validate the email and ...
I'm learning Scala at the moment via Odersky's Programming Scala (2nd). I'm upto chapter 10 where he starts introducing parameterless and empty-paren methods. I just can't get my head around it. So far, all I understand is that I should use empty-parens if a method has side-effects and parameterless methods otherwise. ...
I thought I understood inheritance and polymorphism, but I was given this question, and I can't, for the life of me, figure out what the proper answer is or what they're trying to get at: The process of determining which method in a class hierarchy should execute is known as: a) inheritance b) polymorphism c) is-a ...
Preface: I am working in PHP (Abandon hope all ye who enter here). Background: There exists a large set of global functions in PHP, a number of which are miscellaneous system calls, like sleep (and others). Now, I use sleep (and others) in a bunch of different scripts I run in a bunch of different places, and I have f...
I'm trying to come up with some data structures for rendering my map on OpenGL. It is going to be ~ 100x100 blocks(squares) total, with each block being around 100 pixels. However, the screen will only display about 20x10 of these blocks at a time, depending on character location. So from this post: https://stack...
When I look at things like Twitter, it seems like the idea is so simple to implement initially that the founder does not have to be very technically talented. Basically it's just a guy with a good idea. But when an app / software blows up and entails much harder engineering problems, how does the founder deal with it? ...
I got confused about if a domain is required to access an external service in some state of it's life cycle. The business rule is this : If an Employee is accepting a JobSeeker's JobApplication, then the Employee must create an Appointment and have it e-mailed to the JobSeeker. My current solutions are: 1 - Leav...
I want to learn to Design Hash table with simple hash function for better understanding. I understand that the hash table will work as long as the hash function maps each key to a non-negative integer less than the size of the hash table, but it will only perform well if it distributes different keys across different b...
The usual way (that I'm familiar with) to divide the server side is the n-layer architecture : DAL - data access layer, usually has the Entities and the context (and maybe include also a repository) BLL - business logic layer Contract - Interfaces Services - classes which implement the interfaces ( could be a Web API ...
I've heard, that parsing HTML using the Cthulhu way is not very good. But what are the right ways to parse HTML? Or is it possible to parse it at all?
EDIT The original title of the question was Is there a non-derogatory term for 'monkey patching'. As I have learned that the term is actually not derogatory, or is at least not meant to be, I changed the name to free it from mistaken implications. I would like to describe a piece of software, and try not to use emot...
I would like to modify and use code of a MIT project within a MS-PL project. Am I allowed to do that? I've already searched for it with Google and Bing, but I could not find anything like "Yes (No) you can (not) use MIT code within a MS-PL project". I am no jurist, so it is quite hard to interpret any license.
I'm working on website for the game of bridge and I am process to designing the table to store the bidding. Shortly about the bidding. 4 people at a table will bid clockwise until 3 players has passed so it could be many rotations of bidding with a one of the four to start the bidding like this: North East South West P...
Okay, so the goal here is to implement a strategy pattern that can be tested using any sort of automated testing tool. I've been struggling with this problem conceptually for a few weeks now and I want to clarify it. So the current setup is something like this: <?php // CreateReportUseCase.php class CreateReportUseCase...
This might be a silly question, but I've reading a little bit about NoSQL databases on the past few days and I'm trying to understand when really they help us. One thing I've realized though is that it seems that NoSQL databases are closer to OOP than RDBMS. I say that because usually when we deal with OOAD we don't ge...
I want my unit tests to be able to verify that some events were subscribed or unsubscribed at specific points. Currently, I see two options. VerifiableEventHandler Each client subscribes using the common += and -= notation. Each class that has a verifiable eventhandler needs to implement IsSubscribed(), which can quer...
I am sure many people involved in the software development projects came up with this question, but I could not actually come up with satisfying answer. How to explain to a manager used to having a huge gantt-chart, resource allocation, critical-paths (etc) benefits of using agile process tool such as Scrum or Kanban?...
I'm currently refactoring an application which periodically downloads content from various sources (http, ftp, sql, etc). There is a schedule which controls the times during which the application can be active. For example, it can download content between 8AM and 16PM. The application has been written in an object orie...
I have found myself a few times in the situation where a client reports an issue like 'I can no longer login to my account'. Sure enough when trying to login with the client's credentials myself everything works. After that, you start testing in other environments and situations, but still it works every time. After ...
So in a nutshell I have an abstract class : public abstract class Member { public string PCode { get; set; } public string Reference { get; set; } public DateTime? ElectedDate { get; set; } } And this is inherited by 3 other classes: public class Fellow : Member { // some class level properties here } public class ...
I will give a simple example to help you understand my question. Suppose we have a rectangle and a Utility class with a method that creates a buffer arround a shape. The .createBuffer method has required and optional arguments: required: radius optional: direction (for example "inside" or "outside", default is "outsid...
I am developing a retail management system with inventory management module, I am facing a logic design problem and I don't really know how to address the problem in an easy way, so I wrote an example which illustrates that problem: Let's say I have an item (e.g. Cola Can), this item have a Barcode (11...1), this is s...
I am currently checking through the syllabus for the ISTQB "Technical Test Analyst" certification. This syllabus (henceforth called "TTA syllabus") contains a chapter dedicated to "condition testing" (apparently this is also called "condition coverage" or "condition coverage testing".) Condition testing as defined in t...
As far as I know, deleting a non empty directory could work the same way as deleting an empty directory: by removing the pointer to the directory's metadata there would be no pointers to the items it contained, effectively deleting all its children recursively. If that's true, then why must directories be empty before ...
I'm developing software in VB.NET and C#.NET and planning to release their source codes as fully open source. Are these projects "open-source" safe? My doubts are: VB.NET and C#.NET are using the .NET framework which is not open source. The source codes depends on the compiler and the IDE, although there's 100% open ...
Class Sub is a subclass of class Sup. What does that mean practically? Or in other words, what is the practical meaning of "inheritance"? Option 1: The code from Sup is virtually copied to Sub. (as in 'copy-paste', but without the copied code visually seen in the subclass). Example: methodA() is a method originally in ...
Let's say that a user requests for some piece of data. Usually the data is processed via a server and then returned in XML/JSON format. Im guessing another piece of processing happens to convert it into HTML/CSS so that it could be displayed on a browser. Why do we bother returning XML/JSON for API requests? Why can't...
I have a system in which I will perform queries to a database. I want Query1, Query2 and Query3 to use the same methods in their way to the data source layer. To do that I would like to make something similar to Strategy or Template Patterns, where I have a part of the code which is a default behavior for all queries (...
Are there any valid uses for the classes in the System.Collections.Specialized namespace any more or are they all superseded by the classes in the System.Collections.Generic, System.Collections.Concurrent and System.Collections.ObjectModel namespace now? The classes in the namespace are: HybridDictionary ListDictionary...
I have a first project has a feature to viewing, inserting and updating an employee record, with this possibly I will create a java class for the UI and another for the database connection with commands for viewing, inserting and updating a record. Then I have a second project that will compute the salary of employee. ...
I have a small C# project that reads a file and gives me an output: a string that does not contain spaces nor any types of punctuation marks. It may also contain a few misspellings. Ex. Output: THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG I wonder if there is a way to analyze this string by using text mining/data mining and/o...
Factory pattern (or at least the use of FactoryFactory..) is the butt of many jokes, like here. Apart from having verbose and "creative" names like RequestProcessorFactoryFactory.RequestProcessorFactory, is there anything fundamentally wrong with the factory pattern if you have to program in Java/C++ and there is a use...
I've written a program in Java, it's only fairly small and I started programming and ended up just building one big class with everything inside it. The program works fine and exactly how I wanted it to, however, when writing up the documentation I've realized that it doesn't follow any sort of architecture pattern lik...
Suppose I have a list of Ingredients In My Fridge which are going off soon, and a list of Recipes which use up various Ingredients. (Some of which I don't currently have.) Is there an algorithm which produces the optimal set of Recipes, where an optimal set maximises the number of Ingredients In My Fridge used up and m...
I have the blocking code shown below. Is calling monkey.patch_all() enough/optimal to make it non-blocking? Does Gevent handle iterations like these? # front page def front_page(): database = db.posts.find() # find all items in posts collection return render_template( 'index.html', ...
We have two C++ classes named Important and Small The class Small use a few methods and attributes from the class Important, but not all. Since our application is performance critical, instead of copying all attributes (possibly pointers) of Important that are needed by Small and redefine the few methods in Small, we ...
I need a class where this can be done: // user program elder_tales.Player p = elder_tales.generate_player(); elder_tales.level_up_player( p ); but not: // user program elder_tales.Player p = new ...whatever p.set_stats(); p.set_server(); p.calculate_experience() elder_tales.level_up_player( p ) Basically, I want the ...
How do I measure team productivity over time using consistent story sizes? To take a simple example, if I can do a story every two days, then I can do five stories in a two-week sprint. By definition (as one story is two days), I will continue to complete five stories per sprint forever. In order to demonstrate improve...
I'm employing TDD quite a bit these days and really enjoying myself - everything seems to flow better and be naturally better constructed and organized. However, while writing a bit of IO code, utilizing System.IO.Streams, and I was wondering - when is it ever worth not using a factory? Because in Streams case, it cert...
public static IEnumerable<Type> GetAccessibleTypes(this Assembly assembly) { try { #if NET40 return assembly.GetTypes(); #else return assembly.DefinedTypes.Select(t => t.AsType()); #endif } catch (ReflectionTypeLoadException ex) { // The ex...
I am currently implementing a lexer that breaks XML files up into tokens, I'm considering ways of passing the tokens onto a parser to create a more useful data structure out of said tokens - my current plan is to store them in an arraylist and pass this to the parser , would a link list where each token points to the n...
As a web application developer, recently my work in creating Social Applications has taken a lot of momentum (specifically, Social Login buttons.) Is it ok to use my company's social network developer credentials for this? I don't want to sign each client up for between 1 and 20 different services based on their needs....
Suppose one would like to use in an iOS app only one function from a GPLv3 library that contains a large number of them. One cannot simply link the whole library beacuse otherwise the resulting software, having to be GPLv3, would be incompatible with the App Store. Can one "take inspiration" from the source code of the...
I was having a conversation with a colleague and although my opinion makes sense to me, I wasn't able to back it up. I'm in the process of creating an API that will be hit hundreds of thousands of times per day. It's fairly simple, and will just be doing some inserts into a relational database. There are essentially 3 ...
MongoDB is dual-licensed with AGPL (the engine) and ASL 2.0 (the drivers). In a nutshell, merely using MongoDB through the drivers does not dictate to release your source code (due to drivers' ASL 2.0 license). AFAIK, only if you directly call the mongo engine, you need to give out your code that's using it (but still ...
Consider a class that implements IDisposable, and that has members in such a way that it will never become eligible for garbage collection when it is not disposed. And as it will not be garbage collected, it will not have the chance to use the destructor for cleaning up. As a result, when it is not disposed (e.g. unrel...
I'm working on an cross platform C++ project, which doesn't consider unicode, and need change to support unicode. There is following two choices, and I need to decide which one to choose. Using UTF-8 (std::string) which will make it easy to support posix system. Using UTF-32 (std::wstring) which will make it easy to c...
I'm developing an ASP.NET webforms application with pages which displays information based on the authorization level of the authenticated user (very typical). I will write a simple example of the issue I'm facing: Let's pose I want to have a page with 4 buttons: 1- "OnlyForAdmins" button. 2- "OnlyForManagersAndAdmins"...
One has established design patterns so ingrained in their brain, that when sometimes somebody does something unexpected, it is a revelation. My colleague in an iOS project did call the delegate method from the delegate class itself. That means the delegator was not involved in invoking this method at all. Does this bre...
What is the difference precisely between an Embedded System (like Tegra, Raspberry or similar) and a Microcontroller? I understand there is a difference but I'm finding it difficult to understand. What does one intent when he says: "are you able to develop for microcontrollers"? Does it mean simply program in C/C++ for...
I have a website (which is actually mainly a Web API site) and I'd like to be able to simultaneously access multiple versions of it. What I'm currently doing is creating a new website for each version under IIS and referring to sync2.site.com, sync3.site.com etc. This solution is not very scale able nor maintainable. H...
I have a wrapper DLL that interfaces to another DLL that contains the following function: char * Foobar(void) { // BLAH is the function from the DLL this wrapper interfaces too char *array = 0; // Set up an array pointer for dynamic memory allocation. int NumOfChar = 0; // Build array for (int n=...
Is it possible to convert a list of object directly to byte[] (and vice versa) to gain performance (by avoiding serialization/de-serialization)? What I have in mind is that a list is somewhere in memory(heap). If I could read the bytes in heap for my list I could just assign it a variable (of byte[]) in my program. Is...
I'm creating a 2D game in plain ANSI-C using SDL2. I'm planning to let users create their own graphics. So, to achieve this, I'll use an information file which will hold some data such as Width, Height, X and Y position of each frame. But I have two views of this. One is to use a single file which will hold the informa...
Let's pretend I work on a project tracking application. The application is a database backed, server hosted, web application. In this application there are Projects which have many Activities which have many Tasks. A Task has two date fields an originalDueDate and a projectedDueDate. In addition, there are dynamic f...
Every developer advocates test-driven development, but I am coding a website in NodeJS and I am not testing my app. This is not because I don't see any reason. I know it allow me to check at each commit whether my code is right, thus avoiding security flaws. I don't do any tests because I don't know how or what to test...
I'm pretty sure that the following two snippets are equivalent but I wanted to double check: CALLBACK STYLE function foo(input, callback) { // do stuff with input callback(); } function bar(input, callback) { // do stuff with input callback(); } foo("hi", bar("bye", function() { ...
this is my first time here. I'm a physics grad student and I've recently found a research group to work with. We study statistical mechanics using computer models, so there is a significant programming aspect to it. My first job has been to take the old data analysis code (written in java) and clean it up in c++. The ...
When building a unit test, is it appropriate to use a mocking tool to assist you in setting up an object even if you will not be mocking any behavior or verifying any interaction with that object? Here is a simple example in pseudo-code: //an object we actually want to mock Object someMockedObject = new Mock(Object.cla...
In mark-sweep-compact garbage collection algorithm you have to stop-the-world when relocating objects because reference graph becomes inconsistent and you have to replace values of all references pointing to the object. But what if you had a hash table with object ID as a key and pointer as value, and references would ...
I have a function which receives a buffer and returns some data in the buffer. The data can be smaller than the buffer capacity. Which is the best and safest API for this? int fn(void *buffer, size_t buffer_len): the size of the data written to buffer is returned by the function. Downside: the return value must also h...
So while I've been doing some lengthy compiles I decided to take the C++ general test on ODesk and came across this question. If I'm not mistaken, given the wording (or lack thereof) all of these could be true. a. int Foo() { } int Foo(int bar) { } b. Well, return void; would be incorrect semantically but functions ...
Imagine your customer want's to have a possibility to add new property (e.g. color) to product in their eshop in their CMS. Instead of having properties as fields: class Car extends Product { protected String type; protected int seats; } You would probably end up doing something like: class Product { protecte...
I'll keep it simple, I want to make C#'s methods work like javascript's functions. Mainly so I can convert this - function makeVariable(terp) { var me = {value: 0}; return function () { terp.stack.push(me); }; } into C#. Is there ANY way, no matter how complex or time consuming, to do this?
In most MVC web projects there is a User class. Many times a user has something else in a one-to-many relationship, i.e. orders. If we have a user class that has many orders, should methods that add, edit or delete orders for a user be placed in the user class, or in a separate Order class? i.e. 1. user.add_order(order...
The project I'm currently working on has an issue: bugs and tasks are often assigned to people who are too new or too inexperienced and their work ends up producing more bugs down the road. The problem is that parts of our software are much more "dangerous" to work on than others due to code quality issues. I've been t...
I'm building an Internet of Things solution that has a number of real time feeds. I need to make a couple of design decisions with regards to the data store and reporting and looking for input. I have two deployment models, local where a small Linux server captures multiple streams usually a new data point each second ...
Imagine there is an application (ASP.NET MVC) that processes some documents. The document must be revised several times by different group of users. state/role rules: simple user can only publish document; (priority: low) userGroup1 can switch it to next state or reject it; (priority: higher) userGroup2 can confirm p...
I'm looking for a very exotic thing and have no idea if it exists at all in SQL Server 2012. (Please forgive me - my background is in T-SQL, but not yet the fine details of SQL 'programming'.) So, whether this 'this' is a UDF or SP or something else - I don't know. The challenge is to have something so flexible that it...
Say I have an aggregate root Entity with some flags which are represented by an encapsulated object EntityFlags: class Entity { /** @var EntityFlags */ private $flags; ... } I have a repository for this entity. My goal is to modify flags in the DB. There are two ways I see: Get entity from the repository,...
When learning C# (and OO concepts more generally at the same time) something I found very distracting is exemplified by the following line: ExampleClass exampleObject = new ExampleClass(); It's the apparent redundant repetition that bothered me. Some light dawned when I grasped the difference between declaring a varia...
I have a web based project that allows users to work both online and offline and I'm looking for a way to generate unique ids for records on the client side. I'd like an approach that works while a user is offline (i.e. unable to talk to a server), is guaranteed to be unique, and is secure. By "secure", I'm specificall...
Let's say I am doing a 2D application with the following design: There is the Level object that manages the world, and there are world objects which are entities inside the Level object. A world object has a location and velocity, as well as size and a texture. However, a world object only exposes get properties. The...
Templates are nice for similar algorithms of different data types. Say I make a template stack of a basic data type... Stack<int> stck(10); stck.Push(5); I'd pop it... int x = stck.Pop(); x would be 5. If I call pop again, there are no items, so I have the method just return 0 for null. It could be something else, b...
I have a summary tool written in python that reads input files, and writes them into a summary file. I have the following stipulations: No duplicates. If it exists, add a count to it. Is it better / faster to write one GIANT output file THEN de-duplicate the entries or to dedupe as you go (ie, each write command ch...
Consider the following "if cast": class A { public void f1() { ... } } class B : A { public void f2() { ... } } A a = foo(); // might return A or B if ( a is B ) { // Inside block, implicitly "redeclare" a as type B // It's B, go for it a.f2(); // Wouldn't compile. a = new A(); } We don't ...
I have 5 user controls on the page and each control implements it's own interface that contains properties and events. In order to enable communication between user controls, I am creating a property of target user control inside other user control. Through this property, it's state can be altered and be able to regist...
I was wondering, if it makes sense to encrypt passwords for external services stored in my config file with an symmetric encryption algorithm? On the one hand I think, if someone gets access to the config file, he will probably also get access to the code and it will relatively easy to decrypt the passwords... on the o...
Can someone help me to find a easy way to parse XML? I have an iOS 7 Application using Google Map API. I tried to learn this on my own. I try to create an application that uses Web Services like Google Map. These web services use HTTP requests to specific URLs, passing URL parameters as arguments to the services. Gener...
In my RESTful API, I have Users, Applications, and Tokens. An application has an owner, which is a user. A token is linked to both an application, and a user. A user has both public and private representations: GET /user - Retrieve current authenticated user GET /users/:user - Retrieve given user An application has a...
I'm trying to make a number of data classes for my C#/XNA game, which would essentially be a wrapper around T[,]: public interface IGrid<T> where T : struct { Point Size { get; } T this[int x, int y] { get; set; } } For example, I might have a Heightmap object which is essentially an IGrid<float>, or I mig...
When I compile a C program, it is compiled first to assembly code, then assembled into machine code. I'm curious why it doesn't just convert straight to machine code in the first place.
I have a library implemented in C++ which has a C interface. This C interface is, for all intents and purposes, the only way to use this library. C++11 seems to discourage the use of raw pointers but neither shared_ptr or unique_ptr are suitable in this case. From what I understand, intrusive_ptr is an option, but I am...
Might be kind of an odd question. A guy writing a C++ compiler (or whatever non-VM language): Does he need to be able to read/write raw machine language? How does that work? EDIT: I am specifically referring to compilers that compile to machine code, not to some other programming language.
I connected iPod with Arduino using serial (UART) connection. Arduino sends 0-1023 number (so it's two bytes) as it's samples light sensor value. I'm asking about advice about simple and reliable communication protocol. Do I need magic constants to start/stop communication. Maybe I need sent data of small chunks. N...
I have singleton in Java and I have realized, that I could make its fields static and it would work same way as regular instance fields. Would there be a performance / optimization difference? If so, what would turned out better? Is there a preferred way to implement singleton fields? (again, I am talking fields, not ...
I am writing a static library for C/C++ (personal project). As my headers became rather large, I thought that splitting my headers would be a good idea. Right now a header looks like this: MainClass.hpp: namespace impl: implementation details enclosed in a namespace impl forward declarations of classes declared below...
Most BST examples show a sample of a BST with unique values; mainly to demonstrate the order of values. e.g. values in the left subtree are smaller than the root, and values in the right subtree are larger. Is this because BSTs are normally just used to represents SETs ? If I insert an element say 4 which already exist...
Problem: The Oscar Committee wants to decide which person should get the best actor award among the given N actors.For that they decided to use a random function random_bit() which returns either 0 or 1 with equal probablity. For the results to be fair,the committee was asked to generate a random number between 1 to N...
I was looking at the google coding guide [here] and they do not recommend that one use the using namespace or namespace::function - if I did not misinterpret it. Does this apply to std as well? cout<< does not work without it. This book, recommends the same. So how do I go about using cout<< without using namespace std...
Currently I am developing Multi-Branch Retail software. All branches have the same set of items. However, each one has its own stock quantity. My question is, what is the best practice to apply in branch quantity control for items? I am currently thinking about the following design: Item Table ======== -Id -Descri...
We are small start-up now, we don't have a DBA. if our project succeed, it will have a lot of data that will likely need to be distributed over several machines. So we want to make that step easier, so what we should take in consideration now to make it so? What we can think of now is using uuid instead of autoincremen...
I know absolutely nothing in low-level stuff, so this will be a very newbie question. Please excuse my ignorance. Is machine language - the series of numbers to that tell the physical computer exactly what to do - always binary? I.e. always composed of only zeros one ones? Or could it also be composed of numbers such a...
I have designed an management system for a medical practice and I am writing the design specification and I am kind of stumped by what to write for a section. It asks for me to write about the components of a system but I am perplexed. What exactly are components within a system? Is this generally considered as the fe...
I was reading the paper Out of the Tar Pit authored by Ben Moseley and Peter Marks when I came across the following section on page 25 regarding essential mutable derived data: Essential Derived Data — Mutable As with immutable essential derived data, this can be excluded (and the data re-derived on demand) and hence ...
I am creating , a site like gsmarena , can any one help me with database design to store mobile specifications like here "http://www.gsmarena.com/asus_padfone_infinity_lite-6120.php" as user can add more custom specification ,
Well known is the split of a whole application into several bounded contexts to emerge an Ubiquitous language. while practicing Domain-Driven Design. In general, 1 bounded context = 1 archive file ready to be deployed (JAR / EAR / DLL etc..) My question concerns the bounded contexts deployment regarding hardware optim...
I'm seeking vital naming of string filename parameter in parameter list used in various methods where filename with full path is expected. In many cases also UNC path can be actually supplied as full path because many libraries handle it natively. I usually call the parameter just filename, but it can be misleading in ...
I've been finding a lot of blog posts claiming JS encryption is unsafe, here's a couple of detailed ones: http://www.matasano.com/articles/javascript-cryptography/ http://rdist.root.org/2010/11/29/final-post-on-javascript-crypto/ My question is, if browsers truly are inherently unsafe then, by extension, entering any P...
I have a controller method like listed below whose argument is annotated with @Valid to validate PasswordChange object using a Hibernate validator @Constraint. Both PasswordChange and a sample constraint are listed below. As you can see, I am injecting up loginDao inside the constraint. Is this an anti-pattern ? The o...