Monday, November 29, 2021

Share Folder in Mac with Multipass Ubuntu Instance

 Share Folder


multipass mount local/folder/path multipass-instance-name

multipass mount /Users/bparanj/cloud gold


multipass info gold

Name:           gold

State:          Running

IPv4:           192.168.64.2

Release:        Ubuntu 20.04.3 LTS

Image hash:     91740d72ffff (Ubuntu 20.04 LTS)

Load:           0.71 0.53 0.32

Disk usage:     2.6G out of 4.7G

Memory usage:   241.0M out of 981.3M

Mounts:         /Users/bparanj/cloud => /Users/bparanj/cloud

                    UID map: 501:default

                    GID map: 20:default

Saturday, November 27, 2021

ssh into multipass instance

 Launch Ubuntu instance:

multipass launch --name gold   

Copy the IP address from:

multipass list 

Log in to multipass instance:

sudo ssh -i /var/root/Library/Application\ Support/multipassd/ssh-keys/id_rsa ubuntu@192.168.64.2



Friday, November 19, 2021

Tuesday, November 09, 2021

Postgresql Post Install Message

 To migrate existing data from a previous major version of PostgreSQL run:

  brew postgresql-upgrade-database


This formula has created a default database cluster with:

  initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres

For more details, read:

  https://www.postgresql.org/docs/14/app-initdb.html


To restart postgresql after an upgrade:

  brew services restart postgresql

Or, if you don't want/need a background service you can just run:

  /opt/homebrew/opt/postgresql/bin/postgres -D /opt/homebrew/var/postgres


Zoom Link:

sqlite3 install

After brew install, the output: 

If you need to have sqlite first in your PATH, run:

  echo 'export PATH="/opt/homebrew/opt/sqlite/bin:$PATH"' >> ~/.zshrc


For compilers to find sqlite you may need to set:

  export LDFLAGS="-L/opt/homebrew/opt/sqlite/lib"

  export CPPFLAGS="-I/opt/homebrew/opt/sqlite/include"


For pkg-config to find sqlite you may need to set:

  export PKG_CONFIG_PATH="/opt/homebrew/opt/sqlite/lib/pkgconfig"

Monday, November 08, 2021

Warning! PATH is not properly set up

Warning! PATH is not properly set up, /Users/n1576925/.rvm/gems/ruby-3.0.2/bin is not at first place.

         Usually this is caused by shell initialization files. Search for PATH=... entries.

         You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles

         To fix it temporarily in this shell session run: rvm use ruby-3.0.2

         To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.


In MacOS Monterey, add the following to .bash_profile:


# RVM can encounter errors if it's not the last thing in .bash_profile

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to path for scripting (to manage Ruby versions)

export PATH="$GEM_HOME/bin:$PATH"


