javascript – JS, a multi purpose function

this is an Angular application, this page will have a list and sublist with action for each one (add/edit/delete)
enter image description here
the buttons (add/edit) will show a popup with the same form except the landmark will show one more filed.

<ng-template #modaleTemplate>
  <div class="modal-header">
    <h4 class="modal-title pull-left">Modal</h4>
    <button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body text-center">
    <div class="d-flex justify-content-center">
      <div class="w-50">
        <input
        class="form-control shadow-sm bg-white rounded"
        ((ngModel))="areaModel.name"
        placeholder="{{ 'Name' | translate }}"
      />
      </div>
      <div class="w-50" *ngIf="showTypes">
        <select-menu
        (label)="'landmarkType'"
        (itemKey)="'Id'"
        (dropDownListInputs)="landmarkTypeList"
        (SearchVAlue)="getLandmarkType($event)"
        (selectedListChange)="onLandmarTypekDDLChanged($event)"
        (options)="selectMenuOptions"
      ></select-menu>
      </div>
    </div>




    <div class="pt-5">
      <tabset>
        <tab heading="Location" class="py-3" id="tab1">
          <input
            class="w-100 d-inline-block form-control shadow-sm bg-white rounded"
            ((ngModel))="areaModel.location"
            placeholder="{{ 'Name' | translate }}"
          />
        </tab>
        <tab heading="MoreDetails" class="py-3">
          <div class="row">
            <div class="col-12">
              <div class="form-group">
                <label for="description">{{"Description" | translate}}</label>
                <input type="text" class="form-control shadow-sm bg-white rounded" ((ngModel))="areaModel.description" placeholder="{{ 'Description' | translate }}" id="description">
              </div>
            </div>
            <div class="col-6">
              <div class="form-group">
                <label for="telephone1">{{"Telephone #1" | translate}}</label>
                <input type="text" class="form-control shadow-sm bg-white rounded" ((ngModel))="areaModel.telephone1" placeholder="{{ 'Telephone #1' | translate }}" id="telephone1">
              </div>
            </div>
            <div class="col-6">
              <div class="form-group">
                <label for="telephone2">{{"Telephone #2" | translate}}</label>
                <input type="text" class="form-control shadow-sm bg-white rounded" ((ngModel))="areaModel.telephone2" placeholder="{{ 'Telephone #2' | translate }}" id="telephone2">
              </div>
            </div>
            <div class="col-6">
              <div class="form-group">
                <label for="Mobile">{{"Mobile" | translate}}</label>
                <input type="text" class="form-control shadow-sm bg-white rounded" ((ngModel))="areaModel.mobile" placeholder="{{ 'Mobile' | translate }}" id="Mobile">
              </div>
            </div>
            <div class="col-6">
              <div class="form-group">
                <label for="Fax">{{"Fax" | translate}}</label>
                <input type="text" class="form-control shadow-sm bg-white rounded" ((ngModel))="areaModel.fax" placeholder="{{ 'Fax' | translate }}" id="Fax">
              </div>
            </div>
            <div class="col-6">
              <div class="form-group">
                <label for="Website">{{"Website" | translate}}</label>
                <input type="text" class="form-control shadow-sm bg-white rounded" ((ngModel))="areaModel.website" placeholder="{{ 'Website' | translate }}" id="Website">
              </div>
            </div>
            <div class="col-6">
              <div class="custom-control custom-checkbox">
                <input type="checkbox" class="custom-control-input" ((ngModel))="areaModel.isLive" id="isLive">
                <label class="custom-control-label" for="isLive">{{ "IsLive" | translate }}</label>
              </div>
            </div>
          </div>
        </tab>
      </tabset>
    </div>
  </div>
  <div class="d-flex p-3 justify-content-end">
    <button type="button" class="btn btn-link" (click)="modalRef.hide()">cancel</button>
    <button type="button" class="btn btn-primary" (click)="save()">save</button>
  </div>
</ng-template>


