Sunday, 27 June 2021

Powershell commands

Check whether a port is open or not in windows

netstat -an | find "80" 

Note: this is not exact match, this is contains. Result will also return port listening results for 

8081

9801

Instead of search for "80" use ":80" in search text, it will reduce search results & will show more meaningful result.



Saturday, 26 June 2021

Copy file from windows to Linux

Permanently added 'nagesh.eastus.cloudapp.azure.com,13.68.184.88' (ECDSA) to the list of known hosts.

ssh -o StrictHostKeyChecking=no <username>@<ip_or_domain_name> "command"
eg.
ssh -o StrictHostKeyChecking=no nageshajab@nagesh.eastus.cloudapp.azure.com "command"

Copying file

scp myApp.db nageshajab@nagesh.eastus.cloudapp.azure.com:/var/www/nageshajab/db

Deploy .net core app to Ubuntu

Step 1 : Create Azure VM 

Ubuntu Server 20.04 LTS - Gen1

Standard B1s (1 vcpu, 1 GiB memory)

0.0104 USD/hr

Step 2 : Register Microsoft key and repository feed

wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb Jump -O packages-microsoft-prod.deb

sudo dpkg -i packages-microsoft-prod.deb

Step 3 : Install Dot NET Core

-------.net sdk 3.1----------
sudo apt-get update; \
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-3.1

-------.net sdk 5----------
sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-5.0

Step 4 : Install Nginx Web Server
sudo apt-get update
sudo apt-get install nginx

#Enable Nginx
sudo systemctl enable nginx

#Start Nginx
sudo systemctl start nginx

#check service status
sudo systemctl status nginx

#check service log
journalctl -u nginx.service

Step 5 : Deploying ASP.NET Core App

Create directory under nginx 
sudo mkdir /var/www/myapp

sudo chmod 777 /var/www/myapp

Step 6 : Clone git repository

git clone https://github.com/nageshajab/myapp.git

git clone will copy files into your home directory/ username
cd /home/nageshajab/myapp

Step 7 : Publish your code to server directory

run dotnet restore to get nuget libraries from server
dotnet restore

go to web directory to publish ur code to server directory
cd myApp.web
dotnet publish -c release --output /var/www/myapp

Step 8 : Configure a new website in nginx

Open nginx config file
sudo nano /etc/nginx/sites-available/default

add this block to opened file

server {
    listen 80;
    root /var/www/myapp;
    location / {
  proxy_pass http://localhost:5000;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection keep-alive;
  proxy_set_header Host $http_host;
  proxy_cache_bypass $http_upgrade;
  }
}


Save file & exit
  • Save the modified default file press (Ctrl + O) and hit the enter
  • To exit the nano editor press (Ctrl + x) it will ask you to exit write Y and hit the enter on your keyboard.

We have replaced content of the default server block file on Nginx so we need to reload changes that we have made before we running the following command.

sudo nginx -s reload

Step 9 : Create ubuntu unit service to host .net core app


Create a service definition and put below code in it. For creating/ stopping / starting/ edition/ enable/ disable services refer - How To Use Systemctl to Manage Systemd Services and Units | DigitalOcean

[Unit]
Description=Asp.NET Web App now is running on Ubuntu

[Service]
WorkingDirectory=/var/www/myapp
ExecStart=/usr/bin/dotnet /var/www/myapp/myApp.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=myapponlinux-log
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target


Step  9 : Copy database backup file to server



Wednesday, 16 June 2021

xampp apache port issue

 Step 1 - From the XAMPP Control Panel, under Apache, click the Config button, and select the Apache (httpd.conf).

Inside the httpd.conf file, somehow I found a line that says:

Listen 80

And change the 80 into any number / port you want. In my scenario I’m using port 8080.

Listen 8080

Still from the httpd.conf file, I found another line that says:

ServerName localhost:80

Change 80 to 8080.

ServerName localhost:8080

Step 2 - From the XAMPP Control Panel, under Apache, click the Config button again, but this time select the Apache (httpd-ssl.conf). Inside the httpd-ssl.conf file, find line that says

Listen 443

And change the 443 into any number / port you want. I’ll using 4433 as the new port number.

Listen 4433

Still from the httpd-ssl.conf file, find another line that says

<VirtualHost _default_:443>

ServerName localhost:443

And change 443 to 4433.

<VirtualHost _default_:4433>

ServerName localhost:4433

Sunday, 13 June 2021

Jquery basic syntax

Basic document ready syntax

 $(document).ready(function () {

    console.log("ready!");

});

