teleren/devto huggingface dataset:
Parse a YML/YAML file in a Ruby on Rails app
Tags: ruby, rails, yaml, yml
Published: 2023-01-30 18:00:26

---
title: Parse a YML/YAML file in a Ruby on Rails app
published: true
tags: ruby,rails,yaml,yml
canonical_url: https://blog.corsego.com/parse-yaml-yml-with-ruby-on-rails
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/thpwrizs4ur6kpmluhyw.png
---

Instead of storing **static data** a database, you can create a structured YML or JSON file and parse it from your Ruby/Rails app.

I really like the data structure of a `.yml` file, because it is much cleaner to write than `.json`.

Here’s an example list of schools in the YAML format:

```yml
# db/view_data/schools.yml
- name: Austin High School
  team_name: Austin Mustangs
  city: Houston
  state: TX
  primary_color: green
  secondary_color: white

- name: Bellaire High School
  team_name: Bellaire Cardinals
  city: Houston
  state: TX
  primary_color: red-lighter
  secondary_color: white

- name: Carnegie Vanguard High School
  team_name: Carnegie Vanguard Rhinos
  city: Houston
  state: TX
  primary_color: blue
  secondary_color: red-lighter
```

You can parse this data (convert it into a Hash or Array) using Ruby on Rails **native yaml parsers**!

1. Parse a local YAML file with pure **Ruby** :

```ruby
require 'yaml'
path = "/Users/yaroslavshmarov/Documents/GitHub.nosync/schools.yml"
@schools = YAML::load File.open(path)

@schools.first.fetch('name')
# => "Austin High School"
```

