teleren/devto huggingface dataset:
Setup Rabbitmq With Users for Docker Compose
Tags: rabbitmq, docker
Published: 2022-01-15 10:38:47

---
title: "Setup Rabbitmq With Users for Docker Compose"
published: true
description: 
tags: 
    - RabbitMQ
    - Docker
---

This guide is written for **RabbitMQ 3.9**!

# Configuring the RabbitMQ Server

For the configuration of the RabbitMQ server we will use a `rabbitmq.conf` and a `definitions.json`. I stored these files in a `rabbitmq` folder to keep my project folder structure clean. This setup is derived from  [**sudo**s answer on StackOverflow](https://stackoverflow.com/a/42251266/1224467)

The `rabbitmq.conf` deactivates the default *guest* user and tells RabbitMQ to load the definition file.

```
loopback_users.guest = false
management.load_definitions = /etc/rabbitmq/definitions.json
```

In the definition file we can define our users, vhosts and permissions.

```json
{
 "rabbit_version": "3.9",
 "users": [
  {
   "name": "local_jobs",
   "password_hash": ">>>HASH<<<",
   "hashing_algorithm": "rabbit_password_hashing_sha256",
   "tags": ""
  },
  {
   "name": "adminuser",
   "password_hash": ">>>HASH<<<",
   "hashing_algorithm": "rabbit_password_hashing_sha256",
   "tags": "administrator"
  }
 ],
 "vhosts": [
  {
   "name": "\/"
  },
 ],
 "permissions": [
  {
   "user": "local_jobs",
   "vhost": "\/",
   "configure": ".*",
   "write": ".*",
   "read": ".*"
  }
 ],
 "parameters": [],
 "policies": [],
 "queues": [],
 "exchanges": [],
 "bindings": []
}
```

To add the configurations to the RabbitMQ server they are added via the volumes options in the `docker-compose.yml`

```yaml
  rabbitmq:
    hostname: rabbitmq
    image: rabbitmq:3.9-management
    command: rabbitmq-server
    ports:
      - "5672:5672"
      - "15672:15672"
    volumes:
      - ./rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
      - ./rabbitmq/definitions.json:/etc/rabbitmq/definitions.json:ro
```

# Generating Password Hashs

In order to generate the password hashs I used the python script by [**Todd Lyons** on StackOverflow](https://stackoverflow.com/a/53016240/1224467)

```python
#!/usr/bin/env python3

# rabbitMQ password hashing algo as laid out in:
# http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2011-May/012765.html

from __future__ import print_function
import base64
import os
import hashlib
import struct
import sys

# This is the password we wish to encode
password = sys.argv[1]

# 1.Generate a random 32 bit salt:
# This will generate 32 bits of random data:
salt = os.urandom(4)

# 2.Concatenate that with the UTF-8 representation of the plaintext password
tmp0 = salt + password.encode('utf-8')

# 3. Take the SHA256 hash and get the bytes back
tmp1 = hashlib.sha256(tmp0).digest()

# 4. Concatenate the salt again:
salted_hash = salt + tmp1

# 5. convert to base64 encoding:
pass_hash = base64.b64encode(salted_hash)

print(pass_hash.decode("utf-8"))
```
Try Andy's Desk
Tags: webdev, javascript, programming, desktop
Published: 2022-01-15 10:35:29

LINK: https://desk.glitchy.website/

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

This is a nostalgic (and not very faithful) recreation of the Windows 7 desktop UI.

The code is intentionally not too polished, as this is a project I work on for fun.

Things might be buggy but that's part of the fun.

You WILL find weird hacks and work-arounds and lots of inefficient stuff.

One of my main goals with this project was to build it as fast as possible. I managed this by integrating as many existing projects/code as I could find. Of course, everything is credited if you open `CREDITS.txt`. You can also take a look at the source code for more information!

You can find the repo here: https://github.com/KaeruCT/desk.glitchy.website
How to get YouTube video transcripts with Python
Tags: python, html, selenium, tutorial
Published: 2022-01-15 10:13:45

## Why not just watch the video?

One night, when I was deciding what to create for my final year project, I decided to go to YouTube and watch a video. It was a long video, and after I'd finished watching it, I couldn't even remember the beginning of it. Ever felt the same? I looked at the transcript menu YouTube provides and it was so clunky to navigate through it as it assigns timestamps to each line.

Here is where my solution comes in. I wanted a way to get the transcript of a video without having to be on YouTube. This way I could make notes easier and I wouldn't have to keep going back to the video and skipping around to find what I'm looking for.

## Creating the solution

I'd heard of Selenium and headless browsers in the past but didn't really know what they were. I had a play around with Selenium using Python and I was surprised at how simple it was to get it doing simple things on the internet, such as clicking buttons.

Within an hour, I could accept cookies and open the transcript menu on YouTube. This had me pondering whether I could solve captcha's, maybe with some Machine Learning to work out what's it asking to do? Nevermind. I guess that's for another day.

Once I had the transcript menu open, I extracted the information from the page. From my time at university, I'd used BeautifulSoup4 before. It's a Python library that can scrape the web and parse HTML. I used it in this context to extract the transcript from the page. After getting the transcript, I saved it to a text file.

As I'm writing this, I've just had the idea of using the NotionAPI to save it to Notion. I'll probably do that after finishing this write up actually, seems like a good idea.

## Using the script

I put the script up on GitHub as a gist. It's available here: [https://gist.github.com/baranbbr/7bbefe30cf7783fd392043d3e7e98fc5](https://gist.github.com/baranbbr/7bbefe30cf7783fd392043d3e7e98fc5).

To get it running yourself, you'll need to install the following packages:

- Selenium
- Selenium driver (of your choice, I used Firefox; if you use something different, you'll need to specify it in the code)
- BeautifulSoup4

Then, of course, you'll need to edit the script to point to the YouTube video of your choice.

> Important side note, this only works with YouTube videos that have a transcript.

I'm trying to get a software developer job.
If you're also looking for your first role, join me.

## Conclusions

This is a very crude way of doing things and I realise that. There's a lot of scope for improvement. Considering it took me a couple of hours to get working, I think it's a decent starting point, and ultimately, it works for now. I have a feeling that it'll stop working as soon as YouTube changes the UI even a little bit, but I guess we'll see with time.
Gelato Network is hiring! Technical content lead, Web3 research analyst, back-end and front-end engineer!
Tags: blockchain, automation, tooling, hiring
Published: 2022-01-15 09:54:57

[Gelato Network](https://gelato.network/fdap) is a protocol that automates smart contract executions on Ethereum. We develop an open-source decentralized network of relay nodes that developers can plug into to create amazing automated dapps for their users. 

Join our growing team and work directly with the founders to build the future of Automation on Ethereum. Enjoy a lot of perks, travel with us to cool events, and participate in amazing off-site retreats with the team!

## Technical Content Lead (Remote)
 

## What we offer:

- A fully remote team with team members in Zug, Paris, New York, Berlin, and many other cool places
- Join the "Gelato Legendary Member Club" and work directly with the founders
- Participate in building the infrastructure that aims to become the glue between all crypto networks and power the most promising dapps on Ethereum and beyond
- Generous Token Package - Get a share of the network's token and be able to participate in the Gelato DAO
- Chance to participate in shaping the future of web3 by working together with the biggest projects in this space, such as MakerDAO, Connext, Quickswap, etc.
- Worldclass Investors - We are backed by top class VCs and Angels including Dragonfly, Galaxy Digital, ParaFi, Gnosis, Stani Kulechov and many more!

## What you will accomplish:

- You will define and execute the content strategy to communicate the benefits of our product offering to the existing and prospective developers across multiple channels, including blog, YouTube, Twitter, Newsletter, Discord, and other editorial and social media channels
- You will engage directly with developers in our community and other Web3 developer communities to acknowledge their needs and create educational content such as tutorials and guides to help them succeed
- You will be the one that amplifies our voices in the Web3 developer communities
- You will work with data to measure the impact and effectiveness of all the content

## Our ideal candidate has:

- Track record of creating engaging content for the developer audience — you define yourself as a technical content creator
- Working knowledge of programming languages such as Solidity
- Excellent written and presentation-based communication skills (native or fluent English speaker) 
- Strong curiosity or understanding of the blockchain landscape (Ethereum, DeFi, etc.)
- The basic understanding of how SEO works

## Bonus points if you can demonstrate:

- You have a growing social media channel like YouTube, Podcast, or Tiktok
- You are actively involved with the developer communities
- Developer marketing experience in the B2B technology space

If this list gets you pumped, we want to hear from you -- email us at jobs@gelato.digital

More job openings: https://recruitcrm.io/jobs/Gelato_Network_careers
Day 78 of 100 Days of Code & Scrum: Digital Marketing Services, Interview Practice, and Reviewing
Tags: 100daysofcode, beginners, javascript, productivity
Published: 2022-01-15 09:53:30

Happy weekend, everyone!

Another productive day for me. I worked on my website, practiced for interviews, and reviewed Node.js as well as other backend concepts and tools.

I finished building another page for my website today, which was about the Digital Marketing Services. The design and layout are similar to the Web Development Services page, which kind of works for now. 

![Rammina Digital Marketing Services](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/un87ipw2zjh8qtadlq63.png)

I only have one more page left for the Services pages, which I'm looking forward to finish in the coming days.

Anyway, let's move on to my daily report!

## Yesterday

- I finished building the Web Development Services page for my [web development site](https://www.rammina.com) and continued to learn more about Scrum.

## Today

### Company Website

- finished the Digital Marketing Services page.

### Next.js

- reviewed various data fetching techniques and patterns in Next.js.

### Scrum

- read this article, [Scrum from the Trenches - the Sprint Goal](https://www.scrum.org/resources/blog/scrum-trenches-sprint-goal).

### Interview Practice

- did some mock interviewing for my technical interviews next week.
- reviewed Node.js and other backend concepts.

Thank you for reading! Have a good day!

![Rammina Thank You Banner](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x9ayfxxxaz2g2hfcqbsk.png)

## Resources/Recommended Readings

- [The 2020 Scrum Guide](https://scrumguides.org/scrum-guide.html)
- [Next.js & React by Maximilian Schwarzmüller](https://www.udemy.com/course/nextjs-react-the-complete-guide/)
- [Next.js official documentation](https://nextjs.org/docs/getting-started)
- [SWR official documentation](https://swr.vercel.app/)
- [Scrum from the trenches - the Sprint Goal](https://www.scrum.org/resources/blog/scrum-trenches-sprint-goal)

## DISCLAIMER

**This is not a guide**, it is just me sharing my experiences and learnings. This post only expresses my thoughts and opinions (based on my limited knowledge) and is in no way a substitute for actual references. If I ever make a mistake or if you disagree, I would appreciate corrections in the comments!

<hr />

## Other Media

Feel free to reach out to me in other media!

<span><a target="_blank" href="https://www.rammina.com"><img src="https://res.cloudinary.com/rammina/image/upload/v1638444046/rammina-button-128_x9ginu.png" alt="Rammina Logo" width="128" height="50"/></a></span>

<span><a target="_blank" href="https://twitter.com/RamminaR"><img src="https://res.cloudinary.com/rammina/image/upload/v1636792959/twitter-logo_laoyfu_pdbagm.png" alt="Twitter logo" width="128" height="50"/></a></span>

<span><a target="_blank" href="https://github.com/Rammina"><img src="https://res.cloudinary.com/rammina/image/upload/v1636795051/GitHub-Emblem2_epcp8r.png" alt="Github logo" width="128" height="50"/></a></span>
What is AWS? (for Newbies)
Tags: aws, cloud, devops, webdev
Published: 2022-01-15 09:52:07

What is AWS?🤔
Hey!
It's Mubashir Ibrahim, aka Mubi. It is 2022 and AWS is getting so popular nowadays, but still some of the College and University Students like me🌚 still don't know that "What is AWS (Amazon Web Services)"? So let's explore the Basic Definition of AWS and why it is getting so popular nowadays.
Now here comes the Definition from Google and other sources: -
"AWS provides servers, storage, networking, remote computing, email, mobile development, and security."
Still doesn't get it🤔? The AWS is basically a cloud provider–from infrastructure technologies like computing, storage, and databases–to emerging technologies, such as ML and AI, data lakes and analytics, and the IoT.
AWS and some of its most used technologies, But???
There are other Cloud infrastructure technologies too like Azure, Google Cloud, IBM Cloud, Oracle Cloud, and many more…
So what makes AWS so popular? Following are some of the famous reasons for choosing AWS:-
Large Community
AWS has the largest community, with more than a million active users and thousand of partners worldwide. People across the world use AWS from every country and industry. Whether it is a Tech Giant or a Small Startup, Programmers and Cloud Architects love to play with AWS technologies and services.
Secure
AWS is considered to have one of the most secured and flexible cloud computing environments today. AWS supports 80+ security standards and compliance certifications, more than 100 AWS services that are storing customer data offer the ability to encrypt that data, and all of this is backed by a deep set of cloud security tools, with 200+ security, compliance, and governance services and features.
THE END
This is the first part of this article on "What is AWS and Why it is so famous?". Let me know if you liked the first part, then I will write the second part too 😊.
Thank you
Hack Solidity: Tx Origin Attacks
Tags: solidity, security, samrtcontract, blockchain
Published: 2022-01-15 09:48:54


`tx.origin` is a global variable in Solidity which returns the address of the account that sent the transaction.

Contracts that use the `tx.origin` to authorize users are vulnerable to phishing attacks. How?

Let’s say, a call could be made to the vulnerable contract that passes the authorization check since `tx.origin` returns the original sender of the transaction which in this case is the authorized account.

Let's look at the example.

```
contract Wallet {
    address public owner;

    constructor() payable {
        owner = msg.sender;
    }

    function transfer(address payable _to, uint _amount) public {
        require(tx.origin == owner);

        (bool sent, ) = _to.call{value: _amount}("");
        require(sent, "Failed to send Ether");
    }
}

contract Attack {
    address payable public owner;
    Wallet wallet;

    constructor(Wallet _wallet) {
        wallet = Wallet(_wallet);
        owner = payable(msg.sender);
    }

    function attack() public {
        wallet.transfer(owner, address(wallet).balance);
    }
}
```

I created two contracts: `Wallet` that stores and withdraws funds, and `Attack` which is a contract made by an attacker who wants to attack the first contract. 

Note that the contract authorizes the `transfer` function using `tx.origin`. 

Now, if the owner of the `Wallet` contract sends a transaction with enough gas to the `Attack` address, it will invoke the fallback function, which in turn calls the `transfer` function of the `Wallet` contract with the parameter attacker. 

As a result, all funds from the `Wallet` contract will be withdrawn to the attacker's address. This is because the address that first initialized the call was the victim (i.e., the owner of the `Wallet` contract). 

Therefore, `tx.origin` will be equal to the owner and the `require` on will pass.


## How to prevent Tx Origin attacks

The best way to prevent Tx Origin attacks is not to use the `tx.origin` for authentication purposes. Instead, it is advisable to use `msg.sender` (see below)

```
function transfer(address payable _to, uint256 _amount) public {
  require(msg.sender == owner);

  (bool sent, ) = _to.call.value(_amount)("");
  require(sent, "Failed to send Ether");
}
```


### Sources

- https://solidity-by-example.org/hacks/phishing-with-tx-origin/

- https://medium.com/coinmonks/solidity-tx-origin-attacks-58211ad95514

- https://blog.sigmaprime.io/solidity-security.html#tx-origin
Design Patterns for Resilient Serving - Stateless Serving Function
Tags: machinelearning
Published: 2022-01-15 09:42:55

Using this design pattern, we can have a production ML system synchronously handle millions of prediction requests per second.

| Stateless components | Stateful components |
| - | - |
| Output is determined purely by the inputs | Output depends both on inputs and internal state |
| _**No state**_ => can be shared by multiple clients | Need to store each client's conversational state |
| _**Highly scalable**_ => initialized on first request and destroyed when client terminates or timed out | Expensive and difficult to manage |

> Exporting a model as a stateless function means the stateful variables such as epoch number, learning rate, etc. need to be tracked separately and not to be included in the exported file.

## Demerits of carrying out inferences on an in-memory object

1. Loading the entire model (which can be large in size) into memory
2. Limits on latency on predictions
3. Programming language dependency
4. The model input and output may not be user-friendly

## Achieving statelessness

1. Export the model into a format that is programming language independent
2. Restore the model as a stateless function in production
3. Make the stateless function available via REST endpoint

To save a model in Keras: `model.save(export_path)`

This will export the model as a `<model>.pb` file - **protocol buffer** and extracts out other stateful variables into separate files.

`model.save` also takes an optional argument `signatures`. This can be used to define a dictionary stating different serving functions. If not specified, the model's forward pass is exported.

To determine the signature of the stateless function that we will use for serving:

```bash
!saved_model_cli show --dir {export_path} --tag_set serve --signature_def serving_default
```

Finally, we can use this as follows:

```python
restored = tf.keras.models.load_model(export_path)
infer = restored.signatures['serving_default']
outputs = infer(input)
```
How to test a React App, with Jest and react-testing-library
Tags: react, typescript, jest, testing
Published: 2022-01-15 09:36:00

How to test a React App, with Jest and react-testing-library

Prerequisites: An existing React app.

You can find the full source code @ github: https://github.com/alexadam/project-templates/tree/master/projects/react-app-tests

## Setup

Install *Jest* and *react-testing-library*

```sh
yarn add --dev jest @types/jest ts-jest @testing-library/react @testing-library/jest-dom
```

In the project's root folder, create a file named `jest.config.js` and add:

```js
module.exports = {
  roots: ["./src"],
  transform: {
    "^.+\\.tsx?$": "ts-jest"
  },
  testEnvironment: 'jest-environment-jsdom',
  setupFilesAfterEnv: [
    "@testing-library/jest-dom/extend-expect"
  ],
  testRegex: "^.+\\.(test|spec)\\.tsx?$",
  moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"]
};
```

Update `package.json` by adding a new script entry:

```json
"scripts": {
    ...
    "test": "jest",
    ...
```

## Create a Test

We'll test the basic React app created from scratch here: https://alexadam.dev/blog/create-react-project.html

To test the **Numbers** component, create a file named `numbers.test.tsx`, in the `src` folder:

```js
import React, { Props } from "react";
import { fireEvent, render, screen } from "@testing-library/react";
import Numbers from "./numbers";

describe("Test <Numbers />", () => {

  test("Should display 42", async () => {
    render(<Numbers initValue={42} />);
    const text = screen.getByText("Number is 42");
    expect(text).toBeInTheDocument();
  });

  test("Should increment number", async () => {
    const { container }  = render(<Numbers initValue={42} />)

    const incButton =  screen.getByText('+')

    fireEvent(
      incButton,
      new MouseEvent('click', {
        bubbles: true,
        cancelable: true,
      }),
    )

    const text = screen.getByText("Number is 43");
    expect(text).toBeInTheDocument();
  });

  test("Should decrement number", async () => {
    const { container }  = render(<Numbers initValue={42} />)

    const decButton =  screen.getByText('-')

    fireEvent.click(decButton)

    const text = screen.getByText("Number is 41");
    expect(text).toBeInTheDocument();
  });

});
```

Run the tests:

```sh
yarn test
```

See the results:

```sh
$> yarn test
yarn run v1.22.17
$ jest
 PASS  src/numbers.test.tsx
  Test <Numbers />
    ✓ Should display 42 (29 ms)
    ✓ Should increment number (14 ms)
    ✓ Should decrement number (8 ms)

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        2.893 s
Ran all test suites.
✨  Done in 3.88s.
```
The obvious reason why Google is loosing the cloud battle to AWS and Azure?
Tags: googlecloudservice, microsoftazure, amazonwebservice, kubernetes
Published: 2022-01-15 09:35:11

If you want to be successful in a market, you either need to be the first, latest, best or only, AWS was first.  

Microsoft Azure is clearly best for companies already running lots of Microsoft software. Microsoft is also the only cloud provider that makes Windows, a huge plus for everyone running Windows VMs on Azure.

Let's take a quick peak at what Google Cloud is best at. If they came up with anything, it was probably either Kubernetes or open source. Those are advantages, for sure, but in times like these where the race to meet high demands is very competitive, these advantages Google Cloud has is not enough, at least not yet. 

Google Cloud certainly has the technical chops and engineering talent to compete with Microsoft Azure and Amazon’s AWS when it comes to cloud infrastructure, edge computing – and especially inferencing/training for machine learning models. However, Google may lack focus due to Search and YouTube being the main revenue drivers. This is seen from the company’s inability to ignite revenue growth in the cloud segment during a year when digital transformation has been accelerated by up to six years due to work-from-home orders. 

There are a bunch of lower level features that Google Cloud has that others don't, but it's hard to sell your product that way.

Microsoft’s roots in enterprise created a direct path to upsell on-premise and become the leader in hybrid. The majority of the Fortune 500 is on Azure as they want seamless security and APIs regardless of the environment. 

To catch up, Google will need to identify 1–3 important areas in which to be the very best. It's going to be hard to do that via open source, which AWS and Microsoft have also adopted. Kubernetes is probably one. What might others be? That perhaps should be the big question.

If you gained something from this article, take a minute of your time, hit the share button and share this piece with your network on social media, also give me a follow on all social media platform via @ifycoool.

Be the first to catch my next article, visit and subscribe to my official blog via https://www.blog.ifeanyiokeakwam.com