Move Github Sub Repository back to main repo

 -- delete .gitmodules


git rm --cached MyProject/Core


git commit -m 'Remove myproject_core submodule'


rm -rf MyProject/Core


git remote add models-origin https://github.com/myproject/myproject_core


git fetch models-origin


git merge --allow-unrelated-histories models-origin/master


mkdir -p MyProject/Core


git mv Api MyProject/Core/

git mv Services MyProject/Core/


git commit -m "Move submodule contents to subdirectory"


git remote remove models-origin

Web protocol evolution

 

Scenario:

The end-to-end principle is a network design method in which application-specific features are kept at communication end points. So not to have features on intermediate points between the client and end points, like gateways and routers. E.g. Net neutrality.
  • i/p -> tcp i/p -> HTTP.
    • HTTP 1.0 [1993/4]
      • CERN
        • For researchers [university] to shared papers [text and some images].
    • HTTP 1.1
      • Syntax & Semantics separated
        • Syntax - Network/format/what goes over the wire
        • Semantics - Headers, Response Codes & Methods [POST/GET etc.] 
      • Keep Alive
      • No TLS mandate
    • HTTP 2.0
      • Web 2.0
      • Initial Window - TCP [2 packets] and add more as you get ACK, took to 7 packets.
      • Parallel/Multiplexing - Adding streams to one connection. Earlier browser multiple connections to same site and limit of 6.
      • Ahead of Line blocking - TCP layer:
        • If 3 packet or resource in queue you cant send 4.
        • TCP - guaranteed and in sequence
          • FTP is fine. If one line is missing. Packets sent fast. Ack tells missing and resend again only at the end its blocked/stopped and not render. 
          • As Initial Window grew, there are more things in queue, more blockages.
          • It may not be needed, one frame in video, scrolled now section.
        • 2.0 solved resource blocking, it can come out of sequence, but within resource Ahead of Line Packets. 
      • Google Chrome - Google Servers. 
        • Middle Boxes like ISP they block traffic [ingress/egress to the network]. They only allowed Tcp to go out, so you cant add protocol on top.
    • HTTP 3.0
      • Use UDP to Tcp
        • UDP
          • Is Connection less.
          • UDP before TCP
          • UDP has limited services and so you have to build.
          • Might get blocked in hospital, banks..
        • TCP
          • 3 way handshake - TCP uses a three-way handshake, both sides synchronize (SYN) and acknowledge (ACK) each other; SYN, SYN-ACK and ACK.
          • 4 way handshake FIN -> ACK -> ACK.
      • If does not work fall back to http2 due to UDP blockage.
      • QUIC
      • 99.999 % web is on TLS, due to free certs
      • Traffic shaping - Manage bandwidth to delay the flow of certain types of network packets to ensure network performance for higher priority apps, e.g. DataCenters.
      • IPv6  - address consists of eight groups of four hexadecimal digits.
        • IPv4 - 32 bit, so 2^32 = 4 Billion
        • IPv6 - 128 bit = Quandralion
        • Network address translation (NAT) - Conserves IP addresses by enabling private IP networks using unregistered IP addresses to go online. 
        • Reclamation of unused IPv4 space. Under TCP, there are 1–65535 ports
        • Zero RTT
          • 4 way for 1st
          • Next time - Use same key, after challenge, based on 1st call.
          • Connection migration w/o connection re negotiation from wifi to cellular
    • Web RTC
      • UDP
      • Peer to Peer
        • Initial Server then p2p
      • RTMP -  Real-Time Messaging Protocol
      • Earlier browser was just write file, not read. Devices read like mic and camera.
      • Codec
        • Compress/ Decompress audio-video
  • Web 1.0
    • Mostly static pages connected by  hyperlinks
    • HTML forms get sent through e-mail
    • The content comes from the server's filesystem, not DB
    • Encyclopedia available online
    • Linked Web Pages
  • Web 2.0
    • Read
    • Write
    • Dynamic
    • Wikipedia
    • Linked Apps
  • Web 3.0
    • Personal
    • Block chain
    • Semantic Web/Chat GPT
    • Linked Data

