Featured

How to replace space with underscore in an xml file using Notepad++

It is very easy to achieve this using a regex expression. Suppose we have below in an xml file and we want to replace the space inside DisplayName node with underscore.

Sample xml –

<User id="11068577">
	<UserId>11068577</UserId>
	<DisplayName>Dolcese Vita</DisplayName>
	<Address>Texas, US</Address>
</User>
  1. Open Notepad++
  2. Click Ctrl+H to open replace dialog box
  3. Add below in Find What:
(?i)(<DisplayName>.*?)[\s](?=.*</DisplayName>)

4. Add below in Replace with:

\1_\2

5. Result –

<User id="11068577">
	<UserId>11068577</UserId>
	<DisplayName>Dolcese_Vita</DisplayName>
	<Address>Texas, US</Address>
</User>
Featured

How to Add a Container in Google Tag Manager

Add a Container in Google Tag Manager

  1. Open Google Tag Manager and login. You will see the the Accounts screen with a list of all existing GTM containers.

2. To create/add a new container, click the three dots on the right – next to the settings icon as below

3. Click on Create Container and you will see the below screen

Note: In order to Create a Container, you need to have permission for it. Please ask the account admin, if you don’t have it

4. Add the container name, e.g. techiespice.com and select the Target Platform, e.g. Web. Click Create and your container is ready.

5. Once you click Create, you will see the below screen with all the container settings (Tags, Variables, Triggers, etc.) along with the GoogleTagManagerID (marked in red) on the right.

6. Click the GoogleTagManagerID and you will see the popup with GTM script that you need to add to your site.

Rebuild examine index programmatically

Rebuild examine index

You can rebuild the examine index programmatically by using the following code –

ExamineManager.Instance.IndexProviderCollection["InternalIndexer"].RebuildIndex();
               

Combine one or more generic lists in C#

Combine one or more lists in C#

One or more generic lists can be combined or merged using zip() method in C#.

Below is an example of combining 4 lists by creating an extension method.

public static IEnumerable<TResult> ZipFour<T1, T2, T3, T4, TResult>(
            this IEnumerable<T1> source,
            IEnumerable<T2> second,
            IEnumerable<T3> third,
            IEnumerable<T4> fourth,
            Func<T1, T2, T3, T4, TResult> func)
        {
            using (var e1 = source.GetEnumerator())
            using (var e2 = second.GetEnumerator())
            using (var e3 = third.GetEnumerator())
            using (var e4 = fourth.GetEnumerator())
            {
                while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext())
                    yield return func(e1.Current, e2.Current, e3.Current, e4.Current);
            }
        }

Usage

list1.ZipFour(list2, list3, list4, (a, b, c, d) => new { A = a, B = b, C = c, D = d });

Generate a hex encoded HMAC-SHA256 hash using Crypto in Nodejs

How to generate an encoded hash in nodejs using crypto

import { Service } from './service';
import crypto from 'crypto';

export class TestService extends Service {
    private _secretKey: string;

    constructor() {
        this._secretKey = '1234567890';
		this._userId = '123';
    }

    /**
     * Get Hex encoded hash of secret key
     */
    private GetHashKey(): string {
        return crypto
            .createHmac('sha256', this._secretKey)
            .update(this._getUserString(this._userId))
            .digest('hex');
    }
}
%d bloggers like this: