instruction
stringlengths
34
36.1k
<iframe> elements are documented as The HTML Inline Frame Element (<iframe>) represents a nested browsing context, effectively embedding another HTML page into the current page. However, most WYSIWYG editors HTML5 frameworks (such as tinymce, Aloha, Maqetta, etc...) are using a lot <iframe> but they intuitively do no...
I fooled around with for-loops, remembered the with keyword from delphi and came up with following pattern (defined as a live template in IntelliJ IDEA): for ($TYPE$ $VAR$ = $VALUE$; $VAR$ != null; $VAR$ = null) { $END$ } Should I use it in productive code? I think it might be handy for creating temporary shortcut...
I was reading through the LGPL license and found a requirement that I was previously unaware of. Section 4 (Combined Works) states: You may convey a Combined Work [...] if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Li...
I am looking for a viable design/architecture pattern for securing several web applications. Here is the situation: Multiple web applications must enforce roles and permissions at Java service method level Roles and permissions have to be stored centrally, in a separate component How the roles and permissions are enfo...
When doing single-threaded asynchronous programming, there are two main techniques that I'm familiar with. The most common one is using callbacks. That means passing to the function that acts asynchronously a callback-function as a parameter. When the asynchronous operation will finish, the callback will be called. Som...
I'm building a web application in Spring. I'm using an in-memory (embedded) database for my integration test - HSQL My production database is MySQL. When i setup my integration tests a while back i took a SQL dump from production db and converted that to HSQL (DDL & inserts). Now, my production database is going throu...
I came across an interesting perspective at a recent job interview. Hoisting in Javascript is about moving the variable declarations and function declaration at the top of the script. Can we call this phase as compilation? I am aware about the fact that the Javascript interpreter has 2 passes over the input script wher...
When should a ESB vs ETL tool be used? I have worked on ESB projects using Tibco Businessworks quite a few years ago. The message bus that we built used to consume messages from a source system , applying validation , perform transformation and send it to appropriate destination. The source could be a db , service , fi...
My first question is, is the Liskov principle applied even on constructor declaration? I mean there, am I forced to have exactly the same number / types of parameter in my constructor for each (different) class? Looking at this: package com.apptest.test; public class Application { public static void main(String[]...
This is a theoretical question, and excuse me if it is not clear, I am new to this field. Thing is, I was asked to design a chess game in an interview (java/ android.) And my intuition was that P. Norvig is a very good and known designer, and that pocker is very similiar to chess. So I tried to imitate his pocker desig...
In Python when writing file management scripts I will often have a base path that is a constant, BASE = "C:/" Of course I'll be using that base path to create other paths later on, including other paths that will change in no other place. So I define constants like this: SUB_FOLDER = os.path.join(PROJECT_BASE, "folder...
There is an application based on multiple screen model with pretty complex net of transitions between these screens. It has some similarities to a web page or Football Manager like games. Its main properties are: It has screen stack and it has back/history like function. Events cause screen transitions. Some of scree...
I see Hungarian notation in almost all Android code I see. It is used in the source code, in the samples, in code from other programmers I get to see, in code that presenters show at Android conferences. They use mContext rather than context, mTextView rather than just textView. Hungarian notation is useless in Java, e...
One of the most touted rules of OOP is to keep classes small. This means that in a significantly sized project there are bound to be thousands of classes. Logically it seems to make sense to combine related classes into various "subsystems" (or various levels of subsystem). My understanding of Demeter's law here is tha...
I am writing an interpreted domain-specific language for my application. Each statement is parsed and executed as soon as lexical analyser decides that the end of statement is reached. It's handling one token at a time and makes recursive calls evaluating expressions and reducing current token stack. It intuitively mak...
I just started at a new job as a database developer for a medium-small sized, company based on Microsoft-technology. I noticed early on how much practices deviate from what I've been taught at school regarding best practices, design patterns, testing and project management. What is bugging me the most is how our main d...
I'm new to Ruby and I was surprised when I found out that all objects are true apart from nil and false. Even 0 is true. A nice thing about that property of the language is that you can write: if !variable # do stuff when variable is nil end My colleagues, who are more seasoned Ruby developers, insist I should choos...
In a database I work on, most of the datetimes I store are converted to and from UTC so all of my datetime columns end in UTC such as CanceledUTC. I have a situation where I need to store a "local" time and want to signify that it is a local time in the column name. Is there a convention for signifying local datetime ...
I have to read through an extremely large amount of network data from various log files, and compile relevant information about that data to perform statistical analysis on it (the top communicators, top ip addresses that send on average the largest packets, average packet size, etc.) I decided to make a matrix where e...
According to Refactoring to Patterns: When a class is trying to do too much, it often shows up as too many instance variables. When a class has too many instance variables, duplicated code cannot be far behind. How does having too many instance variables lead to duplicate code?
Sometimes a GitHub Gist contains carefully crafted code that seems to qualify for what the Apache License would call a "original work of authorship", but the as far as I can tell the author never selected or knowingly agreed upon a license. Is there a default license for content on gists.github.com? What I assume is t...
By my understanding, a "unit test" is a test that makes assertions about the "smallest testable unit" - and an "integration test" is a test that depends on integration with an external system, e.g. database, mail server, REST API, etc. It occurs to me that a test could fit both of those classifications. Let's say we ha...
I'm inexperienced with Git but I try my best to get used to it, and so far I'm just using it for projects I work on alone. When I code there's some top-down approach naturally (as I can't know the future), and there's a reoccurring theme: I do some work. I find out that to get my work into something "commitable" I need...
The book I am reading on Java states something confusing and unacceptable. Learning About Ambiguity When you overload methods, you risk creating an ambiguous situation - one which the compiler cannot determine which method to use. For example, consider the following overloaded computeBalance() method declarations: pub...
In the past few years, 'client-side' web applications have become popular. A common approach nowadays is to have the backend as thin as possible, mostly exposing an API for the client-side Javascript app to consume. What I'm interested in is not the advantages of this approach, as this seems to be the preffered approac...
I'm a bit fascinated by the current paradigms shift libraries like ReactJs and Redux have caused in web development. Apart from computer science classes, I wasn't much affected by functional programming, immutability and so on, and I've yet to develop something in a purely functional language. While there are a lot of...
I'm trying to design a database for a simple text based game where the player characters have a large number of statistics that I want to track. Currently I have a few groups of related statistics, skills, finances, basic attributes, and a few others. There are quite a few fields that are 1 to 1 with a character which ...
I'm building a nodejs app I would like to make available under various settings by my customers. I want my customers to build their websites on top of my app, so: - the app can be configured in a way that domains "A.com" and "B.com" use the configuration "X" of the app, while "C.com" uses "Y", etc. - I'm thinking abo...
When I read coding style guides, such as the AirBnB Javascript Style Guide I just realized that these often do not provide deeper explanations why something should be done in a particular way. At most there are brief statements, rarely links e.g. "It won't work in IE8. More info." Why is that that so? At least a list ...
I am trying to understand the subtleties of Publisher-subscriber and similar notification mechanisms. I was checking Cocoa NSNotificationCenter, but it's unclear to me if it can be defined as a PubSub, strictly speaking. Is NSNotificationCenter a PubSub?
I know that best practice is to let everything about authentication/authorization to the service layer. Controller should not be aware of that. But how to let a service (from service layer so) to check for http session if I do not pass in the http request? In this particular case, when login needs some http request c...
As far as i know, we do not add an attribute like id to the classes in the class diagram. right? But when we create a database, or when we want to call an instance, we need its id, so why do not we have this attribute in our diagrams?
Why is it beneficial to use the strategy pattern if you can just write your code in if/then cases? For example: I have a TaxPayer class, and one of its methods calculates the taxes using different algorithms. So why can't it have if/then cases and figure out what algorithm to use in that method, instead of using the st...
I transferred to Computer Science my Freshman year so never really got a chance to look at schools for CS in particular. I breezed through with a 3.9 and never really felt challenged. I did three internships at startups, and all of my employers seemed to really like me so I think I'm ok at programming. However, I'm bec...
I am trying to write a backend for a taxi service (university assignment) and I am stuck on the algorithm. whenever a new client posts a request, all the taxi drivers nearby get an email notification and, for five minutes, I have to collect the positive answers (the ones who are willing to give a lift). After five minu...
For example, why doesn't JavaScript provide a BST as a native data structure you could use? var bst = new BST(); bst.insert('5'); bst.insert('3'); bst.find('5'): Alternative question: what are the costs and benefits to including such structures in a language? I don't see what the costs are, other than the time it take...
Call stack size in JavaScript: Three results: - Node.js: 11034 - Firefox: 50994 - Chrome: 10402 It seems like it would be a bad idea to use recursion for things like BST insertion, because there's a chance you may be dealing with input sizes in the millions or billions.
Introduction I'm working on an application where organisations pay for each user they add to their 'environment'. Organisations have a credit/balance, and as long as the user is not removed, the organisation pays a small hourly fee per user. Organisations can choose between recurring and one-time payments. An invoice w...
We currently have a SVN repo structured like so /trunk/library/libA /libB /libC . . /trunk/tools/toolA /toolB . . (it is more complicated than that, but this is sufficient to describe my issue) I want to migrate this to gi...
I am parsing many JSONs and DOMs in PHP. The problem is that the my knowledge about the structure of the JSON/DOM is mixed with code. For example, suppose that I have few sources of first and last names. Each data source can look different and have its own tricks, for example: [ {"firstname": "FirstName1", "lastna...
I'm designing 2 functions, I'm trying to be sure I doing correctly. The idea is that in the first function , a struct pointer is created and passed to a function that might or might not fill the said struct. In the event the struct is not filled I was hoping that the pointer in the first function would get removed by a...
So I used wrap to override the malloc call in my program, I didn't think that if I exec'd another it would work, and it didn't. I figure this is because it wasn't linked with my program. How could I overwrite a C call in another program? Sample: void* __wrap_malloc(size_t size) { void* mal = __real_malloc(size); ...
In my project IntentExamples, I have this filter, corresponding to a service. <intent-filter> <action android:name="biz.rpcodes.apps.intentexamples.START_SERVICE" /> </intent-filter> In another project, UseExampleService, I have something like: Intent i = new Intent("biz.rpcodes.apps.intentexamples.ST...
For a binary heap we have O(log(n)) for insert, O(log(n)) for delete min and heap construction can be done in O(n). In the context of using a binary heap in Djikstra, my exam paper involved an "update" in the heap where the priority of a vertex is changed. I assumed that the time complexity of this update would be O(n)...
If you have custom code for models (custom validators and custom fields are examples), Django Migrations will import them directly into the migration files. An example: file web/models.py def validate_power(self, power): if power == 'fly': raise ValidationError('Heroes cannot fly!') class Hero(Model): ...
OK, so I have this homework question whereby we are given a rather complex system description and need to create several UML diagrams that describe the system being described. I'm having an issue with designing the Use-Case diagram for it. Here is a very simplified description of the system: The system being described...
I want to create a simple configuration framework. Yes I know, there are many frameworks, which make their job very well. But for interesting in architecture, I want to create my own. My framework should notice the principles of SOLID You should be able, to store you configuration in several formats. As a proof on conc...
I always seem to come back to this question and cannot settle on a convention that I'm comfortable with or that I can concretely define: when naming a constant, how narrowly or broadly should it be named? For instance, let's say I've written a workflow application that has workflow items (instances of the workflow) and...
Rest without PUT models immutable, append-only (event-sourced) state changes by favouring POST-ing new reified change resources over PUT-ing updates to original. Example: making and then changing a coffee order... Traditional REST: POST /order {type: latte} → 201 Created /order/1234 PUT /order/1234 {type: mocha} → 200...
When the CPU with an L1 cache does a write, what normally happens is that (assuming that the cache line that it is writing to is already in the L1 cache) the cache (in addition to updating the data) marks that cache line as dirty, and will write the line out with the updated data at some later time. One possible optimi...
If you had to decide between queueing emails and sending them real-time, is it always the best way to go putting them in a queue and sending them one by one instead of instantly as soon as a user sends the request? Emails are sent using an external service that is Mandrill. Evertime someone submits a specific form in o...
Please bear with me, if this type of question has been asked before. I am having a dilemma with object design and seeking experts' help here to come up with the correct/better design for a webservice client. I am attaching a crude UML diagram below: I have been writing/fixing Java code, but just getting into object des...
Okay, so I have a Laravel 5.1 project with close to 200 models. This is fine for the core operation of the app, however, in many cases a client may want us to grab something from the database in a special way. For example, we have a client that wants to calculate the a pension amount slightly different than the normal...
I believe this is language agnostic question - if it's not then please correct me. Let's say I have a class (code snippet is a kind of 'pseudo code') class Car: private steering_wheel private engine public Car(steering_wheel, engine): this.steering_wheel = steering_wheel this.engine = engine public vo...
I am developing a backend for a taxi app in Laravel 5. Up to now, served areas are defined by the admins but I would like to change the way it works. I would like each taxi driver to define their working areas setting up a starting point and a radius (thus creating a circular area) and the final area is calculated by c...
I have 3 simple classes. A Reference, a Parent, and a Child. The Child knows the Reference and Parent instances it's associated with. Here they are, initialization and other data/methods omitted: class Reference { public int ID { get; private set; } } class Parent { public int ID { get; private set; } } cl...
As a good programmer one should write robust codes that will handle every single outcome of his program. However, almost all functions from the C library will return 0 or -1 or NULL when there's an error. It's sometimes obvious that error checking is needed, for example when you try to open a file. But I often ignore e...
As a part of my school CS class, I am reading Python Programming by John Zelle. In the book, Zelle talks about surrounding the invocation of a main method with if <condition>: main() where the condition is something like __name__ == '__main__'. My computer science teacher said that the necessity of this loop de...
Suppose you want to sort your movie collection, from favorite to hated. You apply the rules of some sorting algorithm by asking many questions of the form: "Did I like A or B more?" It's now sorted, right? Logically, every necessary question was asked to prove that when index(A) < index(B), A > B. But you can show that...
I don't know if this is a best practices or not. If I have a interface that extends another interface such as : public interface A extends B{ public void something(); }; and a concrete class that implements A such as: public class MyClass implements A { @Override public void something(){ System.ou...
Sorting algorithms assume you have a defined comparator. For example, if sorting integers A and B, the A > B operation allows you to determine if A should be after or before B. Imagine you want to implement a sort, but rather than a defined and consistent comparator, the comparison uses a heuristic of some sense - so ...
We have a service that based on a local timer does a GET request to our server on Azure to transmit some information to be saved on the server. At this stage we are only testing and we are finding that some of the clients are synchronizing so they hit the server at the same time. This seems to be caused due to delays...
I'm trying to load test/benchmark a http server with a very large number of simultaneous connections (10-100k). What is a good procedure for doing this? On linux I've seen that both the client and host likely need to have the number of permitted threads to be explicitly increased. Also, does anyone have a good feel for...
Guid has been a Global Unique Identification. Why does "PGuid" (Global Unique Identification) appear? 1) Is Guid NOT PERMENT for unique? (I sometimes wonder whether Guid is REALLY PERMENT generator in .NET or Java) 2) Is "PGuid" just for "easy to read with namespace"? In what kinds of situations can we choose "Pguid" i...
I have two Tables T1 and T2 in which, where in T1 contains column name 'Year' which saves year information and T2 contains column name as 'P_year' which saves year information. In the Table T1, I saved some data for the years '2011,2012,2013,2014'. In the Table T2, I am saving the data for the years '2015,2016...and it...
In absence of this pattern, downcasting is needed in the derived classes. My question is does this pattern solve only the problem of downcasting? And why is downcasting bad compared to the alternative offered by Intelligent Childrean Design Pattern?
I have noticed a pattern while working on several software projects: the big majority of the bugs reported had a high/very-high priority. I asked some colleagues about why this may be happening, and they mentioned that if a bug doesn't haven't that level of priority it is very rare that the Bug gets developer attention...
I am trying to generate a table which would show all possible combinations based on the key. To make it more clear lets say I have a kind of Key, Value pair set(Its mentioned kind of because there are unique keys and different values). I need to fill the table with all possible combinations of the values with differen...
Ok, this question has been asked before, but it's still not clear to me. What exactly is internal state? So far state is clear to me: Functions contain behavior, variables have state, values don't. So state typically means the current value or data something like variables contain, simply said, if I'm right. By changin...
Why does this ShapeFactory use conditional statements to determine what object to instantiate. Dont we have to modify ShapeFactory if we want to add other classes in the future? Why doesnt this violate the open closed principle?
In my company we develop medical data-acquisition systems. The main functions of each application are: Interface with data-sampling hardware; Save/load collected data to/from files on disk; Perform mathematical analyses (DSP, image processing) to collected data; Display/plot the information using a graphics-heavy UI; ...
this question looks like How to plan/manage multi-platform (mobile) products but the answers there suggest using abstractions to ensure a common code repo, which is something that we decided not to do. We a have a mobile website and are in the process of building its native mobile equivalents on Android and iOS. Each o...
Since CQRS and DDD do not imply one another I was curious what terms belong to DDD and what terms belong to CQRS. Because the two concepts are so much used together in the literature I usually mix them up. I came up with this list of the terms that I think go to one camp or the other. DDD Domain model Aggregate (and a...
I'm CS student. I am currently attending lectures, where we're taught Objective Analysis and Design. It consists mostly of writing use cases, analysing the problem that we can face when writing some application for the client, and how to design the project so that it's both extensible, clear to developers, and doesn't ...
In a case where multiple variables are set equal to an operation using the result of an other operation, is it best to create a temporary variable for the result of the second operation (this would save memory) or is it best to create a temporary variable for the result of the second operation (this would save time)? F...
There are these relevant questions questions: Strategy for keeping secret info such as API keys out of source control? How do you deal with configuration files in source control? How to version control config files pragmatically? But as far as I can tell, they deal with the opposite side of the problem. So yes, we've...
I have noticed a common issue in code reviews, that takes this form: // "arr" is an array for (i = 0; i < arr.length; ++i) { if (i == 3) { // do something with arr[i] } if (i == 8) { // do something else with arr[i] } } I call this the "array = loop" mindset. Somehow they have in their...
I see the following design in the code which is part of the default web application project in visual studio: A single data model class in constructed and decorated with various data validation annotations. For Example, there's a RegisterViewModel class that looks like this: public class RegisterViewModel { [Requir...
In my company we have this obligatory practice before a review to be send the binary size impact of the code change to be measured and provided. We must use -Os for this metric to avoid unpredictable inlining. There is no customer or product driven arguments for it. It is a big server that is installed as singleton of...
Consider the following contrived program: class Program { static void Main(string[] args) { var myClass = new MyClass(); var stuff = myClass.MyProperty; // this takes 5 seconds var stuff2 = myClass.MyProperty; // this is effectively instantaneous } } class MyClass { private Lazy...
This question has been going round and round in my head since I read the release notes (and other related hype) around React 0.14 - I'm a big fan of React and I think that stateless components (https://facebook.github.io/react/blog/2015/09/10/react-v0.14-rc1.html#stateless-function-components) are an excellent idea, bo...
How do I design code that has two qualities: uses similar but different subtypes of an object uses similar but different types of computation on the above objects Example I am refactoring this from a legacy code that had if/then/else statements for different object types in one file, and if/then/else statements for ...
Say that I have an abstract base class Shape and its derived classes Triangle, Square, etc. Currently I have the following (simplified) structure to fetch a list of Shapes and filter them (mostly using Fluent): public abstract class BaseSearch<T> where T : Shape { protected readonly IRepository<T> repository; ...
I need a recommendation about my software model. I think it is not that good, since there is some kind of cyclic dependency. I have an OSGI bundle under Kura application framework, here are the classes: Main class: the entry point of the bundle TwoWaySerialComm: for serial communication with an Arduino device SerialRe...
I'm starting work a new personal project to send out emails using different email services (like mailchimp, for example). I just started coding and I have a base class called Email: public class Email { private string _to; private string _from; private string _body; private string _templateName; pu...
For the strategy pattern, why do we need a context class to call the appropriate algorithm? Why can't we just do Strategy s = new OperationAdd()? This way, we still use polymorphism.
I'm not sure if this right location for this question, but here it is. I currently have about 30 different CSV or TXT product data feeds. I am trying to build a tool to 1) upload each feed 2) break apart each feed line by line 3) extract every title, category, price, etc. into a product object, and... 4) either create...
What is the optimal architecture for such case: Web application(.Net Web Forms) connects to third party web service via wcf. Third party web service accepts only digitally signed soap requests Some typical business processes consist of several soap requests. User must start business process (send several soap request...
Through the years I've worked in web development it's been ingrained in me that client-side validation is absolutely and completely necessary in all web applications. Seems to me like all the people in the profession are very adamant on using it every single time. The most commonly mentioned benefits are: Instantaneou...
The short version The code As part of TDD, we often end up with functions that follow this pattern: function onSendRequestForSelected() { this.deselectStepsWithRequest(); this.sendRequestForSelected(); } Each of the internally called functions has their own unit tests. The tests Our unit tests for this functio...
I need to represent an abstraction over various parts of the hardware for a game. I'm trying to decouple the code that does things like manage the logic of the game from the code that is API/platform specific or any ugly implementation details. Like this: std::unique_ptr<IDevice> device(CreateDevice()); IGraphicsDevic...
I'm trying to grok streams - my world is C# but I suspect the principles are general. I understand the general principle of reading/writing bytes from/to a store. However, what I don't understand, specifically in a read scenario, is what has happened when you've created an instance of a stream (FileStream, for instanc...
What are the ways of managing the evolving requirements without turning them into a mess? We do not have a dedicated analyst in our team so this role is shared by all the members. Our reoccurring workflow is the following: Users send us the initial version of requirements for new functionality which is then followed b...
At work I bumped into a problem to see how enums are growing and storing business logics. As they grew, the constructors grew a lot. At one point I found out instead of putting in let's say the tenth boolean parameter (and which already had various other parameters than boolean) into the constructor, and expand all the...
I am on an ASP.NET MVC project where we use Razor to define pages. One thing I like to do is to use Razor's @helper to DRY up pretty much any duplication in HTML (i.e. formalize even small UI patterns). To give an example. At the top of the page there are 3 "quick links" buttons at the top of the page, titled A, B and ...
I have a proper SOA architecture, with web services defined with WSDL and responding to SOAP requests. But this application has also an endpoint that responds to json request and replies in json format, so a little bit more like REST. My goal is to transform this application into a sort of platform, exposing an API, a...
React.js provides JSX as an XHTML-like syntax for constructing a tree of components and elements. JSX compiles to Javascript, and instead of providing loops or conditionals in JSX proper, you use Javascript directly: <ul> {list.map((item) => <li>{item}</li> )} </ul> What I haven't been able to explain yet is,...
We are looking to incorporate an open source font which uses the Apache License v2 in our mobile application. I have a couple of questions on proper procedure/etiquette: For a font, does creating an application that incorporates the font count as a derivative work (in other words, do we need to include the Apache licen...
Here's the situation. I have two table (Table 1 and Table 2) with the same entities and a class(ClassA) which was mapped to Table 1 but in some scenario I have to transfer the specific data from Table 1 to Table 2. How can I map the two table (Table 1 and Table 2) to ClassA using Entity Framework Code First?
So this may come off a bit broad and generalized, but after spending some time working around under developers, I've come to notice many different methods and design patterns. However, one big thing that sticks out to me is how mind-bendingly complex some of these relatively simple (logic-wise) classes can get. For exa...