Lambda Calculas

        

Scenario:

  • λx.x [Function Notation,Argument.Body(Return)] like function (x) {return x}
  • Function Application - λx.x (y). So substitute all x with y
  • λx(bound variable).x y(free variable). 
    • Substitution/Reduction
      • Substitution is left-applicative as you apply from left (when value is applied to a function, it is substituted in the function itself)
      • E.g. - λx.x5 => x[x: = 5] => 5
      •  λx. λy.y x => λx. λy.y => λy.y
    • Multiple Variables
      • λx.λy.t also called currying, so its like Function x has body of λy.t [Function calling Function]
    • Parenthesis:
      • λx.(λy.y x) => λx.(λy.yx) => λx.(y[y: = x]) => λx.x
      • λx.λy.y x => λx.λy.yx => λx.(λy.y) => λy.y
    • Combinators [Combination of Functions]
      • Boolean
        • λx.λy.x [true]
        • λx.λy.y [false] 
      • Conditional
        • λx.λy.λz.x y z
      • Numbers
        • λf.λx.x=0
        • λf.λx.f(x)=1 => λx.x (like identity)
        • λf.λx.f(f(x))=2
        • λf.λx.f(f(f(x)))=3
      • Omega Combinator [looping]
        • Ω => λx.xx(λx.xx) => λx.xxλx.xx
      • Y combinator [for each, only once]:
        • Y = λf.(λx.f(xx))f.(λx.f(xx))
    //Identity Function/I Combinator
    
    function myFunc(x){return x}
    
    console.log((x=>x)(10));
    
    
    //Constant Function
    
    let y = 5
    
    console.log((x=>y)(10));
    
    
    //Substitution
    
    //Constant [Returns 5]
    let y = 5
    
    console.log((x=>y)(10));
    
    //Identity [Returns 10]
    let y = 5
    
    console.log((x=>x)(10));
    
    
    //Multiple
    
    console.log(((x,y) => x+y)(5,10));
    
    
    //5
    console.log((x => y => x + y)(2)(3));
    
    //Error
    console.log((x => x) (y => y)(2)(3));
    
    //2
    console.log((x => x) (y => y)(2));
    
    
    //Combinators 
    
    //Boolean
    
    let True = (x => y => x);
    
    let False = (x => y => y);
    
    console.log(True(true)(false));
    
    console.log(False(true)(false));
    
    let If = (x => y => z => x(y)(z));
    
    console.log(If(True)("TRUE")("Yes"));
    
    console.log(If(False)("NOT")("nah"));
    
    //Numbers:
    
    let calculate = f => f(x => x + 1) (0)
    
    let zero = f => x => x;
    let one = f => x => f(x);
    let two = f => x => f(f(x));
    
    console.log(calculate(zero));
    console.log(calculate(one));
    console.log(calculate(two));
    
    
    //Omega [for]
    let Omega = x => x(x);
    console.log(Omega(Omega));
    
    //Y Combinator [For each]
    //Fibonnaci
    let Y = f => (x => x(x))(x => f(y => x(x)(y)));
    let fib = f => n => n <=1 ? n : f(n-1) + f(n-2);
    let fibfunc = Y(fib);
    console.log(fibfunc(10));

.NET Enum Comparison

       

Scenario:

Compare 2 Enums 

Solution:


     public enum Mode
        {
            Dark,
            White
        }
    
    
    var mode =  IsMobile()
                        ? Mode.White
                        : Mode.Dark;
    
    return data
    	.Where(i.Mode.Equals(mode))
    	.Select(data.render);

NHibernate

 

Scenario:

Use a ORM framework to work with your database.

Solution:

NHibernate is an open-source ORM framework, which is persistence layer for the .Net  based on Object-Relational Mapping Technique. It  creates a "virtual representation" of database objects within the code. 

