teleren/devto huggingface dataset:
Web Developer Monthly 💻🚀 October 2019
Tags: webdev, productivity, news, github
Published: 2019-11-07 12:11:04

**16th issue! If you missed the last few months, check them all out**
**[here](https://zerotomastery.io/blog/?tag=WDM&utm_source=devto&utm_medium=blogpost&utm_campaign=WDMOCT19/)**.

### If it’s your first time here… (otherwise skip this part)

Being a web developer is a fantastic career option. You have many job opportunities, you can work around the world, and you get to solve hard problems. One thing that is hard, however, is staying up to date with the constantly evolving ecosystem. You want to be a top performing web developer, coder, programer, software developer, but you don’t have time to select from hundreds of articles, videos and podcasts each day.

This monthly newsletter is focused on keeping you up to date with the industry, keeping your skills sharp, without wasting your valuable time. I will be sharing the most important articles, podcasts and videos of the month. Think [Tim Ferriss](https://medium.com/u/56d3bc91794f) and [the Pareto Principle](https://en.wikipedia.org/wiki/Pareto_principle) (80/20 rule) meeting the Software Development world. What’s the 20% that will get you 80% of the results?


### What you missed in October as a Web Developer…

*****

### Git Branches Everywhere 🌲🌳
Ever get confused by how git branching works, and what a proper workflow should look like? Don’t lie, we all have had a tough time learning about this. Luckily, [there is now a fun interactive tool](https://learngitbranching.js.org/) for you to learn without destroying everyone’s day at work by ruining everything with your merge. Finally, here is [a little git cheat sheet](https://gitsheet.wtf/) for you.


### Free Tools For Web Developers ✂️
… wait where is the rest? Well, the full version of the post can be found [here](https://zerotomastery.io/blog/web-developer-monthly-october-2019?utm_source=devto&utm_medium=blogpost&utm_campaign=WDMOCT19/).
[RSpec] shared_context
Tags: rails
Published: 2019-11-07 12:09:07

---
title:  [RSpec] shared_context
tags: rails
published: true
---

## simple code sample

```ruby
subject { word }

shared_context 'hoge' do
  let(:word) { 'hoge' }
end
shared_context 'fuga' do
  let(:word) { 'fuga' }
end

context 'hoge' do
  include_context 'hoge'
  it { is_expected.to eq 'hoge' }
end
```

## merit
Assume that you have like this many contexts, and the `let()` is not short.  
In this way, we can concentlate to see what we test, instead to read a lot of code.

```ruby
shared_context 'people_happy' do
  # looong!
end

context 'dog' do
  let(:animal) {creat(:dog)}
  context 'people_happy' do
    include_context 'people_happy'
    # test
  end
end
context 'cat' do
  let(:animal) {creat(:cat)}
  context 'people_happy' do
    include_context 'people_happy'
    # test
  end
end
context 'horse' do
  let(:animal) {creat(:hourse)}
  context 'people_happy' do
    include_context 'people_happy'
    # test
  end
end
```

---

## 🔗 Parent Note
{% link n350071/my-rspec-note-17ec %}
[RSpec] What does assigns mean in RSpec?
Tags: rails
Published: 2019-11-07 11:59:45

---
title: [RSpec] What does assigns mean in RSpec?
tags: rails
published: true
---

## 🤔 Situation
```ruby
describe 'InviteUserController', type: :controller do
  describe '#edit' do
    before { get :edit, token: user.token }
    it 'should have user_form' do
      # 🦄 Here 🦄
      expect(assigns(:user_form).class.name).to eq 'UserForm'
    end
  end
end
```

## 👍 Meaning
assigns relates to the instance variables created within a controller action (and assigned to the view).

So, You might have such like Controller.
```ruby
class InviteUserController
  def edit
      # 🦄 this @user_form 🦄
    @user_form = UserForm.new(token: user_params[:token]) 
    render :edit
  end
end
```


---

## 🔗 Parent Note
{% link n350071/my-rspec-note-17ec %}
[RSpec] Factorybot transient & trait with argument
Tags: rails
Published: 2019-11-07 11:53:27

---
title: [RSpec] Factorybot transient & trait with argument
tags: rails
published: true
---

## 🤔 Situation
You want to make a user with a book that title is 'Ruby'.

```ruby
class User
  has_many: books
end
class Book
  belongs_to: user
end
```

## 👍 Solution
- trait: you can run the process
- trait with arguments: [It is DEPRECATED](https://github.com/thoughtbot/factory_bot/issues/527#issuecomment-194207669), we should use `transient` instead.
- transient: you can define and pass arguments with the block

```ruby
FactoryBot.define do
  factory :user, class: User do
    trait :with_book
      transient do
        # 🦄1. default value when you use :with_book trait
        # 🦄2. Dont't assign just 'Agile'. see also: https://thoughtbot.com/blog/deprecating-static-attributes-in-factory_bot-4-11
        title { 'Agile' }
      end
      after(:build) do |user, evaluator|
        user.book = FactoryBot.create(:book, title: evaluator.title)
      end
    end
  end
  
  factory :book, class Book do
    sequence(:title) { |n| "book no.#{n}" } # 🦄 default value
  end
  
end
```

```ruby
let!(:user) { create(:user, :with_book, title: 'Ruby') }
```


---

## 🔗 Parent Note
{% link n350071/my-rspec-note-17ec %}
View & Helper Tips Note
Tags: rails
Published: 2019-11-07 11:49:26

---
title: View & Helper Tips Note
tags: rails
published: true
---

## View
### 👍 pass a variable into partial
The file `app/views/shared/_question.html.erb` will be called, and it receives a variable `model`.

```ruby
<%= render partial: 'shared/question', locals: { model: @attender } %>
```

### 👍 pass all variables into parcial or use it.
```ruby
<%= render partial: 'shared/question', locals: local_assigns } %>
```

#### 🦄 Another technique
```ruby
<% unless local_assigns[:hide] %>
  hello
<% end %>
```

## Helper
### Setting to use only the helper with same name controller
`config/application.rb`
```ruby
config.action_controller.include_all_helpers = false
```

### Use helper method
```ruby
module MyHelper
  def some
    # do something
  end
end

class SomeController
  include MyHelper
end
```


## 🔗 Parent Note
{% link n350071/my-rails-note-47cj %}
What’s the weather like where you live?
Tags: watercooler
Published: 2019-11-07 11:46:25

Well the first snowfall has arrived in Montreal.

{%twitter 1192405769368588288 %}

What’s the weather like where you live? Post some pictures! It’s always great to see pictures from different places around the world.

![First snowfall](https://thepracticaldev.s3.amazonaws.com/i/p8jhu6l2msykhk1l79xh.jpeg)

Update 2019-11-12:

Now it’s winter ❄️

{%instagram B4ybkf7pI9O %}
Portal with detailed architectural solutions recipes?
Tags: discuss, angular, javascript, webdev
Published: 2019-11-07 11:25:17

---
title: Portal with detailed architectural solutions recipes?
published: true
description: Some helpers for SA and PM for Angular projects?
tags: discuss, angular, javascript, webdev
cover_image: https://thepracticaldev.s3.amazonaws.com/i/dnot6k4hhb9pq1ucpta6.jpg
---

Hey, ppl!

Do we have some portal with architectural solutions recipes?

###Example (out of thin air):
Q: I need to upload and store files
A: Aws s3 - up to N Mb - free, more - paid
API is described here(some link)
Angular FE part - this article

###Example #2

Q: I need to store customers profiles
A: Login system - aouth0, store info - firestore(?), mongoDB. File upload - AWS S3. Article with explanations: here(link)

**So main goal - share some practical concrete working architectural solution with specified service providers.**

Or it will be too large to keep it in one place?
Maybe some chat/community where one can address such question?Because I'd like to pump hosting/SA/PM/CI-CD skill (hosting files, DB, CI/CD)
Template strings in documentation?
Tags: help, writing, documentation
Published: 2019-11-07 11:13:02

---
title: Template strings in documentation?
published: true
description: Are there any tools that can replace tokens for writing ?
tags: #help #writing #documentation
---


I'm looking into doing more writing and documentation and one of the biggest problems I'm facing is keeping certain pieces of information up to date.

For example, I named `Chapter 2: Usage`, referred to it a few times, and decided that I would like to change the title to `Chapter 2: Tutorial` . 

Are there any existing solutions that would allow me to store these values somewhere as a single source of truth ?
the eval meta programming power. Making .env file and Set Constant values from the file
Tags: rails
Published: 2019-11-07 11:06:37

---
title: the eval meta programming power. Making .env file and Set Constant values from the file
tags: rails
published: true
---

## 🤔 make a .env file, but how can I read and set it?
```
# .env
PASSWORD=12345678
ALBUM_URL=valkj82fakx
```

## 🦄 Set them by eval.
```ruby
# Read the .env file and set constants
File.foreach('.env') do |line|
  key, value =  line.strip.split('=')
  eval "#{key}='#{value}'" # 🦄
end
```

## 🔗 Parent Note
{% link n350071/my-rails-note-47cj %}
path resolves
Tags: rails
Published: 2019-11-07 11:01:04

---
title: path resolves
tags: rails
published: true
---

## 👍 Case: in not Controller
Assume that, you're in `app/service`.

```ruby
class SomeService
  # 🦄 include the url_helpers
  include Rails.application.routes.url_helpers

  user_path
end
```

## 👍 Case: in Rails console

```ruby
app.user_path
#=> "/user"
```

## 👍 Case: check current path & action name

```sh
[1] pry(#<UserController>)> controller_path
=> "user"

[2] pry(#<UserController>)> action_name
=> "index"
```

## 👍 Case: Get an absolute path from the current source file
There are two ways.
```ruby
File.expand_path(relative_path, __FILE__) # from the current source file
File.expand_path(relative_path, __dir__)  # from the current source file
```

## 🔗 Parent Note
{% link n350071/my-rails-note-47cj %}
How to minimize security concerns in your applications
Tags: todayilearned, security
Published: 2019-11-07 11:00:16

*TL;DR style notes from articles I read today.*

### [Securing REST APIs](http://bit.ly/2JV2ugS)

- Ensure that you only accept queries sent over a secure channel, like TLS.
- Use API keys to secure, authenticate and track usage of a REST API.
- Validate parameter-based inputs for queries. 
- Whitelist permitted HTTP methods and block those accessed via a public API.
- Authenticate individual users for specific actions. 
- Log all failed requests and look for patterns to identify sustained attacks. 
- Use a security framework with policies to decide whether the querying party can see the data.

*[Full post here](http://bit.ly/2JV2ugS), 6 mins read* 

---

### [How to minimize security debt from the start](http://bit.ly/2rlg2vP)

- Retrofitting security issues requires that you refactor not only code but also human behavior.
- Take stock and build an inventory of all connected devices and applications within your network, locate where all data reside, and audit access to them.
- Secure data travelling within as well as across networks.
- Take special care to secure DevOps projects as they introduce considerable security risks.
- Establish an access management policy that evolves as your organization grows.
- Encrypt data (in rest and in motion), use multi-factor authentication, ensure redundancy, and segment data and systems.
- Build a good incident recovery plan right from Day 1.  

*[Full post here](http://bit.ly/2rlg2vP), 5 mins read* 

---

### [How to combat cloud software security threats](http://bit.ly/36ISK2Y)

- Deploy strong identity management and access management systems. 
- Understand how security works with third-party apps & integrations in detail. Ensure you know what exactly does granting access for anything to a third-party app means. 
- Ensure that your cloud vendor provides audit logs and check them regularly. 
- Check that your cloud software vendors are compliant with the widely accepted standards & regulations pertaining to your industry. Consider security assessments by third parties as well. 
- Look for how seriously your cloud & cloud software vendors take their bug bounty programs. 

*[Full post here](http://bit.ly/36ISK2Y), 5 mins read* 

---

*[Get these notes directly to your inbox every weekday by signing up for my newsletter, in.snippets(), here.](https://mailchi.mp/appsmith/insnippets?utm_source=devto&utm_medium=post08&utm_campaign=is)*
Return a static error page by Rails standard function
Tags: rails
Published: 2019-11-07 10:48:34

---
title: Return a static error page by Rails standard function
tags: rails
published: true
---

## 👍 Use **config.application.rb**

```ruby
config.action_dispatch.rescue_responses.merge!(
     ‘My::Error’ => :not_found
   )
```

## 📚 Reference
[3.9 Configuring Action Dispatch](https://guides.rubyonrails.org/configuring.html#configuring-action-dispatch)

> config.action_dispatch.rescue_responses configures what exceptions are assigned to an HTTP status. It accepts a hash and you can specify pairs of exception/status. By default, this is defined as:

> Any exceptions that are not configured will be mapped to 500 Internal Server Error.


```ruby
config.action_dispatch.rescue_responses = {
  'ActionController::RoutingError'               => :not_found,
  'AbstractController::ActionNotFound'           => :not_found,
  'ActionController::MethodNotAllowed'           => :method_not_allowed,
  'ActionController::UnknownHttpMethod'          => :method_not_allowed,
  'ActionController::NotImplemented'             => :not_implemented,
  'ActionController::UnknownFormat'              => :not_acceptable,
  'ActionController::InvalidAuthenticityToken'   => :unprocessable_entity,
  'ActionController::InvalidCrossOriginRequest'  => :unprocessable_entity,
  'ActionDispatch::Http::Parameters::ParseError' => :bad_request,
  'ActionController::BadRequest'                 => :bad_request,
  'ActionController::ParameterMissing'           => :bad_request,
  'Rack::QueryParser::ParameterTypeError'        => :bad_request,
  'Rack::QueryParser::InvalidParameterError'     => :bad_request,
  'ActiveRecord::RecordNotFound'                 => :not_found,
  'ActiveRecord::StaleObjectError'               => :conflict,
  'ActiveRecord::RecordInvalid'                  => :unprocessable_entity,
  'ActiveRecord::RecordNotSaved'                 => :unprocessable_entity
}
```


## 🔗 Parent Note
{% link n350071/my-rails-note-47cj %}
Setup CSS modules in POSTCSS
Tags: css, react, javascript
Published: 2019-11-07 10:21:33

So I was trying to include the modular way of styling sass in my project. Just cuz I feel that it's a convenience for me, no leakage of styles. No strong opinions about it. Initially, I was under the impression that the tech stack that the framework that I was using allowed it i.e. ParcelJS.

Bear with me as I don't have much idea and I just put stuff in place. Now ParcelJS use PostCSS. 

More information about [PostCSS](https://postcss.org/)

Upon researching a bit more I realized that there is a command that I can call from the `npm start` script. 

`"start": parcel --no-hmr src/index.html`

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/piv4qc01dosc7ae8gfss.jpeg)

Which makes no sense to me. 

So hmr is Hot module Reloading huh... Looking at this image it seems like the next process to where I am at. As it is, the documentation (https://parceljs.org/hmr.html) states that when you build the app and use it in production, there is no hmr(Hot Module Reload), but it's just for the convenience of the engineer that it's there.

![Alt Text](https://media.giphy.com/media/QJKu9V1DTvGI0TWdEa/giphy.gif)


So I went up the page and saw that I need to make a file named `postcss.config.js` and set

```
{
  "modules": true
}

```
Did that, didn't work. * Sigh *

Check this out for more [info](https://parceljs.org/transforms.html#postcss)

I can only assume that Parcel people(what I refer to the maintainers), want to keep as much payload away from the dist as possible. So they don't wanna include an out of box solution. Maybe, just an assumption.

But anyway, how it did work was that I had to make a `.postcssrc` file at the root folder and add the above content to it.

Don't forget to restart the server though. I got stuck at this step for a minute.

It works! 

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/i897cnytlj21efqvklv4.jpeg)

The extra characters are just hashes, I'd assume.

Hopefully, this was helpful and helps those in need of setting up modular design pattern in ParcelJS.

By the way, check out my [org](https://github.com/WrippleFoss/mentorFix) where you can help make some open-source awesomeness and help other devs in the process too.

Also, do check out [Fave](https://careers.myfave.com/), we are hiring.
Ruby array multiple assignment
Tags: rails
Published: 2019-11-07 10:42:14

---
title: Ruby array multiple assignment
tags: rails
published: true
---

## Assignment to variables

```ruby
a, b = [:hello, :world]
puts a #=> :hello
puts b #=> :world
```

## Assignment as arguments ( 2 Ways )
```ruby
def show_two_arguments(a,b:)
  puts a
  puts b
end

show_two_arguments(:hello, b: :world)
#=> :hello
#=> :world

show_two_arguments(*[:hello, b: :world])
#=> :hello
#=> :world
```


## 🔗 Parent Note
{% link n350071/my-rails-note-47cj %}
mattr_accessor and meta programming. Thanks you, devise_invitable 👍
Tags: rails
Published: 2019-11-07 10:31:18

---
title: mattr_accessor and meta programming. Thanks you, devise_invitable 👍
tags: rails
published: true
---

## It was a impressed for me.
I have a code that inherits Devise::InvitationController, and the controller seems to inherits ApplicationController too.
It was magic. I wanted to understand why. so I read the code. 

## Then, open them.
```sh
$ bundle open devise_invitable
$ bundle open devise
```

app/controllers/devise/invitations_controller.rb
```ruby
class Devise::InvitationsController < DeviseController
```

app/controllers/devise_controller.rb
```ruby
class DeviseController < Devise.parent_controller.constantize
```

lib/devise.rb
```ruby
# The parent controller all Devise controllers inherits from.
# Defaults to ApplicationController. This should be set early
# in the initialization process and should be set to a string.
mattr_accessor :parent_controller
@@parent_controller = "ApplicationController"
```

## What happen?
The `mattr_accessor` is similar with `attr_accessor`. It automatically makes a get/set method for the module.

Then, `Devise.parent_controller` become  "ApplicationController". Of course, you can customize it.

The reference of [mattr_accessor](https://apidock.com/rails/Module/mattr_accessor).

This programming gives you power.

## 🔗 Parent Note
{% link n350071/my-rails-note-47cj %}
Managing CORS in Express – Allow Cross Origin Requests
Tags: expressjs, managingcors, allowcrossorigin
Published: 2020-02-07 09:27:41

---
title: Managing CORS in Express – Allow Cross Origin Requests
published: true
date: 2019-11-07 10:16:40 UTC
tags: Express JS, Managing CORS, Allow Cross Origin 
canonical_url: https://www.positronx.io/express-cors-tutorial/
---

The post [Managing CORS in Express – Allow Cross Origin Requests](https://www.positronx.io/express-cors-tutorial/) appeared first on [positronX.io](https://www.positronx.io).

**Learn to enable CORS in Express or Node server for enabling cross-site requests. CORS refers to cross-origin request sharing. In this tutorial, we will look at how to manage CORS in Express.js. Along with that, we will check out the custom header types and how to set HTTP cookies.**

A web or mobile application can access HTTP resources from the same origin it is being served. To access the resources (images, stylesheets, scripts, iframes, and videos.) from the other domains or origin, this mechanism is known as CORS.

[click here to read more](https://www.positronx.io/express-cors-tutorial/)
bnnum - npm package
Tags: numbertobangla, numbertranslate, npm
Published: 2019-11-07 09:52:49

---
title: bnnum - npm package
published: true
description: Number conversion npm package from English to Bengali
tags: number-to-bangla,number-translate,npm
cover_image: https://thepracticaldev.s3.amazonaws.com/i/w9ji4e3nrzhu60u8asv9.png
---


## Translate number to `Bengali`

**Installation**

```js
npm install bnnum

// or

yarn add bnnum
```

**Example**

```js
import bnNum from 'bnnum'

console.log(bnNum(4587))
// => ৪৫৮৭

console.log(bnNum(4587, true))
// => ৪,৫৮৭
```

**Parameters**

| Name  | Data Type | Description                                   |
| ----- | --------- | --------------------------------------------- |
| num   | `int`     | Number to convert in Bengali                  |
| komma | `boolean` | (**Default:**`false`) Komma notation on number |


**Returns**

```
@return {string} Translated bangla number
```

### Known Issue

This package will not works in backend

{% github kingRayhan/bnnum %}

http://bit.ly/create-ghost-theme
Introducing the FormData Viewer Extension
Tags: javascript, extension, formdata, chrome
Published: 2019-11-07 09:52:43

FormData is an amazing API to handle forms.

It allows a simple peeking into the forms as well by generating `formData` for already existing forms.

We had talked about using FormData API to handle forms in this post: [FormData API: Handle Forms like Boss 😎](https://time2hack.com/2018/06/formdata-api-handle-forms-like-a-boss/)

Later than that, we saw some nifty examples of file upload to Firebase and PHP Backend with the help of FormData API.

Here I am introducing the FormData Viewer Extension; an extension for Chromium-based browsers like Google Chrome, [Brave](https://brave.com/tim448), Opera, IE Edge built with Chromium, etc.

---

[![](https://res.cloudinary.com/time2hack/image/upload/c_scale,h_100,f_auto/v1571226788/web-store-button.png)](https://chrome.google.com/webstore/detail/mnjfjpoendmmboclknfcllimnneeiflg/)

---

## Features

With this extension you can inspect the following:

- Filled or UnFilled form and it's fields
- Find all the forms in the page named or unnamed
- No need to submit the form and inspect the Networks Panel in DevTools

![](https://res.cloudinary.com/time2hack/image/upload/q_auto:good,f_auto/chrome-formdata-viewer-extension.png)

---

## Possibilities

Future possibilities with the extension can be the following:

- Access to this info form DevTools Panels or Omnibox
- Information about the Form submit URL
- and many more ...

---

The extension is opensource itself and can be found at [https://github.com/pankajpatel/FormData-viewer-extension](https://github.com/pankajpatel/FormData-viewer-extension)

---

## Conclusion

If you find this extension helping in your development workflow, please share it with others. You can also support us by checking out our Support page.

Let me know what do you think about this article through comments 💬 or on Twitter at @patel_pankaj_ and @time2hack

If you find this article helpful, please share it with others 🗣; subscribe for the new posts and see you the next time.


---


### Footnotes

This article was originally published on [Time to Hack](https://time2hack.com/) at [Introducing the FormData Viewer Extension](https://time2hack.com/2019/10/introducing-formdata-viewer-extension-html-forms/)
#codevember — 4 — Big 🏙️🎥
Tags: codepen
Published: 2019-11-07 09:39:45

---
title: #codevember — 4 — Big 🏙️🎥 
published: true
tags: codepen
---


codevember 2019 day 4
Big buildings with dolly zoom

{% codepen https://codepen.io/trinketmage/pen/jOOZZge %}