Configure Tor with Bridge in Ubuntu

sudo apt-get install tor

After runing tor you can see the log of the tor by

journalctl -exft Tor

If the service started without errors, look at the Tor log

sudo journalctl -b --no-pager /usr/bin/tor
sudo apt install obfs4proxy

then you should get the bridge line. for get the bridge line go to https://bridges.torproject.org/ and get your bridge line.

nano /etc/tor/torrc
UseBridges 1 
ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy 
Bridge obfs4 132.145.63.40:47347 5C72EEEE587AB1C7021A78707DAB80427F7A9B43 cert=HAZq1DmA4kR1/IFy1TBeSd67BNQI4SDur+U3zxun+G7HCWJ+x66eUyM6/sariPQYDJ9aIw iat-mode=0
Bridge obfs4 132.226.205.56:1991 6CA77FBE6752502259A3D0079F1C510663166404 cert=yrWZOUqsfQ9IyCj3LFwXSqFqbh+59S+1P9yPh/obHt4fbVYrE3ypGthX/+ZvM207I3xIBQ iat-mode=0
Bridge obfs4 45.33.1.189:9123 F9DFF618E7BA6C018245D417F39E970C2F019BAA cert=mDZuXuqSTjX1OjN7zLybTYzNi0A21A7G0DRNmW79029cSvLYSOk/KhGftcnmxruTmhRfZQ iat-mode=0
systemctl restart tor.service

References
https://askubuntu.com/questions/1183145/how-can-i-configure-tor-with-bridge-and-privoxy-to-proxy-entire-system
https://askubuntu.com/questions/607961/error-with-tor-in-ubuntu14-04

Use mongorestore to restore a database to MongoDB with –auth enabled

mongorestore --host databasehost:12345 --username restoreuser --password restorepwd --authenticationDatabase admin --db targetdb ./path/to/dump/
mongorestore --db monitoring --collection items_history_202208 items_history_202208.archive.gz --gzip --archive=items_history_202208.archive.gz --username=user --password=pass --authenticationDatabase=admin

References
https://stackoverflow.com/questions/42349047/use-mongorestore-to-restore-a-database-to-mongodb-3-4-with-auth-enabled-sas

Install GitHub Desktop on Ubuntu

wget -qO - https://mirror.mwt.me/ghd/gpgkey | sudo tee /etc/apt/trusted.gpg.d/shiftkey-desktop.asc > /dev/null
# if you want to use packagecloud.io
sudo sh -c 'echo "deb [arch=amd64] https://packagecloud.io/shiftkey/desktop/any/ any main" > /etc/apt/sources.list.d/packagecloud-shiftkey-desktop.list'

# if you want to use the US mirror
sudo sh -c 'echo "deb [arch=amd64] https://mirror.mwt.me/ghd/deb/ any main" > /etc/apt/sources.list.d/packagecloud-shiftkey-desktop.list'
sudo apt update && sudo apt install github-desktop

References
https://github.com/shiftkey/desktop

Install GitHub CLI on Ubuntu

curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
sudo apt update
sudo apt install gh

References
https://github.com/cli/cli/blob/trunk/docs/install_linux.md
https://cli.github.com/manual/gh

Child Component Support in Blazor CSS isolation

The CSS isolation is only applied to the component level by default but you can extend it to the child component using “::deep” attribute in the CSS file. This attribute is the Blazor attribute so, it only understands and parses by the Blazor engine. When “::deep” attribute used in the CSS file, the Blazor engine also applied scope identifier to all descendants of components.

ChildComponent.razor

<hr />
<p>
    paragraph:: This is child component content
</p>
<div>
    div:: This is child component content
</div>
<hr />
@code {
}

ParentComponent.razor

@page "/parentcomponent"
<h3>Parent Component</h3>
<div>
    <p>paragraph:: This is Parent Component content</p>
    <ChildComponent></ChildComponent>
    <div>
        div:: This is parent component content
    </div>
</div>
@code {
}

ParentComponent.razor.css

p {
    color: red
}
::deep div {
    color:orange;
    font-weight:bold;
}

References
https://docs.microsoft.com/en-us/aspnet/core/blazor/components/css-isolation?view=aspnetcore-6.0
https://www.c-sharpcorner.com/article/css-isolation-in-blazor/

Add/Load Components Dynamically in ASP.NET Blazor

@page "/somepage"

@dynamicComponent()

@functions{
  RenderFragment dynamicComponent() => builder =>
    {
        builder.OpenComponent(0, typeof(SurveyPrompt));
        builder.AddAttribute(1, "Title", "Some title");
        builder.CloseComponent();
    };
}

References
https://stackoverflow.com/questions/50188680/add-load-components-dynamically
https://github.com/dotnet/aspnetcore/issues/16104
https://docs.microsoft.com/en-us/aspnet/core/blazor/components/dynamiccomponent?view=aspnetcore-6.0

Get Current URL in a Blazor Component

protected override async Task OnInitializedAsync()
{
    NavigationManager.LocationChanged += NavigationManagerOnLocationChanged;
    // access to uri on first page load
    Logger.LogInformation(NavigationManager.ToBaseRelativePath(NavigationManager.Uri));
}

private void NavigationManagerOnLocationChanged(object? sender, LocationChangedEventArgs e)
{
    // access to uri on change
    Logger.LogInformation(NavigationManager.ToBaseRelativePath(NavigationManager.Uri));
}

References
https://stackoverflow.com/questions/50102726/get-current-url-in-a-blazor-component

Set up Automapper in ASP.NET Core

Add the main AutoMapper Package to your solution via NuGet.

Add the AutoMapper Dependency Injection Package to your solution via NuGet.

Create a new class for a mapping profile. (I made a class in the main solution directory called MappingProfile.cs and add the following code.) I’ll use a User and UserDto object as an example.

public class MappingProfile : Profile {
     public MappingProfile() {
         // Add as many of these lines as you need to map your objects
         CreateMap<User, UserDto>();
         CreateMap<UserDto, User>();
     }
 }

Then add the AutoMapperConfiguration in the Startup.cs as shown below:

public void ConfigureServices(IServiceCollection services) {
    // .... Ignore code before this

   // Auto Mapper Configurations
    var mapperConfig = new MapperConfiguration(mc =>
    {
        mc.AddProfile(new MappingProfile());
    });

    IMapper mapper = mapperConfig.CreateMapper();
    services.AddSingleton(mapper);

    services.AddMvc();

}

To invoke the mapped object in code, do something like the following:

public class UserController : Controller {

    // Create a field to store the mapper object
    private readonly IMapper _mapper;

    // Assign the object in the constructor for dependency injection
    public UserController(IMapper mapper) {
        _mapper = mapper;
    }

    public async Task<IActionResult> Edit(string id) {

        // Instantiate source object
        // (Get it from the database or whatever your code calls for)
        var user = await _context.Users
            .SingleOrDefaultAsync(u => u.Id == id);

        // Instantiate the mapped data transfer object
        // using the mapper you stored in the private field.
        // The type of the source object is the first type argument
        // and the type of the destination is the second.
        // Pass the source object you just instantiated above
        // as the argument to the _mapper.Map<>() method.
        var model = _mapper.Map<UserDto>(user);

        // .... Do whatever you want after that!
    }
}

References
https://stackoverflow.com/questions/40275195/how-to-set-up-automapper-in-asp-net-core