<div class="branch-management container-fluid">
  <div class="row">
    <div class="col-12">
      <span class="actions d-flex justify-content-end mb-3">
        <a class="add-btn" (click)="showModal(modaleTemplate, {name: 'area', action: 'add'})">
          <i class="fas fa-plus"></i>
          addArea
        </a>
      </span>

      <div class="level-areas" id="areas">
        <div class="item d-flex justify-content-between align-items-center">

          <div class="btn btn-link collapsed"
            data-toggle="collapse"
            data-target="#area-1">
            <div class="btn btn-link icon">
              <i class="fas fa-plus"></i>
              <i class="fas fa-minus"></i>
            </div>
            Area title
          </div>
          <span class="actions">
            <a class="add-btn" (click)="showModal(modaleTemplate, {name: 'city', action: 'add', id: 1})">
              <i class="fas fa-plus"></i>
              addCity
            </a>
            <a class="edit-btn" (click)="showModal(modaleTemplate, {name: 'area', action: 'edit', id: 1})">
              <i class="fas fa-pen"></i>
              edit
            </a>
            <a class="delete-btn" (click)="delete({name: 'area', id: 1})">
              <i class="fas fa-trash-alt"></i>
              delete
            </a>
          </span>
        </div>


        <div id="area-1" class="collapse" data-parent="#areas">
          <div class="level-cities" id="cities">

            <div class="item d-flex justify-content-between align-items-center">

              <div class="btn btn-link collapsed"
                data-toggle="collapse"
                data-target="#city-2">
                <div class="btn btn-link icon">
                  <i class="fas fa-plus"></i>
                  <i class="fas fa-minus"></i>
                </div>
                City title
              </div>
              <span class="actions">
                <a class="add-btn" (click)="showModal(modaleTemplate, {name: 'landmark', action: 'add', id: 1})">
                  <i class="fas fa-plus"></i>
                  addLandmark
                </a>
                <a class="edit-btn" (click)="showModal(modaleTemplate, {name: 'city', action: 'edit', id: 1})">
                  <i class="fas fa-pen"></i>
                  edit
                </a>
                <a class="delete-btn" (click)="delete({name: 'city', id: 1})">
                  <i class="fas fa-trash-alt"></i>
                  delete
                </a>
              </span>
            </div>
            <div id="city-2" class="collapse" data-parent="#cities">
              <div class="level-landmarks">
                <ul>
                  <li class="item d-flex justify-content-between align-items-center">
                    landmark name
                    <span class="actions">

                      <a class="edit-btn" (click)="showModal(modaleTemplate, {name: 'landmark', action: 'edit', id: 1})">
                        <i class="fas fa-pen"></i>
                        edit
                      </a>
                      <a class="delete-btn" (click)="delete({name: 'landmark', id: 1})">
                        <i class="fas fa-trash-alt"></i>
                        delete
                      </a>
                    </span>
                  </li>
                </ul>

              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

</div>
</div>

So, instead of creating a function for every action for each element and repeat the modal template I’ve created two functions and passed parameters to tell the function to show the modal as needed.
enter image description here
Also, on the modal save button it fires a save() method, which is will execute a method depends on what has passed on show modal function.

Then, I’ve checked the income action by swich statment to call its service.

modalRef: BsModalRef;
showTypes = false;
areaModel: AreaModel = new AreaModel();
  action = {
    action: string,
    name: string,
    id: string
  };
  showModal(template: TemplateRef<any>, props: any) {
    console.log(props);
    this.action = props;
    if(props.action === "edit") {
      switch (props.name) {
        case 'area':
          console.log(props.action, props.name);
          this.cpService.getAreaById(props.id).subscribe(res => this.areaModel = res.Value);
          break;
        case 'city':
          console.log(props.action, props.name);
          this.cpService.getCityById(props.id).subscribe(res => this.areaModel = res.Value);
          break;
        case 'landmark':
          console.log(props.action, props.name);
          this.cpService.getLandmarkById(props.id).subscribe(res => this.areaModel = res.Value);
          break;
      }
    }

    if(props.name === "landmark") {
      this.showTypes = true;
    } else {
      this.showTypes = false;
    }

    this.modalRef = this.modalService.show(
      template,
      Object.assign({}, { class: 'modal-lg' })
    );
  }



  delete(name, id) {

    switch (name) {
      case 'area':
        this.cpService.deleteArea(id).subscribe(res => console.log(res))
        break;
      case 'city':
        this.cpService.deleteCity(id).subscribe(res => console.log(res))
        break;
      case 'landmark':
        this.cpService.deleteLandmark(id).subscribe(res => console.log(res))
        break;
    }
  }


  save() {
    const currentAction = this.action.action as any;
    switch (this.action.name as any) {
      case 'area':
        if (currentAction === 'edit') {
          this.cpService.editArea(this.areaModel).subscribe(res => console.log(res));
        } else {
          this.cpService.addArea(this.areaModel).subscribe(res => console.log(res));
        }
        break;
      case 'city':
        if (currentAction === 'edit') {
          this.cpService.editCity(this.areaModel).subscribe(res => console.log(res));
        } else {
          this.cpService.addCity(this.areaModel).subscribe(res => console.log(res));
        }
        break;
      case 'landmark':
        if (currentAction === 'edit') {
          this.cpService.editLandmark(this.areaModel).subscribe(res => console.log(res));
        } else {
          this.cpService.addLandmark(this.areaModel).subscribe(res => console.log(res));
        }
        break;
    }
  }

