author avatar

sachin.kabadi

Wed Jan 24 2024

To install <http://fly.io|fly.io> on macOS using Homebrew and authenticate with flyctl, you can follow these steps:

1. Open a terminal on your macOS machine.

2. Install Homebrew if you haven't already. Run the following command in the terminal: /bin/bash -c "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>)"

3. Once Homebrew is installed, you can use it to install flyctl. Run the following command in the terminal: brew install superfly/tap/flyctl

4. After the installation is complete, you can authenticate with flyctl using the auth login command. Run the following command in the terminal: flyctl auth login

This will open a browser window where you can log in with your <http://fly.io|fly.io> account credentials. Once you log in, the authentication token will be saved on your machine.

5. After successful authentication, you can start using flyctl commands to manage your <http://fly.io|fly.io> resources.

That's it! You have now installed <http://fly.io|fly.io> on your macOS machine using Homebrew and authenticated with flyctl.

author avatar

sachin.kabadi

Wed Jan 24 2024

Install Tailwind CSS with Ruby on Rails

1. Create your project

  rails new my-project
  cd my-project

2. Install Tailwind CSS

  rails tailwindcss:install

This will generate tailwind.config.js file in the /config directory.

3. Configure your template paths Add the paths of all your template files to your /config/tailwind.config.js file.

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './public/*.html',
    './app/helpers/**/*.rb',
    './app/javascript/**/*.js',
    './app/views/**/*',
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

4. Add the Tailwind directives to your CSS Add the @tailwind directives for each of Tailwind's layers to your application.tailwind.css file located in the ./app/assets/stylesheets directory.

  @tailwind base;
  @tailwind components;
  @tailwind utilities;

5. Start your build process

  ./bin/dev 

6. Start using Tailwind in your project Start using Tailwind's utility classes to style your content.

/config/tailwind.config.js file

  const defaultTheme = require('tailwindcss/defaultTheme')

  module.exports = {
    content: [
      './public/*.html',
      './app/helpers/**/*.rb',
      './app/javascript/**/*.js',
      './app/views/**/*.{erb,haml,html,slim}'
    ],
    theme: {
      extend: {
        fontFamily: {
          helvetica: ['Helvetica', 'Arial', 'sans-serif'],
        },
      },
    },
    plugins: [
      require('@tailwindcss/forms'),
      require('@tailwindcss/aspect-ratio'),
      require('@tailwindcss/typography'),
      require('@tailwindcss/container-queries'),
    ]
  }

index.html.erb

&lt;h1 class="container mx-auto mt-16 px-5 font-helvetica flex"&gt;
    Hello world!
&lt;/h1&gt;

<https://tailwindcss.com/docs/guides/ruby-on-rails|Reference official website for more information>.

author avatar

soniya.rayabagi

Tue Jan 23 2024

  • Ansible Provisioning :* Example : Setting up Ansible Provisioning for Nginx Installation on Vagrant:

Step 1: Install Ansible on Your Machine :

sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

Step 2: Go to your server's /etc/hosts file and add the hostname and the IP address of the host:

hostname    : vagrant 
hostname -I : 10.0.2.15.

Step 3: As Ansible works on the agentless architecture of using SSH to communicate with its hosts, set-up the ssh keys:

ssh-keygen 
cat ~/.ssh/id_rsa.pub
ssh-copy-id root@10.0.2.15.

Step 4: Add the Vagrant SSH Key inside authorized_keys:

sudo nano ~/.ssh/authorized_keys

Step 5: Configure Ansible Hosts , Edit the /etc/ansible/hosts file and add the hostname:

sudo nano /etc/ansible/hosts
vagrant 

Step 6: Verify Connectivity:

ansible -m ping all

output ---> 
vagrant | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"

Step 7: Write Ansible Playbook for Nginx Installation:

vi nginx-playbook.yml

Step 8: Run the Ansible Playbook:

ansible-playbook nginx-playbook.yml

output :

PLAY [Install and configure Nginx] *************************************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************************************************
ok: [vagrant]

TASK [Update apt package cache] ****************************************************************************************************************************************************************************
changed: [vagrant]

TASK [Install Nginx] ***************************************************************************************************************************************************************************************
ok: [vagrant]

TASK [Start Nginx service] *********************************************************************************************************************************************************************************
ok: [vagrant]

PLAY RECAP *************************************************************************************************************************************************************************************************
vagrant                    : ok=4    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
author avatar

syedsibtain

Tue Jan 23 2024

In Dart, JSArray<Object> and ConstantStringMap<String, Object> are part of the dart:js library, which is used for interoperability between JavaScript and Dart. They provide ways to interact with JavaScript objects and arrays within Dart code.

  1. JSArray<Object>: This represents a JavaScript array. It extends Dart's List class and allows us to interact with JavaScript arrays as if they were Dart lists. This means we can use methods like add, remove, length, etc., on a JSArray<Object> instance. This makes it easier to work with JavaScript arrays in Dart code.
  2. ConstantStringMap<String, Object>: This represents a constant JavaScript object. Unlike JSArray<Object>, which allows us to modify the JavaScript array, ConstantStringMap<String, Object> is read-only. This means we can access properties of the JavaScript object, but we can't modify them. This is useful when we want to ensure that the JavaScript object isn't accidentally modified by Dart code. Example:
