mardi 3 mars 2020

REGEX - Matching pattern to extract value between two strings

I need to extract a value between two strings --> "ifName." and " = STRING: VDSL 0/n/m" where n and m are variable and are going to be set by me at runtime.

The point is that i need the last number, for example, if i have n=3 and m=9 i will match this "4160774720". I hope i explained well.

ifName.4160774464 = STRING: VDSL 0/3/5 ifName.4160774528 = STRING: VDSL 0/3/6 ifName.4160774592 = STRING: VDSL 0/3/7 ifName.4160774656 = STRING: VDSL 0/3/8 ifName.4160774720 = STRING: VDSL 0/3/9 ifName.4160774784 = STRING: VDSL 0/3/10 ifName.4160774848 = STRING: VDSL 0/3/11 ifName.4160774912 = STRING: VDSL 0/3/12 ifName.4160774976 = STRING: VDSL 0/3/13 ifName.4160775040 = STRING: VDSL 0/3/14 ifName.4160775104 = STRING: VDSL 0/3/15 ifName.4160775168 = STRING: VDSL 0/3/16 ifName.4160775232 = STRING: VDSL 0/3/17 ifName.4160775296 = STRING: VDSL 0/3/18 ifName.4160775360 = STRING: VDSL 0/3/19

Thanks to everybody;D Someone save me and my working day

Angelo

I'm trying to find a pattern between numbers and dates - still no luck are you able? ;)

There is no fixed intervall in the numbers based on number of days between them. If you like numbercrunshing and patterns, here is a fun task.

DATE FORMAT: DD.MM.YYYY

1583017200000 02.03.2020 1582498800000 24.02.2020 1580598000000 03.02.2020 1575241200000 02.12.2019 1548457200000 28.01.2019 1425250800000 02.03.2015

Purpose: Create number-sequence based on date.

lundi 2 mars 2020

Searching for words of a column in the texts of another column

I have a table of 1500*6 and a column of 3000 (Seg.name). you see parts of them here.

I need to find the rows in R.name column in the table that have a word in Seg.name column. For instance, it searches "TRUE" in R.name column to find if this word has occurred in any of the rows in R.name. If finds it, then replaces the count with TRUE, otherwise leaves count as NA. Thats why I have two For loops.

I have also my ifelse and for loop part of the code. The code works with no error but it only saves a letter in count column! for instance instead of Pemex, it has P and so one. What do you think is happening here?

**Year  Rystad Operator Names    Country**
2018    Pemex                    Mexico
2018    Other partner(s) US      United States
2018    PetroChina               China
2018    Equinor                  Norway
2018    Saudi Aramco             Saudi Arabia

Seg.name

TRUE
ZYNERGY
ZUEITINA
ZINSZER
ZENITH

for loop code:

for (j in 1:1000)

{
 for (i in 1:20)
{
test=mapply(grepl, pattern=data.s$Seg.name[j], x=data.r$R.name[i], fixed=TRUE)
if (test == TRUE) data.r$count[i]=data.s$Seg.name[j] else {
    if (data.r$count[i]=="NA")  data.r$count[i]="NA" else data.r$count[i]=data.r$count[i]
}        
}
}
return(data.r)

data.r returned in this format:

**Year  R.name                   Country            count   pass**
2018    Pemex                     Mexico               P    NA
2018    Other partner(s) US       United States        S    NA
2018    PetroChina                China                P    NA
2018    Equinor                   Norway               NA   NA
2018    Saudi Aramco              Saudi Arabia         S    NA

Angular is Based on Event Driven or Data Driven Model

Angular is based on Event Driven or Data Driven Model.

using of ngRx follows which pattern data driven or event driven.

What is a good way to make references between each UIView in the hierarchy?

Suppose you have a UIView hierarchy like this

UIViewController
->UITableView
-->UITableViewCell
--->UITextView

Now when an event happens say

func textViewDidEndEditing(_ textView: UITextView) {}

You have a reference to the textView, but lets say you need an UI to change for the entire hierarchy and also data models, how do you do that?

One approach is to give it all the references, but it's very tedious

class CustomTextView {
  init(model:Data, cell:UITableViewCell, tableview:UITableView) {//...}
  func textViewDidEndEditing(_ textView: UITextView) {
     //update model, update cell, update tableview
  }
}

Also I would need to pass similar references to the cell and the tableview.

Another approach is to set the delegate at the controller level. And then you have:

class myController:UITableViewController {
  func textViewDidEndEditing(_ textView: UITextView) {
    //tableView.updateUI()
    //cell = tableView.cellForRowAtIndexPath...
    //cell.updateUI()
    //cell.textView.updateUI()
    //model.updateData()
  }
}

But then this leads to a massive view controller.

What is the right design pattern here where every view needs access to every other view?

How to communicate between library and app in Java Android?

Suppose the following scenario:

Class S is part of an SDK or Library being used by many custom apps.
Class A is part of one app which employs the SDK.
Class S contains a server response variable I want to send over to Class A, as soon as it lands, for further processing (some logs and analytics). Class A is the only one capable of doing this job.

The premises are that apps using the SDK can access its classes, but not viceversa.
So class S cannot use anything related to class A.

Question:
How can I achieve this?

The language I am writing in is Java.
I have tried implementing an Observer pattern, but I don't think it's what I am after. It's probably a callback mechanism that will sort this out for me, but I cannot seem to pinpoint it.

Right way to implement world of entities

I'm looking for the right way to implement a world for my game. The world holds and updates every entity but some entities may modify the world back. I've tried to use RefCell but I got an error in Entity::update method:

use std::cell::RefCell;
use std::rc::Rc;

struct World {
    entities: Vec<Entity>,
}

impl World {
    fn update(&mut self) {
        for entity in self.entities.iter_mut() {
            entity.update();
        }

        println!("World has been updated");
    }

    fn influence(&mut self) {
        println!("World has been influenced");
    }
}

struct Entity {
    world: Rc<RefCell<World>>,
}

impl Entity {
    fn update(&mut self) {
        self.world.borrow_mut().influence(); // ERROR GOES HERE
        println!("Entity has been updated");
    }
}

fn main() {
    let world = Rc::new(RefCell::new(World {
        entities: Vec::new(),
    }));
    world.borrow_mut().entities.push(Entity {
        world: world.clone(),
    });
    world.borrow_mut().entities.push(Entity {
        world: world.clone(),
    });
    world.borrow_mut().entities.push(Entity {
        world: world.clone(),
    });
    world.borrow_mut().update();
    world.borrow_mut().update();
}
thread 'main' panicked at 'already borrowed: BorrowMutError', src/libcore/result.rs:1188:5

What is the right way to implement this kind of world?

Similar question was Passing mutable self reference to method of owned object but I need more complex logic since an entity may modify the world or other entities. I even plan to hold generic traits so that some entities will have different logic.

I know why I got this error, my question is more about design-pattern.