teleren/devto huggingface dataset:
Self and Scope
Published: 2021-03-02 03:44:46

The keyword "self" in Ruby always refers to the current object within that context. Self can be referenced to a class as well as  an instance ![anime.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 9_41_54 PM (2)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/61tx0p0hckxs46s5s04r.png)
 

Scope refers to the level of accessibility our variables have. Allowing our program to have different levels of scope allow certain variables to be accessed or referenced at different times. 3 types of scope would be local, instance, and class

Local
Refers to a variable that is declared within a method and cannot be accessed outside of said method ![anime.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 9_17_50 PM (2)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uv6e84p3ltx2utkt4otx.png)
  

Class 
Refers to variables that are accessed within all instances of our class. An easy way to detect a class variable is by the "@@" character next to our variable ![anime.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 9_20_57 PM (3)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n755kjxzdpaqxrco8toj.png)
 

Instance 
Instance variables values are only used within specific instances of an object. Similar to our class variable we use a single "@" in order to declare our instance variable ![anime.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 9_20_57 PM (4)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ckqv1lq0nvkq29ql2jz9.png)
The 8 must know JavaScript looping array function 
Tags: javascript, es6, loop, cleancode
Published: 2021-03-02 03:44:09

#Array.map()
Iterate through the array and returning a new value

```javascript
const array1 = [1, 4, 9, 16];
// pass a function to map
const map1 = array1.map(x => x * 2);
console.log(map1);
// expected output: Array [2, 8, 18, 32]
```

#Array.forEach()
Iterate through the array

```javascript
const array1 = ['a', 'b', 'c'];
array1.forEach(e=> console.log(e));
// expected output: "a"
// expected output: "b"
// expected output: "c"
```
#Array.every()
Iterate through the array and check every element, return true if every element is right and false if it's not

```javascript
const array1 = [1, 30, 39, 29, 10, 13];
console.log(array1.every(e => e < 40));
// expected output: true
```

#Array.some()
Iterate through the array and return true if there is one element is right and false if it's not

```javascript
const array1 = [1, 30, 39, 29, 10, 13];
console.log(array1.some(e => e < 10));
// expected output: true
```

#Array.find()
Iterate through the array and return the first element if it's true and undefine if there is no the right element

```javascript
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(e=> e> 10);
console.log(found);
// expected output: 12
```

#Array.findIndex()
Iterate through the array and return the index of first element if it's true and -1 if there is no the right element

```javascript
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(e=> e> 10);
console.log(found);
// expected output: 1
```

#Array.sort()
Sort and array through every element, return a ascending order array if the result is greater then 0 and descending if the result is lesser then 0;

```javascript
let numbers = [4, 2, 5, 1, 3];
numbers.sort((a, b) => a - b);
console.log(numbers);
// [1, 2, 3, 4, 5]
```

#Array.reduce()
A reducer function on each element of the array, resulting in single output value.

```javascript
const array1 = [1, 2, 3, 4];
// 1 + 2 + 3 + 4
console.log(array1.reduce((accumulator, currentValue) => accumulator + currentValue));
// expected output: 10
```
Sinatra Project
Tags: sinatra, ruby
Published: 2021-03-02 03:13:03

    I wrote my first Sinatra web app. It doesn't do too much other than allow the user to create an account through username, email, and password creation. The main purpose was for the user to create a registry of all the pets that they own. This gave the chance to explore how a database was created and how information is able to be stored separate from other users as well as learning more about associations. 
    Associations are how one about object (the user) is related to another in this case was a Pets class object. The User class was able to hold a has many relationship with the Pets class allowing for more than one pet to be associated with a user (aptly named the owner). The pet in question was only able to be to paired with a single owner as it held a belongs to relationship with the user. A foreign key was used to connect the user to the pet.
    With that in place I was able to produce information about any pet that was created by a single user and through the use of the authenticate method to ensure only the owner was able to view this information. The said information only contained the pet's name, species, and age. This leaves plenty of room put in additional details such as a breed, traits, notable qualities, a pet "bio" if the owner so wished it. I had particular issues with creating error correction during the section which the controller would be to blame for this, but possibly due to a missed commit on this single file which gave me troubles. A couple lines of code later and the ability to "view" a pet which did not exist would simply send the user attempting such a search would find themselves back at home with a message noting there is no file.
    There is more that I'm hoping that will come with the learning of Ruby on Rails and using MVC more so that I may get the hang of it a little bit more. Sinatra has been that stepping stone into the world of web dev that I've been curious about for so long. Thinking that one must write line-by-line, page-by-page of HTML, thankful that is not the case.