Is that a good practice, or there is another good options to do that?

What should be the purpose of jail/prison? | Forum Promotion

❓ASK – Purpose of research in SEO | Proxies-free

Thread starter Title Forum Replies Date

RaOne

❓ASK Programming languages with same purpose, then why there are a lot? Design & Programming 12

N

❓ASK What is not the central role of research in SEO Search Engine Optimization 0

salvi

☑️NEW Real Research app Airdrops (New) Airdrops Forum 1

N

❓ASK How not to apply research in SEO Search Engine Optimization 0

N

❓ASK How not to use keyword research in SEO Search Engine Optimization 0

J

☑️NEW Real research Airdrops Forum 0

aryan4

❕NEWS Research on Bitcoin Electricity consumption Bitcoin Forum 5

aryan4

❕NEWS Research: Elon’s Impact on Cryptocurrency Prices Altcoins Forum 6

Miya

✅LEGIT Verizon Media Research Reviews: SCAM OR LEGIT? Best Paid Surveys 1

salvi

☑️NEW Real Research app Airdrops (New) Airdrops Forum 3

kazandiran

☑️NEW Real Research Survey App Reviews: SCAM or LEGIT? Rewarding Apps 68

chiftine

☑️NEW YFST Protocol airdrop $25. Looks legit (Do your own research) Airdrops Forum 2

Josemendez

❕NEWS Australia’s Reserve Bank forms partnership for CBDC research Crypto Currencies 12

Josemendez

❕NEWS Philippines central bank to research further before launching CDBC Crypto Currencies 1

ayeshamirza786588

☑️NEW mining-research.life Reviews: Scam or Legit? HYIPs Forum 0

Mattias

☑️NEW CPX Research Reviews: SCAM or LEGIT? Affiliate Programs Reviews 0

D

☑️NEW Gauge Research Reviews: SCAM or LEGIT? Rewarding Apps 2

I

I am Indrajit Prasad Science teacher , computer expert in website surfing research , design etc .. Introductions 1

S

☑️NEW E-Research-Global Reviews: SCAM or LEGIT? Best Paid Surveys 6

S

✅LEGIT Panda Research Reviews: SCAM or LEGIT? Best Paid Surveys 0

Yugocean

☑️NEW bit-research.net Reviews: SCAM or LEGIT? HYIPs Forum 0

CAMPER2030

❓ASK Do you know which Keyword research software is good in 2018 ? Search Engine Optimization 5

B

✅LEGIT FACEBOOK RESEARCH PROGRAM Reviews: SCAM or LEGIT? Rewarding Apps 46

BMF

☑️NEW Valient Market Research Reviews: SCAM or LEGIT? Best Paid Surveys 3

BMF

☑️NEW Fairfield Research Reviews: SCAM or LEGIT? Best Paid Surveys 1

BMF

☑️NEW Ingather Research Reviews: SCAM or LEGIT? Best Paid Surveys 0

M

☑️NEW Research Participants Institute (RPI) Reviews: SCAM or LEGIT? Best Paid Surveys 2

D

✅LEGIT Pinecone Research Reviews: SCAM or LEGIT? Best Paid Surveys 50

B

✅LEGIT Vindale Research Reviews: SCAM or LEGIT? Best Paid Surveys 33

Hephaestus

❓ASK Internet consumers and market research Affiliate Marketing 1

Apollo

❓ASK How to Do Keyword Research for FREE Search Engine Optimization 3

N

❓ASK What tasks are not necessary in SEO Search Engine Optimization 0

N

❓ASK How to position components in SEO Search Engine Optimization 0

N

