node.js – npm package as amqp client helper

I want to create a common helper for my application that manages all amqplib calls from all of my nodeJS microservices.

I want to import my amqplibHelper into every micro service and only use my auxiliary commands, which they call internally in the amqplib node.js library, so that I can use other libraries in the future to make changes to the amqp commands easily at a central one Place.

I created a new npm package for it and tried to write something from scratch, but since I don't have much experience with amqp, I'm looking for a "bootstrap" or template as a starting point.

Can anyone give advice?

I started but I feel like I'm not on the right track …

class commonAmqp {
   amqp = require('amqplib');      
   connection = start();

   constructor(rabbitmqClientm, validQueues) {
      this.rabbitmqClient = rabbitmqClient;
      this.validQueues = validQueues;

      const { queuesLocal, queuesRemote } = rabbitmqClient;
      const isLocal = queuesLocal.includes(queue);
      const isRemote = queuesRemote.includes(queue);
   }


   async initQueue(queue, data) {
      if (!validQueues.includes(queue)) throw HttpError(g.f('Not valid queue'));

      const { connection, queue } = this;
      const valid = queueValidator(queue, data);
      const channel = connection.then(conn => (conn.createChannel()));

      if (!channel || !valid)
        throw new Error('Not valid queue || queue-data');

      channel.then(function(ch) {
        return ch.assertQueue(queue).then(function(ok) {
          return ch.sendToQueue(queue, new Buffer.from(JSON.stringify(data)));
        });
      });

    };


    async start() {      

      const connection = await this.amqp.connect(rabbitmqClient.url);
      console.log('Connected to RabbitMQ-server');

      connection.on('error', (err) => {
         console.log('rabbitmq-err', err);
         setTimeout(start, 2000);
      });

      connection.on('close', () => {
         console.log('rabbitmq-connection closed');
         setTimeout(start, 5000);
      });

      return connection;       
    }

    config(config) {
       this.config = config;
       console.log('config: ' + this.config);
    }

 }

 module.exports = {
   commonAmqp   
};

magento2.3 – Magento 2.3 – Overwrite the Swatches Helper

I am trying to override a function in the Helper of the Swatches module of Magento 2. The function is in the Data.php file. As some of you may know in certain versions of Magento 2, the text box values ​​are reset to the default admin value due to an error.

An update was published here: https://github.com/magento/magento2/pull/15960

I am trying to implement this update by overriding the function in Data.php by default.

Since the postage theme I used already overrides some other functions, I decided to add my override there.

app / code / Smartwave / Porto / etc / di.xml





    
        
            MagentoFrameworkViewElementTemplateContext
            MagentoFrameworkRegistry
        
    


    
        
            MagentoFrameworkViewElementTemplateContext
            MagentoCatalogHelperCategory
            MagentoCatalogModelIndexerCategoryFlatState
            MagentoThemeBlockHtmlTopmenu
        
    





As you can see, I added the setting on the last line.

app / code / Smartwave / Porto / Helper / Swatches / Data.php

namespace SmartwavePortoHelperSwatches;

class Data extends MagentoSwatchesHelperData
{

/**
 * @param array $fallbackValues
 * @param array $swatches
 * @return array
 */
public function addFallbackOptions(array $fallbackValues, array $swatches)
{
    $currentStoreId = $this->storeManager->getStore()->getId();
    foreach ($fallbackValues as $optionId => $optionsArray) {
        if (isset($optionsArray($currentStoreId)('type'), $swatches($optionId)('type'))
            && $swatches($optionId)('type') === $optionsArray($currentStoreId)('type')
        ) {
            $swatches($optionId) = $optionsArray($currentStoreId);
        } elseif (isset($optionsArray($currentStoreId))) {
            $swatches($optionId) = $optionsArray($currentStoreId);
        } elseif (isset($optionsArray(self::DEFAULT_STORE_ID))) {
            $swatches($optionId) = $optionsArray(self::DEFAULT_STORE_ID);
        }
    }

    return $swatches;
}

}

However, this doesn't seem to work. Can someone tell me why this is the case?

magento 1.9 – PHPUnit tests a method Calls internally a helper method

Testing in magento 1.9 is painful. But somehow I try to find out PHPUnit,

I have a method that I want to test. And for unit testing, I want to mock all dependencies that this method has.