Docker | Which network is your container running under?
Tags: docker
Published: 2021-03-02 02:57:57

I use docker-composer created 4 containers: 
* phpmyadmin
* wordpress
* mariadb
* worker
to simulate a cluster.

The `worker` container should publish read/edit WordPress posts through REST api, so the first thing I have to know is the IP address of `wordpress`.

```
docker inspect --format='{{json .NetworkSettings.Networks}}' wordpress
```
got this:
`{"test4_default":{"IPAMConfig":null,"Links":null,"Aliases":["wordpress","3c643dafbb8a"],"NetworkID":"5a0f08a9dda9e1649a50568c697753c8b04277cf4fff73450aeef90bbceab2b4","EndpointID":"6513b7a1cc85f59bac846e979dd2226057654667c27cfeec0fffad505caa5bb7","Gateway":"192.168.80.1","IPAddress":"192.168.80.5","IPPrefixLen":20,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:c0:a8:50:05","DriverOpts":null}}`

```
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' wordpress
```
got the ip:
`192.168.80.5`

**Hope this helps!**
**So proud to be a coder!**
Curry, code, and databases
Tags: mongodb, database, javascript, functional
Published: 2021-03-02 02:56:39

You may have heard of curry, it's a type of food. People eat curry, and they may or may not like it. There is also a concept in programming called currying, and there is a lot to like about it.


## The curry part

A curried function is a function that uses partial functions as it's arguments. It's a large part of functional programming and allows for better composition of software. 

Here is an example
```javascript
const add = a => b => a + b;
```

You may notice that there are two arrow functions. That is how you curry. You take the first parameter, `a`, and it creates a partial function that is used as an argument for the second parameter `b`.

These are functionally equivalent:

```javascript
// Curried add
const add = a => b => a + b;

// Regular add
const add = (a,b) => a + b;
```

However, the curried version is a lot more diverse because of the partial function it creates.

```javascript
const add = a => b => a + b;

add(1) // --> function
add(1)(2) // --> 3

// The first function is called, a partial function is created, 
// and then it's passed to the second for the final calculation.
```

We can use that partial function to create "presets". 

```javascript
// Create preset using curried add function above
const add5 = add(5); // Partial function with 5 stored as variable 'a'

const add5(5) // --> 10
```

You can start to see how this is powerful. 

## The database part

A little while ago I made a Mongodb library for my own use because I was annoyed with the default driver. I used currying to create a really simple API and I just released it on NPM for everyone to use.

It's called `mongo-curry`. It supports ES6 syntax, is super easy to test, and is just a really nice little library

If you want to try it, you can install it with 

`npm install mongo-curry`

or 

`yarn add mongo-curry`

