javascript – Is there a better way to copy dynamic data from one sheet to another in google sheets script?

I’m pulling data in from an API and putting it in the top two rows of a sheet. This script is to copy the data from the “pull” sheet into a daily sheet. The rub is that the data may change and I want to dynamically copy the data over; i.e. if the column header exists, put the new data in the bottom row. If the column header does not exist, create a new column and copy in the data into the correct row.

The script feels cumbersome and not reusable. Is there a better and/or more generic way to do this?

 function runCopyToDailyScript(){
var souceSheetName = "AAVE Data Pull";
var targetSheetName = "AAVE Daily" ;
let ss = SpreadsheetApp.getActiveSpreadsheet();           // get active spredsheet
let sourceSheet = ss.getSheetByName(souceSheetName);
let targetSheet = ss.getSheetByName(targetSheetName);
var nextTargetRow = targetSheet.getLastRow() + 1. // where the next row of data is going

// get the data in top two rows of source sheet
var sourceRange = sourceSheet.getDataRange();  // get range of all data on source sheet
var sourceData = sourceRange.getValues(); // get the values of all the data in the source sheet
var sourceArray = transposeArray(sourceData); // transposeArray from genearal functions

// target data
var targetHeadersRange = targetSheet.getRange(1,1,1,targetSheet.getLastColumn());  // get top row of daily data
var targetHeaders2DArray = targetHeadersRange.getValues();  // array of headers within an array
var targetHeaders = targetHeaders2DArray(0);  // creats an array of the headers

/** go through source (the data pull) headers and see if they are in target sheet */
sourceArray.forEach(element => checkDailySheet(element));  // goes through each pair of source data. checkDailySheet is another function

function checkDailySheet(subArray){
  let theIndex = targetHeaders.indexOf(subArray(0)) // returns the index of the key in the pair in the target sheet if it exists

  // test to see if the the column head is in the target sheet
  if (theIndex != -1) { 
          let targetCell = targetSheet.getRange(nextTargetRow, theIndex + 1, 1, 1) // nextTargetRow is constant declared above
          targetCell.setValue(subArray(1)) // sets the last row in the target column to the source value
          
  } else {
          /** find the next avail column in target range */
          targetHeadersRange = targetSheet.getRange(1,1,1,targetSheet.getLastColumn() + 1);
          targetHeaders2DArray = targetHeadersRange.getValues();
          targetHeaders = targetHeaders2DArray(0); // array with the target headers + one extra
          let targetHeadersLength = targetHeaders.length;

          let newTargetHeaderCell = targetSheet.getRange(1, targetHeadersLength, 1, 1);
          newTargetHeaderCell.setValue(subArray(0)); // set the next collum header with the missing key

          let targetCell = targetSheet.getRange(nextTargetRow, targetHeadersLength, 1, 1) // nextTargetRow is constant declared above
          targetCell.setValue(subArray(1)) // sets the last row in the target column to the source value
          
   }; // end of else
  }; //end of CheckDailySheet
}; // end of runCopyToDailyScript()

magento2 – How to show uploaded image in dynamic rows?

I have added image field in dynamic rows like below

$this->addColumn(
    'image',
    (
    'label' => __('Image'),
    'renderer' => $this->getImageRenderer()
));

private function getImageRenderer()
{
    if (!$this->imageRenderer) {
        $this->imageRenderer = $this->getLayout()->createBlock(
            VendorModuleBlockAdminhtmlBlocksEditTabImageRenderer::class,
            '',
            ('data' => ('is_render_to_js_template' => true))
        );
    }
    return $this->imageRenderer;
}

ImageRenderer class

<?php

namespace VendorModuleBlockAdminhtmlBlocksEditTab;

class ImageRenderer extends MagentoFrameworkViewElementAbstractBlock
{
    /**
     * {@inheritdoc}
     */
    protected function _toHtml()
    {
        $html = '<input type="file" name="' . $this->getInputName() . '" id="' . $this->getInputId() . '" ';
        $html .= '<image name="' . $this->getInputName() . '" id="' . $this->getInputId() . '" />';
        return $html;
    }
}
 

Now I am able to browse image and save in database.

enter image description here

Now how to show uploaded image in the grid?

Most probable I would like to use _prepareArrayRow function like below to achieve it