Jquery selector, anchor under all ul->li, add css class, remove css class

$("ul li > a").click(function () {

    $("ul li > a").removeClass('active');

    $(this).addClass('active');

});

Get windows URL

http://localhost/menuname.de?foo=bar&amp;number=0

var pathname = window.location.pathname; // Returns path only (/path/example.html)
var url = window.location.href; // Returns full URL (https://example.com/path/example.html)
var origin = window.location.origin; // Returns base URL (https://example.com)


Saturday, 12 June 2021

Entity framework - distinct & Order By together

  public List<string> ListServers()

        {

            MyDbContext myDbContext = new();


            var results = myDbContext.Apps

              .Select(c => new { c.IISServer})

              .Distinct()

              .OrderBy(x => x.IISServer)

              .Select(x => x.IISServer);


            return results.ToList();

        }

Friday, 11 June 2021

Setting wiki locally

bitnami/bitnami-docker-mediawiki: Bitnami Docker Image for MediaWiki (github.com)

https://hub.docker.com/_/mediawiki

mediawiki needs a database to store data. It supports various databases

---------------------------------------------------------------------

bitnami/bitnami-docker-dokuwiki: Bitnami Docker Image for DokuWiki (github.com)

docuwiki is easy to install & configure. Does not need any database. It stores data on filesystem.

----------------------------------------------------------------


Rabbit Mq - docker

docker run -d --rm -it --hostname my-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management

You can then go to http://localhost:15672/#/ in a browser.


In case you want to change port after container is created

  1. stop running container

    docker stop some-rabbit
    
  2. commit the container

    docker commit some-rabbit rabbitMq
    

    NOTE: The above, test02 is a new image that I'm constructing from the test01 container.

  3. re-run from the commited image

    docker run -p 8080:8080 -td rabbitMq


Sunday, 6 June 2021

Using Sqlite database in .Net (entity framework)

https://kontext.tech/column/dotnet_framework/275/sqlite-in-net-core-with-entity-framework-core

1. Add package reference 'Microsoft.EntityFrameworkCore.Sqlite'

2. Add Model class 

   public class Blog

    {

        [Key]

        public int BlogId { get; set; }

        [Required]

        [MaxLength(128)]

        public string Title { get; set; }

        [Required]

        [MaxLength(256)]

        public string SubTitle { get; set; }

        [Required]

        public DateTime DateTimeAdd { get; set; }

    }

3. Add DbContext class

public class MyDbContext : DbContext
     {
         public DbSet<Blog> Blogs { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
         {
             optionsBuilder.UseSqlite("Filename=TestDatabase.db", options =>
             {
                 options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName);
             });
            base.OnConfiguring(optionsBuilder);
         }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
         {
             // Map table names
             modelBuilder.Entity<Blog>().ToTable("Blogs", "test");
             modelBuilder.Entity<Blog>(entity =>
             {
                 entity.HasKey(e => e.BlogId);
                 entity.HasIndex(e => e.Title).IsUnique();
                 entity.Property(e => e.DateTimeAdd).HasDefaultValueSql("CURRENT_TIMESTAMP");
             });
            base.OnModelCreating(modelBuilder);
         }
     }

4. Adding database migration

dotnet ef migrations add some_name --project myApp.DataAccess.csproj -s ..\myApp.web\myApp.csproj -c ApplicationDbContext --verbose 

dotnet ef database update some_name --project myApp.DataAccess.csproj -s ..\myApp.web\myApp.csproj -c ApplicationDbContext --verbose 

Selenium Quick Start

1. create nunit test project

2. add following nuget packages

a. Selenium.Support

b. Selenium.WebDriver

c. Selenium.WebDriver.ChromeDriver

3.

using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;
using System.Text;

[TestFixture]
public class YourTestClass2
{
    private ChromeDriver driver;

    [OneTimeSetUp]
    public void Setup()
    {
        driver = new ChromeDriver();
        // Initialize your driver here
    }

    [Test]
    public void registerclient()
    {
        driver.Navigate().GoToUrl("https://localhost/interface/smart/register-app.php");
        driver.FindElement(By.Id("details-button")).Click();
    }

    [OneTimeTearDown]
    public void TearDown()
    {
        if (driver != null)
        {
            driver.Dispose();
            driver = null;
        }
    }
}

4. Thats it. Now you can run test from test explorer

Search This Blog

Creating your first "Alexa" Skill

Index What is Alexa What is Alexa Skill? Why is it required when Alexa already equipped with voice assistant? Dev...