[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*


The .zshrc has only one line:

source ~/.bash_profile


Tuesday, September 07, 2021

Rails on Docker Tips

1. Reduce size of the image

RUN apt-get clean && rm -f /var/lib/apt/lists/*_*

2. Combine update, install and clean:

RUN apt-get update -y \

&& apt-get install -y -q package-name \

&& apt-get clean \

&& rm -f /var/lib/apt/lists/*_*

3. Use a separate build stage

FROM base-image AS builder

COPY . /app

RUN apt-get install build-essential \

&& bundle install --deployment


FROM base-image

COPY --from=builder /app /app

4. Set the system locale

RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \

&& locale-gen en_US.UTF-8

ENV LANG en_US.UTF-8

ENV LANGUAGE en_US:en

5. Create an unprivileged user

# After build

RUN adduser -s /bin/sh -u 1001 -G root \

-h /app -S -D rails \

&& chown -R rails /app

USER rails

6. Prefer exec form for CMD

CMD ["bundle", "exec", "rails", "s"]

7. Specify resource constraints in production

requests:

  memory: "100Mi"

  cpu: 0.5

 limits:

  memory: "200Mi"

  cpu: 1.0

8. Log to STDOUT or an external agent

ENV RAILS_LOG_STDOUT=true



Friday, August 27, 2021

Dockerfile with caching for Rails 6.1

 FROM ruby:2.7


LABEL maintainer="Brianna"


RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -

RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list


RUN apt-get update -yqq && apt-get install -yqq \

    nodejs \

    npm \

    yarn


RUN node -v


COPY Gemfile* /usr/src/app/

WORKDIR /usr/src/app


RUN gem install bundler:'~> 2.1.4'

RUN gem install rails

RUN bundle install


RUN echo $PWD

COPY . /usr/src/app

RUN rails webpacker:install


CMD ["bin/rails", "s", "-b", "0.0.0.0"]


https://drive.google.com/file/d/1nuZE88MOmMqiM2DMbur1RWPJvjUQ0rSf/view?usp=sharing

Dockerfile for Rails 6.1

 FROM ruby:2.7


RUN apt-get update -yqq

RUN apt-get install -yqq nodejs npm

RUN node -v


RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -

RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN apt-get update -y

RUN apt-get install yarn -y


RUN gem install bundler:'~> 2.1.4'


COPY . /usr/src/app

WORKDIR /usr/src/app

RUN bundle install

RUN bin/rails webpacker:install


Saturday, August 21, 2021

speedtest from terminal in Ubuntu 20.04

  sudo apt update

 sudo apt install speedtest

 sudo apt update

 sudo apt-get install python3-pip

 sudo pip3 install speedtest-cli

 speedtest-cli

 speedtest-cli --share

go: go.mod file not found in current directory or any parent directory; see 'go help modules'"

 Run from the terminal:

go mod init example.com/m/v2


Copy the generated file before you build the go program in the Dockerfile:

 

FROM golang:alpine

WORKDIR /myapp

COPY welcome.go .

COPY go.mod .


RUN go build -o welcome .

ENTRYPOINT ["./welcome"]


Make the generation of go.mod as part of the docker container:


FROM golang:latest AS builder

WORKDIR /myapp

COPY welcome.go .


RUN go mod init example.com/m/v2

RUN go build -o welcome .


FROM scratch

WORKDIR /myapp

COPY --from=builder /myapp/welcome .

ENTRYPOINT ["./welcome"]

Finding the number of cores in Ubuntu 20.04

 $ lscpu | egrep 'CPU\(s\)'

CPU(s):                          4

On-line CPU(s) list:             0-3

NUMA node0 CPU(s):               0-3


$ cat /proc/cpuinfo | grep processor | wc -l

4


$ nproc

4

Monday, August 16, 2021

React and Libraries Book Notes

  1. yarn create react-app starter-project --template TypeScript
  2. yarn add -D typescript @types/node @types/react @types/react-dom @types/jest @typescript-eslint/scope-manager
  3. yarn add -D node-sass
  4. yarn add -D scss-loader typings-for-scss-modules-loader
  5. yarn add -D redux @reduxjs/toolkit react-redux @types/react-redux
  6. yarn add -D @material-ui/core @material-ui/icons
  7. Edit tsconfig.json:
// tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "es6", "dom",
  ...
      ...
    ],
    "noImplicitAny": true,
    "noImplicitThis": true,
    "strictNullChecks": true,

8. yarn add -D styled-components @types/styled-components
9. yarn add -D react-router-dom @types/react-router-dom
10. yarn add -D enzyme enzyme-adapter-react-16 react-test-renderer
11. yarn add -D enzyme-to-json
12. yarn add sinon @types/sinon
13. yarn add puppeteer jest-puppeteer ts-jest
14. yarn add yarn add @types/puppeteer @types/expect-puppeteer @types/jest-environment-puppeteer
15. Create these folders:

src/components
src/features
src/layout
src/pages
src/redux
src/recoil/atoms

16. mkdir src/components src/features src/layout src/pages src/redux src/recoil/atoms
17. npx generate-react-cli component Header
18. Change generate-react-cli.json to 

{
  "usesTypeScript": true,
  "usesCssModule": false,
  "cssPreprocessor": "scss",
  "testLibrary": "Enzyme",
  "component": {
    "default": {
      "path": "src/components",
      "withStyle": true,
      "withTest": true,
      "withStory": false,
      "withLazy": false
    },
    "page": {
      "customTemplates": {
        "component": "templates/page/component.tsx",
        "style": "templates/page/style.scss",
        "test": "templates/page/test.tsx"
      },
      "path": "src/pages",
      "withLazy": false,
      "withStory": false,
      "withStyle": true,
      "withTest": true
    },
    "layout": {
      "customTemplates": {
        "component": "templates/component/component.tsx",
        "style": "templates/component/style.scss",
        "test": "templates/component/test.tsx"
      },
      "path": "src/layout",
      "withLazy": false,
      "withStory": false,
      "withStyle": true,
      "withTest": true
    }
  }
}

https://drive.google.com/file/d/1nlgGdZLfsfmElS1xVGW6BoB_1jTtRT7x/view?usp=sharing


Tuesday, August 10, 2021

Bala Paranj

 Bala Paranj is focused on tackling the technical challenges to software development. He enjoys working on complex problems and applying design techniques to accelerate development and build elegant systems.

Monday, August 09, 2021

Brackets, Braces and Parentheses in Javascript

Brackets [] hold arrays.

Braces {} is used to create objects and group statements.

Parenthesis () is used to supply parameters, group expressions and execute functions.

Thursday, August 05, 2021

Ruby times and and upto in Javascript

 Number.prototype.upto = function(t, cb) {

  var i = this;


  if(t < this) return +this;


  while (i <= t) {

    cb(i++);

  }


  return +this;

};


(1).upto(5, function(i){console.log(i);})



// Ruby = 5.times { |i| puts i }

// JS   = (1).times(function(i){console.log(i);})

Number.prototype.times = function(cb) {

  var i = -1;


  while (++i < this) {

    cb(i);

  }


  return +this;

}



(5).times(function(i){console.log(i);})


Tools


Thursday, July 29, 2021

Design Notes

Write tests that confirm what the code does without any knowledge of how the code does it. Test WHAT, not the HOW. Tests should not be tightly coupled to implementation details. Program to the interface not to the implementation.

Theme of Design Patterns book: The focus here is encapsulating the concept that varies, a theme of many design patterns.


Wednesday, March 24, 2021

linkedlist notes

 CreateList(),createsandreturnsanew,emptylist.

• InsertListNode(L,p,n),addsnodenafternodepinlistL.Ifpisnull,then we insert n as the new head of the list. The function returns a pointer to n. We assume that the node n has already been created with some data that we want to add in the list. We will not get into the details on how nodes are actually created. Briefly, some memory must be allocated and initialized, so that the node contains the data we want and a pointer. InsertListNode then needs only change pointers. It must make the pointer of n point to the next node, or to null, if p was the last node of the list. It must also change the pointer of p to point to n, if p is not null.

• InsertInList(L, p, d), adds a node containing d after node p in list L. If p is null, then we insert the new node as the new head of the list. The function returns a pointer to the newly inserted node. The difference with InsertListNode is that InsertInList creates the node that will contain d, whereas InsertListNode takes an already created node and inserts it in the list. InsertListNode inserts nodes, whereas InsertInList inserts data contained in nodes it creates. That means that InsertInList can use InsertListNode to insert in the list the node it creates.

RemoveListNode(L, p, r), removes node r from the list and returns that node; p points to the node preceding r in the list, or null if r is the head. We will see that we need to know p in order to remove the item pointed by r efficiently. If r is not in the list, it returns null.

• RemoveFromList(L, d), removes the first node containing d from the list and returns the node. The difference with RemoveListNode is that it will search the list for the node containing d, find it, and remove it; d does not point to the node itself; it is the data contained inside the node. If there is no node containing d in the list, RemoveFromList returns null.

• GetNextListNode(L, p), returns the node following p in list L. If p is the last node in the list, then it returns null. If p is null, then it returns the first node of L, the head. The returned node is not removed from the list.

• SearchInList(L, d), searches the list L for the first node containing d. It returns the node, or null if no such node exists; the node is not removed from the list.