Of course you need to know how to use it, so [here is the docs](https://gitlab.com/Creplav/mongo-curry/-/wikis/home)

## The last part

I hope you found something here helpful.

If you have some ideas on how to improve either the documentation, or the library, or would like to hear more about functional JavaScript please let me know. 

*Writing and publishing the library and documentation took a couple weeks worth of work. If you find it helpful and would like to see me make more stuff you can [buy me a coffee](https://www.buymeacoffee.com/creplav)*
Why did I choose Software Engineering
Published: 2021-03-02 02:48:05

Being a software engineer is not only a choice but a dream since I was a kid.
As a little boy, I was opening my home computer and take out all the pieces than put them back as a puzzle, I was able to spend the whole day on a computer without internet. 
After graduating in the high school I joined the university in Algeria to study software engineering, I thought realizing my dream but not yet, lot of a challenges waiting for me.
When you are on your laptop and a problem to solve and you need hundreds lines of code it's stressful and exciting, after debugging with no errors and you run the program and it works it's just an amazing feeling.
it's this adrenalin witch went up, and all this challenges everyday, and all this feelings witch make me choosing software engineering.
Top 50 Anime Gem
Published: 2021-03-02 02:46:05

The gem I created helps users look at the top 50 anime from the past year. The system uses the run method to get things going as well as use my "get_data" method from my API class.  ![api.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 8_41_41 PM (2)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ul07zm70l8ca6l3vx0l.png)
   
The user is first greeted and then can continue on to be presented with the list if they wish to continue. The "anime_list" method I created first tells the user to select an anime and the is able to output the anime's title and index. ![cli.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 6_13_02 PM (2)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8jzqjm3p5s2shsr7sd4g.png)
 
From there the user is able to input the index or title of the anime in order to gather more information. I had created a conditional statement that can take in the title, index, and also exit if the user wishes to ![cli.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 8_17_41 PM (2)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4hrk82vabq9nr66btzhs.png)
 

Depending on the input the user is then greeted with one of 3 methods ![cli.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 8_17_41 PM (3)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1ww4poj1ejrfior37ue.png)
 
After selecting one of the conditional statements the user is then greeted with a second menu that allows them to continue searching and puts them into a loop. ![cli.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 8_17_53 PM (2)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/068upiv2hslqptvyhdvf.png)
  

Once the user is done searching he or she can exit the loop by typing in either "exit" or "n" depending on where they are in the loop.

 When exiting the program the user is given a goodbye message saying "We hope to see you again". ![cli.rb - code [WSL_ Ubuntu] - Visual Studio Code 3_1_2021 8_17_53 PM (3)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ex5dh23g4qrtw83h9zjj.png)
Day 29: Heap Sort
Tags: 100daysofcode, csharp
Published: 2021-03-02 02:22:55

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8towv3ukbtn07k80m3th.gif)

```csharp
using System;
 
public class Day29 {
    public void sort(int[] arr)
    {
        int n = arr.Length;
 
        for (int i = n / 2 - 1; i >= 0; i--)
            heapsort(arr, n, i);
 
        for (int i = n - 1; i > 0; i--) {
            int temp = arr[0];
            arr[0] = arr[i];
            arr[i] = temp;
 
            heapsort(arr, i, 0);
        }
    }
 

    void heapsort(int[] arr, int n, int i)
    {
        int largest = i; 
        int l = 2 * i + 1; 
        int r = 2 * i + 2;
 
        if (l < n && arr[l] > arr[largest])
            largest = l;
 
        if (r < n && arr[r] > arr[largest])
            largest = r;
 
        if (largest != i) {
            int swap = arr[i];
            arr[i] = arr[largest];
            arr[largest] = swap;
 
            heapsort(arr, n, largest);
        }
    }
 
    static void printArray(int[] arr)
    {
        int n = arr.Length;
        for (int i = 0; i < n; ++i)
            Console.Write(arr[i] + " ");
        Console.Read();
    }
 
    public static void Main()
    {
        int[] arr = { 67, 17, 44, 87, 9, 2, 90 };
        int n = arr.Length;
 
        HeapSort ob = new Day29();
        ob.sort(arr);
 
        Console.WriteLine("Sorted result: ");
        printArray(arr);
    }
}
```
Reflecting on 5 years of remote work
Tags: remote, workplace
Published: 2021-03-02 02:11:51

Let me start with what I miss. I miss seeing people in person and being able to periodically hang out with them. Everyone is feeling this now with the pandemic, but I still feel this is worth calling out as the thing that makes remote work hardest on me.

OK, let's get back on track.

# Going remote

When I started working remotely, I ultimately wanted two things.
1. To be able to work for interesting companies
2. To live where I already lived

That was it.  Articles talk a lot about perks of working remotely, but if I'm being honest, this was all I really cared about and everything else was a bonus.

At the time, I was tired of my first job and said "I don't want to work in the industry I currently am, and there aren't many other jobs around here."

It was always my wife and my plan to stay in the area so that we'd have family support when we had children.  That decision has really paid off since our first was born in 2020 in the middle of the pandemic.  It took 4 years, but it's vindicating to have that decision work out how we wanted it to.

So, I decided if I wanted to achieve both of my two goals, that required I work remotely.  I went on StackOverflow jobs and searched "Remote, Java" which eventually landed me at Rocana, an all-remote company, which was eventually acquired by Splunk where I work now.

# Remote work is a trade-off

Remote work definitely has its perks such as no commute, ability to live wherever (including somewhere with a low cost of living), the ability to reduce in-person distractions, or the ability to raid your own fridge whenever you'd like.  But there are also things you miss out on like easier networking and mentorship opportunities, more difficult and missed communications, and free company swag/meals/happy hours/holiday parties.

You also can run into leaders who are less empathetic about remote work.  One leader offhandedly ended a story with "and that's why I don't trust remote workers" while I was on the call (that leader has since left).  Having that story ring in my ears each time I was thinking about my future and the future of my remote direct reports was pretty demoralizing.

When thinking if you want to stay remote full-time after the pandemic, these are things to think about.

# What next

I see myself continuing to work remotely for the foreseeable future since my family is best suited where we are now.  I definitely miss seeing people in the office, and I know that traveling to the offices will be harder post-pandemic since I have the baby at home, but I think this is still what works best for me and the family.

So, ultimately, as much as I love the flexibility and opportunities I've gotten from working remotely the last 5 years, I wanted to make sure I painted a realistic picture here.  It's not completely perfect for me, but I still think it's worked out well the last few years.
Building a CLI with an API✨
Published: 2021-03-02 01:38:23

  Building a CLI from scratch has been a headache and a blessing at the same time. I now understand more about coding and feel 100% more comfortable with continuing on with this journey. But let me tell you, it didn’t come easy. I spent days working on this project, thinking, how will I ever graduate in five months if I can’t even understand the beginning concepts, but as the time passed and I went over the material more and more, it all became easier. I would find myself saying “ahhhhh” more often. Like a 💡 went on and it all finally made sense.

 Something I originally had trouble with was metaprogramming. In Wikipedia, this is defined as a programming technique in which computer programs have the ability to treat other programs as their data. In other words, metaprogramming is the practice of writing code that writes code for us. Making it easier to work with our programs.
           
For example, if we take a look at the codes below, we can see the difference between not using and using metaprogramming.

The first image shows how you can create attribute accessors of the data you want your objects to have. You then would initialize with those attribute accessors (creating writer and reader methods) and save the instance. It then shows how you would shovel that instance method into the @@all array.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yy0gfcmktp9vt5ekfzsb.png)

