theory

Is there such a thing as a reverse foreign key?

亡梦爱人 提交于 2019-12-12 14:08:11
问题 In MySQL, is there a way to specify that a.column cannot exist in b.column - a reverse foreign key? In other words: # Would not return any rows ever SELECT * FROM a INNER JOIN b ON a.column = b.column; # Would fail INSERT INTO a SELECT * FROM b; # Would not insert any rows INSERT IGNORE INTO a SELECT * FROM b; 回答1: No there is no such thing. You would need to do that in a trigger: DELIMITER $$ CREATE TRIGGER bi_a_each BEFORE INSERT ON a FOR EACH ROW BEGIN DECLARE forbidden_key INTEGER; SELECT

Asynchronous function in a while-loop

强颜欢笑 提交于 2019-12-12 11:53:00
问题 I have a question about how to perform an asynchronous task in a while-loop until some condition is met. This is more of a theoretical question but I can see how this could be an issue in some scenarios. I'll try demonstrate the problem at an example (I'm using JavaScript here, but you can use any language): I could have a device and I want to hold my application until that device has reached a specific state. If the method with which I can getrieve with state of the device is synchronouse,

Can std::function be serialized?

北战南征 提交于 2019-12-12 10:36:07
问题 This is a theoretical question. Say there are some objects which among others contain lists of callback functions subscribed to events of those objects. Now we want to store those objects on disk. Is a std::function serializable? 回答1: No. Whenever using type erasure (ie, hiding implementation details behind an interface), the only operations available without knowing the dynamic type of the object are those provided by the interface. There is no serialization in the C++ Standard, and there is

Dependency Injection Container

北慕城南 提交于 2019-12-12 09:25:44
问题 I have a Data Access Layer library that I would like to make "portable". The reason I like it to be portable is because I want to work with SQL Azure & Azure File Storage (eg, data + pdf reports) as well as Sql Server 2008R2 and File System storage on a concrete server. Based on spec the system is supposed to go live with the later implementation (sql + file system storage), while upon a meeting a certain scalability threshold we plan on moving to Azure. The data access class I use implements

A method to calculate the centre of mass from a .stl (stereo lithography) file?

…衆ロ難τιáo~ 提交于 2019-12-12 08:01:17
问题 I am trying to calculate the centre of mass (x,y,z) coordinates of an object defined in an STL file (stereo lithography, not to be confused with the standard template library). The STL file contains a closed object (or objects) defined by a boundary made of triangles. The triangles themselves are not necessarily in any order, the file is simply the coordinates 3 vertices of each triangle floating in 3D space plus a normal vector to the triangle (the normal should be disregarded as it is not

Limiting upload speed on Java?

三世轮回 提交于 2019-12-12 07:14:26
问题 I'd like to programmatically limit an upload or download operation in Java. I would assume that all I'd need to do was do check how fast the upload is going and insert Thread.sleep() accordingly like so: while (file.hasMoreLines()) { String line = file.readLine(); for (int i = 0; i < line.length(); i+=128) { outputStream.writeBytes(line.substr(i, i+128).getBytes()); if (isHittingLimit()) Thread.sleep(500); } } Will the above code work? If not, is there a better way to do this? Is there a

Storing Images in DB - Yea or Nay?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 05:38:47
问题 Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. So I'm using an app that stores images heavily in the DB. What's your outlook on this? I'm more of a type to store the location in the filesystem, than store it directly in the DB. What do you think are the pros/cons? 回答1: I'm in charge of some applications that manage many TB of images. We've found that storing file

Finding Faces in a Geometric Directed Graph

有些话、适合烂在心里 提交于 2019-12-12 04:07:58
问题 I'm confronted with a rather unusual problem dealing with an directed geometric graph. Imagine the graph being borders of countries. I'm looking for a way to find the faces. My graph consists of directed edges which may form cycles (but not necessarily). What I am looking for are the left and right faces as well as the predecessors and successors of the left and right faces for each edge. Each face should be constructed anti-clockwise, meaning that the left face of an edge is always inside

Why doesn't strict mode restrict the identifiers “eval”, and “arguments” from appearing as label names?

走远了吗. 提交于 2019-12-12 03:46:01
问题 So, as you may know, the strict mode of JavaScript adds restrictions on the identifiers eval , and arguments , effectively making them reserved words, with two exceptions: they can still be uses as expressions, i.e. in places where an expression is expected (with a couple of exceptions, though), they can still be used as label names, and in break / continue statements to reference labels. Now, I understand the first bullet. If, for instance, the identifier eval wasn't allowed as an expression

Parse Tree Of Context Free Grammar

馋奶兔 提交于 2019-12-11 20:26:08
问题 I'm trying to figure out how to do parse trees correctly to show whether a grammar is ambiguous or not. my grammar is S -> xSy | ySx | SS | e any help would be great. thanks in advance below is my crack at it... S / \ / \ x y / \ / \ x x y y 回答1: As a hint, pretty much any grammar with a production of the form S → SS will be ambiguous, because if you want to produce three S nonterminals you can do so in two ways: S S / \ / \ S S S S / \ / \ S S S S Assuming those S's can actually produce