❓ASK Function of labels in SEO Search Engine Optimization 0

N

❓ASK Not applicable areas of SEO Search Engine Optimization 0

N

❓ASK What makes SEO feasible Search Engine Optimization 0

N

❓ASK How to compact elements in SEO Search Engine Optimization 0

N

❓ASK How not to diffuse errors in SEO Search Engine Optimization 0

N

❓ASK What mechanism not to use in SEO Search Engine Optimization 0

sh199

❓ASK Can Duplicate contents do SEO? Search Engine Optimization 2

N

❓ASK Difficult areas in SEO Search Engine Optimization 1

N

❓ASK Which areas are unimportant in SEO Search Engine Optimization 1

N

❓ASK How not to construct strategies on SEO Search Engine Optimization 0

N

❓ASK How to craft solutions in SEO Search Engine Optimization 0

N

❓ASK How to generate ideas in SEO Search Engine Optimization 3

N

❓ASK Why is SEO not dynamic Search Engine Optimization 0

N

❓ASK Why is SEO essential Search Engine Optimization 1

N

❓ASK Vital strategies in SEO Search Engine Optimization 1

N

❓ASK Why is SEO pivotal Search Engine Optimization 0

N

❓ASK What makes SEO distinctive Search Engine Optimization 0

Do you save money and for what purpose? | Forum Promotion

purpose of stack segment in assembly language

The code snippet below is the “beginning lines of an assembly language program” used to display a single line string .

stack segment para stack 'stack'
       db 16 dup(0)
stack ends 

my question is : why stack segment is available in assembly program? And how do I define this ‘stack’? Any help will be appreciated. My basic idea is that it is used to temporarily hold data.

configuration – what is the purpose of the config shema file?

  1. I have createad this /config/schema/drupolo.yml
drupolo.social_network.setting: 
  type: config_object 
  label: 'Sacd Menu module settings.'
  mapping:
    facebook_page:
      type: string #Type: can be string | integer |  boolean
      label: 'Facebook page'
    twiiter_page:
      type: string
      label: 'Twitter page'
  1. Then I have created the /config/install/drupolo.social_network.setting.yml with a key that doesn’t exist in the schema file(linkedn_page), the problem is that the module installed and the config is stored in the config table so it doesn’t respect the schema file
facebook_page: 'https://facebook.com/default'
twitter_page: 'https://twiiter.com/default'
linkedn_page: 'http://linkedin.com' # key that don't respect the "drupolo.social_network.setting" strucutre that has been declared in the drupolo.yml

the question is : what is the purpose of the */config/schema/{module}.ymlwhat is file if the
conifg/install won’t respect that structure?

certificates – ntfsdecrypt – Key does not have an EFS purpose OID

I’m trying to copy EFS-encrypted files from an NTFS partition using:

ntfsdecrypt -k mycert.pfx /dev/sda2 -i 32768

and I get:

Key does not have an EFS purpose OID
Failed to extract the private RSA key.

More info:

  • The password is indeed correct (the error is different when entering something else).
  • I have previously (recently) used the same certificate and method with success.
  • I’m on Arch Linux 5.10.20-1-lts and using ntfsdecrypt v2017.3.23 (libntfs-3g).

What’s the EFS purpose OID?

What’s the problem?

design patterns – How to deal with classes with same purpose from different libraries?

I have a question regarding software design/architecture.

Are there any best practices or design patterns regarding the usage of classes with the same purpose from different libraries?

Let’s imagine this simple project P which uses two libraries A and B. A and B both have a class to deal with 3D-Positions (this question is not about naming problems). Library A has the class Position to store x, y, z values. Library B has a similar class:

namespace A 
{
    class PositionA { ... }
}

namespace B 
{
    class BPosition { ... }
}

In the project P both Position classes are used depending on the current use-case and sometimes there is a need to convert one into another.

My goal what i want to achieve now is to abstract this Position classes away. So that the Project P should only deal with IPosition and the sub-projects which wrap the library should deal with the implementation type, e.g.:

namespace AbsractDataLayer{
    class IPosition{};
}

namespace AWrapper {

    class AWrapPosition : public IPosition{
        AWrapPosition(PositionA& pos) : _Pos(pos) {}
        
        PositionA& _Pos;
    };
    
    class Foo{
    public:
        IPosition* Get() { return new AWrapPosition(PositionA()));

