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