architecture – TransactionScope in DAO or in BLL (Business Logic Layer)?

I’ve been working with Entity Framework, Repositories, Unit of Work, DDD, CQRS…

But I have an different challenge now…my company is working in the below architecture:

Contrllers -> BLL (Business Logic Layer) -> DAO with raw sql connection…

I have to insert a Customer with many dependents. I have a DAO for Customer and another for Dependent. So, I will insert in two tables…

I now how to use TransactionScope, how it works…But…what’s the best practice? Using TransactionScope in Business Layer? In DAO?

I have CustomerDAO, CustomerBO…where should I put the transaction scope? some people say to create a service class, but is it the same of CustomerBO?

Texas hold’em game logic loop

Ok, so I was thinking of making a Texas Hold’em game, and I wanted to write down the game logic loop before starting. Here’s what I have. Tell me if I missed anything or if anything is wrong.

  1. Game sets or determines the number of players.
  2. Game hands out 2 cards to each players.
  3. Game takes a minimum amount of tokens from each player
  4. Game lets players fold, play, or raise
  5. If someone raise, the game let’s other players fold or play, and then loop through the players who decided to play, but haven’t put in the amount of required tokens.
  • If someone goes all in and one other person accepts, then the cards
    of both players are shown.
  1. Game draws 3 random cards and show it to the players.
  2. Steps 4 to 5 are repeated to the player who didn’t fold.
  3. Game draws 1 more card and show it to the players
  4. Steps 4 to 5 are repeated to the players who didn’t fold.
  5. Game draws 1 more card and show it to the players.
  6. One player wins the lot
  7. Repeat until one player is left.

Is this the correct loop? Is there anything to add or modify? Can you make this clearer?

javascript – Rewrite to use only promise-generating asynchronous operations and use only promises for logic flow and avoid setTimeout

The current code in the question is working code that already accomplishes the objective, but I would like to solicit ways to make it “better” code.

The code is to upload large files from Node.js to OneDrive, is based in code that I found here:

Upload large files from Node.js to OneDrive

I made a reduce version of the code to avoid the need of a token to explain my issue, and also use npm got package instead of npm request package because this last has been deprecated.

The code has a simulated server version where files are uploaded an a client.

The server application running in http://localhost:5000 is as follow:

const express = require('express');
const app = express();

app.put('/', function (req, res) { // PUT http://localhost:5000
     const rawHeaders = req.rawHeaders
     const bytesElement = rawHeaders(5)

     console.log(bytesElement)

     if(bytesElement === 'bytes 62914559-68663828/68663829'){
          res.send('Finish Uploading Data')
      }
})

 const port = 5000
 app.listen(port, () => console.log(`Listening port: ${port}`))

The client version that works ok is as follow:

const fs = require('fs');
const got = require('got');
const async = require('async');

const file = "./video.mp4"; 

function resUpload(){
   const uploadUrl = 'http://localhost:5000'
   uploadFile(uploadUrl);
}


function uploadFile(uploadUrl) {  
    const params = (
           {bstart: 0, bend: 62914558, cr: 'bytes 0-62914558/68663829', clen: 62914559, stime: 10000},
           {bstart: 62914559, bend: 68663828, cr: 'bytes 62914559-68663828/68663829', clen: 5749270, stime: 10000}
)

 async.eachSeries(params, function(st, callback){
    setTimeout(async function() {  

         fs.readFile(file,  async function read(e, f) {
             try {
                 const response = await got({ 
                     method: 'PUT',
                     url: uploadUrl,
                     headers: {
                         'Content-Length': st.clen,
                         'Content-Range': st.cr,
                     },
                       body: f.slice(st.bstart, st.bend + 1)}
                     );

                 console.log(response.body); // Finish Uploading Data
             } catch (error) {
                 console.log(error)
             }    
         });

       callback();  
  
     }, st.stime);
 });
}

 resUpload();

Thank jfriend00 for yours answers to my original question,
based on them I rephrase my initial question to:

Who could this code be rewrite using only promise-generating asynchronous operations and using only promises for logic flow and also avoiding the use of the setTimeout (Because is just an attempt to work around some other problem too)?

undecidability – Does Rice’s theorem apply to sequential logic circuits?

I am wondering if Rice’s theorem (or something similar to that) applies also to sequential circuits. I.e. given any finite sequential circuit, can there be an algorithm that can formally verify any property of this circuit? I’m thinking yes, because the number of latches is bounded, so is the number of states. Even if the input is unbounded, at some point you have to arrive at a state that you’ve already seen before.

