teleren/devto huggingface dataset:
Understanding Hoisting in JavaScript
Tags: javascript, webdev, programming, react
Published: 2022-10-06 16:09:16

Hoisting is a concept in JavaScript, not a feature. In other scripting or server side languages, variables or functions must be declared before using it.

In JavaScript, variable and function names can be used before declaring it. The JavaScript compiler moves all the declarations of variables and functions at the top so that there will not be any error. This is called hoisting.

```
x = "Neeraj Kumar";

alert('x = ' + x); // display x = "Neeraj Kumar"

var x;
```
functions to the top of their scope by compiler itself just before the execution of code is known as Hoisting.

Also, a variable can be assigned to another variable as shown below.

```
x = "Neeraj";
y = "Kumar";

alert('x = ' + x);
alert('y = ' + y);

var x;
var y;
```
Hoisting is only possible with declaration but not the initialization. JavaScript will not move variables that are declared and initialized in a single line.
`Example: Hoisting not applicable for initialized variables`

```
alert('x = ' + x); // display x = undefined
        
var x = "Neeraj";
```
As you can see in the above example, value of x will be undefined because var x = "Neeraj" is not hoisted.
**Hoisting of Function**
JavaScript compiler moves the function definition at the top in the same way as variable declaration.
`Example: Function Hoisting`

```
alert(Sum(50, 50)); // 100

function Sum(val1, val2)
{
    return val1 + val2;
}
```
`Please note that JavaScript compiler does not move function expression.`

`Example: Hoisting on function expression`

```
Add(50, 50); // error

var Add = function Sum(val1, val2)
{
    return val1 + val2;
}
```
`Hoisting Functions Before Variables`
JavaScript compiler moves a function's definition before variable declaration. The following example proves it.
`Example: Function Hoisting Before Variables`
alert(UseMe);

```
var UseMe;

function UseMe()
{            
    alert("UseMe function called");
}
```
As per above example, it will display UseMe function definition. So the function moves before variables.
`Points to Remember :`
1.JavaScript compiler moves variables and function declaration 
  to the top and this is called hoisting.
2.Only variable declarations move to the top, not the 
  initialization.
3.Functions definition moves first before variables.
Interesting JavaScript Tips
Published: 2022-10-06 16:03:48

At the start, JavaScript seemed overwhelming to me with everything that it had to offer. I've come to learn over time that this isn't something to worried about but rather thankful for. There are a lot of cool tricks that you can do with JavaScript and it is exciting knowing just how much more is out there to learn. I'm going to go over some cool things you can do in JavaScript and hopefully teach you something new!

### Filter Unique Values from Arrays

With the introduction of ES6, we can use the new Set object and "spread operator" to create a new array with unique values.

```javascript
const array = [1, 1, 2, 3, 5, 5, 1]
const uniqueArray = [...new Set(array)];
console.log(uniqueArray); // Result: [1, 2, 3, 5]
``` 

### Ternary Operator

The ternary operator is a quick write to write quick conditional statements.

```javascript
function getFee(isMember) {
  return (isMember ? '$2.00' : '$10.00');
}

console.log(getFee(true));
// expected output: "$2.00"

console.log(getFee(false));
// expected output: "$10.00"

console.log(getFee(null));
// expected output: "$10.00"
```

In this example isMember is the condition. If the condition is true, whatever expression is after the "?" will be returned. If the condition is false, the expression after the ":" will be returned. This syntax is relatively simple and is great for conditional rendering in programs like React.

### Convert to String

To convert a number to a string quickly, we can add an empty string to the number.

```javascript
const val = 1 + "";
console.log(val); // Result: "1"
console.log(typeof val); // Result: "string"
```
### Convert to Number

The opposite can also be quickly achieved using the addition operator. 

```javascript
let int = "15";
int = +int;
console.log(int); // Result: 15
console.log(typeof int); Result: "number"
```

### Random Item from Array

Although some programs make this easier with much less code, it is still cool that JavaScript can manage this.

```javascript
let items = [12, 548, "a", 2, 5478, "foo", 8852, , "Doe", 2145, 119];

let randomItem = items[Math.floor(Math.random() * items.length)];
```

### Empty out an Array

Calling the length function on an array and setting it equal to 0 will make the array empty. Similarly using a number other than 0 will truncate the array to that specific length.

