Algorithm for detecting overlaps

This is a real-world application, not a student assignment.

Suppose a list of events of that have startTime and endTime, and some overlap information. In pseudocode:

class Event {     Time startTime;     Time endTime;     bool overlapsStart;     bool overlapsEnd; } 

Events are considered overlaping if and only if their times intersect, but it’s not considered overlap if some event just “touches” another (starts exactly when some other finishes).

There are two types of event: NormalEvent and EmptyEvent.


What I want?

For each event in the list, I want to:

1) Remove all EmptyEvents that overlap another event of any type. In special, if some EmptyEvent overlaps another EmptyEvent, only one needs to be removed, so that the overlap ceases.

2) The NormalEvents are first ordered by startTime, and then their booleans are set:

  • overlapsStart is true if the event overlaps some event that comes before it.

  • overlapsEnd is true if the event overlaps some event that comes after it.


A trivial example:

event1 = 6:00AM ➜ 8:00AM  

and

event2 = 7:00AM ➜ 9:00AM 

then:

event1.overlapsStart == false event1.overlapsEnd == true  event2.overlapsStart == true event2.overlapsEnd == false 

Another example:

Now, this is what happens if some event “contains” another:

event1 = 6:00AM ➜ 9:00AM  

and

event2 = 7:00AM ➜ 8:00AM 

then, first event1 is put before event2, since it starts before. Then:

event1.overlapsStart == false event1.overlapsEnd == true  event2.overlapsStart == true event2.overlapsEnd == false 

Naive implementation: I could analyze each event in turn, one by one, looking at all other events. That’s easy, however this is too slow for a large number of events.

My question: What’s an efficient way of solving this?

Monitoring and detecting AdSense issues on your site

Our Ads Monitor service can continuously track AdSense ads displayed on your site and timely inform you of potential revenue affecting issues.

It works with the Ads Monitor agent that periodically visits your site as a regular user from a desktop or a mobile device and captures displayed ads. The service analyses the ads and reports to you in a convenient daily or weekly email digest. On the Ads Monitor site you can review the ads for any time period and…

Monitoring and detecting AdSense issues on your site

Monitoring and detecting AdSense issues on your site

Our Ads Monitor service can continuously track AdSense ads displayed on your site and timely inform you of potential revenue affecting issues.

It works with the Ads Monitor agent that periodically visits your site as a regular user from a desktop or a mobile device and captures displayed ads. The service analyses the ads and reports to you in a convenient daily or weekly email digest. On the Ads Monitor site you can review the ads for any time period and…

Monitoring and detecting AdSense issues on your site

TLS connection – Detecting data breach / manipulation [duplicate]

This question already has an answer here:

  • Protect SSL connections from MITM for users with modified clients 2 answers
  • How can I prevent a man-in-the-middle (MITM) attack on my Android app API? 2 answers

I need some help in creating a secure connection using TLS.

I have a downloadable software that connects to our server using TLS connection. We want to ensure that the data sent by client to the server is secure and cannot be seen or manipulated by the user of our software.

I have bundled our CA certificate with the software so that it can verify the host and man-in-the-middle attack. CA certificate is self-signed certificate generated by openssl.

+---------------------+                      +----------------+ |                     |                      |                | |                     |      TLS connection  |                | |  Client Software    +                      |                | |  + Our CA certificate +------------------->+  Server        | |                     +                      |                | |                     |                      |                | +---------------------+                      +----------------+ 

However, what happens if a user who downloaded the software spoofs the DNS/ARP poisoning, replaces CA certificate with the fake one and creates man-in-the-middle situation to manipulate/view the traffic. In this case, the CA validation will pass and client software will not be able to detect any abnormal behaviour.

+----------+------+           +------+-----------+          +-----------------+ |   Client +      |           | MITM +           |          |  Server         | |   Fake CA cert  |  TLS      | our CA cert      |    TLS   |                 | |                 +---------->+                  +--------->+                 | |                 |           |                  |          |                 | +-----------------+           +------------------+          +-----------------+ 

So possibly using CA certificate is not of much help here.

Any suggestions on how to ensure that the client software make a secure connection with server which can not be compromised by situation like one described above.

5 VirusTotal engines detecting the apk as malicious file. Should I be worried?

I don’t usually download apps from untrusted sources or which are not available on play store but for some reason I really need to install this apk and just to make sure it is not malicious, after downloading the apk I submitted it to Virus Total and there five engines detected the apk file.

So as an average Android user what I understand from the above detection that it is just a adware(after some googling). But there are many technical details about this on Virus Total report. So I don’t really understand it. I am no Android Security expert that’s why I am asking here if anyone can tell that this app is malicious or just a false positive?