What are the limits of model-checking sequential circuits?

javascript – Good ways to prevent client side logic duplication without HATEOAS?

I know HATEOAS can be a bit of a heated topic. Some people like it, some people don’t. That is not what I want to discuss.

What I want to discuss is what technology other than HATEOAS (or some form of telling the client what can be done with an entity) can be used to prevent the client from writing the same logic that the API has. And this is perhaps subjective, but it seems to me that I see a lot of (web)apps that have the same entity logic on the client and server and I don’t understand why.

In this case I would like to propose that the client is a SPA to indicate that the server can’t render the page differently based on the state of an entity; the SPA has to do this.

For example:

Let’s say we have a Blog entity which has a list of Comment entities. Let’s say that adding a comment is no longer allowed when the Archived property of the Blog is set to true. Let’s also say that adding a comment is not allowed when the amount of Comments is 100 or more. We also say that adding a comment is not allowed when the user is not logged in.

At my workplace we use HATEOAS for this. We don’t really use the URLs that the API returns (you might even say we don’t use it 100% correctly?); it’s mostly about the links that are returned which are really useful for us. For example, let’s say this is a Blog returned from api/blogs/3

{
  "id": 3,
  "title": "Why StackExchange is great!",
  "text": "Lorem Ipsum",
  "archived": false,
  "comments": (
    {
      "id": 1,
      "user": "john@example.org",
      "text": "Great post, man!",
      "links": (
        {
          "rel": "delete",
          "href": "api/blogs/3/comments/1",
          "method": "DELETE"
        }
      )
    }
  ),
  links: (
    {
       "rel": "addComment",
       "url": "api/blogs/3/comments",
       "method": "POST"
    }
  )
}

This makes it very easy for our client to decide if it should render a “add comment” button! If we can find a HATEOAS link where the rel is addComment, we do so. The API can even take care of the authorization for us. If the user that performed the request is not logged in, the link also won’t be returned. Same goes for deleting a comment, I think you get the point! 🙂


The great benefit in my eyes is that we don’t need to write the logic twice in the front-end and back-end. I think it speaks for itself, but this has several benefits as well for example less code, fewer (complicated) unit tests, and a smaller bundle size.

If in the future a blog is allowed to get new comments until there are 200 comments instead of 100, ideally we would only need to change code in our Blog entity (or, less broadly speaking, the server) and no changes to the/any client(s) would need to be made, tested, or deployed!

What are your views on this? Are there other/better standard technologies/ways to prevent duplicate logic?

Thanks!

logic – Does any finite L-Structure has its k-catecory theory? (where k is of course the structure’s cardinality)

How to show that for any finite language L and finite L-structure A, there is an L-sentence b, such that for all L-structure B, $Bmodels b iff Bcong A$?

I searched for many first-order logic notes but didn’t find anything to make this seems solvable.

reference request – Where are good sources for correspondences in relevant logic?

Relevant logics for entailment have correspondences for a ternary relation $textit{R}$ such that $M,avDash (Ato B)$ just if $forall b, c(M,bvDash A Rightarrow M,cvDash B)$.

Various conditions upon $textit{R}$ correspond with, or induce axioms for $to$. Some examples are stated in the following Wikipedia article Relevance logic; as an example, $textit{R}aaa$ induces the axiom $(Awedge(Ato B))to B$.

Where may I find more correspondences, in order to identify the conditions we need upon $textit{R}$ to obtain the modal logic identified as $textit{TW}$ in (Relevance logic)?1

mysql – Understand the underlying logic of Sakila DB

I’m working with Sakila database, trying to find which film is instock in store 1. However, before going to the syntax, I have basic question about the database first.

  1. If a movie is rented out, I think it’s captured in the rental Table. However, if it has been returned, would it be captured in rental table or will be deleted?
  • If it’s captured in ‘rental table’, then how do we know which movie has been returned and which movie has not been returned? I just observe the table, and it looks like the ‘return date’ are all BEFORE ‘last update’. does that mean all movies have been returned? (refer to the picture)
  • If it is NOT captured in ‘rental table’, then which Syntax does the job of ‘deleting the record’?
  1. What are these syntax for? (Rental table) what does KEY for?
    KEY idx_fk_inventory_id (inventory_id),
    KEY idx_fk_customer_id (customer_id),
    KEY idx_fk_staff_id (staff_id),

Thanks so much

enter image description here