        void Do(IPosition* position){
            auto pos = dynamic_cast<AWrapPosition*>(position);
            if(pos){
                ... // correct type
            }
            else {
                ... // what to do here, I need to convert to the correct one?
            }
        }
    };
}

namespace BWrapper {

    class BWrapPosition : public IPosition{
        BWrapPosition(BPosition& pos) : _Pos(pos) {}
        
        BPosition& _Pos;
    }
    
    class Foo{
    public:
        IPosition* Get() { return new BWrapPosition(BPosition()));

        void Do(IPosition* position){
            auto pos = dynamic_cast<BWrapPosition*>(position);
            if(pos){
                ... // correct type
            }
            else {
                ... // what to do here, I need to convert to the correct one?
            }
        }
    }
}

Now the problem which arises is the conversion from one type into another which I cannot think of a clean way to do.

As a goal I wanted to achieve that AWrapper wraps library A (so that project can only see A-types) and the same applies to B. Project P should not know about A and B at all, only know the Abstract-Data-Layer type and the wrappers.

To summarize my questions:

  1. Is this a good way to deal with these kind of problems or is there a better way? Keep in mind that this solution is used to use DI for unit testing and the goal that these libraries could be easily exchangable, therefore I want P to be loosely coupled as possible to any dependency

  2. And then the bigger question: How could I deal with converting one type into on another if project P should not care about that stuff?

This question is asked with C++ context (even the code is some pseudo/c++) This question can also be applied to C# or any other OOP-language if wanted.

iptables – What is the purpose of TPROXY, how should you use it and what happens internally?

After reading a bit about TPROXY (e.g at https://www.kernel.org/doc/html/latest/networking/tproxy.html ) I now have more questions then answers. I actually don’t even know what TPROXY should do…

Some assumptions about what I should do and what happens inside.
Can you correct the following assumptions ?

From what i understand these are the commands that you should run (although i have no idea why):

  • iptables -t mangle -N DIVERT :
    • A chain named DIVERT is created.
    • You can choose the name. (As long as it’s the same in all commands).
    • It has to be part of mangle because you will being doing things that are less trivial than redirecting, blocking and NAT.
  • iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT :
    • The PREROUTING chain makes sure that once a TCP packet is passed from a networkdevice to the kernel, the very first thing that will happen is that it is being sent to the DIVERT chain.
    • -p tcp makes sure that this it is not the case for non-TCP traffic .
    • -m socket makes sure that this it is not the case for packets that create and close the connection (e.g. SYN/ACK)
    • By removing -p tcp -m socket TPROXY will affect all IP(v4) packets. It will be a different, but working, setup.
  • iptables -t mangle -A DIVERT -j MARK --set-mark 1 :
    • The kernel will mark those packets with the number 1. You can choose another number.
    • It’s also possible to add multiple marks to a packet. For example: By adding the command iptables -t mangle -A DIVERT -i eth0 -j MARK --set-mark 2 you would make sure that all TCP-packages get the mark 1 and all TCP-packages that arrive from eth0 get both the mark 1 and 2.
    • “Marking with number X” just means “categorizing as member of category X without actually changing anything in the packet”.
    • Both the kernel and programs in userspace can read the mark(s) of packets
    • Only the kernel can mark packets
  • iptables -t mangle -A DIVERT -j ACCEPT : By default the kernel discards the packets so you are now making sure it doesn’t.
  • ip rule add fwmark 1 lookup 100 :
    • Instead of using the default routingtable, all packets with mark 1 now use a table named 100.
    • You can use choose another number, as long as you make sure that you use the same number everywhere else
  • ip route add local 0.0.0.0/0 dev lo table 100 : I haven’t the faintest clue what this does…
    Just a guess: Changes routing table 100 in such a way that packets from the range 0.0.0.0/0, so in this case every packet, are sent to localhost (add local and dev lo) as long as they are marked with 1 (otherwise they wouldn’t end up in 100)
  • iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TPROXY --tproxy-mark 0x1/0x1 --on-port 50080:
    • All packets sent to tcp/80 receive the mark 1 and end up at tcp/50080
    • For some, to me, unknown reason, they are marked. (It looks to me that they pass by DIVERT anyway where they are marked again)
    • For some, to me, unknown reason 0x1 is written twice

My assumption about what the purpose of TPROXY is: Re-routing packets without altering them