Sunday, September 25, 2022

KUBERNETES COMMANDS

 minikube version 

kubectl version 


minikube start   #starts cluster 

kubectl cluster-info

kubectl get nodes

kubectl get pods

kubectl get services


kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1


kubectl proxy 



kubectl get pods -o  go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}'


$export POD_NAME=$(kubectl get pods -o  go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')



kubectl get pods -o  go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}'


Saturday, August 20, 2022

C# Linq Min method

// Online C# Editor for free

// Write, Edit and Run your C# code using C# Online Compiler


using System;

using System.Linq;

using System.Collections.Generic;


public class HelloWorld

{

    public static void Main(string[] args)

    {

        List<test> testlist = new List<test>();

        testlist.Add(new test { id = 5});

        testlist.Add(new test { id = 7});

        testlist.Add(new test { id = 2});

        testlist.Add(new test { id = 8});

        //find the min

        var min = testlist.Min(x=>x.id);

        

        //get the object with min component

        var y = testlist.Where(x=>x.id == min).FirstOrDefault();

        Console.WriteLine ($"The min is  {min} {y}  {y.id}");

    }

    

    public class test { 

        public int id { get;set;} 

    } 

}

Output: 

The min is  2 HelloWorld+test  2


NOTE: {y} prints "HelloWorld+test" which is the object hierarchy of parent class and contained class.


Wednesday, July 13, 2022

Nuget PMC Error while adding migration: The entity type 'Employee' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types, see https://go.microsoft.com/fwlink/?linkid=2141943.

 This happens when you dont define primary key for an entity type. 


Define a primary key either explicitly or implicitly. 

Nuget PMC error: No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.

 This error means you have created the DbContext but not configured/added  it to the project using either DI in startup.cs or by using DbContext.OnConfiguring method. 


Add DbContext in starup.cs or configure it by overriding the virtual  DbContext.OnConfiguring  method.

============================================================

  1. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  2. {
  3. optionsBuilder.UseSqlServer("server=.;database=myDb;trusted_connection=true;");
  4. }

NOTE to use connectionString from appsetting.json. follow these steps:
1. In appsettings.json add ConnectionStrings section below allowedhosts and add a name-value pair for connection string.
2. Inject IConfiguration in DbContext constructor. You will need to add "using Microsoft.Extensions.Configuration" statement for this.
3. You can now get the conn string by using configuration.GetConnectionString("name");
    public class EmployeeContext : DbContext
    {
        
        private readonly IConfiguration configuration;
        public DbSet<Employee> Employees { get; set; }

        public EmployeeContext(IConfiguration configuration)
        {
            this.configuration = configuration;
        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            string str = configuration.GetConnectionString("conn");
            optionsBuilder.UseSqlServer(str);
        }
    }

===================================================================================


  1. public void ConfigureServices(IServiceCollection services)
  2. {
  3. services.AddDbContext<MyDbContext>(options => {
  4. options.UseSqlServer("server=.;database=myDb;trusted_connection=true;"));
  5. });
  6. }

OR
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddDbContext<EmployeeContext>(options => {
            options.UseSqlServer(Configuration.GetConnectionString("conn")));
        }



NOTE that once you configure DbContext in ConfigureServices, you must wire it with DbContext by using a constructor that takes DbContextOptions as parameter and passes it to base contructor.


public class EmployeeContext : DbContext { public EmployeeContext(DbContextOptions<EmployeeContext> options) : base(options) { } DbSet<Employee> Employees { get; set; } }
  1. ===================================================================================

Monday, July 11, 2022

Git Pull Request

 1. Create new branch 

git checkout -b test 



2. Make changes and do add, commit and push. 

While pushing  changes, keep in mind you have to mention 

branch name as "test" 


git push origin test 


3. Now go to Azure and create a Pull Request. 


Select "test" as source branch and "main" as destination branch


Friday, July 1, 2022