protected function _prepareArrayRow(MagentoFrameworkDataObject $row)
    {
        if (isset($row('image'))) {
            $image = $row->getImage(); // image path here
            // how to add image src from here
    }

My question is how to add html properties like img src in _prepareArrayRow function?

statistics – Sliding window max/min algorithm without dynamic allocations

I’m working on a suite of DSP tools in Rust, and one of the features of the library is a collection of windowed statistics (mean, rms, min, max, median, etc) on streams of floating-point samples. The user provides an iterator of floats and a fixed-size mutable slice/array of floats as inputs, and get back a iterator that lazily calculates the desired stat one sample at a time. The contents of the float slice/array become the initial window, and can be used as scratch space internally. This slice/array also determines the sliding window size.

// A sliding mean with a window size of 64, initially filled with 0.42.
let sample_iter = /* an iterator that yields floats */;
let buffer = (0.42; 64);
let sliding_mean_iter = SlidingMean::new(sample_iter, buffer);

I’d ideally like to have my library also usable in an embedded environment, and so far I’ve been able to do so by not using any dynamic memory allocations.

As of now, I have efficient mean and rms implementations, but I’m stumped on the windowed min/max. Looking up sliding window min/max algorithms online(1)(2), I see that:

  1. A naive approach of scanning the window after each update leads to a O(nk) runtime, where n is the length of the input iterator and k is the window length. This feels like it could be inefficient for larger window sizes.
  2. Using a deque allows for an efficient implementation of O(n) (with amortized insertion of O(1)), but using a deque would require dynamic allocations.
  3. Since the passed-in buffer is overloaded to both set the initial window contents as well as to serve as scratch space, I can’t mess with the type of that, it has to stay as a slice/array of plain floats. This means I can’t make it an array of (int, float) to store array indices alongside the data, for example.

Are there any clever tricks or optimizations I can use to have my cake (efficient sliding min/max) and eat it too (avoid having memory allocations)?

url rewriting – How to translate slugs in custom post types or making them dynamic?

How can we translate the rewrite slug in custom post types? Or making them dynamic with regex?

For example:

function news_init() {
    $args = array(
        'labels' => array(
            'name' => __('News (Pages)'),
            'singular_name' => __('News'),
            'all_items' => 'All News'
       ),
        'public' => true,
        'rewrite' => array(
            'slug' => 'news',
            'with_front' => true
        ),
    register_post_type('news', $args);
}
add_action('init', 'news_init');

That 'slug' => 'news', needs to be dynamic for different translation sites. Can we do it without any plugin?

mac – Disable Dynamic Menu Bar in macOS Big Sur

mac – Disable Dynamic Menu Bar in macOS Big Sur – Ask Different

unity – Dynamic bridge via joints

When a new object is added to the bridge, the bridge shakes violently, and when objects are added even faster, it breaks.

I’ve tried changing mass and changing time step, but that doesn’t solve the problem.

enter image description here

Code for adding a new object:

(SerializeField)
Rigidbody _last;

(SerializeField)
GameObject _prefab;

void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        var go = Instantiate(_prefab);
        var fj = go.GetComponent<FixedJoint>();
        fj.autoConfigureConnectedAnchor = false;
        fj.connectedAnchor = new Vector3(0f, 0f, -2f);
        fj.connectedBody = _last;
        _last = go.GetComponent<Rigidbody>();
    }
}

The first cube is kinematic.
prefab:

enter image description here

How can you solve this?
Thanks for help

magento2 – How to Get/Show Dynamic rows data from custom tab in Magento 2?

I have added a new tab as shown below.

enter image description here

Related code is given below.

VendorMobileApiBlockAdminhtmlBlocksEditTabs

<?php

namespace VendorMobileApiBlockAdminhtmlBlocksEdit;

class Tabs extends MagentoBackendBlockWidgetTabs
{
    protected $blockModel;
    protected $blockTemplateModel;

    public function __construct(
        MagentoBackendBlockTemplateContext $context,
        MagentoFrameworkJsonEncoderInterface $jsonEncoder,
        MagentoBackendModelAuthSession $authSession,
        array $data = (),
        VendorMobileApiModelBlocks $blockModel,
        VendorMobileApiModelBlockTemplate $blockTemplateModel
    )
    {
        $this->blockModel = $blockModel;
        $this->blockTemplateModel = $blockTemplateModel;
        parent::__construct($context, $jsonEncoder, $authSession, $data);
    }

    /**
     * Constructor
     *
     * @return void
     */
    protected function _construct()
    {
        parent::_construct();
        $this->setId('mobileapi_blocks_edit_tabs');
        $this->setDestElementId('edit_form');
        $this->setTitle(__('Block'));
    }
    protected function _beforeToHtml()
    {
        if (!$this->getRequest()->getParam('id')){
            return  parent::_beforeToHtml();
        }



                $this->addTab(
                    'item_info',
                    (
                        'label' => __('Manage Items'),
                        'title' => __('Manage Items'),
                        'content' => $this->getLayout()->createBlock(
                            'VendorMobileApiBlockAdminhtmlBlocksEditTabItems'
                        )->toHtml(),
                        'active' => true
                    )
                );
        return parent::_beforeToHtml();
    }
    
}

VendorMobileApiBlockAdminhtmlBlocksEditTabItems

<?php

namespace VendorMobileApiBlockAdminhtmlBlocksEditTab;
use MagentoBackendBlockWidgetFormGeneric;
use MagentoBackendBlockWidgetTabTabInterface;


class Items extends Generic implements TabInterface
{
    /**
     * @var MagentoCmsModelWysiwygConfig
     */
    protected $categoryType;
    protected $blockData = ();
    protected $templateData = ();
    protected $authSession;