As you can see below, metaprogramming is used to create easier and more manageable code. Here you can initialize with a hash and iterate over that hash using the #each method to return the key and value of that hash. Then using the method #send to create the key of the attributes named and their value.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ata29xfc71f4kvr7sk2h.png)

Coding this way is better in the long run because I can always return to this section to get the values I am essentially looking for. It makes managing my API easier  by creating new objects using that hash.  

The last thing I want to mention is that using the concept of separations of concerns has been a life saver. It makes your code so much easier to read and handle. It is having a file that only deals with your CLI, a file that only deals with your API, having a file that only deals with your objects, and having a file that only deals with your execution code and another for your required environment. 

You know when you want to execute your code you place that in your run file. And it's the same concept for all your other files. 

In order for code to become easier, practice, practice, practice.
Docker Network Error
Tags: docker
Published: 2021-03-02 01:35:03

```
ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network
```

I got this error, then run `docker network ls`, 32 lines of network list showed up.

Exclude `host`, there are 31 uses DRIVER `bridge`.

I removed some old ones with `docker network rm`.
Computer Graphic with Python: setup libraries
Tags: python, computerscience
Published: 2021-03-02 01:21:06

This post is just how I install stuffs to deal with Computer Graphic course by using Python on Windows.

My environment:
- Python 3.8
- Windows 10 Pro 20H2 64bit

## [PyOpenGL](http://pyopengl.sourceforge.net/documentation/index.html)