Sql Server OFFSET and FETCH

 https://www.sqlservertutorial.net/sql-server-basics/sql-server-offset-fetch/



SQL Server OFFSET and FETCH

Sunday, June 26, 2022

flexbox form example

 https://webdesign.tutsplus.com/tutorials/building-responsive-forms-with-flexbox--cms-26767



<style>

body {

  font: normal 18px/1.5 "Fira Sans", "Helvetica Neue", sans-serif;

  background: #3AAFAB;

  color: #fff;

  padding: 50px 0;

}


.container {

  width: 80%;

  max-width: 1200px;

  margin: 0 auto;

}


.container * {

  box-sizing: border-box;

}


.flex-outer,

.flex-inner {

  list-style-type: none;

  padding: 0;

}


.flex-outer {

  max-width: 800px;

  margin: 0 auto;

}


.flex-outer li,

.flex-inner {

  display: flex;

  flex-wrap: wrap;

  align-items: center;

}


.flex-inner {

  padding: 0 8px;

  justify-content: space-between;  

}


.flex-outer > li:not(:last-child) {

  margin-bottom: 20px;

}


.flex-outer li label,

.flex-outer li p {

  padding: 8px;

  font-weight: 300;

  letter-spacing: .09em;

  text-transform: uppercase;

}


.flex-outer > li > label,

.flex-outer li p {

  flex: 1 0 120px;

  max-width: 220px;

}


.flex-outer > li > label + *,

.flex-inner {

  flex: 1 0 220px;

}


.flex-outer li p {

  margin: 0;

}


.flex-outer li input:not([type='checkbox']),

.flex-outer li textarea {

  padding: 15px;

  border: none;

}


.flex-outer li button {

  margin-left: auto;

  padding: 8px 16px;

  border: none;

  background: #333;

  color: #f2f2f2;

  text-transform: uppercase;

  letter-spacing: .09em;

  border-radius: 2px;

}


.flex-inner li {

  width: 100px;

}

</style>




<div class="container">

  <form>

    <ul class="flex-outer">

      <li>

        <label for="first-name">First Name</label>

        <input type="text" id="first-name" placeholder="Enter your first name here">

      </li>

      <li>

        <label for="last-name">Last Name</label>

        <input type="text" id="last-name" placeholder="Enter your last name here">

      </li>

      <li>

        <label for="email">Email</label>

        <input type="email" id="email" placeholder="Enter your email here">

      </li>

      <li>

        <label for="phone">Phone</label>

        <input type="tel" id="phone" placeholder="Enter your phone here">

      </li>

      <li>

        <label for="message">Message</label>

        <textarea rows="6" id="message" placeholder="Enter your message here"></textarea>

      </li>

      <li>

        <p>Age</p>

        <ul class="flex-inner">

          <li>

            <input type="checkbox" id="twenty-to-twentynine">

            <label for="twenty-to-twentynine">20-29</label>

          </li>

          <li>

            <input type="checkbox" id="thirty-to-thirtynine">

            <label for="thirty-to-thirtynine">30-39</label>

          </li>

          <li>

            <input type="checkbox" id="fourty-to-fourtynine">

            <label for="fourty-to-fourtynine">40-49</label>

          </li>

          <li>

            <input type="checkbox" id="fifty-to-fiftynine">

            <label for="fifty-to-fiftynine">50-59</label>

          </li>

          <li>

            <input type="checkbox" id="sixty-to-sixtynine">

            <label for="sixty-to-sixtynine">60-69</label>

          </li>

          <li>

            <input type="checkbox" id="other">

            <label for="other">Othessr</label>

          </li>

        </ul>

      </li>

      <li>

        <button type="submit">Submit</button>

      </li>

    </ul>

  </form>

</div>

Comparing features of LangGraph vs CrewAI

LangGraph Orchestration vs CrewAI Orchestration The following table compares LangGraph and CrewAI orchestration across their menta...