instruction stringlengths 34 19.9k |
|---|
I'm making an Android app and have it structured as a simple multi-activity app. I want to add a navigation drawer to it, and it looks like I will need to completely restructure the app and load everything as fragments. (http://developer.android.com/training/implementing-navigation/nav-drawer.html)
How should I begin p... |
Which one of the ways has better performance, or is a good programming practice, making the holder activity extend OnClickListener and make a Switch() clause for getItemId() or making one OnClickListener for each one of the buttons or widgets that need it or making separated classes in the same (or another) package th... |
Usually when you do a new java project, there are several essential file such log4j properties file, other properties file and log file and you need to tell java where they are and where do you want to save the log file.
I don't want to hardcode the absolute path to these file because I am putting the projects in diffe... |
In a license.txt file, this:
Part of this program uses the following clause
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
is definitely different from t... |
I've recently read several articles about the advantages of the composition over inheritance. Their authors said that you can always replace inheritance with composition (to be precise, they say they don't know such situations where it can't be done). However, I can't think how to do this in the following case:
abstrac... |
I have inherited a project from another developer, and it is riddled through and through with the following type of error:
echo $data['example'];
Notice: Undefined index: example
Obviously, I'm going to refactor this to check for the existence of the key prior to the print statement. However, my question is not rela... |
Reactive programming and MVVM are two approaches that can address the problem of separating the domain layer from the UI.
MVVM does this by defining a viewmodel, which is a data structure mapped to UI components. The UI display the data, and maybe update it when user occurs.
a reactive framework defines a graph of ob... |
Before I continue, I just want to mention I have heavily researched and searched on this topic, but I need the opinion of people who have worked/and or have practical knowledge with regards to this topic.
We are currently looking at developing an API so that clients can utilize this. We are definitely set on REST as op... |
I am trying to implement boolean data type in C. Basically, I am working with sets.
The following code can be used to access each bit but I am unsure whether I can represent sets using this method.
Can somebody clarify this for me?
struct SET {
unsigned int b0 :1; // bit 0 single bit
unsigned int b1 :1; ... |
Bloom filters look really great when you consider you can determine if an Int is in a set with 99% certainty in constant time. But so can hashes, with the only difference that, in a hash, most of the time you are accessing the memory only once. With bloom filters, you need to access them ~7 times per request in complet... |
I am using a lot of DateTimes in my application. Now I usually name it like StartDateTime, EndDateTime, etc, to imply there is also a time involved.
I am getting a bit tired of this (it is tiresome to read), and most of the time it is quite logical there is a time compartment to it anyway.
Now I'm thinking about ditchi... |
Imagine this set up:
public interface IMass{
double Mass {get;}
}
public static class IMassExtension {
public static double ToKg(this IMass massObject) {
return massObject.Mass / 1000.0;
}
public static double CalculateInteractiveGravity(this IMass massObject, IMass otherMassObject)
... |
Is there a known method or pattern to implement a simple controller for an MVC design in pure C or the switch case approach is the standard?
Background :
I have an embedded application and I'm pleased with how the business logic turned out. I also finished the UI which boils down to basically 2 functions:
uint8_t getIn... |
I am preparing a single page application that would be sometimes used over slow mobile connection. Some of its part are quite heavy in terms of API requests (fetching ten different resources for a new screen display).
Now, is it a good idea to merge these services to one that provides all required data, but is not as "... |
In this StackOverflow question I asked about the behavior of the @throws annotation in Scala. Now that I understand how it works I want to ask about best practices with using it. Here's a repost of my code from that question:
abstract class SFoo {
def bar(): Unit
}
class SFoobar extends SFoo {
@throws[Exceptio... |
I'm migrating a website that use Javacsript/HTML/PHP using reusable javascript code, in certain moment I saw the opportunity to simplify code in functions that use almost the same code.
Let's say: I want to display values from the database into various <span> or <div> elements using AJAX. all the referred elements use... |
I have been researching why the origins for most graphic applications are located in the top left corner of the screen. From everything I have read, they are located there because that is where the electron gun on a cathode ray tube would start to scan, from top to bottom.
Other than this historical reason, is there a... |
I am building a new application and was reading about micro-services architecture. The architecture itself makes lot of sense from a development, deployment and life cycle management point of view. However, one issue that came up was with regards to how to handle master data.
For example, I have 2 apps: say Sales app a... |
Due to partnerships, we are required to host our website through our partner company. However, we had an idea that perhaps we could offload the document storage to an AWS document server. The thinking is that we could serve the html from our server, and serve any large document files from the AWS server, which would g... |
How come the complexity of fetching a value from an array by it's index is O(1)?
I thought the algorithm has to go through all the indexes, find the correct index, and then know what value to return. So that means the complexity is O(n/2) on average.
Why is it actually O(1)?
|
I'm building a system has both a WPF desktop application as well as an Asp.net MVC application.
I need a common user identity component so that user can log on to either one with the same credentials.
Is ASP.NET Identity appropriate for this task?
Has anyone used ASP.NET Identity with a WPF application?
Are there any... |
I am teaching myself to program in C and have been for a few months. I recently took a one month break and came back a week ago, and it's all gone. I had to look up some things that I really put effort into understanding (see: pointers) and some others just stuck with me. Now learning about malloc and dynamically alloc... |
I see a lot of code with variables declared right after the function, but when I post something like that people end up mad and say it is better to declare them when they are used.
I assume this all compiles to the same executable, so it is simply a matter of style. As far as I can tell, pretty much all C code (99.9% t... |
I've worked as a team lead/developer in a large financial enterprise environment for the better part of three years. Our production release process is a nightmare because it revolves around Clearcase. We have a change management group who executes all releases and who will only allow code into production that was taken... |
I want to build a web application that will allow multiple users to collaboratively populate the contents of a fairly conventional relational database. (The database will have a fixed schema, which is known in advance).
I can see how to define the schema for the necessary object types, relations, and foreign key constr... |
I once in my childhood read a SF story in which it was assumed that the capital letter 'P' would be a good representation for a question mark, if you cannot use that character directly, eg. in variable names. However the story is quite old and things may have changed :)
Is this a good practice?
BTW: The story was calle... |
When doing Domain Driven Design it is advised that services should be stateless. There are several kinds of services when doing DDD:
Application services.
Domain services.
Infrastructure services.
Factories, Repositories, Specifications,...etc.
How exactly do I make a service stateless?
Does that mean I shouldn't hav... |
This is something I often struggle with in testing, yet can never find a canonical or reasonable answer to.
Simple scenario
A function, f(), takes a file, processes it, and returns the processed file. f() has unit tests to check that it performs as expected.
A command-line interface application (CLI) takes a file pat... |
I'd like to know if my Architecture idea, is the best approach following some pattern.
I'll create a Dashboard for my company, and I never will delete or update data in my database, just read the data from database.
Nowadays we just work with our SQL Server database, but I want a solution that will provide a easy way ... |
I'm creating an MVC application in VS2012 and I reverse-engineered the models from existing Oracle tables. The tables are part of a MASSIVE database. Besides the main tables that I need to insert, update and delete from I also (on a whim) selected a few tables and views that my application only needs to read from. Now ... |
Is there any terminology for a problem that is caused by a previous wrong decision?
For example you build your own framework, with a flawed MVC design. This in turn leads to weird situations when routing requests. A person then asks how to solve the latter problem, while the actual problem is the wrong design of the fr... |
I have a git repository with a folder in it. The folder is listed in my .gitignore file. I cloned another repository into that ignored folder from github. I may want to work inside of the new repository but I don't see any reason for it to be a part of the original repository. Perhaps I should just keep it outside of t... |
I have a video library that I need to publish for my clients. The clients need to be able to embed a player into their sites and play the videos. I need to restrict access to my clients only so that no one else could put videos on their sites or access them programmatically.
To be more clear, I am trying to figure out... |
I'm building a solution based on Domain Driven Design, I'm trying to implement the security system (authentication, authorization, roles, system configuration, connection strings, etc..) in a transversal layer (cross cutting concerns like Caching, Security, Logging, etc).
The tiers of my application are two projects (C... |
I am fluent in most of Java and have thought about moving on to a .Net language. Obviously C# and Java are very similar so I have chosen to learn C#. When programming in Java I would always use Eclipse as my IDE, which doesn't have a Drag and Drop system for creating the UI. I noticed, however, that Visual Studio does ... |
This is a general question to understand how await in C# works, and particularly I am interested in implementing it in Android.
So C# await allows you to go in to waiting mode in the middle of the method until the the task you are waiting for is complete, then you will continue the method execution.
How ever the intere... |
I am trying to decide whether to just use individual tables with more fields for storing posts, pages and events or using tables with basic fields plus having EAV tables as well for fields that are optional. Also EAV would allow to add more 'attributes' to each entity without actually changing the database at all (just... |
I am working on an application where a user has to complete a puzzle and check within a given time limit.
This is an HTML5 based game, I can't keep the solution on the client side.
but I also want to avoid the latency that will be caused when we check for the correctness of the player's attempt.
Is there a way I can c... |
I am attempting to encapsulate several features about a user in a single class. Although the main use for this class would be to initialize it once and never have to call set any variables again, I would like this class to be scalable to be called many times. Although by putting this into a class I feel like I am eithe... |
So, if I (as the programmer) know that my value will never exceed a small number (say 100) because it is really just a counter-controlled loop or whatever, may I use short or char instead of int for the minute memory savings?
|
I have generally read that having many (>4) arguments to a function/constructor is a bad practice.
Is this still considered a bad practice? And is there a non-obvious reason?
In something like a Scala Case Class where there may be many fields what can be done to avoid such a construction?
(Not sure if this is best f... |
The question is not about changing the method/function visibility or extract local variable into instance variable in order to perform unit tests.
There are cases where we could include some logic in the source code in order to help us performing some functional tests or end-to-end tests. Generally speaking, these cod... |
Specifically, I'm writing in JavaScript.
Let's say my primary function is Function A. If Function A makes several calls to Function B, but Function B is not used anywhere else, then should I just place Function B within Function A?
Is that good practice? Or should I still put Function B at the same scope as Function A... |
A lot of thought went into the implementation of the set algorithms in LINQ: Distinct, Except, Intersect and Union. They guarantee that the items are returned in the same order that they appear in before calling the method. So, these two expressions return the items in the same order:
var authors1 = books.Select(b => b... |
I am trying to figure out the best design for instantiating an object which requires two separate calls to the data layer through a DAO. The object is not usable until these calls have been made (because it requires the data retrieved from the database). I have come up with three possible solutions:
Create a method in... |
In an ideal world, dev/ops are working together as one team to release something onto production.
However, there are organizations with limitations so that release engineers/teams are kept completely away from development/project teams.
This not only added the communication pain for releases but also making the produ... |
If I have a generic function that takes a void* as a parameter, can Auto in C++11 help stop any bad casting of that parameter?
For instance, we may have an event system that sends events and a pointer to some data that is relevant for the event it sends.
void EventClass::SendEvent (eventTypeEnum eventType, void* eventD... |
We have half-implemented proper key management at our dev shop. We have a SOAP web service (the key management web service) that can be used to retrieve passwords for other systems. So for instance, I might make a request to this service for the password to, say, a production PostgreSQL DB. I hit the web service with m... |
Let's say we have two ifs that depend on each other:
if var exists {
if var is array {
//Do stuff with var
} else {
//Resolve the problem
}
} else {
//Resolve the problem in the exact same way as above
}
//Continue execution with the assumption that var is in the appropriate state
How c... |
I have a class written on a project I'm working on that I've been told is using the module pattern, but it's doing things a little differently than the examples I've seen. It basically takes this form:
(function ($, document, window, undefined) {
var module = {
foo : bar,
aMethod : function (arg) ... |
I am a programmer hobbyist (self learnt), and once in a while I like to make games and interactive scripts (nowadays mostly in JavaScript for its ease).
Sometimes I start long projects that end up being forgotten because of other things I have to do.
Sometimes a project gets really big (say, 3000 lines is a huge deal... |
I'm a junior developer in a small company (in a team of 2 developers). Everytime we are asked to implement a new feature:
the deadline is set so that we just have time to do the development: there is no error margin (if something takes a little bit more time than expected, we are late) ; almost no time for tests (we a... |
I am implementing the Douglas, Peucker's Line Simplification algorithm in Python. I started with this implementation. However, it fails to run in Python due to Maximum Recursion Depth being hit. How can I convert this algorithm to a iterative one? I am not able to imagine this problem in an iterative view.
My expectati... |
I am trying to think of the most sensible way to design the architecture of a data generation system with several steps.
Data in the system goes through several transformations which can be divided into separate steps (from the business logic point of view).
I would like the system to keep this modular design, in such ... |
We have the following problem: at the end of the iteration we give our Android app to our customers to test.
Our customers report bugs that are not reproducible on our test devices.
How can we deal with this situation?
Are there any tools we can use (for example to record their actions)?
Or is it possible to remote deb... |
I am looking for a solution that is fast and still readable. I have to do this in C but the code will be static in the end, which mean I could use any tool to generate it.
I have a task which runs cyclically and calls different functions also cyclically
Main functions cycle is 1.
Function a has also cycle 1. So the ma... |
I've got a few non trivial responsive website builds coming up. They are not platforms or apps, but large marketing / brochure websites where eye for detail is important.
I've used bootstrap extensively as well as pure.io, as well as my own rules.
I'm wondering what is the most efficient way to build these. I am planni... |
One way to optimize code is to minimize the access to arrays and use variables instead, because that way we use registers instead of loading data to cache memory.
For example, if in a loop I'm going to use 3 times a data from an array, say radius[i], I'd better declare a variable tmp, and give it the value of radius[i]... |
I have developed .NET software that uses two libraries:
Library A has MIT licence and I'm using my own version of it as I edited the source code of this library.
Library B has Ms-PL licence and I use only the binaries.
My application will be distributed freely in binaries and source code(including the source code of ... |
I am working in an organisation with 11 scrum teams developing on the same code base. Currently, all development is done in trunk, and at the end of a sprint everything MUST be releasable, or it must be backed out (an arduous process) as a release is cut.
My opinion is that while work in a sprint is (ideally) 'done' a... |
I have a struct which I want to add static methods to. Yes, you guessed right I'm talking about Datetime.
It's a pretty typical requirement to add MyCustomParse. It happens to return Datetime?, so it's not a constructor, but it's in that area, a static method that returns an instance. The content of this method has alr... |
Consider the following C function which takes as argument a string, which is then stored inside a struct:
struct mystruct* usestring(char* string)
{
struct mystruct *struct;
struct = malloc(sizeof(struct mystruct));
struct->string = string;
return struct;
}
My understanding is that the string passed to... |
Just talking about internal applications or intranet web apps... At some companies I've seen their business-logic piece (Model in MVC/VM in MVVM) on one (or both) sides of a Web Service. And on the other side of the web service is the Persistence.
MVC/MVVM > Service Layer > Persistence
This is only for intranet/inter... |
First, let me show you an example (written in ActionScript 3.0):
class GameObject {
public static function MakeFromName( pName:String,
pAtlas:TextureAtlas = null,
pGameData:Object = null ):GameObject {
// If these arguments a... |
Using this calculator, I can see how the decimal ".8" and the expression ".7 + .1" have different representations:
.8 = 1.1001100110011001100110011001100110011001100110011010 *2-1
.7 + .1 = 1.1001100110011001100110011001100110011001100110011001 *2-1
^^ ... |
I've got an MVC 4 site where I'm using Forms Authentication. I'm setting a cookie when a user logs in. The majority of my site does NOT require a user to be logged in though.
What I'd like to do, whenever a user FIRST accesses my site, I'd like to update my "LastLogon" that I have stored in my database table to the cor... |
I'm a new software developer, and in my internship my boss asked me to develop an application that allows him to manage his inventory. Something small but, for me, very enriching.
The application is running, he found some bugs and problems but I fixed them. This is not the problem. My problem is that when I was working... |
I need to interface with a 3rd party API. With this API I make a GET request from within the end user's browser and receive an XML response. This data is to be used in a browser based application where the user can search through it, use it to make decisions, etc. The main issue is that most browsers have locked down c... |
I was reading in Peter Norvig's Design Patterns presentation. From slide 13:
Dynamic version needs only the Window classes.
The classes themselves serve as factories
This works because classes are first-class values We can say make(c)
Does it mean that Java and C# don't need the factory design pattern since they can... |
I've been interested to start using the Null Object / Option Type approach for replacing my old habits of null-checking multiple parts of my code. But, from the many examples I saw out there, it seems it's a pattern used in conjunction with generics.
Great for C#, Java, Haxe and a bunch of others I'm sure.
NOT so great... |
First off, I do realize this is not a perfect Q&A style question with an absolute answer, but I can't think of any wording to make it work better. I don't think there is an absolute solution to this and this is one of the reasons why I'm posting it here instead of Stack Overflow.
Over the last month I have been rewriti... |
We have a database of television scripts and we'd like to search it, getting results as we type.
We often remember words or snippets of dialogue but can't remember exactly what was said or what episode it was said in: "What was the episode where George goes against his instincts and walks up to the girl at the diner a... |
Quick background: I am designing a Pythonic language that I want to be as powerful as Lisp while remaining easy to use. And by "powerful", I mean "flexible and expressive".
I've just been introduced to Python function decorators, and I like them. I found this question that suggests decorators are not as powerful as Lis... |
I am making an iOS app which contains museum gallery: user can look through exhibits and then select info about it, etc.
On the exhibit screen I have two ScrollViews that are different, but are being fed by common data source. Each view is a set of images. Two top grey squares are the previews and the bottom one (where... |
Given X number of leaves (the ringed leaves in the picture) in an unbalanced tree with depth aroun 100-1000 and total number of nodes around 15 000 000. I'm looking for the first common ancestor for those leaves.
What is the most efficient way to achieve this?
|
Consider a LALR(1) parser for a file format that allows integer numbers and floating point numbers.
As usual, something like 42 shall be a valid integer and a valid float (with some automagic conversion in the background).
There might be parsing rules where a floating point number or an integer number is expected, and... |
Say that we've decided on following a "release-based" branching strategy, so we'll have a branch for each release, and we can add maintenance updates as sub-branches from those.
Does it matter whether we:
develop and stabilize a new release in the trunk and then "save" that state in a new release branch; or
first cr... |
I have three Scala packages being built as separate sbt projects in separate repos with a dependency graph like this:
M---->D
^ ^
| |
+--+--+
^
|
S
S is a service. M is a set of message classes shared between S and another service. D is a DAL used by S and the other service, and some of ... |
I'm totally new to CVCS (SVN specifically). I find that most resources focus very strongly on the command-line commands (irrelevant; we use Windows Explorer + TortoiseSVN) and about structure (e.g. projects inside our outside TTB, etc). Here's a thing about merging I'm not sure of:
Based on my sandbox testing, I got th... |
I'm getting started with SVN and so many sources say that merging is very difficult in SVN as compared to DVCS tools. The most recent questions I could find here on SE are from 2012.
Sometimes there's a mention that the reason is that SVN prior to v1.5 didn't have metadata, but SVN is at version 1.8.9 now.
Given that ... |
We have new (quite big) project starting, that we planned to develop using TDD.
The idea of TDD failed (many business and non-business reasons), but right now we have a conversation - should we write unit tests anyway, or not.
My friend says that there is no (or close to zero) sense in writing unit tests without TDD, ... |
I have a service that allow users to add dynamic content to a repository. So basically I have a generic Document class that contains a list of property for that specific object depending on what type of document the user is adding (eg. an invoice document has an invoice number property while a wiki document has an auth... |
I've been doing a lot of work with VMs recently and can see the massive advantages of the platform.
It's my understanding that subscriptions are a very good way of managing your clients. For example I have some software which requires a VM, a SQL database and two websites. When I sign up a new client I create a new Sub... |
I've got a question about author rights and open source software.
Assuming I want to build a software. A similar software is already created, but isn't free at all and owned by a company. Can a build an open source clone of the proprietary software from scratch? Or is it forbidden by intellectual property?
And what if ... |
During a conversation with our Domain Expert we can across this feature:
A Customer service agent can cancel an Order by decreasing its quantity. To cancel an Order we decrease its quantity by the specified quantity, change its status to either partially cancelled or fully cancelled and log the CS agent who issued the... |
This is something that's been troubling me for a while now. Is it actually worth unit-testing an API client?
Let's say you're creating a small class to abstract-away the calls to a petshop REST API. The petshop is a very simple API, and it has a basic set of methods:
listProducts()
getProductDetails(ProductID)
addProd... |
We've got a web application which is 99% complete prior to public beta, were currenlty securing the site from security perspective, locking down the server, db etc, one thing I'm concerned about but not really sure of the best way to test is for authentication loop holes.
For instance there a 3 user types - System adm... |
Which is the appropriate way of representing a queue processor in a UML sequence diagram?
I want to represent in the same diagram two systems that are loosely coupled through a queue. The first system, performs some actions and insert an action in a queue, the other system is always listening and when the event appears... |
I don't find any deep explanation on the web about a comparison between ElasticSearch and the graph databases.
Both are optimized to traverse data.
ElasticSearch seems to be optimized for analytics.
However Neo4j is also based on Lucene to manage indexes and some fulltext features.
Why would I use ElasticSearch if I al... |
While reviewing another programmer's implementation of a function to calculate the normal distribution CDF, I made a suggestion to either replace the entire implementation with Python's built-in functions or use SciPy, a common scientific library.
Another programmer pointed out that neither math.erfc() nor scipy.stats.... |
We are writing a flight search engine. We want to pre-fill the departure airport for mobile users with the closest one to their location. To do that, our plan is to
Find a list of airports with their latitude/longitude.
Find the user geolocation using something like HTML5 Geolocation (which asks the user for permissio... |
I've got three Raspberry Pis sitting around. I want 2 of them to be able to chat while the 3rd routes the messages (acts as a server between them).
The general flow of events should be something like this:
Server starts running on Pi #1
Pi #2 starts running and connects to the server (who's IP will be static I guess) ... |
I like the Node.JS style of JavaScript, where I can write all of my functionalities into smaller files and then require those neatly from within my code. I'm even thinking about trying to write a framework to mimic that behavior in client-side JS.
My goal would be to implement the module loading system as accurately a... |
I can find lots of information regarding the restrictions imposed on linking GPL licensed libraries from non-GPL licensed software. However, I'd like to do the opposite - I'd like to distribute some software under a GPLv3 license that has the option to dynamically link to a proprietary shared library.
The proprietary l... |
I'm writing an application in C++ using libpq as the interface to postgresql. I'm currently putting together a small library of helper functions to help deal with the conversion from C++ to C for an application to be used on either a PC or an ARM device (2GHz 2GB ram).
With regards to pulling data from the database, I'... |
I want to share the code of a research project, for academic purposes, in Bitbucket and Matlab's FileExchange.
The code is in both Matlab and Mathematica, and I want to restrict its use for commercial purposes. I don't know if I can use Affero GPL for this, as both Matlab and Mathematica are commercial software.
This... |
I was looking to an alternative to Repository Pattern and I've read about "Query object pattern" (http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/). However the implementation provided in the link above is not exactly what I was looking for - I look for something that can be easily in... |
C/C++ implicit conversions can cause bugs. Here's one example:
int foo, bar;
scanf("%d", &foo);
scanf("%d", &bar);
float foobar = foo / bar;
If I input 7 and 2, it's not 3.5 as expected - it's 3 -> bug (let's ignore the buffer overflow).
gcc's -Wconversion warns about this kind of stuff, so I turned it on. But it just... |
In the plain javaScript world I've learned that nested functions can be problematic because the inner function is "re-created" every time the outer function is called:
function outer(a) {
function inner(arg1,arg2){
return arg1 + arg2;
}
return inner(a, 6);
}
myVar = outer(4);
Apparently the inner f... |
I am writing a JavaFX GUI program for user configuration of an embedded systems device. The device will be connected by a wired or wireless serial connection which is not 100% reliable. Therefore when the user makes settings changes in the GUI, the program sends a set message to the device, then must verify they are se... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.