    public function __construct(
        MagentoBackendBlockTemplateContext $context,
        MagentoFrameworkRegistry $registry,
        MagentoFrameworkDataFormFactory $formFactory,
        array $data = (),
        MagentoBackendModelAuthSession $authSession
    )
    {
        $this->authSession = $authSession;
        parent::__construct($context, $registry, $formFactory, $data);
    }


    public function _prepareForm()
    {
        $blockData = $this->authSession->getBlockData();
        $templateData = $this->authSession->getTemplateData();
        /** @var MagentoFrameworkDataForm $form */
        $form = $this->_formFactory->create();
        $form->setHtmlIdPrefix('block_');
        $fieldset = $form->addFieldset('base_fieldset', ('legend' => __('Config Information')));
        if ($blockData->getId()) {
            $fieldset->addField('id', 'hidden', ('name' => 'id'));
        }

        $layoutBlock = $this->getLayout()->createBlock(
            ItemRow::class
        );
        $fieldsetRow = $form->addFieldset('item_update', ('legend' => __('Item Updates')));
            $form->getElement('item_update')->setRenderer($layoutBlock);
            $form->setValues($blockData->getData());
            $this->setForm($form);
            return parent::_prepareForm();
    }

    public function getBlockData() {
        return $this->authSession->getBlockData();
    }

    public function getTemplateData() {
        return $this->authSession->getTemplateData();
    }

    public function getTabLabel()
    {
        // TODO: Implement getTabLabel() method.
    }

    public function getTabTitle()
    {
        // TODO: Implement getTabTitle() method.
    }

    public function canShowTab()
    {
        // TODO: Implement canShowTab() method.
    }

    public function isHidden()
    {
        // TODO: Implement isHidden() method.
    }
}

Dynamic Rows class

<?php
declare(strict_types=1);
namespace VendorMobileApiBlockAdminhtmlBlocksEditTab;
use MagentoBackendBlockTemplateContext;
use MagentoConfigBlockSystemConfigFormFieldFieldArrayAbstractFieldArray;
use MagentoFrameworkViewHelperSecureHtmlRenderer;

class ItemRow extends AbstractFieldArray
{
    protected MagentoBackendModelAuthSession $authSession;
    protected $selectRenderer;
    public function __construct(
        Context $context,
        array $data = (),
        ?SecureHtmlRenderer $secureRenderer = null,
        MagentoBackendModelAuthSession $authSession
    )
    {
        $this->authSession = $authSession;
        parent::__construct($context, $data, $secureRenderer);
    }
    /**
     * {@inheritdoc}
     */
    protected function _prepareToRender()
    {
        $this->addColumn(
            'field_name',
            (
                'label' => __('Field Name'),
                'type' => 'text',
                'class' => 'required-entry'
            )
        );
                    $this->_addAfter = false;
                    $this->_addButtonLabel = __('Add'); 
    }
}

Now when I try to get data in the Save controller, I am not getting data from the dynamic rows input field. I am only getting data from first tab “Block Information”;

Using $this->getRequest()->getParams() to get data in the controller. How to get data in controller so that I can save it in my custom table ? I also want to show saved data in the same tab.

dynamic – Svelte component created with JavaScript not receiving reactive updates

I dynamically create a component on button click with the following JS:

const modal = new OrderModal({
  target: document.querySelector('.modal_container-' + order.id),
  props: {
     order: order
  },
});

However whenever I update the order object it does not reactively reflect in the created component.

If I put the component directly in the html instead of making it dynamic like this:

<div class="modal_container-{order.id} fixed">
    <OrderModal {order} />
</div>

Then it works correctly and the elements are reactively updated.

Is there a way to make components created by JavaScript update reactively?

sql server – Turn SQL tables into Views – with Dynamic SQL

Your specific error is due to you directly referencing your @viewName variable in your dynamic SQL string in Step 2, but it doesn’t exist in that context. You have to concatenate the value that variable holds to your dynamic SQL string instead. Something like this perhaps:

DECLARE @dynamicSQL NVARCHAR(MAX) = N'CREATE VIEW ' + QUOTENAME(@viewName) + ' AS SELECT * from tableName'

EXECUTE sp_ExecuteSQL @dynamicSQL

Note the usage of sp_ExecuteSQL in my example above, as this is the recommended way of executing dynamic SQL for security reasons. It looks like you’re already doing that in Step 1.

That being said, a little more context on your why would be important here. If you plan to remove, rename, or alter the underlying table that you’re currently creating views for, then your view will potentially no longer work as well, since a view is just an unmaterialized placeholder for a query that references other objects, and therefore depends on those objects. Please elaborate in your post on what the end goal of your tables are, and perhaps a better recommendation can be made to what you should do.

Dynamic Rendering vs Google Analytics

Hi there,

is there any best practice regarding how to correctly match Dynamic Rendering with Analytics, and avoid errors in Google Analytics data collection?

Many thanks

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123