In PHPUnit, there is a way to mock another class method using dependency injection. But the problem comes when my other class I mock is my helper class myself.

I call my helper class method as follows: Mage::helper('ClassXMLname')->getMyMethod(),

So my problems are:

  1. Is there any other way than dependency injection to mock my helper class method, and my method uses this mocked method in testing?
  2. How can we inject a helper class in dependency injection in our class?

Any answer to this question will really help the people they are still struggling with magento 1.9 , Thank you in advance.

windows – String helper functions in NASM Win16 Assembly

Surroundings

NASM is required to create this program, and DosBox is required to run it. I would recommend installing them with the Scoop Package Manager. You can ignore install statements for any programs already installed.

iwr -useb get.scoop.sh | iex
scoop install git
scoop install dosbox
scoop install nasm

building

nasm -f bin -o helper.com helper.asm

To run

burden DosBox, then mount the path where helper.com is on an available drive. For those who are unfamiliar, it can be any drive in the A-Z Range.

mount H: C:UsersT145Desktop
H:
dir
helper.com

helper.asm

bits 16
org 0x100

section .text

_main:
    lea     di, [prompt]
    call    putstring

    lea     di, [string]
    call    getstring

    lea     di, [hello]
    call    putstring

    lea     di, [string]
    call    putstring

    mov     ah, 0x4c     ; standard exit code
    mov     al, 0
    int     0x21

; no parameters
; returns a char in ax
getchar:
    mov     ah, 0        ; call interrupt x16 sub interrupt 0
    int     0x16
    mov     ah, 0
    ret

; takes a char to print in dx
; no return value
putchar:
    mov     ax, dx       ; call interrupt x10 sub interrupt xE
    mov     ah, 0x0E
    mov     cx, 1
    int     0x10
    ret

; takes an address to write to in di
; writes to address until a newline is encountered
; returns nothing
getstring:
    call    getchar      ; read a character
    cmp     ax, 13       ; dos has two ascii characters for new lines 13 then 10
    je      .done        ; its not a 13, whew...
    cmp     ax, 10       ; check for 10 now
    je      .done        ; its not a 10, whew...
    mov     [di], al     ; write the character to the current byte
    inc     di           ; move to the next address
    mov     dx, ax       ; dos doesn't print as it reads like windows, let's fix that
    call    putchar
    jmp     getstring
.done:
    mov     dx, 13       ; write a newline for sanity
    call    putchar
    mov     dx, 10
    call    putchar
    ret

; takes an address to write to in di
; writes to address until a newline is encountered
; returns nothing
putstring:
    cmp     byte [di], 0 ; see if the current byte is a null terminator
    je      .done        ; nope keep printing
.continue:
    mov     dl, [di]     ; grab the next character of the string
    mov     dh, 0        ; print it
    call    putchar
    inc     di           ; move to the next character
    jmp     putstring
.done:
    ret

section .data

    prompt: db "Please enter your first name: ", 0
    string: times 20 db 0
    hello: db "Hello, ", 0

output

output

Criticizing optimizations by unused instructions is particularly welcome, but everyone is welcome!

SQL Server – Why does this partitioning helper view the error "Input string did not have a correct format"?

In a database that I examine, a view is defined admin.View_PartitionRangeswhich strongly depends on the view PartitionRanges can be found in this MSDN blog post from the year 2009. The local view definition is:

CREATE VIEW (dbo).(PartitionRanges) AS
select pf.name as (partition_function),
       ps.name as (partition_scheme),
       1 as (partition_number),
       case when prv.value is null then NULL else '<' end as (relation),
       prv.value as (boundary_value),
       type_name(pp.system_type_id) as (type),
       fg.name as (filegroup),
       case when ps.name is null then NULL else N'IN USE' end as (status)
  from sys.partition_functions pf
  join sys.partition_parameters pp on pp.function_id = pf.function_id
  left join sys.partition_schemes ps on ps.function_id = pf.function_id
  left join sys.destination_data_spaces dds
    on dds.partition_scheme_id = ps.data_space_id and dds.destination_id = 1 
  left join sys.filegroups fg on fg.data_space_id = dds.data_space_id
  left join sys.partition_range_values prv
    on prv.function_id = pf.function_id and prv.parameter_id = 1 and
       prv.boundary_id = 1
 where pf.boundary_value_on_right = 1
 union all
