database design – MySQL: Should I add NOT NULL UNIQUE to the field for primary key?

Hi I’m completely new to MySQL, I’m creating a database and my question is that:

Should I add NOT NULL UNIQUE to the field for primary key?

For example I have:

CREATE TABLE Account (
    AccountID varchar(25) NOT NULL,
    ...
    PRIMARY KEY(AccountID)           // <------- (*)

I’m thinking about whether the (*) would implicitly mark the field as UNIQUE NOT NULL.

Btw, could anyone provide good resources about best practices of MySQL(I’m currently interested about creating table) so I won’t add redundant restriction(s) in any schema.

How to add filter in Gmail to label any email which is from/to an email address from one of your Google Contact labels?

I want to make my clients’ emails stand out more than just “important” allows, and also group them better. I have added all client emails to a Google Contacts “Label” and want to make all emails to/from these client email addresses to be labelled in Gmail.

There is a manual solution here: How to add filter and label to group in Gmail contacts?

But it doesn’t account for new emails you add to the contact label in future, and required manual updating.

Any help on my specific question, or an alternative solution would be much appreciated.

magento2.3 – How to add Product Attribute Values from Custom Model Data

I’m building a module for Supplier Inventory.

I created a UI Component for creating Suppliers in the dashboard.

In my ModelData I added the Supplier Name.

    class Supplier extends AbstractExtensibleObject implements SupplierInterface
    {
    /**
     * Get supplier_id
     *
     * @return string|null
     */
    public function getSupplierId()
    {
        return $this->_get(self::SUPPLIER_ID);
    }

    /**
     * Set supplier_id
     *
     * @param string $supplierId
     *
     * @return SupplierInterface
     */
    public function setSupplierId($supplierId)
    {
        return $this->setData(self::SUPPLIER_ID, $supplierId);
    }

    /**
     * Get supplier_name
     *
     * @return string|null
     */
    public function getSupplierName()
    {
        return $this->_get(self::SUPPLIER_NAME);
    }

    /**
     * Set supplier_name
     *
     * @param string $supplierName
     *
     * @return SupplierInterface
     */
    public function setSupplierName($supplierName)
    {
        return $this->setData(self::SUPPLIER_NAME, $supplierName);
    }

    /**
     * Retrieve existing extension attributes object or create a new one.
     *
     * @return VendorModuleApiDataSupplierExtensionInterface|null
     */
    public function getExtensionAttributes()
    {
        return $this->_getExtensionAttributes();
    }

    /**
     * Set an extension attributes object.
     *
     * @param VendorModuleApiDataSupplierExtensionInterface $extensionAttributes
     *
     * @return $this
     */
    public function setExtensionAttributes($extensionAttributes)
    {
        return $this->_setExtensionAttributes($extensionAttributes);
    }

    /**
     * Get supplier_shipping_days
     *
     * @return string|null
     */
    public function getSupplierShippingDays()
    {
        return $this->_get(self::SUPPLIER_SHIPPING_DAYS);
    }

    /**
     * Set supplier_shipping_days
     *
     * @param string $supplierShippingDays
     *
     * @return SupplierInterface
     */
    public function setSupplierShippingDays($supplierShippingDays)
    {
        return $this->setData(self::SUPPLIER_SHIPPING_DAYS, $supplierShippingDays);
    }

    /**
     * Get supplier_feed_url
     *
     * @return string|null
     */
    public function getSupplierFeedUrl()
    {
        return $this->_get(self::SUPPLIER_FEED_URL);
    }

    /**
     * Set supplier_feed_url
     *
     * @param string $supplierFeedUrl
     *
     * @return SupplierInterface
     */
    public function setSupplierFeedUrl($supplierFeedUrl)
    {
        return $this->setData(self::SUPPLIER_FEED_URL, $supplierFeedUrl);
    }

    /**
     * Get supplier_feed_separator
     *
     * @return string|null
     */
    public function getSupplierFeedSeparator()
    {
        return $this->_get(self::SUPPLIER_FEED_SEPARATOR);
    }

    /**
     * Set supplier_feed_separator
     *
     * @param string $supplierFeedSeparator
     *
     * @return SupplierInterface
     */
    public function setSupplierFeedSeparator($supplierFeedSeparator)
    {
        return $this->setData(self::SUPPLIER_FEED_SEPARATOR, $supplierFeedSeparator);
    }

    /**
     * Get supplier_feed_sku_field
     *
     * @return string|null
     */
    public function getSupplierFeedSkuField()
    {
        return $this->_get(self::SUPPLIER_FEED_SKU_FIELD);
    }

    /**
     * Set supplier_feed_sku_field
     *
     * @param string $supplierFeedSkuField
     *
     * @return SupplierInterface
     */
    public function setSupplierFeedSkuField($supplierFeedSkuField)
    {
        return $this->setData(self::SUPPLIER_FEED_SKU_FIELD, $supplierFeedSkuField);
    }

    /**
     * Get supplier_feed_stock_field
     *
     * @return string|null
     */
    public function getSupplierFeedStockField()
    {
        return $this->_get(self::SUPPLIER_FEED_STOCK_FIELD);
    }

    /**
     * Set supplier_feed_min_stock_field
     *
     * @param string $supplierFeedStockField
     *
     * @return SupplierInterface
     */
    public function setSupplierFeedStockField($supplierFeedStockField)
    {
        return $this->setData(self::SUPPLIER_FEED_STOCK_FIELD, $supplierFeedStockField);
    }

    /**
     * Get supplier_feed_min_stock
     *
     * @return string|null
     */
    public function getSupplierFeedMinStock()
    {
        return $this->_get(self::SUPPLIER_FEED_MIN_STOCK);
    }

    /**
     * Set supplier_feed_min_stock
     *
     * @param string $supplierFeedMinStock
     *
     * @return SupplierInterface
     */
    public function setSupplierFeedMinStock($supplierFeedMinStock)
    {
        return $this->setData(self::SUPPLIER_FEED_MIN_STOCK, $supplierFeedMinStock);
    }
}

I also add a Product attribute supplier through the VendorModuleSetupPatchDataAddSupplierProductAttribute.php

class AddSupplierProductAttribute implements DataPatchInterface, PatchRevertableInterface
{
    /**
     * @var ModuleDataSetupInterface
     */
    private $moduleDataSetup;

    /**
     * @var EavSetupFactory
     */
    private $eavSetupFactory;

    /**
     * Constructor
     *
     * @param ModuleDataSetupInterface $moduleDataSetup
     * @param EavSetupFactory          $eavSetupFactory
     */
    public function __construct(
        ModuleDataSetupInterface $moduleDataSetup,
        EavSetupFactory $eavSetupFactory
    ) {
        $this->moduleDataSetup = $moduleDataSetup;
        $this->eavSetupFactory = $eavSetupFactory;
    }

    /**
     * @return AddSupplierProductAttribute|void
     */
    public function apply()
    {
        $this->moduleDataSetup->getConnection()->startSetup();
        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(('setup' => $this->moduleDataSetup));
        $eavSetup->addAttribute(
            MagentoCatalogModelProduct::ENTITY,
            'supplier',
            (
                'type' => 'int',
                'label' => 'Supplier',
                'input' => 'select',
                'source' => VendorModuleModelProductAttributeSourceSupplier::class,
                'frontend' => '',
                'required' => false,
                'backend' => '',
                'sort_order' => '30',
                'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
                'default' => null,
                'visible' => true,
                'user_defined' => true,
                'searchable' => false,
                'filterable' => false,
                'comparable' => false,
                'visible_on_front' => false,
                'unique' => false,
                'apply_to' => '',
                'group' => 'General',
                'used_in_product_listing' => false,
                'is_used_in_grid' => true,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'option' => ''
            )
        );

        $this->moduleDataSetup->getConnection()->endSetup();
    }

    /**
     * @return void
     */
    public function revert()
    {
        $this->moduleDataSetup->getConnection()->startSetup();
        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(('setup' => $this->moduleDataSetup));
        $eavSetup->removeAttribute(MagentoCatalogModelProduct::ENTITY, 'supplier');

        $this->moduleDataSetup->getConnection()->endSetup();
    }

    /**
     * @return array
     */
    public function getAliases()
    {
        return ();
    }

    /**
     * @return array
     */
    public static function getDependencies()
    {
        return ();
    }
}

I was wondering how I can add the Supplier Name that is created through the UI Component will automatically add a value to the Product Attribute Supplier.

interaction design – ‘Add to Favorites’ state change immediately or wait for backend confirmation?

Optimistic updates can go wrong too, what if the network request takes time, and use closes the browser or leaves the site and thinks the interaction was successful because of the visual feedback he received?
In my opinion the best practice, for important interactions, is to use some transition that gives feedback on click, but does not hide the pending state in case it takes more than a second or two.
For low-importance interactions, like rating something or clicking ‘like’, the impact of errors is smaller, so optimistic updates are more ok.

forms – How to add “clone” button to WebformMultiple field

I created a custom composite field with a dozen or so fields, in a custom module extending DrupalwebformElementWebformCompositeBase. I need to add a “clone” button to the webform multiple table operations, which when clicked will create a new instance of the webform widget as the “add” button does, except that it is populated with the values existing in the element that is being cloned.

I asked this question in the webform issue queue and @jrockowitz responded

That is very tricky.

First, you would add the new operation via DrupalwebformElementWebformMultiple::buildElementRow and then your would have to examine the $form_state to parse the values of the previous rows.

One trick to adding new functionality like this is to first disable #ajax and get the functionality working without ajax and then enable #ajax.

I’m relatively new to D8 development, so I don’t understand how to override or otherwise commandeer DrupalwebformElementWebformMultiple::buildElementRow. I know how to make a child class of it and start to add my customizations to it, but I don’t know how to get my class to be the one that is executed in place of WebformMultiple::buildElementRow.

forms – How to add and associate Paragraphs to Media Library Images Programmatically

Good day everyone,

Our client wants to have this feature where he can upload/reuse multiple images for an article content type. This can be achieved using a Media Library, where I find it tricky is each images will have additional fields(Alt, Copyright, Description fields), I’ve tried adding the additional fields to the Image Media Type but once the node is saved, their value will be associated to the image’s metadata. The proper functionality should be is when the node is saved, the Alt and Description of the images should be associated to the node’s metadata because Images can be reusable to another node, and the values of Alt and Description varies to each node.

So I talked with someone who really knows a lot about Drupal. He suggested that I keep the Media Library, and create a Paragraph Type. I called it ‘Image Library Paragraphs’, this paragraph has Image, Alt, Copyright, and Description fields. This way the Paragraph can hold the id of the image, alt, description and the node’s ID. In theory, what we’re trying to do here is everytime the user uploads/select an image. We must find a way to associate that image and add corresponding paragraph for each of those images. So if the user uploads/selects 3 images. It will also automatically create 3 paragraphs for those images. We also would need to reconstruct the layout of the form to somehow “blend” the image and its corresponding paragraphs. And since the position of the images can be changed, we also need to somehow reposition its paragraph accordingly to the image.

It’s tricky and a lot of work, honestly it’s even beyond my Drupal skills. But any help to the right direction will truly be appreciated. I haven’t even tried creating a really complex custom module. But would really want to learn how this can be done. Thank you in advance.

In theory this is what it’s gonna look like
enter image description here

enter image description here

Direct link to add email to contact in Gmail

In marketing and transactional emails I send to Gmail address,
I would like to include a link, clicking on which adds my address to the recipient’s contacts.

I have read In Gmail, how do I create a contact from a recipient of an email? but that doesn’t help.

Describing the process to the recipient is more complicated and fraught, e.g. on desktop gmail, one needs to hover on the sender name, then click on “more info”, then click “add to contact icon” in the opened section. Different way on mobile. So if I could generate a link that they can just click to add is the way I’d like to go, if at all possible.

How to add extra speech marks in C scripting program

I am trying to write a C program that will create lines of code on the console window when the program is ran. I can then copy this code and use it to initialise RAM in my VHDL project code.

I have attached images below to show what I am trying to do.

The image of the C code and console show me trying to initialise RAM location 0 with 4 zeros, but in VHDL, these 4 zeros need to be around speech marks, like so: 0 => “0000”;

I will then use a for loop as I need the same instruction 1024 times. I can then copy and paste the code in. Is this possible?

C Image

VHDL Image

google sheets – How to add arrayformula function to this formula with IF function?

I made a table that has two columns (namd & State). The 4th column(check) makes conditional formatting possible for any of these combinations: (if name is either “Ali” or “John”, AND state is “FL”), a conditional formatting rule is applied only if the cell value of E2 is “NO”.

I had to repeat this formula for all rows and I failed to wrap it in an arrayformula function.

I tried this but failed:
=if(OR(AND(C2="John",D2="FL",$E$1="No"),AND(C2="Ali",D2="FL",$E$1="No")),1,0)

adding arrayformula:
=ArrayFormula(if(OR(AND(C2:C="John",C2:D="FL",$E$1="No"),AND(C2:C="Ali",D2:D="FL",$E$1="No")),1,0))

https://docs.google.com/spreadsheets/d/17mmduo0em4PK0FDPxIRTX36CqhW6woI4jdyPSJaiGAM/edit#gid=1414263054

php – How to add API security keys into JS of wordpress securely

I am using wp_localize_script() to add variables from my config.ini file to my inline JS code (inside HTML block element of Elementor) (Please see this for reference)

But this method is unsafe to add Security keys because these variables can be accessed via console. How can I add API security keys to my JS code securely?
Is there any way I can achieve this? Thank you in advance.