Skip to main content

Posts

Showing posts from 2020

Maps In GoLang

✌ Go provides another important data type map that maps unique keys to values. A key is an object that you use to retrieve a value at a later date. Given a key and a value, you can store the value in a Map object. After the value is stored, you can retrieve it by using its key. A Go map type looks like this: map[KeyType]ValueType Declaration and initialization: 1) m := make(map[string]int) 2) m := map[string]int{} 3) var m map[string]int{} Map to get key of value : 1). i := m["route"] 2). i, ok := m["route"] 3). for key, value := range m {            fmt.Println("Key:", key, "Value:", value)      } The built-in len function returns on the number of items in a map: n := len(m) The built-in delete function removes an entry from the map: delete(m, "rouzte") GO Program : package main import ( "fmt" ) func main() {                var m = make(map[st

System Design | Design Scalable Systems

✋System design is the process of designing the elements of a system such as the architecture, modules, and components, the different interfaces of those components, and the data that goes through that system. The purpose of the System Design process is to provide sufficient detailed data and information about the system and its system elements to enable the implementation consistent with architectural entities as defined in models and views of the system architecture. 1) Requirements Clarification: the beginning point of software development activity. Software requirement is one such area to which little importance was attached in the early days of software development, as the emphasis was on coding and design. The main assumption was that the developers understood the problem clearly when it was explained to them, generally informally. Therefore, the need for a more rigorous requirement analysis phase arose. Now, for large systems 2) System Interface Definition: Int

Design Patterns

A design pattern provides a general reusable solution for the common problems occurs in software design. Design Patterns are programming language independent strategies for solving a common problem. that means a design pattern represents an idea, your code more flexible, reusable and maintainable 🍥. Creational design patterns : creational design patterns are concerned with the ways of creating an object. 1. Factory Method: Define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate 2. Abstract Factory: Define an interface or abstract class for creating families of related (or dependent) objects but without specifying their concrete sub-classes 3. Builder: Construct a complex object from simple objects using a step-by-step approach 4. Object Pool: Avoid expensive acquisition and release of resources by recycling objects that are no longer in use 5. Prototype: A fully initialized instance to

Find distance between two points

The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes 🌎 It is a special case of a more general formula in spherical trigonometry, the law of haversines, relating the sides and angles of spherical "triangles". Task: Implement a great-circle distance function, or use a library function, to show the great-circle distance between: Wagle Estate Rd, Padwal Nagar, Thane West, Thane, Maharashtra 400604, which is : N 19.189354, W 72.951225 Swami Vivekananda Rd, Thane West, Thane, Maharashtra 400602, which is : N 19.186333, W 72.966961 Distance: This uses the ‘haversine’ formula to calculate the great-circle distance between two points – that is, the shortest distance over the earth’s surface – giving an ‘as-the-crow-flies’ distance between the points (ignoring any hills they fly over, of course!). Haversine formula : a = sin²(Δφ/2) + co