teleren/devto huggingface dataset:
RSpec let! and before order dependent behavior
Tags: rails, testing, tips
Published: 2019-10-12 11:12:10

RSpec provides `let` and`let!` helpers to create data required by the specs.

We can use them as follows:

```ruby
RSpec.describe Activity, type: :model do
  let!(:user) { FactoryBot.create(:user) }
  let(:account)  { FactoryBot.create(:account) }
end
```

`let` is a memoized method which gets called only when it is referenced in the specs. As it is memoized, if it is called twice, it is not executed again. `let!` is called before every spec. It is not memoized like `let`. 

So in our example above, user is created before every spec, whereas account is created only once and is memoized.


Rspec also has a `before` hook which we can be used to execute some code before all the specs are run in a specific block.

```ruby
RSpec.describe Activity, type: :model do
  let!(:user) { FactoryBot.create(:user) }
  let(:account) { FactoryBot.create(:account) }
  before do
    travel_to Time.new(2019, 10, 27, 10, 00, 00)
  end
end
```

We want to set the current time to a specific time for all specs so we added it in the `before` block.

In my spec, I was setting such custom time in the `before` block and I was expecting user's `created_at` time to be set to that custom time. The user was created using `let!` just like in the example above. But the user was always getting set with current time as `created_at` instead of custom time set in the `before` block.

To figure out why this was happening, I decided to see how `let!` is implemented. Turns out `let!` is implemented as `before` hook under the hood. So I have two before hooks.

```ruby
  before do
    user = FactoryBot.create(:user)                                              
  end
  let(:account) { FactoryBot.create(:account) }
  before do
    travel_to Time.new(2019, 10, 27, 10, 00, 00)
  end
```

These two before hooks get executed serially, so first the user gets created then the time is changed to the custom time.

So the lesson is that, if we want to execute some code in the before block which  is going to impact even the creation of the data created in the specs, have it as your first before hook in the spec.

```ruby
RSpec.describe Activity, type: :model do
  before do
    travel_to Time.new(2019, 10, 27, 10, 00, 00)
  end
  let!(:user) { FactoryBot.create(:user) }                                            
  let(:account) { FactoryBot.create(:account) }                                         
end
```

The tip of the day is that **prefer having the `before` block as first block of the spec**, even before defining `let` and `let!`.

Happy testing.
Installing Docker and Docker Compose on the Raspberry Pi in 5 Simple Steps
Tags: docker, raspberrypi, devops, diy
Published: 2019-10-12 11:00:39

---
title: Installing Docker and Docker Compose on the Raspberry Pi in 5 Simple Steps  
published: true
description: Installing Docker on the Raspberry Pi sometimes can get messy, let me help you with that!
cover_image: https://thepracticaldev.s3.amazonaws.com/i/gwmu3yy2n6bcyvbt0sep.png
tags: docker, raspberrypi, devops, diy
---