void main(){
  const alphabets = [a,b,c];
  const person = {'id': 1, 'name': "Sibtain"};


  print(alphabets.runtimeType); // JSArray<Object>
  print(person.runtimeType); // ConstantStringMap<String, Object>
}
author avatar

mahesh.bhosle

Mon Jan 22 2024

journalctl command can be used to check the system log on the server. you can use the --since and/or --until options to specify a time range. eg: • To filter log between 1st Jan 2024 to 10th Jan 2024: journalctl --since "2024-01-01" --until "2024-01-10" • To filter log between 5am to 6am for 1st Jan 2024: journalctl --since "2024-01-01 5:00:00"" --until "2024-01-10 6:00:00""

author avatar

ayushsrivastava

Mon Jan 22 2024

While creating contracts using Dry Gem it is important to keep in mind that if a validation rule is independent of a key from schema then schema will not process those keys before executing the validation rule.

For Example

class RoomAvailabilityFormContract &lt; Dry::Validation::Contract
  params do
    required(:date_from).filled(:string)
    required(:date_to).filled(:string)
  end

  rule(:date_to) do
    date_from = Date.parse(values[:date_from]) 
    date_to = Date.parse(values[:date_to])

    if date_to &amp;&amp; date_from &amp;&amp; date_to &lt;= date_from
      key.failure('date_to must be ahead of date_from')
    end
  end
end

Our expectation from above contract will be if either date_to or date_from is missing in the schema the rule should not be executed and error should be caught while schema processes the keys which are date_to and date_from

But it will only work in case of date_from because the validation rule is dependent on the date_from key so if we have date_to as nil the rule will still be executed and might cause other errors like in our trying to parse nil value which does not fulfills the purpose of this gem.

To not get into such errors we should make sure that the validation rules are dependent upon the keys that are validated in schema

So the fix in above code will be to include date_to

rule(:date_from, :date_to) do
    date_from = Date.parse(values[:date_from]) 
    date_to = Date.parse(values[:date_to])

    if date_to &amp;&amp; date_from &amp;&amp; date_to &lt;= date_from
      key.failure('date_to must be ahead of date_from')
    end
  end

now before implementing the rule the schema will first validate both the keys and throw error if the values are not abiding to the schema

author avatar

satya

Mon Jan 22 2024

we can raise error using to_raise method inside our webmock in the spec file. for example:

stub_request(:post, "https://slack.com/api/users.info") .with( body: { "user" => "some_random_id" }, headers: { 'Accept' => 'application/json; charset=utf-8', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Slack Ruby Client/2.2.0' } ) .to_raise(Slack::Web::Api::Errors::UserNotFound.new('user_not_found'))

author avatar

ashwanikumarjha

Fri Jan 19 2024

In a web app, certain non-code files like EJS templates are not automatically included in the production build, causing runtime errors as the application can't locate these files.

NestJS provides a built-in solution through the nest-cli.json configuration file. This file allows us to specify non-TypeScript assets to be included in the build process. By defining a pattern for the files and specifying the output directory, we can ensure these files are copied to the correct location during the build process.

Example nest-cli.json:

{
 "collection": "@nestjs/schematics",
 "sourceRoot": "src",
 "compilerOptions": {
 "assets": [
   { "include": "emails/templates/*.ejs", "outDir": "dist/src" }
 ],
 "watchAssets": true
 }
}

In frameworks that do not provide a built-in solution for including non-TypeScript files in the build process, we can use external tools to handle this. For example, in Hapi.js, we can use cpx to copy these files during the build process.

author avatar

soniya.rayabagi

Thu Jan 18 2024

Setting Up SSH Authentication in Git for GitHub

  1. Generate SSH Key Pair: ssh-keygen -t rsa -b 4096 -C "<mailto:your_email@example.com|your_email@example.com>" cat ~/.ssh/id_rsa.pub 2. Start the SSH Agent: eval "$(ssh-agent -s)"
  2. Add SSH Key to the SSH Agent: ssh-add ~/.ssh/id_rsa
  3. Add SSH Key to GitHub Account: 5. Test SSH Connection to GitHub: ssh -T <mailto:git@github.com|git@github.com>
  4. Output: Hi soniyaraibagi! You've successfully authenticated, but GitHub does not provide shell access.
author avatar

nisanth

Thu Jan 18 2024

Encountered an issue with a Docker container image, preventing to destroy the vagrant environment using vagrant destroy. The error message indicated:

An action 'up' was attempted on the machine 'default',
but another process is already executing an action on the machine.
Vagrant locks each machine for access by only one process at a time.
Please wait until the other Vagrant process finishes modifying this
machine, then try again.

To resolve this issue, I used the following steps:

  1. Opened the “Activity Monitor” to identify the PID (Process ID) associated with the Vagrant Docker container.
  2. Executed the following command in the terminal to forcefully terminate the Vagrant process: kill -9 PID

This action allowed me to overcome the locking issue and proceed with the destruction of the Vagrant environment successfully.

Showing 18 to 20 of 66 results