NET Framework. It handles persisting plain .NET objects to and from an underlying relational database. Given an XML description of your entities and relationships, NHibernate automatically generates SQL for loading and storing the objects.

Object Relational Mapping (ORM) is a technique used in creating a "bridge" between object-oriented programs and, in most cases, relational databases. It solves the issues like DB does not have inheritance and the structure is diffrent between DB and classes.

NHibernate, persists the object into the relation database and can do CRUD operations, you dont have to write SQL queries, the data access logic can be contained in  the application. 

1. The XML mapping file, which can be done in the code as well.
2. Configuration file
3. POCO
They need to have atleast one id property
All properties need to be marked Virtual


    //Construct a Session Factory
    
    var sessionFactory  = Fluently.Configure()
                    .Database(MsSqlConfiguration.MsSql2008.ConnectionString(sqlConnection))
                    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyContext>())
                    .BuildSessionFactory();
    
    //start a session and save data/ Flush mode could be Manual, Automatic and commit time
    using (var session = NHibernateHelper.OpenSession()
    Session.FlushMode = FlushMode.Manual) { 
    
    using (var transaction = session.BeginTransaction()) { 
       var user = new User { 
    	  FirstName = "Ram", 
    	  LastName = "Mangal" 
       }; 
    		
       session.Save(customer); 
        
       session.Flush();
       transaction.Commit();
       session.Close();  
    } 
    
    
    //Mapping
    class UserMap : ClassMap<User> { public UserMap() { Id(x => x.Id); Map(x => x.FirstName); Map(x => x.LastName); Table("User"); } //load data using (ISession session = NHibertnateSession.OpenSession()) { using (var tx = session.BeginTransaction()) { /*** Using Query ***/ var users = session.Query<User>().ToList(); foreach (var user in users) { //read user data } tx.Commit(); } }

Sql Commands

Queries:


--convert DateTime to Date

CAST(myDateTime AS DATE)

 

Create Data Pool using Concurrent Queue

      

Scenario:

Create Data Pool of numbers using Concurrent Queue.

Solution:

C# ConcurrentQueue is a thread-safe collection class. It is introduced in .NET 4.0 with other concurrent collection classes. It provides a thread-safe First-In-First-Out (FIFO) data structure. ConcurrentQueue exists in System.Collections.Concurrent namespace. ConcurrentQueue is a wrapper around generic Queue class

    using System.Collections.Concurrent;
    
    namespace TestProject
    {
        public class PoolNextData
        {
            private readonly Dictionary<string, ConcurrentQueue<long>> _dataPool;
            private int _poolLength;
    
            public PoolNextData()
            {
                _dataPool = new Dictionary<string, ConcurrentQueue<long>>();
            }
    
            private long[] GetNextData(ConcurrentQueue<long> pool, string kind, int noOfRecords)
            {
                var result = new List<long>();
    
                for (var i = 0; i < noOfRecords; i++)
                {
                    long data;
                    if (!pool.TryDequeue(out data))
                    {
                        break;
                    }
    
                    result.Add(data);
                }
    
                //not enough available, put it back
                if (result.Count < noOfRecords)
                {
                    FillPool(pool, kind, noOfRecords - result.Count + _poolLength);
    
                    result.ForEach(pool.Enqueue);
                }
                else
                {
                    Task.Factory.StartNew(() => FillPool(pool, kind, noOfRecords));
                }
    
                return result.ToArray();
            }
            private void FillPool(ConcurrentQueue<long> pool, string kind, int noOfRecords)
            {
                //Get next numbers list from DB
    
                var nos = new List<long>();
                nos.ForEach(pool.Enqueue);
            }
    
            private ConcurrentQueue<long> GetPool(string kind)
            {
                var result = new ConcurrentQueue<long>();
                _dataPool.Add(kind, result);
    
                return result;
            }
        }
    }

Move Github Sub Repository back to main repo

 -- delete .gitmodules git rm --cached MyProject/Core git commit -m 'Remove myproject_core submodule' rm -rf MyProject/Core git remo...