select pf.name as (partition_function),
       ps.name as (partition_scheme),
       prv.boundary_id + cast(pf.boundary_value_on_right as int) as (partition_number),
       case when pf.boundary_value_on_right = 0 then '<=' else '>=' end as (relation),
       prv.value as (boundary_value),
       type_name(pp.system_type_id) as (type),
       fg.name as (filegroup),
       case when ps.name is null then NULL else N'IN USE' end as (status)
  from sys.partition_functions pf
  join sys.partition_range_values prv on
       prv.function_id = pf.function_id and prv.parameter_id = 1
  join sys.partition_parameters pp on pp.function_id = pf.function_id
  left join sys.partition_schemes ps on ps.function_id = pf.function_id
  left join sys.destination_data_spaces dds
    on dds.partition_scheme_id = ps.data_space_id and
       dds.destination_id = prv.boundary_id + cast(pf.boundary_value_on_right as int)
  left join sys.filegroups fg on fg.data_space_id = dds.data_space_id
 union all
select pf.name as (partition_function),
       ps.name as (partition_scheme),
       pf.fanout as (partition_number),
       case when prv.value is null then NULL else '>' end as (relation),
       prv.value as (boundary_value),
       type_name(pp.system_type_id) as (type),
       fg.name as (filegroup),
       case when ps.name is null then NULL else N'IN USE' end as (status)
  from sys.partition_functions pf
  join sys.partition_parameters pp on pp.function_id = pf.function_id
  left join sys.partition_schemes ps on ps.function_id = pf.function_id
  left join sys.destination_data_spaces dds
    on dds.partition_scheme_id = ps.data_space_id and dds.destination_id = pf.fanout 
  left join sys.filegroups fg on fg.data_space_id = dds.data_space_id
  left join sys.partition_range_values prv
    on prv.function_id = pf.function_id and prv.parameter_id = 1 and
       prv.boundary_id = pf.fanout - 1
 where pf.boundary_value_on_right = 0
 union all
select pf.name as (partition_function),
       ps.name as (partition_scheme),
       NULL, NULL, NULL, NULL,
       fg.name as (filegroup),
       case when dds.destination_id = pf.fanout + 1
            then N'NEXT USED' else N'NOT USED'
       end as (status)
  from sys.partition_functions pf
  join sys.partition_schemes ps on ps.function_id = pf.function_id
  join sys.destination_data_spaces dds
    on dds.partition_scheme_id = ps.data_space_id and
       dds.destination_id > pf.fanout
  join sys.filegroups fg on fg.data_space_id = dds.data_space_id 

However, if I have one SELECT * With this view in SSMS I get the error

An error occurred while executing batch. Error message is: 
Input string was not in a correct format.

What's wrong with you?

Recursion – What is an example of a (simple) recursive tail algorithm that does not use a helper function?

I know that things can be calculated using tail recursion with auxiliary functions like the following:

let sum_helper n accumulator =
match n with
| 0 -> accumulator
| _ -> sum_helper (n-1) (accumulator+n-1);;

let sum_tail n = sum_helper n accumulator 0;;

sum_tail 3;;

what gives:

# sum_tail 3;;
- : int = 3

but I wanted to give an example of something that uses no helper function (idk, if the above can be done without an helper function).

Ideally, something simple to better understand the concept, since I look like all the tail recursions.

Expert Virtual Assistant Project Helper for $ 10

Expert Virtual Assistant Project Helper

Data Entry / Data Analysis / Admin Support / Data Mining / Web Scraping / Virtual Assistant /Excel formatting / e-mail collection

I'm an expert in Data Entry / Data Analysis / Admin Support / Data Mining / Web Scraping / Virtual Assistant

I can do the following for you:

  • Copy data paste from different links
  • Copy data paste from different websites
  • Data input from PDF files

Above are all the services that I can offer you with a 100% guarantee
Guarantee of the quality of the work, full satisfaction and responsibility for the work.

I am confident to work with you.

Overrides – I override a controller and want to use a custom helper in the overridden controller. How can I do that?

I have overwritten the following controller: –

Magento  Customer  Controller  Account  CreatePost.php