According to [PyOpenGL Documentation](http://pyopengl.sourceforge.net/documentation/installation.html), installing via PIP **should** work

`pip install PyOpenGL PyOpenGL_accelerate`

**It doesn't work irl. If you have installed via pip, please uninstall them.**

Now please go to this site for Unofficial Windows Binaries for Python Extension Packages to get `.whl` files to install PyOpenGL.

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl

Now check your Python version and Windows bit version. Then download PyOpenGL_accelerate and PyOpenGL files corresponding to your enviroment.

In my case, Python 3.8 and Windows 64 bit. I had to download these files then install:
```
PyOpenGL_accelerate‑3.1.5‑cp38‑cp38‑win_amd64.whl
PyOpenGL‑3.1.5‑cp38‑cp38‑win_amd64.whl
```

Note:
- `amd64` is for Windows 64 bit
- `cp38-cp38` is for Python 3.8

Then you just need `pip install` whl files.

`pip install path/to/filename.whl`

## [ModernGL](https://github.com/moderngl/moderngl)

Alternatively, you can choose to use ModernGL which is recommended by a lot of people on Stackoverflow.

> In contrast, ModernGL is easy to learn and use, moreover it is capable of rendering with high performance and quality, with less code written.

~ ModernGL ~

Installation is very simple

```
pip install moderngl moderngl-window
```

Documentation:
- [moderngl](https://moderngl.readthedocs.io/en/latest/)
- [moderngl-window](https://moderngl-window.readthedocs.io/en/latest/) for managing window, mouse, keyboard

## [Pyglet](https://github.com/pyglet/pyglet)

Alternatively, you can use [`pyglet.gl`](https://pyglet.readthedocs.io/en/latest/programming_guide/gl.html).

Installation is very simple

```
pip install pyglet
```

Documentation:
- [pyglet](https://pyglet.readthedocs.io/en/latest/index.html#)
Create mysql user and database 
Published: 2021-03-02 01:29:05

```
$sudo mysql
mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
mysql> \q

//login as newuser
$mysql -u newuser -p
mysql> CREATE DATABASE databasename; 

//option create table
mysql> CREATE TABLE Persons (
    PersonID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255)
);

//insert multiple data
INSERT INTO table_name (column_list)
VALUES
	(value_list_1),
	(value_list_2),
	...
	(value_list_n);

```
Apply Now for Alibaba Cloud Most Valuable Professional (MVP) March 2021
Tags: alibabacloud, mvp, alibabacloudmvp
Published: 2021-03-02 01:24:01

The Spring 2021 batch of [Alibaba Cloud Most Valuable Professional (MVP)](https://mvp.alibabacloud.com/mvp/apply?recommendType=1&recommendId=YrWF1h3sC77EDtH3JUhFAQ==) applications is now open! 

Are you a tech expert, thought leaders with rich knowledge and experience of [Alibaba Cloud](https://mvp.alibabacloud.com/mvp/apply?recommendType=1&recommendId=YrWF1h3sC77EDtH3JUhFAQ==) products? 

Are you willing to help others fully understand and use [Alibaba Cloud](https://mvp.alibabacloud.com/mvp/apply?recommendType=1&recommendId=YrWF1h3sC77EDtH3JUhFAQ==) technologies? 

If so, apply to become an [MVP](https://mvp.alibabacloud.com/mvp/apply?recommendType=1&recommendId=YrWF1h3sC77EDtH3JUhFAQ==) by March 14, 2021.
[APPLY NOW](https://mvp.alibabacloud.com/mvp/apply?recommendType=1&recommendId=YrWF1h3sC77EDtH3JUhFAQ==)
Node js - Which Version is Older Than Time bc That's the One I Need.
Published: 2021-03-02 01:05:36

Hello everybody.  I'm brand new to the community.  Thank you for having me.  I am a Front-End developer/designer.  I am now in the middle of starting on the swivel from front-end to back-end and I have, and please don't laugh, but for the reason that I do recordings, I am still using Windows version 6.1.7601.  Because 10 is too hard to run a DAW on.  So I've seen the lists of versions of Node js but how do I tell which one I need?  Is there a link out there or a way to tell?  Thank you all.