instruction stringlengths 34 36.1k |
|---|
I've got a simple example of using a fluent interface to attach events in JavaScript
function attach(fn){
let handler,to;
handler = fn;
attach.to = function (el) {
to = document.getElementById(el);
return attach;
}
attach.on = function (type) {
to.addEventListener(type,fn);
return attach;
}
... |
Trying this again but with a slightly different approach. My previous thread was here Can anyone explain this one-to-one, one-to-many, many-to-one, many-to-many concept with respect to ORMs? but honestly I think it confused me more than it helped, especially when there seemed to be conflicting views even among the answ... |
I've forked a Github repo and added an upstream remote as described here. I expect to make some backward-compatible bug fixes for which I'd like to submit upstream pull requests, as well as some major non-backward-compatible changes. This question is about how to manage both of those things in one repo, or whether th... |
Is there a possible test to check if a PDF file contains text or it is created by scanning paper sheets ?
text : plain text that, for example, I can copy & paste while I am reading the PDF. Not searchable / hidden text. Created for example from a wordprocessor.
not text : PDF from scanners, containing only JPG or TIFF... |
As an example, in Python I have a lowest_prime_factor function which does it exactly what it says it does. Then, in another function, I need to call this function and store it. In another language where variables and functions can share names then I would simply do lowest_prime_factor = lowest_prime_factor(n). In Pytho... |
Say I wrote a program containing 3 methods. Each method was 100 lines. Method 1 was main(), and Method 2 was called by main().
I then duplicated the program into an identical second program. After duplicating it, I added 4900 lines to Method 3.
Method 3 is never called by either program.
Program 1 has a file size of 3.... |
which is the more efficient approach to print the reverse of an array of integers in Java:
First Approach:
int length=array.length;
for(int j=length-1;j>=0;j--)
{
System.out.print(arr[j]);
}
Second Approach:
List<Integer> listInteger = Arrays.asList(array);
Collections.reverse(listInteger);
int length=listInteger.s... |
We have an existing implementation where all users belong to an organisation will depend on the organisation subscription, so if the subscription has ended all users belong to this organisation will not be able to access our web application. They won't be able to login due to expired subscription.
Sample DB Schema for ... |
If class A has many of class B and class B has many of class A, should we place a diamond on both sides of the line between them?
Like in the picture below, or is it fine to just indicate the amount in both directions and have the diamond only on one side?
|
Suppose that I have a project written in JS via such frameworks like Node.js and Express. It also uses Mocha as a test framework and Gulp as a build system.
I wonder what is the best way to expose installation, testing and deployment to users.
I mean, users typically have to do the following stuff:
Install Node.js and... |
I have an open-source project which requires me to create mathematical models to compute some things. I have to analyze some data to decide which model works well and determine the range of errors produced by the model.
I want to document this analysis, but I don't want to put it directly in the code because:
It can b... |
I have a function, let's call it test. This function has arguments, but I don't know how many arguments it has. It returns always a Boolean.
I have another function, let's call it calibrator. This calibrator function gets the possible alternatives of the test arguments in a 2d array. Every argument can have many altern... |
I am trying to write a simple live sine wave generator from scratch in Qt.
I try not to use any external APIs like ASIO or VST. And I want to generate new audio while playing. (As opposed to the Qt example, it just repeats some samples)
Qt only gives you a QIODevice that you write data to at a fixed sample rate.
(If th... |
I'm programming on a c project and use code from another author. I change the main functionality to a new, complete other one. The most of the new code is my own but some files are untouched and others are modified.
Every file of the other author begins like this:
/*
* Copyright (C) 2005 - authors name <authors_name@ho... |
Let's consider these four functions:
# Racket
(define (square x) (* x x))
(define (sqr a) (* a a))
# Javascript
function square(x) {
return x * x
}
function sqr(y) {
return y * y
}
All functions square the given number but in different languages or with different naming. Output of calling any of them is always ... |
Any libraries, API, or tips are welcome. I am trying to draw Landsat 8 images using Canvas utility of Javascript on my browser. The grayscale reflectance values for Landsat 8 bands are from minimum -32768 and maximum +32767(int16). The Canvas utility offers RGBA for range 0-255. If I scale (-32768, 32767) range to (0,2... |
I started to rewrite very monstrous (and old) web application. It runs on PHP 5.3, the design is completely mad - Models and Viewers, no controllers etc. I have been able to refactor the code to work with PHP 7, bend the autoloader to start using Composer and I want to start refactoring the core.
What I basically need ... |
I'm creating A Map like Travian on Xamarin forms
My map is something like 5000*5000
The way I want to do that is to load part of the map (21*21) of the big map where the current village is the center of the 21*21 map but show a 7*7 map to user(Again current village center of it)
So when user scrolls the map, can see t... |
In traditional Rail app, we need to deal with controller/model/action and has a view that generate HTML output. Now
There are many JS framework like backbone/react that allow us to code client side that consume API very easily.
And our webapp might also provide APIs for public to use.
I am thinking, instead of codin... |
I have two existing tables called VehiclePlants and VehicleModels.
Right now, the VehicleModels are linked to a possible multiple of VehiclePlants
The customer wants this changed to be just a one-to-one relationship.
My question:
When I add this column VehiclePlantId to the VehicleModels, knowing that this has to be ch... |
It looks like there's a problem with our deploy process where old versions of our service are being deployed to certain clusters, but it's hard to tell exactly what's wrong, since all we have as data points are occasionally failing tests which suggest bugs that were fixed in previous builds.
In order to keep an eye on... |
With in the introduction of anonymous types in C# we got the var keyword.
Now people use var everywhere instead of the correct type. The reasons I've heard given for this are:
It makes refactoring easier
It's shorter
it improves readability
A common example might be
var result = client.GetResult(query);
is better th... |
I have created one utility module which converts one file format to another one. File i.e. test.abc will be converted to i.e. test.pqr and internal format of files are totally different. This module involves nearly 5 different file formats.
Internally, it uses one native tool and I do not have any control over it. It ... |
I've started to learn about approaches to integration testing in big enterprise applications (java based, spring, and everything :) ).
So I saw two main approaches:
Running parts of spring context substituting real data parts with in-memory implementation. A drawback of such an approach I guess is that its very hard t... |
I was watching this video about the CAP theorem, where the author explains well the trade-offs of distributed systems. However I disagree with the CAP theorem in the following aspect. Given the picture below:
Whenever there is a partition, in other words, whenever a slave loses its connection to the master, this slave... |
My team is using SVN to store a lot more than just source code - we are storing all kinds of files. A process I'm working on designing is used to generate diff reports whenever a certain Excel spreadsheet is updated and acknowledged by a subset of the team. (This spreadsheet is automatically generated by a separate pro... |
Trying to understand strings better in C#
Are these assertions correct?
string is immutable
string is reference type but behaves like value type
For these code samples...
string x = "one"
(creates string instance holding "one" in memory)
x = "two"
(destroys "one" instance and creates new string instance holdi... |
My understanding is that the system below can accomplish consistency, availability and partition tolerance. So I must be misinterpreting some aspect of the CAP theorem. How come?
Let's say I have a distributed system with 100 redundant nodes: 50 in a datacenter in the US and 50 in a datacenter in Europe. These two data... |
I have 3 billion strings. I want to make a frequency map so I can discard strings that occur fewer than 100 times or more than 100,000 times. What kind of data structure(s) should I use? I'm thinking some kind of bloom filter.
|
Looking at DB tables created by a different developer I have noticed that whenever a table had a forein_key_id field/column, it was always an INDEX/KEY.
I am not sure if it was manually created, or automatically by some 3rd party software. However, I myself usually created keys using different principles. i.e. Just ... |
I understand that CSS only supports multi-line comments like such
/* foobar */
Why is there not support for single line comments.
// foobar
They are just as common in programming and seems particularly useful for a language like CSS where each rule is on it's own line.
If there was no particular historical reason for... |
My code takes 2 dates and finds the age of those dates in days. In my daysBetweenDates method the instructor uses an assert statement:
assert not dateIsBefore(year2, month2, day2, year1, month1, day1)
My question is, why do you have to use 'assert not' in this example and in the signature why is year2, month2, day2 fi... |
Say I have a program where a user is presented with a treeview of multiple directories and must check desired file/directories that they would like to later be copied.
That aside once the user has selected the files how can I go about creating a separate executable after a button is clicked that will perform the copy o... |
I was reading on the TypeScript site and saw that the TypeScript compiler is itself written in TypeScript. "The TypeScript compiler is implemented in TypeScript and can be used in any JavaScript host." I don't understand how this can work, wouldn't that create a circular dependency? Chicken-and-egg-scenario? was the f... |
In C, * is called the indirection operator or the dereference operator. I understand how it works when it is used in a statement. It makes sense to write *p or * p, considering that it is a unary operator.
However, sometimes in a declaration, a * is used.
void move(int *units) { ... }
or
int *p = &x;
It seems strange... |
I have a sorted list , lets say 1, 6 , 10 ,15 ,16 , 18, 30, 50.
How do I find first three items which are in the less than interval of n, say 3.
For example in the above list, 15, 16 and 18 is the answer. Is it possible to get to this in better than O(n) ?
|
I am new to the token concept of Authorization.
I am developing angular app which calls the Web API built with asp.net core. I am currently using JWT(JSON web Token) to authorize the users. These tokens are issued after login and sent in authorization headers on every request. The tokens last for 30 minutes. Now the pr... |
I have few classes which used System.out.println (which should be avoided) and now I am trying to move those into a logger.
We already have been using logger in some other modules. But the module I'm working haven't used it anywhere. So, I thought to create a new common class & put a new entry in logback.xml file for t... |
I am developing an application that has a lot of options like local database CRUD operations, file IO, web APIs calling, notifications, user preference settings, services, widgets etc.
At start it seemed no problem to work with classes, now reaching 50% app completion, I see 20+ classes in my app (all code documented/f... |
I'm discovering craftsmanship and trying to learn it, and I decided first to understand how to work with the SOLID principles.
I'm actually facing some troubles while dealing with the Open/Closed principle.
How I'm working
In fact, I'm usually building applications like the following:
Presentation layer with Angular
B... |
We have a more or less "typical" ReST API that allows clients to interact with a bunch of resources, let's say Maps and Devices. An authenticated client can get a list of maps, it can download a map, upload a map and do similar things with devices.
Currently the resources have URIs that are modeled something like this:... |
I have a hard time understanding when the Single Responsibility Principle is correctly used. Consider the following code:
// --------------------------------------------------------------------------------------------------
void CTCPClient::Try_Send_Data(const char *Outgoing_Message)
// --------------------------------... |
I am developing an online medical website (similar to a HIS) whose users are hospitals specifically hospital administrators, doctors, and other staff authorized by the hospital to use the system. There are many hospitals that would use the website.
There is a feature in my website where the authorized user is able to ... |
Uncle Bob's chapter on names in Clean Code recommends that you avoid encodings in names, mainly regarding Hungarian notation. He also specifically mentions removing the I prefix from interfaces, but doesn't show examples of this.
Let's assume the following:
Interface usage is mainly to achieve testability through depe... |
Citing JUnits homepage: "JUnit is a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks."
According to a the answer of this question: Library vs. framework vs API?, a framework is "a collection of patterns and libraries to help with building an application... |
I use perf to profile my application. To make interpretation of the resulting call graph easier, I partitioned my core loops using label functions like maptable_appendRange that can be easily searched for in the call graph. Unfortunately, these functions are mostly inlined by the optimizer and therefore do not show up ... |
Suppose I have 3 domain events, Event1 Event2 and Event3. When command arrives at my Service Layer, I can rise 2 commands at the same time - e.g. Event1 and Event2. One Class has event listener for both events, but it should basically wait until both events are received to start processing it. Otherwise I need to execu... |
I want to ask for any suggestions for an architecture I can implement for a Java app I need to create (initial thoughts below).
It is supposed to be a local Swing application for tracking financial aspects of multiple construction sites. Excel-like but with a few additional features like mailing data etc.
After some th... |
So, we have a problem. I googled to find if it was a solved problem, and found a link describing an algorithm which is just about what we need. They also included a sample implementation. Just, not a std:: or boost:: library, like I was hoping for.
Copying and pasting is of course dangerous in itself, and of course mi... |
Simple question: is the result of a slope calculation in Python (say, stats.linregress() function) in units of radians, or unitless (e.g. what's 18 deg or 0.314 rad would be equivalent to 0.2 in the function output)?
|
Given a password, I am trying to validate if it passes all validation rules such as
Be at least 6 characters long
Contain at least one letter (a-z or A-Z)
Contain at least one number (0-9)
Contain at least one special character (@, $, %, etc)
So I am creating a common validation class which can be used for in an... |
I use an online kanban-board for my projects. Even though I work mostly alone, it helps me keep track of what would otherwise be an Alexandran Library of post-it notes. While I'm sure my process is pretty far away from actual kanban/scrum, I try to keep my process similar where possible, as it helps me avoid process de... |
I am working in a team, which is developing new web applications versions for our old solutions, but there are some innovative ideas as well. We are using Angular at the front end, Java at the back end, MongoDB for database and running it via Spring Boot.
At the current stage, we have two applications finished, and mor... |
I have a web application with medium-high traffic where users can save designs made by fabricjs, so each saved design is a json with many parameters.
So basically two days after launch users have stored almost 300 rows of designs, PhpMyAdmin says a total of 31 MB of size.
Each json is stored as a longtext data type so ... |
I'm developing an Java Web Application with Spring, and I have some questions about my architecture. Before showing it, here is the context:
I am developing a web application with more than 80 existing tables
in the database.
Both the application and the database are on the same server machine.
My application will gro... |
I would like to hear opinions/best practices for the following scenario:
I have an application A (C# app from a vendor that does not have an accessible database, it has a sqllite db but we don't have access to it) that needs to export small amounts of data to application B (custom C# homegrown app with a SQL Server Bac... |
Hypothetical situation - can a currying function have an unknown number of arguments (kind of like varargs)
Eg in Python:
addByCurrying(1)(2)(3)(4)
Should equal 10
addByCurrying(5)(6)
Should equal 11
How could I implement it?
|
Is there any standard/encouraged Windows batch file coding style?
I would think that if I want my batch files to be easy to read/mantain, I should care about this, but searching the web I found very little about it, and I didn't get any reviews (not even comments) on this Code Review question, so it makes me wonder if... |
We do simple data entry validation with attributes on the viewmodel. Think format of an email address, mandatory clientname, format of a date, the housenumber being numeric etc.
Now there are also more complex validations which will hit the database and external services: check if the id is a valid one (external servic... |
Suppose you are designing today a JavaEE JSF web application. You have a choice on the one hand between making the methods of your CDI beans @Transactional, and on the other hand injecting (session stateless, or singleton) EJBs in the CDI beans, and then the methods of EJBs would be executed under CMT transactions. Wha... |
This might sound weird and probably is, but I am struggling to find a good place where to place what I will just call "Doers" for lack of a better name.
Basically, my project currently has these Namespaces (Folders in src)
/
/Error (Custom exception classes)
/Facade (Facades for legacy operations of things not yet conv... |
So, as stated on wikipedia:
Lustre is a formally defined, declarative, and synchronous dataflow
programming language for programming reactive systems. It began as a
research project in the early 1980s. A formal presentation of the
language can be found in the 1991 Proceedings of the IEEE. In 1993 it
progressed... |
I am currently developing my own programming language (written in Lua). The text analyzer is composed of two functions: lexer and parser.
lexer takes as input a string, cycles over each character of it and divides it in tokens, either single words, numbers, strings, or symbols. It then returns an array of them.
parser ... |
I'm working with a Blue Giga BLE112 usb dongle. They supply an API in the form of several header & *.c files. It all works off of callbacks. For example.
int main()
{
// defined in a "cmd_def.h" & implemented in "cmd_def.c"
ble_cmd_connection_get_status();
// read messages off the usb serial port forever
... |
I define an algorithm to be best if it minimizes the total run time over commodity hardware (e.g. normal desktop and server PCs).
I have sets A and B. I also have function f that works like f(a, b, n), where a is some item in A, b is some item in B, and n is some natural number. The output that this f(a, b, n) returns ... |
At first, I thought that the people writing the code should also document it. But there are reasons why this might not be true. A person who is new to the code could ask the right questions which might be dismissed as "obvious" by the author.
My question is if there is an established practice (or practices), and what i... |
Let's say you implement an interface like:
public interface Example {
InputStream getThatContent();
}
In this case there is no property, and the implementation may also have side effects (it can open a new InputStream).
This is happening also in other API, like JDBC:
public static Connection getConnection(String url... |
The page is loaded as a normal MVC page. The ajax is so the user can add items to their model without having to reload the page.
Right now there is no Web API in the project. I don't want to add it unless it makes sense but I'm worried that using AJAX on an MVC controller is bad.
All the books I've read and at work we ... |
I'm studying the SOLID principles and I'm having some troubles dealing with the Specification Pattern and the open/closed principle.
The fact is that the Specification pattern introduced by Eric Evans and Martin Fowlers creates some abstraction and a really open way to manage business rules.
But I was wondering if it ... |
I have been pondering over the idea of a Python-based Operating System on top of the Linux kernel, much like how Android uses Java.
What if most of the system components were built using Python, this way most of the Operating System can be modified by anybody who understands Python code. This can allow anybody with Pyt... |
Say that I have a REST endpoint that takes an integer as a parameter:
/makeWaffles?numberOfWaffles=3
In this case, I want the number to be positive because I can't make a negative number of waffles (and requesting 0 waffles is a waste of time). So I want to reject any request that does not contain a positive integer. ... |
As I begin to make the leap from the Firefox Selenium IDE to Selenium 2, I'm realizing that a significant portion of tutorials, guides, books, and documentation regarding WebDriver is based in Java; C# seems to take a somewhat close second.
Is there a benefit to one language (C#, Java, Python, Ruby) over the
other?
D... |
Can anyone give me some insight in what happens to traditional release management when an entire enterprise moves into agile?
for example, lets say an enterprise operates in a waterfall method, does one big release a month and the systems are tightly integrated.
lets say the enterprise moves to agile and the dev teams ... |
Gosling said that "[C# is] sort of Java with reliability, productivity and security deleted." (from Wikipedia)
|
We are using gitflow and currently have an open release branch.
The release at A is currently on the test-system to get tested by key-users. In the meantime we need to release an urgent hotfix. Commonly we pull out a branch of master (so the latest live-system release) and merge it into development and master. If we ... |
I'm thinking about the right database design for this requirement.
It's a manual maintenance check. A company can have a maintenance contract comprising HW checks, Sys checks, both or none. The part with the CommandParameters worries me especially. The amount/name of the commands can be changed after a while, furtherm... |
I'm would like to know your opinion of what is an ideomatic way writing a OR function in functional reactive programming.
That is, if I have x number of signals which can return a truthy or falsy value, how can I evaluate if at least one signal is truthy, or all signals are falsy? Finally I would like to send the resu... |
A comment on a previous answer made me think about our hotfix policy. A current project for example is used by about 300 users all around the globe. One location found a strange bug where they issued a specific number into a combobox. That resulted in a complete server error (the session was reset with a 500 http error... |
Is there a convenient and sustainable way to handle code indentation and style in a team in which multiple IDE's (Emacs, XCode, VS) are used by different programmers?
We are using git, so, should we use a precommit hook or should we integrate the auto-formater into the IDE of each developer directly? I think the first... |
I have always known that goto is something bad, locked in a basement somewhere never to be seen for good but I ran into a code example today that makes perfect sense to use goto.
I have an IP where I need to check if is within a list of IPs and then proceed with the code, otherwise throw an exception.
<?php
$ip = '192... |
The basic arithmetic a computer chip can do only works on numbers(integers or floating point) of a fixed size.
There are many algorithms that could be extended to work on numbers of arbitrary size (and some require them). Therefore, a way to store and perform arithmetic with arbitrary-size numbers is good to have.
For... |
I'm trying to learn the language Inform 7 and its very odd programming model.
Unfortunately I'm finding it hard to get my head around it because the language reads so much like natural English. I can't seem to intuitively understand what natural English statements are and aren't valid statements within the grammar.
Ha... |
I've got some code that's searching pixel by pixel from a starting point, at a certain angle, until it finds a pixel (a non-white pixel)
It only has to search around 300 pixels: I'm currently using polar to Cartesian function 300 times...
def pol2cart(rotdist, cwangle):
x = rotdist * numpy.cos(cwangle)
y = rotd... |
These days I'm learning CSS by reading specifications, but I noticed W3C marked CSS Basic Box Model Level 3 as "Dangerously outdated" without any further explanation.
So my question:
What's the reason for considering that specification outdated?
Why CSS3 Box Model is Outdated but CSS2.1 box model is not outdated(beca... |
One of the important concepts in Object Oriented Programming is Encapsulation. However, lately the software world seems to be tilting in favour of other paradigms like functional programming.
It makes me think, what about encapsulation and other OOP tenets? Are they wrong?
Is it that OOP is applied wrong? For instance ... |
I am currently facing a problem in the application I am developing that I think is the same as, or an analogue of, the Dining Philosophers Problem.
In my application I have a list of N resources. I also have a queue of tasks that need a number from 1 to N of these resources to run (which are continually generated at un... |
Lets say that our Tetris board is represented as a 2D array of zeros and ones, where a 0 means empty and 1 means occupied, and you where asked to find the highest row in which a tetromino exists.
Assuming that we didn't keep track of the height that is for every tetramino placed check if its row is > previously placed... |
I stumbled across an API from a popular vendor in my sector that asks the client to dynamically determine the max records allowed in a single POST request by first performing a GET request and retrieving a property called MaxRequestSize. The idea is that the client is to use this property to split up their records and ... |
Suppose you have a very simple CRUD where you are just storing a simple tuple-like type of data, but its natural primary key is cumbersome for the user to remember (very long, difficult to write, etc.). Further, suppose I want to let users refer to the records using a handle such as an autoincremented integer value (wh... |
Assume you have a client application which is known to connect to a given IP, and send a fixed size message (of size X = ~dozen bytes) upon connection, and wait for a reply.
If you're writing a server, can you guarantee that the first (non-EAGAIN) call to read() (assuming no errors) on the (non-blocking) socket after t... |
Our team develops an application. As this application intended to run on Debian, we've done it in a proper Debian way - via .deb packages. This app is written in C++/Python and versioned using Git.
We have a private Debian repo where I place snapshot and release versions (approach taken from Java world):
appname-1.2-S... |
Python has many modules (such as re) that perform a specific set of actions. You can call the functions of this module and get results, and the module as a whole has an idea behind it (in this case, dealing with regular expressions).
Classes seem to do almost the exact same thing, but they also seem to use properties q... |
We are building a REST API which creates items in a CDN. Each item takes between 5 and 7 seconds to create, and we need to create them as quickly as possible until we have about a million of them.
One school of thought in our office is that we should make lots of small transactions. Another is that we should have f... |
I've got a problem and I haven't yet found an explained solution to get it drilled into my head:
I want my object to make a basic rotation TOWARDS the mouse cursor, not the lock-on.
I know it must be embarrassingly easy since there's not many threads documenting this, yet I'm loosing my mind when seeing (wantedAngle-ob... |
I wrote a small program, about 10,500 lines and everything works perfectly.
It is a Math game, which has is login and sign-up process and all data is stored on the user's computer in multiple text files. It has support for multiple users.
I wrote a function which allows the user to search for another user in the datab... |
I have a Java application which does the following:
Tool takes a document which it will parse.
Tool calls external webservice
Tool completes execution
However, when I tried to run this application in two different 'environments', there is a huge gap between the performance of the tool. On the first environment, it ta... |
In language Swift, to initialise an instance, one has to fill in all of the fields of that class, and only then call superconstructor:
class Base {
var name: String
init(name: String) {
self.name = name
}
}
class Derived: Base {
var number: Int
init(name: String, number: Int) {
//... |
I have a method called Buy, when called it does the following:
It calls a factory to create an order
Calls pay on a payment object
Calls empty on the customer's cart
Calls the dao to save the order
This is what my sequence diagram says should happen, however, when I write my unit test for testing that it calls Empty... |
So I am facing a problem with handling all sorts of exceptions within spring-boot application. Basically project is structured:
back-end (services, repositories) <----- RestControllers <---- UI (React\Angular)
The gist is that UI depends on Rest API wile rest API depends on Back-end services
Now - Rest API is designed ... |
I am building Rest APIs for an iPhone app using the PHP framework CodeIgniter. Please let me know how I can ensure that the API is accessible via the app only. This means that if anyone wants to access the APIs from outside the app, it should not be accessible.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.