And the constructor method of this class is:

    public function __construct (
Context $ context,
Session $ customerSession,
ScopeConfigInterface $ scopeConfig,
StoreManagerInterface $ storeManager,
AccountManagementInterface $ accountManagement,
Address $ addressHelper,
UrlFactory $ urlFactory,
FormFactory $ formFactory,
SubscriberFactory $ subscriberFactory,
RegionInterfaceFactory $ regionDataFactory,
AddressInterfaceFactory $ addressDataFactory,
CustomerInterfaceFactory $ customerDataFactory,
CustomerUrl $ customerUrl,
Registration $ registration,
Escaper $ Escaper,
CustomerExtractor $ customerExtractor,
DataObjectHelper $ dataObjectHelper,
AccountRedirect $ accountRedirect,
Validator $ formKeyValidator = null
) {
$ this-> session = $ customerSession;
$ this-> scopeConfig = $ scopeConfig;
$ this-> storeManager = $ storeManager;
$ this-> accountManagement = $ accountManagement;
$ this-> addressHelper = $ addressHelper;
$ this-> formFactory = $ formFactory;
$ this-> subscriberFactory = $ subscriberFactory;
$ this-> regionDataFactory = $ regionDataFactory;
$ this-> addressDataFactory = $ addressDataFactory;
$ this-> customerDataFactory = $ customerDataFactory;
$ this-> customerUrl = $ customerUrl;
$ this-> registration = $ registration;
$ this-> escaper = $ escaper;
$ this-> customerExtractor = $ customerExtractor;
$ this-> urlModel = $ urlFactory-> create ();
$ this-> dataObjectHelper = $ dataObjectHelper;
$ this-> accountRedirect = $ accountRedirect;
$ this-> formKeyValidator = $ formKeyValidator ?: ObjectManager :: getInstance () -> get (Validator :: class);
parent :: __ construct ($ context);
}

I am trying to call a helper in my overdriven controller.

INW  VendorRequest  Controller  Magento  Customer  Account  CreatePost.php

And I've tried it in two ways and here's the code of my constructor:

1-

public function __construct (
Context $ context,
Session $ customerSession,
ScopeConfigInterface $ scopeConfig,
StoreManagerInterface $ storeManager,
AccountManagementInterface $ accountManagement,
Address $ addressHelper,
UrlFactory $ urlFactory,
FormFactory $ formFactory,
SubscriberFactory $ subscriberFactory,
RegionInterfaceFactory $ regionDataFactory,
AddressInterfaceFactory $ addressDataFactory,
CustomerInterfaceFactory $ customerDataFactory,
CustomerUrl $ customerUrl,
Registration $ registration,
Escaper $ Escaper,
CustomerExtractor $ customerExtractor,
DataObjectHelper $ dataObjectHelper,
AccountRedirect $ accountRedirect,
 INW  ReviewMail  Helper  Data $ helper, // MY HELPER I INJECT
Validator $ formKeyValidator = null
) {
$ this-> session = $ customerSession;
$ this-> scopeConfig = $ scopeConfig;
$ this-> storeManager = $ storeManager;
$ this-> accountManagement = $ accountManagement;
$ this-> addressHelper = $ addressHelper;
$ this-> formFactory = $ formFactory;
$ this-> subscriberFactory = $ subscriberFactory;
$ this-> regionDataFactory = $ regionDataFactory;
$ this-> addressDataFactory = $ addressDataFactory;
$ this-> customerDataFactory = $ customerDataFactory;
$ this-> customerUrl = $ customerUrl;
$ this-> registration = $ registration;
$ this-> escaper = $ escaper;
$ this-> customerExtractor = $ customerExtractor;
$ this-> urlModel = $ urlFactory-> create ();
$ this-> dataObjectHelper = $ dataObjectHelper;
$ this-> accountRedirect = $ accountRedirect;
$ this -> _ helper = $ helper;
$ this-> formKeyValidator = $ formKeyValidator ?: ObjectManager :: getInstance () -> get (Validator :: class);
parent :: __ construct ($ context);
}

2

public function __construct (
Context $ context,
 INW  ReviewMail  Helper  Data $ helper
) {
$ this -> _ helper = $ helper;
}

But I get the problem that you can see on the screenshot: –

Enter image description here

Please let me know how to inject helper blocks into the overdriven controller.