Posts

How to install PostgreSQL and pgAdmin4 on Ubuntu 18.04

1. Install PostgreSQL $ sudo apt update $ sudo apt install postgresql postgresql-contrib 2. Update password for postpres user $ sudo -u postgres psql postgres=# ALTER USER user_name WITH PASSWORD 'new_password'; postgres=# \q 3. Install Python PIP for Ubuntu $ sudo apt update $ sudo apt install python3-pip 4. Get the PgAdmin 4 Python Installer at https://www.pgadmin.org/download/pgadmin-4-python-wheel 5. Install pgAdmin4 $ pip install ~/Downloads/pgadmin4*.whl Or for a System wide installation: $ sudo pip install ~/Downloads/pgadmin4*.whl 6. Locate PgAdmin 4 Script $ sudo updatedb $ locate pgAdmin4.py Copy the path displayed from above command. I call it PATH /pgAdmin4.py from now 7. Create config_local.py file for pgAdmin4 local config, add content and save it $ vim PATH /config_local.py import os SERVER_MODE = False DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/')) LOG_FILE = os.path.join(DATA_DIR...

Ubuntu Reading package lists…Error!

Error: Reading package lists…Error! Solution: If you google out this error there are plenty of links which describe this error. It seems that the file is messed up. You can try out the options specified  here . sudo mv /var/lib/dpkg/status /var/lib/dpkg/status.bad sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status sudo apt-get update This below option did not work for this particular case. Another link that describes the similar issue is  here . sudo rm /var/lib/apt/lists/* -vf sudo apt-get clean sudo apt-get update sudo apt-get upgrade

Elixir Phoenix Using GraphQL Basic Flow(My Notes) - Part 1

Image
Elixir Phoenix GraphQL Basic Flow Here we are going to see the basic flow in running a sample GraphQL project. Step1 : Create a Phoenix project and do ecto migration stuff mix phx.new --no-brunch --no-html instagram in config/dev.exs change the password # Configure your database config :instagram , Instagram . Repo , adapter: Ecto . Adapters . Postgres , username: "postgres" , password: "123456" , database: "instagram_dev" , hostname: "localhost" , pool_size: 10 mix ecto . create Step 2 : Install Absinthe dependencies { :absinthe_phoenix , "~> 1.4" } install using this command mix deps . get Step 3: Create file and folders as belows #File lib /instagram_web/ schema.ex #Folder lib /instagram_web/schema lib /instagram_web/ resolvers in  instagram_web/ schema.ex just put a skeleton defmodule InstagramWeb . Schema do use Absinthe . Schema query do end en...

Postgresql Command line - Ubuntu(My Notes)

MYSQL vs Postgresql(Command Comparision)   Description MYSQl PostgreSql Connection mysql -u user_name -p sudo -u postgres psql Show databases SHOW DATABASES; \l Use particular database USE [DB_NAME]; \c [DB_NAME] show tables in that DB SHOW TABLES: \dt Show table details DESCRIBE [TABLE_NAME]; \d+ [TABLE_NAME] Show index SHOW INDEX [TABLE_NAME;] \di (list index of all tables in that DB) Backup all DBs mysqldump –all-databases > /path/to/file.sql pg_dumpall > /path/to/file.sql Backup particular DB alone mysqldump mydatabase > /path/to/file.sql pg_dump mydatabase > /path/to/file.sql Exit quit|exit|[ctrl-c] \q

Phoenix Channels

Channels  Channels add Soft-Real time feature to our application. Channels - Sending and Receiving messages. Senders broadcast messages about Topics.Receivers subscribe to topics so that they can get those messages. Main Parts in Real Time Communication 1.Socket Handlers Socket handlers, such as lib/hello_web/channels/user_socket.ex, are modules that authenticate and identify a socket connection and allow you to set default socket assigns for use in all channels. 2.Channel Routes These are defined in Socket handlers, such as lib/hello_web/channels/user_socket.ex, which makes them distinct from other routes. They match on the topic string and dispatch matching requests to the given Channel module. channel "sample_topic:*" , HelloWeb . SampleTopicChannel They match on the topic string and dispatch matching requests to the given Channel module. The star character * acts as a wildcard matcher, so in the above example route, requests for sampl...

Elixir Ecto - My Notes

Image
Elixir Structs :         Elixir provides Structs.Structs define a set of fields.         A Struct will be referenced by the name of the module where it is defined defmodule User do defstruct [ :name , :email ] end user = % User { name: "John Doe" , email: "john@example.com" } Once a user Struct is created, we can access its email via user.email. Relational Mappers :          An Object Relational Mapper manage the translation of objects in to relational database, and  vice versa Similarly Ecto provides schemas that maps any Data source(Database Tables) in to Elixir Struct.When applied to your Database, Elixir schemas are Relational Mappers. Therefore while Ecto is not a Relational Mapper, it contains a Relational Mapper as a part of the many different tools it offers. For example, the schema below ties the fields name, email, inserted_at and updated_at to fields si...

Elixir Process - My Notes

Elixir Processes :           The basic unit of Erlang concurrency model is processes.                  In Elixir all code runs inside processes.Processes are isolated from each other, run concurrent to one another and communicate via message passing.Processes also provide means for building distributed and fault tolerant programs.          Elixir processes should not be confused with operating system process.Processes in Elixir are extremely lightweight in terms of memory and CPU(unlike threads in other languages).Hence it is common to handle hundreds and even hundreds of thousands processes simultaneously. Where do we need process?        Suppose if a client sends a request to server, the server responds with a response.What if the server gets 5 request from different clients at a same time.Or what if a particular client request takes a long time. ...