teleren/devto huggingface dataset:
Use Random Forest Feature Importance for Feature Selection
Published: 2022-03-29 16:43:13

Saving on computation is a priority for me, as I am practicing data science on an old machine, and don't currently have access to cloud computing software.

So, what to do when recursive feature selection (RFE) runs for 20 minutes while I take a snack break and is still spinning when I return?

The answer is scikitlearn's model.feature_importances_.

My Random Forest models are among my best, so this feature is a really nice way to save on computation and still return a high-performing model.

After fitting, predicting, running a confusion matrix, and a classification report, I turn to feature importance so I am able to iterate and improve my model by running it on fewer features, or report the feature importance to my superiors.

See this bit of documentation code from [sklearn's Feature importances with a forest of trees web page](https://scikit-learn.org/stable/auto_examples/ensemble/plot_forest_importances.html)

One of my favorite things to do with this information, is produce a top ten features bar chart that plots the features by importance.

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

And, here is the code I copied or wrote to produce it:
```
# Feature importance
features = pd.DataFrame(forest6.feature_importances_)
features['Feature'] = X_train.columns.values
features['Feature Importance'] = features[0]
features = features.drop(0, axis=1)
features = features.sort_values(by=['Feature Importance'], ascending=True)
features = features.nlargest(n=10, columns=['Feature Importance'])
features

import matplotlib.style as style
# style.available
style.use('fivethirtyeight')

plt.figure(figsize=(8,8))
plt.barh(range(10), features['Feature Importance'], align='center') 
plt.yticks(np.arange(10), features['Feature']) 
plt.xlabel('Feature importance (Weight)')
plt.ylabel('Feature')
plt.title('Top Ten Features by Importance')
```
I hope this helps you enjoy feature_importances_ by scikitlearn!
Day-53 Training At Ryaz
Tags: webdev, beginners, programming, tutorial
Published: 2022-03-29 16:51:39

Today,I started at about 10:30 am as I was doing the implementation of JWT json web tokens so, I was done with basic implementation as there was some errors with the index.js file soothe jwt tokens did not get with the post request so, that jwt token were not sent and not seen as implemented so, I done some basic changes and would be able to do it by tomorrow as due to some minor errors I was unable to resolve it. in the starting of day I read some of blogs like it shows ro implement the jwt tokens as by passing the ACCESS_TOKEN_SECRET and REFRESH_TOKEN_SECRET but it was also not successful to implement it so, after this I would be able to do it by tomorrow. this way my day ended up.
Kick the Can, Down the Road
Tags: economy, inflation, solution
Published: 2022-03-29 15:23:32


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

There are many strategies to solve real problems rather than to let them persist. A primary method employed in politics is kicking the can down the road instead of reaching for the solution. Every problem is an opportunity for profit under capitalism. Hence, elected officials are loyal to the profit of big corporations than the needs of the people. 

Solving any problem first requires genuine intent to admit the problem. Then, collective efforts need to be in place to find real solutions. However, that means people need to accept the wrongs and willing to do right. Taking responsibility and finding solution to problems are too much work, time consuming and no one gain profit. And, any attempt is likely to receive backlash and be isolated from main players. 

Therefore, community problems are often left unresolved and used for political gains and corporate profit. Often blamed on vulnerable such as minorities, immigrants, non-christians, liberals, media and the deep state. Ever noticed that financial institutions are free from all forms of criticism? 
For an example, the bank account fees are decided based on quarterly performances to meet the unrealistic greed of next quarter. 

Interestingly, our half baked economists argue inflation without analyzing the exponential growth of corporate profit from 1970 to 2020 or CEO salaries along with the expansion of corporate welfare toward greenwashing corporations. That is what happens to our tax dollars under the illusion of democracy. #economics #inflation #solutions
Python Projects for Beginners
Tags: python, beginners, programming
Published: 2022-03-29 16:42:59

## Table of Contents
1. [Know Your Resources](#your-resources)
2. [Your First Projects](#your-first-projects)
3. [Getting More Advanced](#getting-more-advanced)
4. [Conclusion](#conclusion)

Learning any new language can be difficult. Spending time reading textbooks or watching videos may not do much help unless you put the learned knowledge into use. Also, building projects will help you bring together different concepts.

But before you even begin your first project, you will want to know where you're able to go if you ever get stuck and need help.

### Your Resources
[Stack Overflow](https://stackoverflow.com/questions/tagged/python) is a wonderful site to ask questions. If you have a question about something, it is likely that someone else had the same or a similar question in the past. You can also look into [Python 3.10.4 Documentation](https://docs.python.org/3/) if that interests you, though it can be hard to navigate through if you are not used to reading documentation yet. Other resources for general Python knowledge are websites such as [w3schools](https://www.w3schools.com/python/default.asp).

### Your First Projects
Some beginner projects that utilize lists, tuples, dictionaries, and a few other basic modules include:
1. [Acronyms](https://thecleverprogrammer.com/2021/01/13/acronyms-using-python/)
2. [Rock Paper Scissors](https://en.wikipedia.org/wiki/Rock%E2%80%93paper%E2%80%93scissors)
3. [BMI Calculator](https://thecleverprogrammer.com/2020/12/21/bmi-calculator-with-python/)
4. [Roman Numbers to Decimals](https://thecleverprogrammer.com/2021/01/07/convert-roman-numbers-to-decimals-with-python/)
5. [Hangman Game](https://www.youtube.com/watch?v=JNXmCOumNw0)

### Getting More Advanced
When you get to a level where you are more comfortable with Python, you may want a little more challenging projects. Take a look at the following:
1. [Language Translator](https://www.thepythoncode.com/article/translate-text-in-python)
2. [Convert text to Speech](https://www.geeksforgeeks.org/convert-text-speech-python/)
3. [2048 Game](https://www.geeksforgeeks.org/2048-game-in-python/)
4. [Contact Book](https://data-flair.training/blogs/address-book-in-python/)
5. [Alarm Clock](https://thecleverprogrammer.com/2021/01/13/alarm-clock-with-python/)
6. [Numbers to Words](https://github.com/Harsh151200/Beginner-Python-Projects/tree/main/Num2Words)

### Conclusion
Whether you are just starting out with programming or a veteran in computer science refreshing their memory on Python, there are always new, fun and exciting projects to build. If you are looking for more advanced projects, keep a look out for a future post. I am still looking for the best and most popular projects that may interest everyone!

Until then,
Happy coding!
How to Filter Complex Javascript Arrays
Tags: opensource, javascript, laravel
Published: 2022-03-29 16:42:39

---
title: How to Filter Complex Javascript Arrays
published: true
description: Easily filter Javascript arrays with this open-source package which is built to work like Laravel's Eloquent.
canonical_url: https://pyhost.io/blog/how-to-filter-complex-javascript-arrays/
tags: opensource, javascript, laravel
cover_image: https://i.imgur.com/T3NiqJX.png
---

> *TL;DR* I've revived an open-source npm package that I initially built a couple of years ago but have given some TLC in the last few days. You can find it here: [https://github.com/allmanaj/or-where](https://github.com/allmanaj/or-where).

A few years ago, a colleague and I were faced with a problem. We had to make a dashboard with dynamic, intelligent filters for multiple types of data from objects to strings. Usually this would have been a relatively simple thing to accomplish with Javascript's `filter()` function but in this instance we had no real way of knowing what the user was going to try and filter on since the data could vary so much. To help solve the problem, I built a small, single JS file which allowed us to construct logic like Laravel's Eloquent queries. It meant that we could turn a long, meandering condition inside the filtering function to look more like English. Ultimately, we loved working with it and I released it as a small npm package.

Let's take a look at an example and see how it makes life simpler for developers who find themselves with a whole load of data and no easy way to filter it:

```
// without or-where
users.filter(user => {
    return (user.name == 'Angus' || user.name == 'Jess' || user.name == 'Aaron') && user.age >= 25;
});

//with or-where
filter = new Builder(users);
filter.whereIn('name', ['Angus', 'Jess', 'Aaron'])
      .where('age', '>=', 25)
      .get()
```

Even in this relatively basic example it's easy to see the benefits of it. Rather than needing to read the logic gates and pay attention to the brackets, you can read the query like it's English. 

Using the built in methods (`where()`, `orWhere()`,... etc) you build up a query which is eventually passed to Javascript's `filter()` method when you call `get()`. That's all there is to it! You can create incredibly flexible queries with a few simple building blocks leaving your code readable and efficient. What's not to love?

You can find the full documentation on github: [https://github.com/allmanaj/or-where](https://github.com/allmanaj/or-where). Feel free to contribute or open an issue if there's a feature you feel the package is missing!

I'd really appreciate it if you'd take a look and share it with anyone who might find the package useful, and leave a star if you're feeling generous 😉
ActiveRecord Calculations
Published: 2022-03-29 16:40:24

Let's talk about some useful methods that are very handy when we need to do some calculations to our database records.

#### So what is activerecord calculations?



##### ActiveRecord Calculations provide methods for calculating values of columns in the ActiveRecord models.



### `count` Method

Let's start with a method that is widely knowing for simple count.
```
User.count 
#returns the number of users.
```
Keep in mind that count is not always the most performant with that being said 
this [article](https://longliveruby.com/articles/active-record-counting-records) demonstrates the difference between `count`, `size`, `length`.

But `count` has much more to offer 🔥 so let's see the different usage of count below 👇

```
User.count(:address)
# returns the count of all users whose address exist in our db.
```

```
User.distinct.count(:city)
# returns the count of different cities we have in our db.
```

```
User.group(:city).count
# returns a hash with each city and it's count.
#{ 'Cairo' => 5, 'Qina' => 3 }
```

We can also do the above 👆 with multiple columns 

```
Post.group(:status, :category).count
# {["draft", "business"]=>10, ["published", "art"]=>5}
```

### `maximum` Method

```
User.maximum(:age)
# 98
# returns the maximum value on the given column.
```

### `minimum` Method

```
User.minimum(:age)
# 18
# returns the minimum value on the given column.
```

### `average` Method

```
User.average(:age)
# 27.5
# returns the average value on the given column.
```

### `sum` Method

```
User.sum(:age)
# 7845
# returns the sum of the values on the given column.
```

### `ids` Method

```
User.ids
# returns the users ids
```


### Summary
Please check out [the documentation](https://api.rubyonrails.org/v7.0.2.3/classes/ActiveRecord/Calculations.html) for reference.

I hope you found the article useful and enjoyed reading as much as i enjoyed writing it 😃.
Build API Server for upload files to AWS S3
Tags: aws, s3, node, typescript
Published: 2022-03-29 16:32:19


# Build API Server for upload files to AWS S3


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

*Full source code in [here](https://github.com/ductnn/api-upload-to-s3)*

## Project structure

**Overview**:

```sh
.
├── ./src
├── ./Dockerfile
├── ./README.md
├── ./package-lock.json
├── ./package.json
└── ./tsconfig.json
```

**Detail**:

```sh
src
├── config
│   ├── config.ts
│   └── index.ts
├── main.ts
├── routes
│   ├── index.ts
│   └── upload-to-S3.ts
├── services
│   ├── api.ts
│   └── index.ts
└── utils
    ├── index.ts
    └── utils.ts
```

## Install and build

### With manual

Clone this repo:

```sh
git clone https://github.com/ductnn/api-upload-to-s3.git
cd api-upload-to-s3
```

Set the enviroment variables:

```sh
cp .env.example .env

# open .env and modify the environment variables
## AWS_ACCESS_KEY=
## AWS_SECRET_KEY=
## AWS_REGION_DEFAULT=
## AWS_BUCKET_NAME=
```

Install the dependencies:

```sh
npm install
```

Start API Server woth command `npm start`:

```sh
➜  api-upload-to-s3 git:(master) npm start 

> api-upload-to-s3@1.0.0 start
> node --require ts-node/register src/main.ts

Running service:  undefined
🚀 Server started as undefined at http://localhost:5000
```

Open url `127.0.0.1:5000` on browser to view result or use `curl`:

```sh
➜  api-upload-to-s3 git:(master) ✗ curl 127.0.0.1:5000
<h3>Build API Server for upload files to AWS S3</h3>
```

Then, we use **Postman** with method `PUT` in `127.0.0.1:5000/s3/upload` to 
upload files.

### With Dockerfile

Easy to build API with [Dockerfile](./Dockerfile):

```sh
# Build images
docker build -t <YOUR-DOCKER-ID>/api-upload-to-s3:v1 -f Dockerfile .

# Push to your registry
docker push <YOUR-DOCKER-ID>/api-upload-to-s3:v1

# And run this docker image
docker run -itd -p 5000:5000 <YOUR-DOCKER-ID>/api-upload-to-s3:v1
```

## Contribution
Contributions are more than welcome in this project!

## License
The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.
Problem using Observable in the component, Async, trackBy, how to update a list
Published: 2022-03-29 16:16:08

Hi all,
as I saw in many tutorials, it is highly recommended to use native way of Angular if we are dealing with an observable service.

So I have a service like "ActionService" with a method:
`  findAll(): Observable<ActionCode[]> {
    return this.http.post<ActionCode[]>(this.baseUrl)
  }

My Component:
export class ActionCodesComponent {
	actionCodes$: Observable<ActionCode[]>

  constructor(private actionService: ActionService) {
    this.actionCodes$ = this.actionService.findAll();
  }

onDelete() { // how should I refresh the Observable here???
	this.actionCodes$ = this.actionService.findAll();
}

  trackByActionCode(index, actionCode): string {
    return actionCode ? actionCode.id : undefined
  }
}

The Problem:
right now, if I delete an element from a list by clicking on "X" span, the whole list is being rendered again and flicking. So at first the trackBy function does not work (if I use the same function not with observable but with array of elements, it works very fine).
Second: How can I update my Observable without recreation it again like this.actionCodes$ = this.actionService.getAll()?
All examples on youtube and internet showing like myObservable = the Subject() and myObservable.next().
But it does bot work with my Observable this.actionCodes$. There is no next() method available at all.

Can somebody tell me what I am doing wrong here? If I cannot update a list using Observable (not an array), why it is recommended by every Angular expert?
Thanks
docker-compose.yml file
Published: 2022-03-29 16:05:10

version: "3.8"
services:
    mongodb:
        image: mongo
        container_name:  mongodb
        ports:
            - "27017:27017"
        volumes:
            - data:/data
        environment:
            - MONGO_INITDB_ROOT_USERNAME=rootuser
            - MONGO_INITDB_ROOT_PASSWORD=rootpassword
    mongo-express:
        image: mongo-express
        container_name: mongo-express
        restart: always
        ports:
            - "80:80"
        environment:
            - ME_CONFIG_MONGODB_ADMINUSERNAME=rootuser
            - ME_CONFIG_MONGODB_ADMINPASSWORD=rootpassword
            - ME_CONFIG_MONGODB_HOST=mongodb
volumes:
    data: {}
networks:
    default:
        name: mongodb_network
Declaring Variables in JavaScript.
Published: 2022-03-29 16:03:37

There are three ways to declaring Variables in JavaScript.

> Variables are like containers that hold a set of value(s), be it string, boolean, array, numbers or objects.

Because JavaScript is a loosely-typed programming language, specifying the value to be declared in a variable is not needed.


The three ways to declare variables in JavaScript are: var, let and const.


- **const** is used to declare variables that their values are not likely to change during the code runtime.


- **let** and **var**, with some signifiant difference, are used to declare variables whose values are very likely to change over the course of a code runtime.
Validating Views with Capybara Queries
Published: 2022-03-29 15:52:33

When you write a system test (or, as we prefer, a [system spec][rspec system spec]) with Ruby on Rails, you're exercising the whole stack from the point of view of the user. So, naturally, you have to do things like make sure that certain elements are on the page and work as you expect when you click on then, type in them, and drag them around. [Capybara][capybara] works exceedingly well for this, giving you a lovely API for querying HTML.

But system specs are heavy. They need everything spun up. They need a browser. They're faster than a person clicking around, but they need to do things like wait for pages to load, animations to finish, and Promises to resolve. If you can, it's much cleaner to test whether or not you have data in your HTML by using a [view spec][view spec]. You only have to use exactly what the template needs, and stubbing or mocking to get ensure coverage is far less onerous and invasive. Since a view spec only has to worry about rendering the view (and returning a String), it doesn't have to load a whole browser.

Even in the Relish documentation linked above, we see that a lot of view specs involve straight text matching. You could try Rails' [assert_select][assert_select], which makes more structured queries, but an even easier solution exists.

[`Capybara.string`][capybara.string] is a very straight forward method that turns a string into a queryable document. Working with it involves little overhead, especially if you have Capybara installed already (and even if you don't).

```ruby
it "renders the account link when signed in" do
  user = FactoryBot.build_stubbed(:user)
  assign(:current_user, user)

  render partial: "layouts/nav"

  doc = Capybara.string(rendered)
  expect(doc).to have_css("nav a[href='/users/#{user.id}']", text: "Account")
end

it "does not render the account link when signed out" do
  assign(:current_user, nil)

  render partial: "layouts/nav"

  doc = Capybara.string(rendered)
  expect(doc).to have_no_css("nav a", text: "Account")
end
```

You get access to all the Capybara matchers, and, with RSpec, you get the nice inflections that make your specs very readable. And since `render` already puts its result into `rendered`, it's very easy to make that into a usable document with `Capybara.string`.

[rspec system spec]: https://relishapp.com/rspec/rspec-rails/docs/system-specs/system-spec
[capybara]: https://teamcapybara.github.io/capybara/
[view spec]: https://relishapp.com/rspec/rspec-rails/v/5-0/docs/view-specs/view-spec
[assert_select]: https://apidock.com/rails/ActionController/Assertions/SelectorAssertions/assert_select
[capybara.string]: https://www.rubydoc.info/gems/capybara/Capybara.string

_Learn more about how The Gnar [builds Ruby on Rails applications](https://www.thegnar.com/software-development/ruby-on-rails-development)._
Lasson 04 | Loops and errors
Tags: whileloop, dowhileloop, forloop, loops
Published: 2022-03-29 15:40:55

## Types of Loops
Loops can be written as `while` loops, `do-while` loops, and `for` loops.

## while Loops
`while` loops iterate until a condition is met.
```c
int a = 0;
while (a < 10) {
  a++;
}
```

## do-while Loops
`do-while` loops are `while` loops that initially execute the body once before checking the condition.

```c
do {
  printf("not true!");
} (while 2 == 3);
```

## for Loops
`for` loops complete a set number of iterations before meeting a condition.

```c
for (int i = 0; i <= 10; i++) {
  printf("Hello!");
}
```

## Loop Keywords
All loops can utilize keywords like `continue` and `break`. `continue` restarts the loop and `break` breaks out of (or ends) the loop.

## Rewriting Loops
A `for` loop can always be re-written as a `while` loop; most `while` loops can be re-written as a `for` loop.
Inspect alternative , CSS helper
Tags: css, html, javascript
Published: 2022-03-29 15:34:34


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z8js5g1bclfa3334f66w.png)
**With this tool you can edit your CSS style and copy your code a powerful Chrome Extension was created to help web developers make CSS editing easy for anyone beginner or professional Copy and paste all your editing code into your project easily This tool does not work directly In your project it helps you to see changes in real-time and copies all your code changes and also you can choose any element to modify by clicking inspect to choose your CSS class or ID to change style
I hope it helps you**
https://www.youtube.com/watch?v=xRmxz41VFqk

[project product hunt link](https://www.producthunt.com/posts/aquarius-css-helper)
New project completed: Let's create a Biometric Security System using Luos by Marie#9390
Tags: arduino, programming, tutorial, luos
Published: 2022-03-29 15:22:07

Marie#9390 has developed a biometric security system using Luos. 
In a quick video, find out how to reproduce this system using an Arduino or a ST Nucleo.

{% embed https://www.youtube.com/embed/GTKc-dwlLMM %}

Watch her video, see other examples in our Discord, or submit your project to our community!
30 Days of Code | Python DSA.
Tags: python, dsa
Published: 2022-03-29 15:13:38

I will only focus on the problem solving, for introduction you can check other available resources like https://www.tutorialspoint.com/python_data_structure/python_data_structure_introduction.html

## Day 1 - Search Algorithm && Two sum problem
### 1.Search algorithm - Linear && search.
```

```
Sample Blog 3
Published: 2022-03-29 15:04:41

But before diving in those of you unfamiliar with `rm`, it is a command used to remove objects such as files, directories, symbolic links, etc. More precisely, `rm` removes reference/pointer to objects from the filesystem. If you have multiple pointers to the file (hard links), then deleting one of those pointers with `rm` leaves the others completely untouched and the data still available. Deleting all of those links still does not touch the data; however, the OS is now free to reuse the previously reserved blocks for storing that data.

It is important to note that the command works silently, and once you delete your files and folders, you won't be able to get them back. At least easily. You can find various "undelete" utilities. But depending on the filesystem, it can get relatively complex.

So I use a custom script that sends it to a recycle bin instead of deleting anything directly. Depending upon your OS, you may or may not have a recycle bin. If you don't have one, you can always make one.

last line