PS1 I am not really asking for free Malware Analysis for me, what I am asking is just have a look on those detections(maybe you have seen them before or they are known) to help me decide that I should install that apk or not?

PS2 I am not supporting piracy or anything, asking in general about the detections VirusTotal have found. Those detection can be in any app not necessarily this one

Homebrew not detecting latest Xcode and Command Line Tools and not uninstalling either

I have macOS Mojave version 10.14.5 installed with Xcode version 10.2.1 and Command Line Tools installed using xcode-select --install. All problem started when I tried to install youtube-dl formula on my system by running:

brew install youtube-dl

The output I get is:

Updating Homebrew... Error: Your Xcode (1) is too outdated. Please update to Xcode 9.0 (or delete it). Xcode can be updated from   https://developer.apple.com/download/more/  Error: Your Command Line Tools are too outdated. Update them from Software Update in the App Store. 

Again, if I run xcode-select --install, I get:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates 

Running:

xcode-select -v

returns

xcode-select version 2354 

(I do not know what this means) and running:

xcode-select -p

yields

/Applications/Xcode.app/Contents/Developer 

Owing to these issues, I tried to uninstall Homebrew (with a plan to reinstall it afresh) by running the command:

ruby -e "$  (curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)" 

but it gives the following error:

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Operation timed out 

Next, I tried to uninstall Homebrew using the unbrew.rb script available at GitHub but it seems not to remove Homebrew. I tried running it with and without sudo. Even after doing this, running brew config returns:

HOMEBREW_VERSION: 1.3.2 ORIGIN: https://github.com/Homebrew/brew HEAD: 751334a257d81851e68da7ab390982d4e9fdf909 Last commit: 1 year, 10 months ago Core tap ORIGIN: https://github.com/Homebrew/homebrew-core Core tap HEAD: 3fd7a855a1a357654a4a9a455162761841a4809d Core tap last commit: 1 year, 10 months ago HOMEBREW_PREFIX: /usr/local HOMEBREW_REPOSITORY: /usr/local/Homebrew HOMEBREW_CELLAR: /usr/local/Cellar HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com CPU: quad-core 64-bit broadwell Homebrew Ruby: 2.3.7 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby Clang: N/A Git: 2.20.1 => /Applications/Xcode.app/Contents/Developer/usr/bin/git Perl: /opt/local/bin/perl => /opt/local/bin/perl5.24 Python: /usr/bin/python Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby Java: N/A macOS: 10.14.5-x86_64 Xcode: 1 => /Applications/Xcode.app/Contents/Developer CLT: N/A X11: N/A MacPorts/Fink: /opt/local/bin/port 

Running brew doctor outputs the following:

Please note that these warnings are just used to help the Homebrew maintainers with debugging if you file an issue. If everything you use Homebrew for is working fine: please don't worry and just ignore them. Thanks!  Warning: Your Command Line Tools are too outdated. Update them from Software Update in the App Store.  Error: Unrecognized Mach-O load command: 0x32 

Is my Homebrew broken by my attempts at uninstalling it? What can I do to repair Homebrew and all these errors in pointing to the right Xcode and command line tools?

Is there a paper or model about detecting whether musical instrument playing right note or not?

I want to create a model that can detecting whether musical instrument play right note or not.

Example: provide mp3 file and musician are playing in piano. How to check the musician play right note according to mp3 file.

I had search GG but not found anything related.

M2 | Customer is not detecting by $customerSession->isLoggedIn()

I am trying to get loggedIn customer ID, I logged in and it is also showing in Online customer grid in the backend also can see on frontend. But if I check by

$  objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $  customerSession = $  objectManager->get('Magento\Customer\Model\Session'); if($  customerSession->isLoggedIn()) {    echo "login"; } 

It gives out as not logged in. (using DI way also result is same)

Also

$  ID = var_dump($  this->_customerSession->isLoggedIn());     echo $  ID; 

It gives output as:

bool(false)

How can I get Logged In customer ID from session ?

Unity Colliders – How do I detect nearby objects without my detection ranges detecting each other

How can I get both colliders’ types in a trigger overlap message like OnTriggerExit2D(Collider2D other)?

Example:

  • objects A and B both have a BoxCollider2D and CircleCollider2D components.

  • Then, object A enters one of the trigger colliders of object B.

  • I can get object B‘s collider type with the is operator.

How can I get A’s collider type?

The reason I want this is that I want only collisions where object A‘s CircleCollider2D touches object B‘s BoxCollider2D.