You know what [Docker]( https://www.docker.com/ ) is. You know what a [Raspberry Pi]( https://www.raspberrypi.org/ ) is. Let me make sure they hit it off together.  😎🤝🏽

This is probably one of the quickest and easiest ways to get Docker and Docker Compose running on the Raspberry Pi. 
(Tested with [Raspberry Pi B+ Rev 1.2]( https://www.raspberrypi.org/products/raspberry-pi-3-model-b/ ) and  [Raspberry Pi 4]( https://www.raspberrypi.org/products/raspberry-pi-4-model-b/))

After searching the Inter-Webs for hours and having several things not work for me, I decided something needed to be done about it. 

# Steps

### 1. Install Docker
`curl -sSL https://get.docker.com | sh` 

### 2. Add permission to Pi User to run Docker Commands
`sudo usermod -aG docker pi` 

_Reboot here or run the next commands with a *sudo*_

### 3. Test Docker installation
`docker run hello-world` 

### 4. IMPORTANT! Install proper dependencies
`sudo apt-get install -y libffi-dev libssl-dev` 

`sudo apt-get install -y python3 python3-pip` 

`sudo apt-get remove python-configparser`

###  5. Install Docker Compose
`sudo pip3 -v install docker-compose` 

## Boom!  🔥 It's done!

>Important Notice about Docker on the Raspberry Pi

> Raspberry Pis use the ARM architecture, and as a result, won't be compatible with all containers out of the box. Images will need to be built from an ARM base image. But, most of these images can easily be found on [Docker Hub]( https://hub.docker.com/ )
HacktoberFest - An introduction and Tip for getting started! [Video]
Tags: hacktoberfest, opensource, github, tutorial
Published: 2019-10-12 10:52:50

That time of the year is upon us again...

## HacktoberFest 2019!


![Celebrate](https://media.giphy.com/media/LSNqpYqGRqwrS/giphy.gif)

The brilliant time of year where people scramble back to their github acounts in order to achieve the most prized and sought-after awards... The fabled "Limited Edition T-Shirt" (and of-course any stickers that come bundled with it, yay stickers)...

Anyway I made a video (below) to explain to any of those people that are looking in from the outside and wondering what all the fuss is about. In this video I explain (hopefully) what HacktoberFest is, how to get involved and signed up and then cover a quick power tip for getting involved and contribute to your first open source project...

Enjoy...

{% youtube KpN2wPIecho %}

My Twitter: [Ben_Kadel Twitter](https://twitter.com/ben_kadel)
Incase you want to reach out or have any questions...

Thanks for watching!
Good luck with your hacking and let me know in the comments down below any other brilliant tips you would give to people that are trying to get involved with open source...
How to Remove Unused CSS
Tags: css, javascript, webdev
Published: 2019-10-12 10:08:42

_Reduce your CSS files more than 60% during your development workflow with Purgecss._

I have been searching for a while a tool that will allow me to clean my CSS from unused style.

Why was I looking for this kind of tool? Because nowadays almost every developer uses a lot of CSS frameworks and libraries to develop interfaces faster and easier so it is inevitable that the size of css files increase a lot.

But how much of the CSS style that you import from external libraries you really use? Sometimes even less than 20%, so why do you need to have all this unused style? No reason!

**Purgecss**
Here Purgecss comes to help, it is a tool which helps to remove unused CSS and it can be used as part of your development workflow.

How Purgecss is working under the scene? It needs to know:
1 - the file css that you want to clean.
2 - the files where it need to inspect
3 - the destination path of the new file generated

So from the initial css file[1] it will search in your html files(for example)[2] and from there it will create a new css file[3] only with the style that you really used.

I’m sure that if you try it you will be able to reduce **more than 60%** the size of your CSS.

**The build tools**
The cool thing of Purgecss is that you can implement it in your development workflow with a lot of popular build tools:
• CLI
• JavaScript API
• Webpack
• Gulp
• Rollup

**The JS frameworks**
We can use it also with the most modern JavaScript frameworks such as:
• React
• Vue
• Next
• Nuxt

**How to use Purgecss**
I wrote a whole article about **how to set up a CSS build process with Gulp**, there I used also Purgecss so if you are interested in this build process I suggest you to read [this article](https://medium.com/notonlycss/setting-up-a-css-build-process-with-gulp-f4fca4b90148).

Here on Medium (https://medium.com/notonlycss/how-to-remove-unused-css-ad67421794a7), I will show you how to implement Purgecss with **Gulp** and **Nuxt.js**.
Build Secure (JWT) Token Based Authentication API with Node
Tags: expressjs, node, tokenbasedauthenticationapi
Published: 2020-02-07 09:15:22

---
title: Build Secure (JWT) Token Based Authentication API with Node
published: true
date: 2019-10-12 08:13:26 UTC
tags: Express JS,Node JS, Token Based Authentication API 
canonical_url: https://www.positronx.io/build-secure-jwt-token-based-authentication-api-with-node/
---

The post [Build Secure (JWT) Token Based Authentication API with Node](https://www.positronx.io/build-secure-jwt-token-based-authentication-api-with-node/) appeared first on [positronX.io](https://www.positronx.io).

**Welcome, programming, buddies! Today, In this tutorial, we are going to learn how to build a secure token-based user authentication REST APIs using JWT (JSON web token), bcrypt, Node, Express, and MongoDB.**

Creating authentication REST API with Node Js is merely effortless. We will be taking the help of Express js to create the authentication endpoints and also make the MongoDB connection to store the user’s data in it.

[click here to read more](https://www.positronx.io/build-secure-jwt-token-based-authentication-api-with-node/)
Tips for a successful hacktoberfest
Tags: hacktoberfest, opensource, github, beginners
Published: 2019-10-12 08:00:23

So you've signed up for [Hacktoberfest 2019](https://hacktoberfest.digitalocean.com/) but have no clue how to get up to four Pull Requests as a beginner? Some tips to help you get started:

- Finding a suitable repository: you can use the tags that Hacktoberfest provides, but you really can search for any topic *you* are familiar with using git search. Be sure to use the Languages filter as well, to narrow down the search to a suitable repository.

*Pro tip: If you're a non native English speaker, you can offer translations, or correct spelling mistakes in the language you're proficient with.*

- Be sure to read the code of conduct and especially the *Contributions.md* if available. This will save the owner/maintainer a lot of headaches on managing and validation your work. It will increase the odds of your PR to actually get merged into production code!

- Make sure you are actually creating value. Hacktoberfest is about celebrating Open Source. If possible, create an issue first and communicate with a maintainer/owner what to pick up. Also, if you've found an issue you want to work on, make sure someone else is not already working on it.

- The flow of working with _clones_, _forks_, _merge requests_, _upstream merging_ can be daunting. 🤷‍♂️ If you have little experience in this, start out with a small change on a repository. Don't focus your efforts on the codechange but rather on familiarising yourself with the flow. The github help section is a good resource, but feel free to ask for help!

- Publishing code can be scary, especially when you're just starting out. Don't worry about it! (After all, October is all about the scary stuff, isn't it? 🎃🦇) Getting exposure is a good practice, since code reviews will be part of a teams development process.

Lastly: have fun! Experiment with Open source contributions. Make changes to the extend you're comfortable with. You might end up loving the open source community! ✌️
Generate dummy data with Postgres
Tags: postgres, database, sql, data
Published: 2019-10-12 07:21:21

### Generate 5 records

```
# SELECT generate_series(1, 5);

 generate_series 
-----------------
               1
               2
               3
               4
               5
(5 rows)
```

### Generate in increments of 5

Start with 1, and generates a series by adding 5 to the previous number.

```
# SELECT * FROM generate_series(1,25,5)

 generate_series 
-----------------
               1
               6
              11
              16
              21
(5 rows)
```

### Generate a series with date

> RedShift, as of OCT-2019 is based on Postgres 8.0. Passing timestamps as intervals is not supported with Redshift. So datetime ranges will not work on Redshift.

```
SELECT generate_series(
  '2019-10-1',
  '2019-10-05',
  '1 day'::interval
);

      generate_series      
---------------------------
 2019-10-01 00:00:00+05:30
 2019-10-02 00:00:00+05:30
 2019-10-03 00:00:00+05:30
 2019-10-04 00:00:00+05:30
 2019-10-05 00:00:00+05:30
(5 rows)
```

The third argument for step interval has to be passed, without which Postgres would not know how much to increment the step for date ranges. We got a list of timestamps. Let us coerce that into a date type instead.

```
SELECT generate_series(
  '2019-10-1',
  '2019-10-05',
  '1 day'::interval
)::date;

 generate_series 
-----------------
 2019-10-01
 2019-10-02
 2019-10-03
 2019-10-04
 2019-10-05
(5 rows)
```

We could also do weekly intervals instead of days.

```
SELECT generate_series(
  '2019-12-1',
  '2019-12-31',
  '1 week'::interval
);

      generate_series      
---------------------------
 2019-12-01 00:00:00+05:30
 2019-12-08 00:00:00+05:30
 2019-12-15 00:00:00+05:30
 2019-12-22 00:00:00+05:30
 2019-12-29 00:00:00+05:30
(5 rows)
```

Try playing with other intervals - 5 weeks, 10 days, 3 months, etc.

### Want more columns?

```
# SELECT generate_series(1, 5), 'hello', '123';

 generate_series | ?column? | ?column? 
-----------------+----------+----------
               1 | hello    | 123
               2 | hello    | 123
               3 | hello    | 123
               4 | hello    | 123
               5 | hello    | 123
(5 rows)
```

### Do more?

```
SELECT
  number,
  concat('hello', number)
FROM
  generate_series(1, 5) AS number


 number | concat 
--------+--------
      1 | hello1
      2 | hello2
      3 | hello3
      4 | hello4
      5 | hello5
(5 rows)
```
How many of these CS books do you read?
Tags: tutorial, computerscience, discuss, books
Published: 2019-10-12 07:16:43

This seems to be a very good CS book list. :+1:
But I found some of them is hard to understand,
I'm a backend engineer with 6 years experiences. :sweat_smile:
Do you think normal programmers need to learn knowledges about compiler?

https://coderscat.com/best-cs-books
ASP.NET MVC 5 Install Bootstrap
Tags: csharp
Published: 2019-10-12 07:11:34

Continue with the previous share, Today I will shared way install Bootstrap in ASP.NET MVC5, I using Visual Studio 2019
You can see again, The article previous
+ [Create Layout Razor & ViewStart](https://dev.to/skipperhoa/asp-net-mvc-5-create-shared-layout-razor-viewstart-4h3)
+ [ASP.NET MVC 5 Helllo World](https://dev.to/skipperhoa/asp-net-mvc-5-helllo-world-1o55)

**Setup Bootstrap 3.3.1 trong ASP.NET MVC 5**
Click right Project -> Manager NuGet Packages -> you click icon setting configuration, add package source
**https://api.nuget.org/v3/index.json**
![ASP.NET MVC 5 Install Bootstrap -  hoanguyenit.com](https://thepracticaldev.s3.amazonaws.com/i/cv0oizw8jtujwgbl7reo.jpg)
Continue! add package source
![ASP.NET MVC 5 Install Bootstrap -  hoanguyenit.com](https://thepracticaldev.s3.amazonaws.com/i/7i1en5w4zea1ubv2b4x5.jpg)
You search keyword "bootstrap" after then install
![ASP.NET MVC 5 Install Bootstrap -  hoanguyenit.com](https://thepracticaldev.s3.amazonaws.com/i/rzy8hqrx8yey8lbim9xs.jpg)
After when you install bootstrap success! you can see bootstrap in project
![ASP.NET MVC 5 Install Bootstrap -  hoanguyenit.com](https://thepracticaldev.s3.amazonaws.com/i/y0fg2ol9zo97zzzawdhs.jpg)

Okay, install success! you can use bootstrap in Layout file of Views/Shared/_LayoutHome.cshtml directory, note you add css,javascript to file
```
<link rel="stylesheet" href="~/Content/bootstrap.min.css" />
<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
```
Example:**Views/Shared/_LayoutHome.cshtml**
```
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    <link rel="stylesheet" href="~/Content/bootstrap.min.css" />
    <script src="~/Scripts/jquery-3.3.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
</head>
<body>
    <div>
        @RenderBody()
    </div>
</body>

</html>
```
**Views/Home/Index.cshtml**
```
<div class="container">
    <div class="row">

        <div class="col-md-12">
            <h2>@ViewBag.title</h2>
            <a href="https://hoanguyenit.com" class="btn btn-success">https://hoanguyenit.com</a>
        </div>
    </div>
</div>
```
Ok, we install bootstrap in ASP.NET MVC 5 success!!

Post:[ASP.NET MVC 5 Install Bootstrap](https://hoanguyenit.com/aspnet-mvc5-install-bootstrap.html)
What is Request Payload / Payload Body 2019
Published: 2019-10-12 04:10:59

When data is sent over the Internet, each unit transmitted includes both
header information and the actual data being sent. The header identifies the source and destination of the packet, while the actual data is referred to as the payload.

For deep detail refer to : https://aarvy.me/blog/2019/10/12/what-is-request-payload/
📣 New Gem! rspec-dry-types
Tags: rspec, ruby, tdd, dryrb
Published: 2019-10-12 03:51:34

---
title: "📣 New Gem! rspec-dry-types"
published: true
description: "Speed up test-driven development with looser or stronger type-checking in your RSpec tests"
cover_image: https://aws1.discourse-cdn.com/standard11/uploads/dry_rb/original/1X/76310a85ab1709296c3b85bcc7897b6eef1d4727.png
tags:
  - rspec
  - ruby
  - tdd
  - dryrb
---

> Speed up test-driven development with looser or stronger type-checking in your RSpec tests

The [rspec-dry-types](https://github.com/patrickclery/rspec-dry-types) gem is a drop-in replacement for RSpec's `be_a_kind_of()` that allows you to TIGHTEN or LOOSEN what object types you expect returned.

Powered by the [dry-types gem](https://dry-rb.org/gems/dry-types/1.2/built-in-types/), you can find a list of all the reference keys for supported types [dry-types documentation for "Built-in Types"](https://dry-rb.org/gems/dry-types/1.2/built-in-types/).

## USAGE:

```ruby
require 'dry-types'
require 'rspec/expectations'
require 'rspec/matchers/be_of_type'

RSpec.describe "check types using be_of_type" do
  include RSpec::Matchers::DryTypes

  it 'can use a symbol to expect a dry-type' do
    expect('a string').to be_of_type(:string)
    expect(123).to be_of_type(:integer)
    expect(0.123).to be_of_type(:float)
    expect("123").to be_of_type(:integer, strict: false)
    expect(nil).to be_of_type(:string, strict: false)
    expect(nil).to be_of_type(:nil)
  end

  # Strings must reference the dry-types docs
  it 'can use string to expect a dry-type' do
    expect('a string').to be_of_type('string')
    expect('a string').to be_of_type('strict.string')
    expect(123).to be_of_type('integer')
    expect(123).to be_of_type('strict.integer')
    expect(0.123).to be_of_type('float')
    expect(0.123).to be_of_type('coercible.integer')
    expect("123").to be_of_type('integer', strict: false)
    expect(nil).to be_of_type('string', strict: false)
    expect(nil).to be_of_type('nil')
  end

  # Strings must reference the dry-types docs
  it 'is backwards compat with be_a' do
    expect('a string').to be_a(String)
    expect('a string').to be_a_kind_of('strict.string')
    expect(123).to be_an(Integer)
    expect(123).to be_an('integer')
  end

  it 'can use a class to check if its a type' do
    # Check inheritance
    expect(String).to be_of_type(Object)
    expect('a string').to be_of_type(Object)
    expect(123).to be_of_type(Object)

    # Check coercion
    expect(123).to be_of_type(String, strict: false)
    expect(0.123).not_to be_of_type(Integer)
    expect(0.123).to be_of_type(Integer, strict: false)
  end

end
```
OVERCOMING OBSTACLES
Published: 2019-10-12 03:39:31


	I have come a long way from where I used to be. I used to let every small thing get to me and ruin my whole day and then that day turned into 2 and then a whole week would go by and  I would have nothing accomplished, and I seemed to somehow make things worse. Everyone has their own struggle but most people have a hard time to survive or thrive when they face a challenge. Running away from a challenge or an obstacle is the worst thing anyone could do. No matter how much we want to run away from problems or challenges in our lives, we have no choice but to face our problems in the face and fight our demons.
	I am new to the Tech world and so far everyday there a new challenge. I never thought I would be sitting here self learning a new career. So when I start getting frustrated when I can figure something out here are a few things I have tried to get me to the next step.

1. Changing my attitude or perception of the problem.

2. You have to remind yourself that you are NEW… Don’t turn a molehill
 into a mountain
3. Stay positive and don’t beat yourself up

4.Stop comparing your work with someone else. WE ARE ALL INDIVIDUALS!!

 So just remember take it one day at a time and when you are struggling use you resources, and don’t be afraid to ask for help.
Mobile Performance Testing using JMeter
Tags: android, mobile, jmeter, testing
Published: 2019-10-12 02:51:43

In this article we are going to do performance testing on Android mobile device using JMeter. Here are the steps to do this.

Step 1: Ensure that Mobile and Laptop (desktop) should be connected to the same wifi network. Make Developer Options enabled on your Mobile phone and you are able to connect to your laptop using Android Debug Bridge(ADB).
Have a look at this article and follow steps, in-case your mobile is not connected through ADB: https://www.guru99.com/adb-connect.html

At command prompt type adb devices command, this will list the connected device.
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/up5tvacff3dkriwptj9v.png)


Step 2: Goto JMeter on your desktop/ laptop and Add Template - RECORDING, from File option to get a test plan with HTTP(S) Test Script Recorder.

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

Set Port for Recording, we will configure the same port on our mobile.

Step 3: Click Start for recording, it will generate a certificate "ApacheJMeterTemporaryRootCA.crt" inside "JMeter/bin" folder. Copy the certificate and put it inside any folder of your phone.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/1gpem0bmdv7b33y6swd8.png)

Step 4: Install Root CA Certificate on the Mobile device.

Goto Your Wi-Fi -> More -> Install Network Certificates. Choose from the folder your have saved in Step 3.

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

Step 5: Configure mobile phone, set IP and PORT. Note down the IP of the Laptop/ Desktop system.
Goto Wi-Fi in your phone -> long press on the Wi-Fi you are connected -> Manage Network Settings enter below things.
IP Settings: DHCP
Proxy Hostname: IP Address of your Laptop/ Desktop
Proxy port: the port you have entered on JMeter for recording. See Step 2.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/2mu3a65c9g019ttrnx6d.png)

Step 6: Start Recording, actions you do on your mobile device should get recorded in JMeter.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/8pxt2yfur2t2dmqg39gz.png)

Step 7: Run & Validate the results.

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

Thanks for reading.