```javascript 
let myArray = [12 , 222 , 1000 ];  
myArray.length = 0; // myArray will be equal to [].

let newArray = [12 , 222 , 1000 , 124 , 98 , 10 ];  
newArray.length = 4; // myArray will be equal to [12 , 222 , 1000 , 124].
``` 

### Sort Array Alphabetically

```javascript
//sort alphabetically
function alphabetSort(arr)
{
  return arr.sort((a, b) => a.localeCompare(b));
}
let array = ["d", "c", "b", "a"]
console.log(alphabetSort(array)) // ["a", "b", "c", "d"]
```
Fun CSS Tricks
Tags: beginners, css, tutorial, programming
Published: 2022-10-06 16:03:33

One of my favorite parts about Flatiron School has been messing with CSS and seeing what cool stuff I can both find and come up with. By reading this blog I'm going to show you some CSS demos that you might be able to spruce up your website with.

### Fonts
A good font can make any website look more stylized. There are a handful of fonts built into CSS but one of the best font features is the ability to import new ones from outside sources. All you need to do is specify which url you are grabbing from and which CSS font you are inheriting from.

{% codepen https://codepen.io/jfinley6/pen/wvjXZNO %}

### Cursors

Several times in my projects, I have used different cursors both for amusement and for practical effects. I learned that it's easy as adding a cursor property to your selector and then adding a keyword. When you hover over the element, the cursor should appropriately change. 

{% codepen https://codepen.io/jfinley6/pen/WNJyBxb %}

### Fade In/Out

Animations can be very powerful in CSS. If you ever have a need to make text or other elements fade in or out from your page, you can easily add a fade property to CSS file. All you need to do is specify the starting and ending opacity, and how long you want the animation to take.

{% codepen https://codepen.io/jfinley6/pen/MWGXdvp %}

### Transform

Another cool and useful animation is Transform, which allows you to move an element around on the page. Below I've added a rotate property to the image, and specify 4 full rotations to happen in 4s. You can do all types of animations with the transform property, such as scale, skew, translate(moves element horizontal/vertical), and even add 3d perspective.'

### Image Filters

Now you, yes you, can build Instagram! Well, there might be some additional programming knowledge involved, but Filters are a HUGE part of instagram. Luckily, the CSS filter property gives you a ton of control on how your images look. Below are some of the filters you can added to spice up your images.

{% codepen https://codepen.io/jfinley6/pen/dyeKEmw %}

### Conclusion

Now these are just a couple CSS tricks you can use to add some styling to your website. In reality CSS is a seemingly endless amount of content that can really bring out the creativity in people. What are some cool things you've managed to find or come up with in CSS?
Rails Command Line Tips and Tricks
Tags: ruby, rails, beginners, computerscience
Published: 2022-10-06 15:58:50

Working in Rails for me has been satisfying as I've learned the ins and outs. Going from not even knowing what an API to being able to build my own API with custom routes and relational tables has made it all feel worth it to me. Often I like to test my methods in the console but the data isn't always formatted very well. I'm going to share a couple ways to make the data more readable so that you can better understand your data.

For all of the following you are going to want to add the gem I've specified to your Gemfile and then run "bundle install". At the time of this writing I am using ruby "2.7.4" and rails "7.0.3".

###Awesome Print

Add gem 'awesome_print' to Gemfile and bundle. After running "rails c" you can put "ap" before the object you want to call and it will print with full color and proper indentation.

```ruby
> ap Movie.first
  Movie Load (0.2ms)  SELECT  "movies".* FROM "movies" ORDER BY "movies"."id" ASC LIMIT ?  [["LIMIT", 1]]
#<Movie:0x00000003fcf7f8> {
             :id => 1,
          :title => "Batman",
           :year => 1989,
          :genre => "Action, Adventure",
       :director => "Tim Burton",
     :production => "USA, Great Britain",
      :boxoffice => "$411 348 924",
    :description => "The Dark Knight of Gotham City begins his war on c...",
          :score => 7.6,
     :created_at => Sat, 23 Jul 2016 09:47:15 UTC +00:00,
     :updated_at => Sat, 23 Jul 2016 09:47:15 UTC +00:00
}
```
---

###Hirb

Add gem 'hirb' to Gemfile and bundle. After running "rails c" you need to enter "hirb.enable". Once you do that, your data will be presented in a nicely formatted table.

```ruby
2.7.4 :002 > Hirb.enable
 => true 
2.7.4 :003 > Comment.all
  Comment Load (0.5ms)  SELECT "comments".* FROM "comments" ORDER BY "comments"."created_at" DESC                                               
+----+--------------------+---------+---------+--------------------+---------------------+
| id | body               | user_id | post_id | created_at         | updated_at          |
+----+--------------------+---------+---------+--------------------+---------------------+
| 2  | Great topic!       | 3       | 1       | 2022-09-16 02:3... | 2022-09-16 02:36... |
| 1  | You also do not... | 2       | 1       | 2022-09-16 02:3... | 2022-09-16 02:36... |
+----+--------------------+---------+---------+--------------------+---------------------+
2 rows in set     
```

### Conclusion 

These are just a couple of ways that you can make your Rails table look a little more organized and easy to read. Give them a try in your next project. Are there any cool tips and tricks for the Ruby command line that you know of?
Convert audio file to text - Python
Tags: python, ai, tutorial, programming
Published: 2022-10-06 15:52:31

I had an audio file that I wanted it in text form. Listening and typing it manually is a hassle, as a programmer I made a quick research on how to convert audio files to text. 
Let's get started.

### Requirements
- speech_recognition
```
pip install speech_recognition
```

#### After installation import the package
```
import speech_recognition
```
#### Import the audio file to be converted

```
audio_file = "sample.wav"
```

#### initialize the speech recognizer

```
 sp = speech_recognition.Recognizer()
```

#### open the audio file
```
with speech_recognition.AudioFile(audio_file) as source:
```
#### Next is to listen to the audio file by loading it to memory
```
audio_data = sp.record(source)
```
#### Convert the audio in memory to text
```
converted_text = sp.recognize_google(audio_data)
```
#### Print out the converted text 
```
print(converted_text)
```
Done.

> This script works for short audio files and the file format should be .wav

Complete Code 
```
#import package
import speech_recognition

#import audio file
audio_file = "sample.wav"

# initialize the recognizer
sp = speech_recognition.Recognizer()

# open the file
with speech_recognition.AudioFile(audio_file) as source:
    # load audio to memory
    audio_data = sp.record(source)
    # convert speech to text
    text = sp.recognize_google(audio_data)
    print(text)
```
Yahoo email backup
Published: 2022-10-06 15:45:06

##                                           Yahoo Email Backup From The Most Trustworthy Source 

I have been robbed of my sleep by downloading freebies for mail backup. You may be welcoming a malware in the name of free, cutting-edge facility. I have seen inefficient tools that are just the type you need to skip otherwise you will waste your important hours by not getting the results no matter how hard you try. It was almost as if I was hoping against hope. However, Mail Backup X by InventPure has saved me from insomnia and disappointments because it is one of the most trustworthy Yahoo mail backup tools from an ingenious developer that has spent years of research before coming up with the final product. It’s reliable software from a reliable team that has wooed thousands of end users by sheer brilliance of their product.

## Be abreast with the latest in technology

No matter how good the current technology, it is bound to become obsolete in the coming years, but this Yahoo mail backup tool is not the one to come last in the race of self-sustenance as regular updates keep it at level with the current tech scene. I cannot describe the zenith of satisfaction I felt ever since buying this software that too at a pocket-friendly rate. There is no perfect way to backup mails, as with each individual preferences change, which is why this [Yahoo backup tool](https://www.mailbackupx.com/yahoo-backup-tool) comes with a wide-array of backup types like full, incremental or selective backup. 

## Keeps complexities at bay

Simplicity is the essence of this software. A clear-cut, properly detailed user interface with no complexities while interacting with it to get the job done, does away with the unnecessary burden on your head. There are so many utilities out there but they fail from the word go because of a complex user interface. Mail Backup X does away with complexities at all levels of operation and thereby is appealing to hordes of end users. 

## To each one his own

There are two versions of this software; a team version (can be shared among many users) and a personal version, which can be used in two computers and is specially formulated to fulfill personal backup needs. But remember there is no difference between these two versions as to the features being provided. Both are fully functional **[Yahoo email backup](https://www.mailbackupx.com/yahoo-backup-tool)** solutions. 

## Summary of telling benefits

To speak precisely, I have been pleasantly surprised to know that how much is available from this software though it has been reasonably priced. It steals the limelight in all regards whether we talk about speed and ease of operation or safety of data. It has an inbuilt module that recognizes a variety of languages and understands the Unicode content, and thus mails are preserved in their original form without chopping and changing the structure of a given mail. I cannot stop from saying that you can reap the same benefits as I have reaped and be rest assured that all your current and future backup needs will be met to the core.
Merging and pulling from git as you were used to
Tags: git, tutorial
Published: 2022-10-06 15:42:31

Okay, we've been using `git pull` for a long time, and also for a long time we have been receiving a warning telling us that the behavior was going to change and the time has come.

But if you are like me you are used to the old times. And no worries you can go back in time and still have the same behavior.

```
git pull --no-ff
```

And
```
git merge --no-ff
```

You can also make it as default but I don't recommend that :)
💥 We passed the 5000 member mark!
Tags: opensource, embedded, edge, luos
Published: 2022-10-06 15:42:07

💥 Woo-hoo! We opened a new community a few months ago for embedded and edge developers and have passed the 5000 member mark!

This Discord aims to exchange with embedded and edge developers on new project development methodologies,  
[➡️Join now](https://discord.gg/luos)

Thanks to all of you maintainers, contributors, communicators and members for being part of this great project!
Things I Learned: Hash methods
Published: 2022-10-06 15:26:10

1. I learned the differences in the .keys and .key() methods when using Hash class/data types.

2. I am learning and compiling information on the various methods across the different data types to better understand them: https://docs.google.com/spreadsheets/d/1usFk0hYIAoIhQtV9HHuKWkF3bT7g8PHe/edit?usp=sharing&ouid=107748750830000072636&rtpof=true&sd=true
Sort Colors - Sort 0,1,2
Tags: javascript, leetcode
Published: 2022-10-06 15:25:08

Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.

We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.

You must solve this problem without using the library's sort function.

Example 1:

Input: nums = [2,0,2,1,1,0]
Output: [0,0,1,1,2,2]
Example 2:

Input: nums = [2,0,1]
Output: [0,1,2]

```js
/**
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var sortColors = function (nums) {
  let start = 0;
  let mid = 0;
  let end = nums.length - 1;
  // setting 3 pointers start, mid , end..

  // Ideally moving from 0 to end
  while (mid <= end) {
    // checking it for 0
    // if nums[mid] === 0 => mean we have lower value..
    // so we swap this value with start pointer & move value at start index to this index
    if (nums[mid] === 0) {
      let temp = nums[start];
      nums[start] = nums[mid];
      nums[mid] = temp;
      start++;
      mid++;
    } else if (nums[mid] === 1) {
      // if nums[mid] === 1 => do nothing just move mid to next place
      mid++;
    } else {
      // if nums[mid] === 2 => swap elemnt from mid & last..
      let temp = nums[mid];
      nums[mid] = nums[end];
      nums[end] = temp;
      end--;
    }
  }
  return nums;
};

console.log(sortColors([2, 0, 2, 1, 1, 0]));

```
Dolphin Chat is here....
Tags: showdev, javascript, node, webdev
Published: 2022-10-06 15:12:36

Hello everyone, welcome back to another post

I am writing this to announce that Dolphin Chat, a chat application that I've been working on with @hugoonreplit , is finally ready for release.

Features include:

- Messaging (duh)
- Public Groups
- Private Groups
- Adding and removing users
- Deleting Groups
- Creating Groups
- Encrypted and secure data

The project is currently hosted on replit:
[dolphinchat](dolphinchat-client.liftoff-ka.repl.co)

Feedback would be appreciated!!
Thank you
New Udemy Course | 3 Portfolio Projects - Laravel + Blade , VueJS, ReactJS
Tags: laravel, vue, react, php
Published: 2022-10-06 15:08:27

{% embed https://youtu.be/cJsC1g6Oi_c %}

Get the Course: https://bit.ly/3SMaeCY
Playlists:
Laravel Reddit clone - https://bit.ly/3UOYS2O
React tutorial for beginners - https://bit.ly/3arkqjX
Laravel Filament Blog - https://bit.ly/3nWYv74
Laravel 9 Full Tutorial - https://bit.ly/3nTiyTR
Laravel 9 Media Library - https://bit.ly/3LpJmVr
Laravel Essentials Full Tutorial - https://bit.ly/3vplyuC
Laravel Mail Tutorial - https://bit.ly/37mJUNh 
Laravel Restaurant Reservation - https://bit.ly/3Jc5IcG
Spatie Laravel Permission - https://bit.ly/3pOsOhN
Laravel Testing For Beginners - https://bit.ly/3t1gNq4
Laravel Roles and Permissions - https://bit.ly/3gOhM7d
LARAVEL INERTIA MOVIE APP - https://bit.ly/3FVMp4Q
Laravel Livewire Movie App - https://bit.ly/3s8D6v1
Laravel Classified Website - https://bit.ly/3nsFRnb
Livewire Employees - https://bit.ly/2ZtIpZY
Laravel Employees Management - https://bit.ly/3Gglt14
Laravel admin panel - https://bit.ly/3CcX75M
Cómo crear una cultura de datos en la empresa
Tags: datascience, beginners, spanish
Published: 2022-10-06 14:11:46

 - Motivar a los empleados a que tomen decisiones basados en datos. Reconocer que todas las empresas tienen y necesitan información. Ayudar a los empleados a entender el valor de los datos e incentivarlos a identificar estrategias para recolectarlos.
 - Recolectar la información. Implementar mecanismos para la obtención de la información. Esto es muy variado y depende de cada empresa, puede tratarse de encuestas, instalar sensores, etc.
 - Medir la información, Importante monitorear la obtención de la información. Pivotear los mecanismos de obtención de información y determinar si cumplen su objetivo o deben efectuarse cambios e incluso implementar nuevos mecanismos de obtención de datos.
 - Determinar cuáles datos son los más relevantes (por ejemplo, algunos datos no requieren obtenerlos de manera instantánea en minutos y segundos, mientras que otros requieren tenerse en la instantaneidad, tal vez la hora de una reserva en un restaurante no se necesita en horas minutos y segundos porque de un segundo a otro no sería mucha la diferencia. Mientras que habrá otros datos en los que la variación de los mismos de un segundo a otro representa una gran diferencia, por ejemplo, en ambientes de mercados financieros) y qué tan precisa es la información (unidades de medidas que pueden variar entre poblaciones, etc. por ejemplo, generalizar valores monetarios entre países, requiere estandarizar a una moneda común, si esta estandarización no ocurre, los datos no serían precisos)
 - Plantear hipótesis y respuestas (plantea preguntas en forma de posibles problemas y cuál sería la posible respuesta o solución).
 - Dadas las respuestas de las hipótesis, es decir, los insights, se procede a actuar (actuar se refiere a una acción empresarial, como una campaña de marketing, llamada a clientes etc.).
 - Cumplir regulaciones o políticas de tratamiento de datos.
 - Automatizar, El estudio del paso 5 se realiza una sola vez, luego este estudio se automatiza mediante software y se puede repetir tantas veces sea necesario.
How to add watermark to image using php gd
Tags: php, beginners, programming, images
Published: 2022-10-06 15:07:31

Using [PHP GD](https://onelinerhub.com/php-gd) library to adding watermark is as simple as merging 2 images.

First, we create gd image from photo to add watermark to:
```php
$bg = imagecreatefromjpeg('photo.jpg');
```

Next, we create gd image from watermark file (`logo.png`) and get it's size:
```php
$wm = imagecreatefrompng('logo.png');
$wm_size = getimagesize('logo.png');
```

Now place watermark at 25 pixels from top & left borders:
```php
imagecopy($bg, $wm, 25, 25, 0, 0, $wm_size[0], $wm_size[1]);
```

Finally, save resulting JPG image to `result.jpg`:
```php
imagejpeg($bg, 'result.jpg');
```

Get and contribute more [PHP GD code solutions](https://onelinerhub.com/php-gd).
Deta is a really good alternative to Heroku!!
Tags: heroku, deta, node, python
Published: 2022-10-06 15:05:12

It's been a long while writing something on dev.to, but I had to recommend a site for ya'll 


It's called deta.sh
I personally find it amazing for developers who want quick python and nodejs sites or apis out


I love the way it's cli works too

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