void OnTriggerExit2D(Collider2D other) {     if (other is BoxCollider2D)         //Do Code } 

Here is a table of what I want: I want only to register trigger overlaps from CircleCollider2D to BoxCollider2D. With the is operator, I can safely remove all collisions to CircleCollider2D but collisions between two BoxCollider2D stay, which I do not want.

+------------------+---------------+------------------+ |  Row to Column   | BoxCollider2D | CircleCollider2D |  +------------------+---------------+------------------+ | BoxCollider2D    | No            | No               |  | CircleCollider2D | Yes           | No               |  +------------------+---------------+------------------+ 

Edit The real questions was to detect nearby objects without the detection range dectecting each other.

Detecting deadlocks in thread safe linked list

I recently got a homework to implement a thread safe singly linked list which locks elements in hand over hand method which means that there is a single lock for every element in the list.I implemented all the functions and tested them without having to deal with problematic thread situations and they all worked but I wanted to test if there could be a situation of a deadlock or a starvation but I do not know how to do it and can I know from looking at my code if I could have deadlock or starvation ? I am also not sure if there there needs to be this much locking and unlocking in the code. Any help or suggestion regarding my code if it its prone to deadlocks and starvation or any other problems ? I will post my code below. Thanks in advance.

concurrent_list.h :

typedef struct node node; typedef struct list list;  list* create_list(); void delete_list(list* list); void print_list(list* list); void insert_value(list* list, int value); void remove_value(list* list, int value); void count_list(list* list, int (*predicate)(int)); 

concurrent_list.c :

 #include <pthread.h>  #include <stdio.h>  #include <stdlib.h>  #include <limits.h>  #include "concurrent_list.h"  struct node {   int value;   node* next;   pthread_mutex_t lock; // hand over hand implies a lock for every node };  struct list {   node* head; };  // print the value of a node void print_node(node* node) {   if(node)   {     printf("%d ", node->value);   }  }  // create  a new empty list list* create_list() {     list* l =(list*)malloc(sizeof(list));      if(l == NULL) return NULL;      l->head = NULL;      return l; }  // delete the entire list void delete_list(list* list) {   if(list == NULL) return; // if list pointer is NULL then do nothing    node* current = list->head;    if(current == NULL) return; // if list head is NULL then do nothing    pthread_mutex_lock(&(current->lock)); // lock list head    node* temp = current->next;   node* dummy;    if(temp == NULL) // delete the only element in the list   {      pthread_mutex_unlock(&(current->lock));      pthread_mutex_destroy(&(current->lock));      free(current);      return;   }    pthread_mutex_lock(&(temp->lock)); //lock successor of the head    while (1)   {      pthread_mutex_unlock(&(current->lock)); // unlock current node      dummy = current;      current = temp; // current becomes it's successor      pthread_mutex_destroy(&(dummy->lock));      free(dummy); // free dummy because it is a pointer to current      temp = temp->next; // current becomes it's successor      if(temp == NULL) break; // exit loop if we are at the end of the       list      pthread_mutex_lock(&(temp->lock)); // lock current's successor   }       pthread_mutex_unlock(&(current->lock));      pthread_mutex_destroy(&(current->lock));      free(current); // free the last element in the list      list->head = NULL;      free(list); // free the list   }    // insert function for a new value if a value already exists then do    nothing   void insert_value(list* list, int value)   {      if(list == NULL) return; // if list pointer is NULL then do nothing       node* new_node = malloc(sizeof(node)); // create new node       if(new_node == NULL) return; // check if allocation fails       new_node->value = value;       new_node->next = NULL;       pthread_mutex_init(&(new_node->lock),NULL);  // initialize fast mutex lock for the new node       pthread_mutex_lock(&(new_node->lock)); // lock the new node       if(list->head == NULL) // new node is the first element in the list      {         new_node->next = NULL;         list->head = new_node;         pthread_mutex_unlock(&(new_node->lock));         return;      }        pthread_mutex_lock(&(list->head->lock)); // lock the head of the list        node* temp;        if(list->head->value >= new_node->value) // new node comes before the list head      {        new_node->next = list->head;        temp = list->head;        list->head = new_node;        pthread_mutex_unlock(&(list->head->lock));        pthread_mutex_unlock(&(temp->lock));        return;      }      else     {       // Locate the node before the point of insertion //       node* dummy;      node* current = list->head;      temp = current->next;       if(temp == NULL) // new node comes after the list head      {          new_node->next = current->next;          current->next = new_node;          pthread_mutex_unlock(&(new_node->lock));          pthread_mutex_unlock(&(current->lock));          return;      }      pthread_mutex_lock(&(temp->lock)); // lock the successor of the head    // perform hand over hand traversal of the list   // and check if temp reaches the end of the list (NULL)     while (temp->value < new_node->value)    {      pthread_mutex_unlock(&(current->lock));      current = temp;      temp = temp->next;      if(temp == NULL) break;      pthread_mutex_lock(&(temp->lock));    }     if(temp == NULL) // new node will be the last element in this case    {        current->next = new_node;        new_node->next = NULL;        pthread_mutex_unlock(&(current->lock));        pthread_mutex_unlock(&(new_node->lock));        return;    }     else // new node should be inserted inside the list    {        dummy = temp;        new_node->next = current->next;        current->next = new_node;        pthread_mutex_unlock(&(dummy->lock));        pthread_mutex_unlock(&(current->lock));        pthread_mutex_unlock(&(new_node->lock));        return;    }  } }   //delete the first appearance of a value in the list if it exists in the list     void remove_value(list* list, int value)     {       if(list == NULL) return; // if list pointer is NULL then do nothing        node* temp;       node* current = list->head;        if(current == NULL) return; // if list head is NULL then just go to a new line       pthread_mutex_lock(&(current->lock)); // lock the head of the list       if(current->value == value) // delete the head of list if it's value is equal to given value     {         temp = current;         list->head = current->next;         pthread_mutex_unlock(&(temp->lock));         pthread_mutex_destroy(&(temp->lock));        free(temp);        return;    }      else    {        temp = current->next;         if(temp == NULL)        {            pthread_mutex_unlock(&(current->lock));            return;        }         pthread_mutex_lock(&(temp->lock)); // lock the successor of the head          // perform hand over hand traversal of the list        //  and check if temp reaches the end of the list (NULL)      while (temp->value != value) // find the first appearance of a node      that has a value the same as the one given         {           pthread_mutex_unlock(&(current->lock));           current = temp;           temp = temp->next;           if(temp == NULL) break;           pthread_mutex_lock(&(temp->lock));         }           if(temp == NULL) // value not found         {             pthread_mutex_unlock(&(current->lock));             return;         }          else // delete the suitable node         {             current->next = temp->next;             pthread_mutex_unlock(&(current->lock));             pthread_mutex_unlock(&(temp->lock));             pthread_mutex_destroy(&(temp->lock));             free(temp);            return;         }     } }   //print the entire list  void print_list(list* list)  {   if(list == NULL) // if list pointer is NULL then just go to a new line   {       printf("\n");       return;   }        node* current = list->head;        if(current == NULL) // if list head is NULL then just go to a new line       {          printf("\n");          return;       }        pthread_mutex_lock(&(current->lock)); // lock the head of the list        print_node(current); // print the head of the list        node* temp = current->next;        if(temp == NULL) // a list with 1 element       {          printf("\n");          pthread_mutex_unlock(&(current->lock));          return;       }       pthread_mutex_lock(&(temp->lock)); // lock the list head's successor      while (1)     {        pthread_mutex_unlock(&(current->lock)); // unlock current node        current = temp; // current becomes it's successor        print_node(current); // print current node        temp = temp->next; // // temp becomes it's successor        if(temp == NULL) break; // exit loop if we reach the end of the list       pthread_mutex_lock(&(temp->lock)); // lock temp    }      pthread_mutex_unlock(&(current->lock)); // unlock the last list      element    printf("\n"); }   // print how many nodes in the list satisfy a given predicate function  void count_list(list* list, int (*predicate)(int))  {     int count = 0;     if(list == NULL) // if list pointer is NULL then print that count =     0 and finish    {       printf("%d items were counted\n", count);       return;    }     node* current = list->head;     if(current == NULL) // if list head is NULL then print that count =     0 and finish    {        printf("%d items were counted\n", count);        return;    }     pthread_mutex_lock(&(current->lock)); // lock the list head     if(predicate(current->value)) count++; // check the predicate for     the list head     node* temp = current->next;     if(temp == NULL) // list has only 1 element    {       pthread_mutex_unlock(&(current->lock));       printf("%d items were counted\n", count);       return;    }     pthread_mutex_lock(&(temp->lock)); // lock the list head's successor     while (1)   {     pthread_mutex_unlock(&(current->lock)); // unlock current node     current = temp; // current becomes it's successor     if(predicate(current->value)) count++; // check predicate for current node     temp = temp->next; // // temp becomes it's successor     if(temp == NULL) break; // exit loop if we reach the end of the list     pthread_mutex_lock(&(temp->lock)); // lock temp    }     pthread_mutex_unlock(&(current->lock)); // unlock the last list element     printf("%d items were counted\n", count); // print count }