Posts

Showing posts from March, 2022

JavaScript: Understanding Prototype and Class methods

Image
So, in JavaScript, first of all, its an object oriented programming but without classes (till ES5), now with ES6 we have classes officially in JavaScript But still the old behaviour of the language is forwarded with newer version In Javascript creating an object is possible via its functions( new [Func]()), function is a first class (can be passed as an argument), function is a high order function(can be received as an argument), function it self acts a constructor( new func() ) take a look at below code function User(name, passwd) { this.name = name; this.passwd = passwd; this.methodname = "User" } u1 = new User("User1", "Password") u2 = new User("User2", "Password") console.log(u1) console.log(u2) User.prototype.method1 = function () { console.log("This is method1"); } u1.method1() User.method2 = function() { console.log("this is method2"); } User.me

GoLang: How To work with JSON Data and Nested structs

GoLang: How To work with JSON Data and Nested structs Hello Everyone, I spent sometime today to craft this code, so this article slowly walk you through how to build a nested struct, how to load data into it, then converting it into JSON, writing to a file, reading from a file and append new data etc. I was learning GoLang and found needed something like this. Hope it helps. package main import ( "encoding/json" "fmt" "os" ) type Schema struct { Users map [ string ] User Posts map [ string ] Post } type User struct { Username string `json:"username"` Email string `json:"email"` } type Post struct { Heading string `json:"post_heading"` Description string `json:"description"` } func main ( ) { u1 := User { Username : "rajag" , Email : "rajag@example.com" , } p1 := Post { Heading : "Post 1 he

PostgreSQL: How To - Installation , Create User , DB and manage permissions

PostgreSQL: How To - Installation , Create User , DB and manage permissions Installation sudo apt install postgresql postgresql-contrib Start the DB you will have instruction printed in the output performing post-bootstrap initialization .. . ok syncing data to disk .. . ok Success. You can now start the database server using: pg_ctlcluster 12 main start Ver Cluster Port Status Owner Data directory Log file 12 main 5432 down postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log update-alternatives: using /usr/share/postgresql/12/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmast er.1.gz ( postmaster.1.gz ) in auto mode invoke-rc.d: could not determine current runlevel invoke-rc.d: policy-rc.d denied execution of start. We are interested in pg_ctlcluster 12 main start line. Creating User Account login into DB root @7204604adf5f : / # sudo -u postgres psql psql ( 12.9 ( Ubuntu

PostgreSQL: How To - Installation , Create User , DB and manage permissions

PostgreSQL: How To - Installation , Create User , DB and manage permissions Installation sudo apt install postgresql postgresql-contrib Start the DB you will have instruction printed in the output performing post-bootstrap initialization .. . ok syncing data to disk .. . ok Success. You can now start the database server using: pg_ctlcluster 12 main start Ver Cluster Port Status Owner Data directory Log file 12 main 5432 down postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log update-alternatives: using /usr/share/postgresql/12/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmast er.1.gz ( postmaster.1.gz ) in auto mode invoke-rc.d: could not determine current runlevel invoke-rc.d: policy-rc.d denied execution of start. We are interested in pg_ctlcluster 12 main start line. Creating User Account login into DB root @7204604adf5f : / # sudo -u postgres psql psql ( 12.9 ( Ubuntu