Source: [Ruby YAML docs](https://ruby-doc.org/stdlib-2.5.1/libdoc/yaml/rdoc/YAML.html)

1. Parse a YAML file inside a **Rails** app:

```ruby
# a controller action
  # @schools = YAML::load File.open("#{Rails.root.to_s}/db/fixtures/schools.yml") # ruby way
  @schools = YAML.load_file('db/fixtures/schools.yml') # rails way
  @schools.inspect
```

Render the results in a view:

```ruby
# a view
<% @schools.each do |school| %>
  <%= school.fetch('name') %>
  <%= school['name'] %>
<% end %>
```

Source: [Rails YAML.load\_file docs](https://apidock.com/ruby/YAML/load_file/class)

That’s it! 🤠
Deploy Your Nodejs app on Render.com
Tags: node, cloud, webdev
Published: 2023-01-30 17:45:39

If you finish a project using Nodejs and wondering where to deploy for free. You have come to the right place. Before talking about this let's talk about why you should deploy your project in the cloud. The main thing is that you can showcase your project to the world. Where others can benefit from your app and also you can showcase it to the recruiter. It helps in landing a job.

There are many cloud services to deploy but here I am focusing on [Render.com](render.com). Why render? because it's completely free. You got free 100 GB bandwidth and 500 build minutes. That’s enough to deploy your project as a student or as a hobbyist. Now, let's start the step-by-step process to deploy the app.

### Step 1 - Create an Account
Sign up for render.com. I recommend you sign up using a GitHub account. So it will be more convenient to add projects from your repository. And also make sure that you push your project into a GitHub repository without .env and node_modules.

### Step 2 - Select the Repository
Click the “new” button on the navbar then select “web service”. Select the repository you want to deploy in the list under “connect a repository” and click “connect”. If you don’t find your list, click on the Configure account under your GitHub account username. Select your username on the install render page. Select ‘All repositories’ and save.

### Step 3 - Create Nodejs App
Fill in the name of your project. If you want to deploy from another branch select branch from the drop-down menu or leave it as the default value. Change your start command to a node + the name of the main file to execute in order to run the application. In my case, it will be ‘node app.js’. And click the “Create Web Service” to initiate your Nodejs app.

### Step 4 - Add Environment Values
Voilà! you just created your first Nodejs app. But there is another important thing to do. Which is adding environment variables. remember that we ignored .env files while pushing the code. So we need to add env variables to the deployed app manually. Click on the environment on the side panel. Click “Add Environment Variable”. Add key and value there. After adding all environments click “save changes”.

Finally, we made it. The app should be redeployed again after updating the environment variables. Check the log section to see any errors. Wait for some minutes and check the URL provided right below the project name.

Thanks for reading! Hope you like it. Follow [me](rabeeh.tech) for more content like this.
Logical Assignment Operators
Published: 2023-01-30 17:40:39

Logical Assignment Operators was introduced in the ECMAScript 2021 update. It is a new feature that combines the assignment operators with the logical operators (||, &&, ??). It that allows you to assign a value to a variable if `true (&&=)`, `false (||=)` or `null (??=)`.

## Types of Logical Assignment Operators
- Logical OR assignment operator ||=
- Logical AND assignment operator &&=
- Nullish coalescing assignment operator ??=

### Logical OR assignment operator ||=
This accessor is used to assign a value to a variable if the variable is not already assigned. If the variable is already assigned, the value is not changed.

//Syntax

```js
a ||= b
```
This syntax is also similar to:

```js
if (!a) {
  a = b
}
```
An example is

```js
let a = 0
a ||= 1
console.log(a) // 1
```
The above example assigns the value 1 to the variable a if the variable is not already assigned. If the variable is already assigned, the value is not changed.

### Logical AND assignment operator &&=
This is used to assign a value to a variable only if the value is a truthy

// Syntax

```js
a &&= b
```
This syntax is also similar to:

```js
if (a) {
  a = b
}
```
An example is

```js
let a = 0
a &&= 1
console.log(a) // 0
```
In the above example, a is a falsy value, so it will not be reassigned. It will only reassign if the value is truthy.

```js
let a = 4
a &&= 1
console.log(a) // 1
```

### Nullish coalescing assignment operator ??=
This is similar to the Logical OR assignment operator ||=, however, it only reassigns if the left operand is null or undefined.

// Syntax

```js
a ??= b
```
This syntax is also similar to:

```js
if (typeof a === "undefined" || a === null) {
  a = b
}
let a = 0
a ??= 1
console.log(a) // 0
let b = null
b ??= 1
console.log(b) // 1
```
How to create and use traits in Laravel
Tags: laravel, codenewbie, beginners, womenintech
Published: 2023-01-30 17:12:51

**Hello Artisans,**

Hey there want to know about traits, and how can we use it in Laravel then you need to read this blog and try to implement in your project. 

- A trait is a group of methods that can be included into a class. Basically it helps us to reuse our code if the same functionality used in different pages, it also helps us to use different sets of method independently in classes living in different class hierarchies.

So let's get started with an example of how to create a trait in Laravel:

- Create a new file in the app/Traits directory and give it a descriptive name, such as MyTrait.php.

- In the newly created file, add the following code to define a trait:

```php
<?php

namespace App\Traits;

trait MyTrait
{
    public function hello()
    {
        return 'This is my first Trait example';
    }
}
```

- To use the trait in a class, you can use the use keyword followed by the namespace and trait name in the class. For example:

```php
<?php

namespace App\Models;

use App\Traits\MyTrait;

class User
{
    use MyTrait;
}
```

- Now you can call the hello method from the User class:

```php
$user = new User();
echo $user->hello();
```

- This is a basic example of how to create a trait in Laravel. You can add as many methods as you like to a trait, and a class can use multiple traits if needed.

- It's also possible to override the methods in a trait in the class that uses the trait.

Save and like the post for your reference, also you can share it on Twitter, Linkedin and follow me for more information about laravel.

**Thank you!!**
**Happy Reading** :unicorn: :heart:
Staring in awe at Pulp Pong
Tags: gamedev, beginners, playdate, pulp
Published: 2023-01-30 17:01:26

The fourth tutorial in the [list of links](https://play.date/dev/links/) is a blog post describing one developer's successful attempt at [re-creating Pong using Pulp](https://devforum.play.date/t/pulp-pong-dev-tutorial/2315).

## I didn't get very far on my own
- I re-created the single room
- I placed text for both players' scores in the room

## Inspecting the `JSON` file in pulp
Thankfully, the author made `PDX` and `JSON` files available for download.

I snagged the `JSON` file and loaded it in a new pulp game.

### Layers and tiles
- World tiles to make the `card` screen
- One item tile for the score divider
- Sprites for player 2 and the ball
- Player tiles for the paddle body, top and bottom
- No Exits

### Sounds
- A one-note sound for when the ball collides with a wall or paddle
- A four-note sound for when either player scores

### Scripts
- These files are intimidating, but accessible
- The author has written some very helpful comments
- A lot of it is understandable
- The tough part is following all the custom functions

### In awe
- I admire the author's ability to simulate smooth animations for the ball and player paddles
- I'm impressed by all the edge-case handling, especially when the ball tile overlaps a paddle tile
- Oh, and switching between a CPU player 2 and human player 2 based on whether the crank is docked or not

## The complexity of managing tiles
- Designing a playdate game in pulp seemed simple at first
- This game's scripts are proof that the tough part is in swapping tiles and accounting for the correct tile being in the right place at all times
- So, the good news is the code will likely often require conditionals to check tile types at target location
- The bad news is the complicated mess of nested conditionals that could amass in even a simple game like this

## I think it's time
- I gotta make something from scratch
- I gotta practice writing PulpScript
- I gotta think of some simple game

Good luck, self. Remember, it's supposed to be fun!
Early return patterns
Tags: beginners, programming, android, computerscience
Published: 2023-01-30 16:57:56

"First write the code for people, then for the machine."
I don't know who originally said this but it's legitasf.

How many times you saw some piece of code and like what!? What is this supposed to do?

One good tip that I accepted from a senior developer in my team is to use that early return statement which is my favorite thing if I have small to medium business logic inside my functions.

You have a function that does something bigger, and it does it well but not too well. 

```kotlin
fun getListOfArticles(hasInternet: Boolean): List<Article> {
    if (hasInternet) {
    //big piece of code. Maybe some data manipulation before 
     //returning the list of Articles from the API.
    } else {
       return emptyList()
    }
 }
```

This is OK, but if you want to make life easier for somebody else that will read your code in half a year we can use that early return pattern which comes in handy sometimes and it looks like this: 

```kotlin
fun getListOfArticles(hasInternet: Boolean): List<Article> {
    if(!hasInternet) return emptyList()

    //Big piece of code here for manipulating the data
    return articles
 }
```

This way is more intuitive to read "if there is no internet,  just return an empty list of articles" or do whatever you need in your app. Just return early as possible and you will make your program [fail fast](https://www.martinfowler.com/ieeeSoftware/failFast.pdf).
 That means: 
1. Easier to read
2. Easier to spot code smell
3. Easier to debug.

Here's one more interesting example using a happy path design

_"The happy path for a function would be where none of the validation rules raise an error, thus letting execution continue successfully to the end, generating a positive response."_

```kotlin
fun logIn(argument1: String?, argument2: String?, argument3: 
 String?) {
  if(argument1 != null || argument2 != null || argument3 != 
   null) {
  //do something and log in the user
    } else {
  // throw exception
  }
}
```

Now happy path applied:

```kotlin
fun logIn(argument1: String?, argument2: String?, argument3: String?) {
 if(argument1 == null) throw Exception() //maybe throw different exceptions
 if(argument2 == null) throw Exception()
 if(argument3 == null) throw Exception()

  //do the happy path of the function here

}
```

Some patterns that are considered as early return: 
- [Bouncer pattern](https://mauriziopireddu.com/clean-code/the-bouncer-pattern)
- [Guard clause](https://deviq.com/design-patterns/guard-clause)
- Happy path 


You have your own style of writing software but be aware that this is popular for a reason and it has a lot of benefits inside the codebase. It will force you to think more with that "TDD" mindset.
Complete Remove/Uninstall node form mac OS
Tags: beginners, node, macos, nvm
Published: 2023-01-30 16:45:30

To remove Node.js from a Mac, follow these steps:

Uninstall Node.js using npm:

```
npm uninstall -g node
```

Remove the Node.js executable and the npm modules:

```
 rm /usr/local/bin/node
 rm -rf /usr/local/lib/node_modules 
```

Remove the Node.js home directory:

```
rm -rf ~/.npm
```
 
 Remove the npm and node directories from PATH:
 
```
vi ~/.bash_profile
```
 
Search for and delete the following lines:
 

```
export PATH=$PATH:/usr/local/bin/npm
 export PATH=$PATH:/usr/local/bin/node
```

 Save and exit the file.
 
Restart the terminal or run the following command:


```
source ~/.bash_profile
```

 This should remove Node.js from your Mac. You can verify the uninstallation by running the following command:
 

```
node -v
```

If Node.js is uninstalled, you should see an error message saying that the command is not found.



## Remove NVM from MacOS

To remove nvm (Node Version Manager) from your Mac, follow these steps:

Remove the nvm installation directory:

```
rm -rf ~/.nvm
```

Remove the nvm configuration from your shell profile:

```
vi ~/.bash_profile
```

Search for and delete the following lines:

```
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
```
Save and exit the file.

Restart the terminal or run the following command:

```
source ~/.bash_profile
```
This should remove nvm from your Mac. You can verify the uninstallation by running the following command:


```
nvm -v
```

If nvm is uninstalled, you should see an error message saying that the command is not found.
How to use React and Firebase together
Tags: react, javascript, firebase, programming
Published: 2023-01-30 16:37:57

React is a JavaScript library for building user interfaces, while Firebase is a real-time, scalable back-end platform. Combining these two technologies can result in a powerful web application with real-time data capabilities. Here is a step-by-step guide on how to integrate React with Firebase.

Step 1: Set up Firebase

Go to the Firebase website and create a new project.
From the Firebase dashboard, create a new Firebase Realtime Database.
In the Database tab, add some sample data to the database for testing purposes.
Step 2: Install dependencies

Create a new React project using the command line tool: npx create-react-app my-app.
Navigate to the project directory: cd my-app.
Install the Firebase library by running the following command: npm install firebase.
Step 3: Connect React to Firebase

In the src directory, create a new file named firebase.js.
Add the following code to the firebase.js file to initialize Firebase:

```
`import firebase from 'firebase/app';
import 'firebase/database';

const firebaseConfig = {
  apiKey: '<your-api-key>',
  authDomain: '<your-auth-domain>',
  databaseURL: '<your-database-url>',
  projectId: '<your-project-id>',
  storageBucket: '<your-storage-bucket>',
  messagingSenderId: '<your-messaging-sender-id>',
  appId: '<your-app-id>'
};

firebase.initializeApp(firebaseConfig);
const database = firebase.database();

export default database;`
```
Note: Replace <your-api-key>, <your-auth-domain>, etc. with the corresponding values from the Firebase project.

Step 4: Display Data from Firebase

In the src directory, open the App.js file.
Import the Firebase library by adding the following line at the top of the file: import database from './firebase';.
Add the following code to retrieve data from Firebase and display it in the React component:

```
import React, { useState, useEffect } from 'react';

function App() {
  const [data, setData] = useState({});

  useEffect(() => {
    database.ref().on('value', (snapshot) => {
      setData(snapshot.val());
    });
  }, []);

  return (
    <div>
      <h1>Data from Firebase:</h1>
      <pre>{JSON.stringify(data, null, 2)}</pre>
    </div>
  );
}

export default App;
Step 5: Deploy the Application

To deploy the application, run the following command: npm run build.
Upload the build directory to a web hosting service.
Visit the URL of the hosted website to see the data from Firebase displayed in the React component.
This is just a basic example of how to integrate React with Firebase. You can expand on this basic setup to build more complex applications with real-time data capabilities.





```
Step 5: Deploy the Application

To deploy the application, run the following command: npm run build.
Upload the build directory to a web hosting service.
Visit the URL of the hosted website to see the data from Firebase displayed in the React component.
This is just a basic example of how to integrate React with Firebase. You can expand on this basic setup to build more complex applications with real-time data capabilities.
Singula digests & events
Tags: webdev, meetups, productivity
Published: 2023-01-30 16:29:34

We run a new communication format — [Singula digest](https://news.singula.team/).

What does it mean for you? We will inform you about all global IT events and provide unique reports from our skilled specialists regularly. We’ll surely discuss the latest news, trends, tendencies of web development and together find out how to make your business at the joint of production and technology even cooler.

View the news on the site, the first digest is on its way!


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6i3m7mycq4f4popkwt3j.jpg)
Yeh Rishta Kya Kehlata Hai Watch Online
Published: 2023-01-30 16:25:28

Star Plus display `Yeh Rishta Kya Kehlata Hai` is getting pretty thrilling with every passing episode. The contemporary music of the display revolves round Abhimanyu and Akshara assembly in Kasauli. Abhinav receives injured and Akshara panics as there`s a doctors` strike withinside the area. Abhir requests Abhimanyu to return back and deal with his father and he obliges.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zdmq8bhzbbkhcpz5p4f5.jpg)

Abhimanyu treats Abhinav and live over at their house. Akshara and Abhimanyu proportion some conversations approximately Ruhi. They additionally proportion awkward moments. Abhi tells her that Abhinav can get cognizance soon. Abhi additionally bonds with Abhir. Abhinav wakes up and feels glad to peer the fear in Akshu and Abhir`s eyes. He thank you Abhimanyu for coming and treating him. He gears as much as leave. He stocks that he remains in Udaipur. 

<a href="https://yehrishtaapnetv.com/">Apne Tv</a>

Abhir tells him that his grandparents additionally live in Udaipur. He tells that he'll meet him if he involves Udaipur. They click on some pics with Abhimanyu earlier than he leaves. Akshu arms him over a parcel and tells him that Abhinav requested her to provide this to him. Abhimanyu musters the braveness and apologizes to her for dragging Sirat`s dying into their argument a few years ago. This leaves Akshu shaken. 

<a href="https://yehrishtaapnetv.com/">Yeh Rishta Kya Kehlata Hai Online</a>

Abhimanyu leaves withinside the automobile at the same time as Akshara recollects her phrases and runs in the back of the automobile. Abhinav unearths it bizarre and later asks Akshu if Dr. Birla is her Abhi. Akshu receives shocked.
Common Git commands
Published: 2023-01-30 16:23:10

**--globally configure username**
$ git config --global user.name "JohnDoe"
$ git config user.name "JohnDoe"

**--globally configure password**
$ git config --global user.email "johndoe@gmail.com"
$ git config user.email "johndoe@gmail.com"

**--Navigate to previous directory**
$ cd ..

**--navigate to the stated directory**
$ cd My_Portal/ChannelsPortal

**--Add a specific file**
$ git add 'My_Portal_lattest.bak'

**--Add all files**
$ git add .

**--Commit changes**
$ git commit -m 'Db Commit'

**--Add to the remote repository**
$ git remote add origin https://github.com/JohnDoe/My_APIs.git

**--Push to the master repository**
$ git push -u origin main

$ git push origin master --force


**ADD A SINGLE FILE**
LENOVO@DESKTOP-PIVU MINGW64 /e/Learning/ReactJs (Main)
$ git init

LENOVO@DESKTOP-PIVU MINGW64 /e/Learning/ReactJs (master)
$ git add 'Intro_To_React.html'

LENOVO@DESKTOP-PIVU MINGW64 /e/Learning/ReactJs (master)
$ git commit -m "First React Commit:file"

LENOVO@DESKTOP-PIVU MINGW64 /e/Learning/ReactJs (master)
$ git branch -M main

LENOVO@DESKTOP-PIVU MINGW64 /e/Learning/ReactJs (main)
$ git remote add origin https://github.com/JohnDoe/ReactJS.git

LENOVO@DESKTOP-PIVU MINGW64 /e/Learning/ReactJs (main)
$ git push -u origin main


**HOW TO CLONE FROM EXISTING REPO**
$ git clone https://https://github.com/JohnDoe/Read.git(url to be cloned)
$ cd name-of-folder
$ git add .
$ git commit "comment"
$ git set-url https://https://github.com/JohnDoe/Tech.git(url to your repo)
$ git push -u origin main

**HOW TO ADD AN ENTIRE FOLDER**
$ git add foldername
$ git commit -m "commit comment"
$ git push
What is stanbic bank ussd code and how to use stanbic ussd code for transactions
Tags: bankussdcode, stanbictransfercode, stanbicibtctransfercode, stanbicussdcode
Published: 2023-01-30 16:22:12


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tivboeakspbtuhm4bol.png)

<a href="https://www.bankussdcode.com/stanbic-ibtc-transfer-code/#utm_source=backlinks&utm_medium=search&utm_campaign=darry+ring+us&utm_content=Michelle">https://www.bankussdcode.com/stanbic-ibtc-transfer-code/</a>