teleren/devto huggingface dataset:
Go: Fiber vs Echo (a developer point)
Tags: webdev, go, frameworks
Published: 2020-11-15 23:27:53

---
title: Go: Fiber vs Echo (a developer point)
published: true
description: About go frameworks
tags: #webdev #go #frameworks
cover_image: https://www.benefiber.com/amp/img/how-much-dietary-fiber-per-day/benefiber-how-much-dietary-fiber-per-day-main.jpg
---

Hi there!

I'm not a Go expert by any means but I grew into really enjoying the language, its opinionated ways, concurrency and sheer performance. While I do frown that it doesn't have the tools for better support of functional patterns, I appreciate the simplicity that makes it easy to get the job done with a reasonable amount of code.

That said, I also like things that make me more productive. Enter frameworks! And Go has so many of them. Minimalist, progressives, swiss-army-knives, you name it!

But until recently, I was (and still am, to a certain extent) a fan of the Echo framework. It's fast enough and has all the features that I look for in a framework:

- no-nonsense router that supports grouping and middlewares
- ton of middleware (some microservice must-haves like Prometheus, JWT and Jaeger)
- a decent logger that defaults to JSON
- easy way to control CORS (for those situations you're not using an external load balancer)

I was always aware that Echo (while fast, at least fast enough for my use cases) wasn't the top of the bunch in Go-world, but the shortcomings and annoyances I have with Gin and others made me overlook that. Also, all those built-in middlewares are awesome - I can't emphasise enough how important it is to have these to get things rolling (particularly Prometheus and JWT).

Yet recently I gave Fiber a shot and boy, was I impressed! Just by switching to it (surprisingly easy, just a couple of methods to replace, handlers, etc) my API response times lowered by roughly 40%. It's not all rosy though as:

- Fiber's logger doesn't do JSON, not by configuration at least. I can provide a pattern for it, but I ended up using my own middleware based on zerolog (it's also a bit faster than the built in logger)
- Fiber doesn't have as many middlewares available. It's a bit annoying to maintain a list of add-ons that belong to third parties, which may go away at any time. I miss Prometheus & Jaeger, for one.
- Fiber's autorecovery goes through the built-in logger which, as mentioned, doesn't do JSON. It's annoying as hell, when you're using external log aggregators, to have a message out of the blue break the serenity of your ingest patterns.
- it's not as easy to hook into an extend with customizations. I guess performance comes with a price as Fiber also has its quirks, mostly related to its zero allocations mantra.

I guess good things come with a price, but I'm more than happy to keep Fiber close!
Immediately invoked object
Tags: javascript, typescript
Published: 2020-11-15 23:11:34

We all know IIFE. In fact we can do the same with objects to omit cumbersome if/else, switch/case.

```js
const color = {
    red: 'rgb(255, 0, 0)',
    green: 'rgb(0, 255, 0)',
    blue: 'rgb(0, 0, 255)'
}[props.color || 'red']
```
Ruby refinements have a second good use case.
Tags: ruby
Published: 2020-11-15 23:04:13

According to Bradley [Refinements have one good use case](http://www.soulcutter.com/articles/ruby-refinements-have-one-good-use-case.html): Conversion Wrappers. I humbly present the second one.

---


Monkey patching in Ruby is a simple as:
```ruby
class String
  def red
    "\e[#31m#{self}\e[0m"
  end
end
```

But what if you don't to pollute the `String`-class for users of your Gem? In the worst case you might actually overwrite a monkey patch provided by the developer. We faced this when we wanted to provide coloring of strings for our logger in [StimulusReflex](https://docs.stimulusreflex.com/). We wanted our users to be able to write a configuration proc like this:

```ruby
config.logging = proc { "#{timestamp.cyan} #{reflex_id.red}" }
```

## Enter `refine`

With refinements we were able to monkey patch only where explicitly called for it:

```ruby
module Colorize
  refine String do
    def red
      "\e[#31m#{self}\e[0m"
    end
  end
end
```

Now you can activate this monkey patch in whatever class you need it:

```ruby
class Logger
  using Colorize
  def error
    "Ooops".red
  end
end
```

# A complication

Procs are a convenient solution, however they get the binding/context of where they are defined, not of where they are called. Just calling the proc in our `Logger`class will not make use of the `colorize`-refinement, actually no method of the `Logger`class is available to the proc, because it was defined in a completely different context (in an initializer of the gem user).

So we made use of [instance_eval](https://apidock.com/ruby/Object/instance_eval)

```ruby
class Logger
  using Colorize
  def log
    puts instance_eval(&config.logging)
  end
end
```

See the commit for [adding colorize](https://github.com/hopsoft/stimulus_reflex/pull/337/commits/ef5e8d0047962740dd5e48919e1c5d3571172d9a) and [using instance_eval](https://github.com/hopsoft/stimulus_reflex/pull/337/commits/0e301d63951eb1910983ddb7c9a934d7d1225e58)
👀Hi all👀
Tags: newbie, streamer, twitch, mrtemofey
Published: 2020-11-15 22:40:19

Всем привет, мне 23 🎈 я из Украины, простите с english небольшая проблема в процессе изучение, что бы не случилось можешь смело обращаться ко мне. Хорошего всем вечера ✨✨🤞
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/y13m0kgx55rg62hrw980.jpg)
How does ({component: Component}) work in PrivateRoute?
Tags: react, beginners, tutorial
Published: 2020-11-15 22:37:47

I am practicing an auth and authorization engine with Firebase. I found a good [YouTube video](https://www.youtube.com/watch?v=PKwu15ldZ7k) and they use the syntax below for a Private Route:

```
<Switch>
							 
    <PrivateRoute exact path='/' component={Dashboard} />
    <Route path='/signup' component={Signup} />
    <Route path='/login' component={Login} />
</Switch>
```

and then

```
export default function PrivateRoute({ component: Component, ...rest }) {
	const { currentUser } = useAuth();
	return (
		<Route
			{...rest}
			render={(props) => {
				return currentUser ? (
					<Component {...props} />
				) : (
					<Redirect to='/login' />
				);
			}}
		></Route>
	);
}
```

If a user is logged in, show the component, if the user is not logged in, redirect to login. The syntax `{component: Component}` kept me wondering... how does it work? I get it that the `Component` arrives within the `component` variable, but then, how does it translate into the `Component` we can use to render content?

Did a bit of Googling, and I found [this](https://forum.freecodecamp.org/t/react-router-explanation/178787/2):

> If I’m not mistaken, the reason that the component prop is reassigned to the Component identifier is because the JSX <component> attempts to create a component DOM element (which doesn’t exist) instead of a React component—a capitalised identifier is required for creating a React component.

Hmm, I didn't quite understand and I thought... `is that complicated`??

I asked in [Stack Overflow](https://stackoverflow.com/questions/64850383/dont-understand-how-component-component-in-a-react-privateroute-works/64850446) and it is much more simple than that: it is [vanilla JS](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Assigning_to_new_variable_names)!

The syntax `{component: Component}` is just taking whatever arrives as `component`, `unpacking it` as MDN docs call it, and assigning it to a new variable, `Component`. 

As simple as that. Now I know.
SignalR core python client (VIII): MessagePack
Tags: core, python, messagepack, signalr
Published: 2020-11-15 22:30:02

---
title: SignalR core python client (VIII): MessagePack
published: true
description: MessagePack implementation and tutorial
tags: core, python,  messagepack, signalr
series: SignalR core python client
cover_image: https://www.campusmvp.es/recursos/image.axd?picture=banner-asp-net-core-750x300.png
---

I had been with this pending task about a year, and a month ago i decided to implement message pack on library pushed by an [issue](https://github.com/mandrewcito/signalrcore/issues/32) on github´s library. These was my original plans, but i´ve been procrastinating it to this weekend.

As it can read on title, my implementation was SignalR message pack protocol. First i need to be thankful to the user [@ Apollo3zehn] (https://github.com/Apollo3zehn) on git. That implementation helped me a lot!. If you want see implementation details you can check library´s github. There is also the @Apollo3zehn´s fork, the links are below.

## The example

The example will be the most simple, a chat. I don't want to make something too long because i have wrote a lot of examples in my library´s examples or previous posts.

### Server configuration 

This configuration is only for message pack. A full example can be found [here]
(https://github.com/mandrewcito/signalrcore-containertestservers).

#### CSPROJ
Add signalr message pack dependency
```xml
    <PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.4" />
```
#### Startup.cs
```cs
public void ConfigureServices(IServiceCollection services)
{
    /// ...
    services
        .AddSignalR()
        .AddMessagePackProtocol();
    /// ...
        }
```

### Python client configuration

Python client syntax is like javascript´s signalr client. This example is an interactive chat (like MS examples). If you have worked with library the only thing you must add to builder config is the following

```python
from signalrcore.protocol.messagepack_protocol import MessagePackHubProtocol

  # 
hub_connection = HubConnectionBuilder()\
  # ...
  .with_hub_protocol(MessagePackHubProtocol())
  # ... builder config
```

A full working example is avaible [here](https://github.com/mandrewcito/signalrcore/blob/master/test/examples/chat_msgpack.py)

## Links

* [Github](https://github.com/mandrewcito/signalrcore)
* [Pypi](https://pypi.org/project/signalrcore/)
* [@ Apollo3zehn fork with async syntax] (https://github.com/Apollo3zehn/signalrcore)

Thank you for reading, and write any thought below :D
My Twitter Mobile Clone
Tags: twitter, javascript, react, css
Published: 2020-11-15 22:27:09

[LINK TO LIVE CLONE](https://5fb29adf74b97e00075f2101--modest-allen-d0c9f4.netlify.app/) (Click the home button at bottom, for some reason it doesn't load the homepage right away)

So, I cloned Twitter's mobile version. It was pretty challenging but I've managed to do the best I could. I used React and SCSS/CSS to build this. I practically made everything a component. I felt that the more components I use the more structured I would feel getting further into this project. After all, that's the point of react right?

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ysrzwvwha4iymqe43294.gif)

#Hompage 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/57jv5oyg01ytq46782c1.png)

This is the Twitter feed you would see. I'm actually using the npm package 'faker' to generate the fake users with fake tweets.

This is the explorer page. I actually have a friend who sent me a random article to use which the one that you see on the page now.

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

The Navbar component at the bottom was the easiest part of the project to implement. The Navbar component is reusable across every page. I love that type of consistency. I tried to do the same with the header but it didn't work out how I wanted because of the icons on the right side of the header. For the most part, they are all different across pages.

# Create Tweet Page
This is the "Create Tweet" page.

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

It was a little tough finding the exact same icons so I had to improvise and find closely similar ones. I actually used fontAwesome for the icons displayed.

My favorite page to build was the one and only 🥁🥁🥁🥁🥁🥁...

##Notifications Page

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

As I looked at this and then looked at my phone to compare the clone and the actual page from the app, I said to myself, "Damn, I'm really getting good at this, the hard work is really paying off". This was a proud moment for me. 

To conclude, not everything on the clone is functional, again, it was mere UI practice. This clone helped me to understand component isolation a bit more. I will definitely be doing more of these. Thanks for reading.

[LINK TO LIVE CLONE](https://5fb29adf74b97e00075f2101--modest-allen-d0c9f4.netlify.app/) (Click the home button at bottom, for some reason it doesn't load the homepage right away)
Linux ext4 superblock errors -- testdisk to the rescue
Tags: linux
Published: 2020-11-15 21:38:00

So, my Sunday has been great, how about yours? It all started trying to upgrade from Ubuntu 19.04 to 20.10...

I've done this a number of times.  You see, I have this system:
- `/home` is in a separate partition
- Most of my applications are installed by my [linux-bootstrap](https://github.com/drmikecrowe/linux-bootstrap) 
- Wipe `/` and install fresh.  Tell the installer to use my `/home` partition
- Use [direnv, pyenv, nodenv, etc](https://dev.to/drmikecrowe/direnv-take-control-of-your-development-environment-1dk) to handle specific versions

The problems started when I used `gparted` to clean up some old partitions (specifically deleting some old Windows diag partitions).  These were from Win7, so it was probably time.  They were hidden/system partitions, and it seemed like `gparted` handled removing them correctly.  I resized the `home` partition to use the (small) space freed, and everything seemed fine.

Started to do the installation, and something weird happened, still not sure what.  The cryptic error message was something to the tune of:

```
The filesystem size (according to the superblock) is 11296582 blocks
The physical size of the device is 10093482 blocks
Either the superblock or the partition table is likely to be corrupt! 
```

Apparently, it resized my `home` partition over the newly deleted diagnostic partitions, but those partitions weren't actually gone.  Fortunately, I was running on the live-usb, and I felt I could recover.  Google to the rescue...

However, most solutions seemed to fall short, and nothing seemed to work.  Then I found [TestDisk](https://www.cgsecurity.org/wiki/TestDisk).  This is the hammer you need when you are really in trouble.  Using this, I was able to scan all the partitions.  It lingered over the newly-resized `home` partition and managed to find the old partitions.  Further, it gave me the choice of how to rewrite the partition table.  I was able to really mark the diag partitions as deleted and write the new partitions.

`e2fsck /dev/sda6` now showed no issues.

Huge sigh of relief...
The top 10 nice-to-have VSCode extensions for a React development 🔥
Tags: vscode, react, development, webdev
Published: 2020-11-15 21:11:25

**[ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)** - A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease

**[Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)** - An opinionated code formatter. Supports many languages, configurable and integrates with most editors

**[DotENV](https://marketplace.visualstudio.com/items?itemName=mikestead.dotenv)** - A zero-dependency module that loads environment variables from a .env file into process .env

**[Bracket Pair Colorizer](https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer)** - A customizable extension for colorizing matching brackets

**[Import Cost](https://marketplace.visualstudio.com/items?itemName=wix.vscode-import-cost)** - Display import/require package size in the editor

**[Auto Import](https://marketplace.visualstudio.com/items?itemName=steoates.autoimport)** - Automatically finds, parses and provides code actions and code completion for all available imports. Works with Typescript and TSX

**[File-icons](https://marketplace.visualstudio.com/items?itemName=file-icons.file-icons)** - File-specific icons in VSCode for improved visual grepping

**[GitLens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens)** - Supercharges the Git capabilities built into Visual Studio Code. It helps you to visualize code authorship at a glance via Git blame annotations and code lens, seamlessly navigate and explore Git repositories, gain valuable insights via powerful comparison commands, and so much more

**[Path Intellisense](https://marketplace.visualstudio.com/items?itemName=christian-kohler.path-intellisense)** - VSCode plugin that autocompletes filenames

**[ES7 snippets](https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets)** - React/Redux/GraphQL/React-Native
Fetching data with React the easy way
Tags: react, api, meoisis
Published: 2020-11-15 21:10:34

I don't use React in my day to day work. When I see articles on it, I'm always surprised how simple things are over complicated

The following example uses several techniques wich simplify state management, but requires explanations.
Feel free to post questions.

 {% stackblitz react-meiosis %}

```js
import React, { useState } from 'react';

const timeOut = 1000;
let request = "https://randomuser.me/api/?results=10";
let response = null;

const fetchUsers = async function (actions) {
  actions.setLoading(true);
  try {
    response = await Promise.race([
      fetch(request),
      new Promise((res, reject) =>
        setTimeout(() => reject(new Error("Timeout")), timeOut))
    ]);
    var data = await response.json();
    actions.loadData(data.results);
  }
  catch (e) {
    actions.setLoading(false);
    alert(e.message);
  }
}

const listUsers = function (data) {
  return (
    <ul>{data.map((d, i) =>
      <li key={i}>
        <img src={d.picture.thumbnail} alt="user" style={{ margin: "10px" }} />
        {d.name.first}
      </li>)
    }
    </ul>
  )
}


const App = ({ states, actions }) => {

  var [init, setInit] = useState(false);
  var [state, setState] = useState(states());

  var dataLoaded = () => (state.loading === false) && 
    (state.data.length > 0);

  if (!init) {
    setInit(true);
    states.map(setState);
  }

  const displayUsers = async () => {
    if (!init) { return };
    actions.setLoading(true);
    fetchUsers(actions)
  }

  return (
    <div>
      <button onClick={displayUsers}>LoadRandomUsers</button>
      <div>
        {dataLoaded() && listUsers(state.data)}
        {state.loading && <h1>searching</h1>}
      </div>
    </div>
  );
};


export default App;

```
Why did I decide to study Software Engineering?
Published: 2020-11-15 20:56:31

Having had a passion for music since a young age, I have always understood the value of writing things out in a sort of formula. Computer languages are not to unlike learning to read and write music. I have been a very driven touring music performer for the past 12 years. In 2013 I attended the Atlanta Institute of Music for a certificate in audio engineering. It was there I discovered the capabilities of what computers can really accomplish. I was fascinated on how these amazing sounds and programs were really just lines of code. From there I toyed around online with some free courses, and enjoyed it immensely. I'm truly excited to enter this chapter of my life and to apply my drive, creativity and passion that I was able to bring to my music career.
Singleton Pattern in a NUTSHELL!!
Tags: design, programming, architecture
Published: 2020-11-15 20:56:02


Singleton Pattern solves problem like

- How to ensure that a class has only one instance
- How can the sole instance of a class be accessed globally


Applicability:
- Hide the constructor of the class using private access specifier
- Define a static function that returns the sole instance of the object created in the constructor.

Example by Code:

Class Logger{
private:
Logger(){
instance = new Logger();
}
public:
static getInstance(){
return instance;
}

}
Do you get to work printers on 32bit Linux Distros? 
Tags: printers, linux, 32bit, mint
Published: 2020-11-15 20:43:49

I'm switching from windows 7 to Linux Mint on my 13yr old laptop. I loved Manjaro OS but I need to run (.deb) driver from Epson archive to stand a chance to run my printer in the office. I've tried the Generic but it prints some weirdo stuff. Also, the .deb driver I mentioned, got installed but doesn't seem to help. Also, I need to use it's scanner. 

Windows 7 is a bit heavy compared to linux. Even chrome crashes every now and then. 


Specs :
Dell Inspiron 1420 
Intel Dual core Pentium
DDR2L 2GB X 2
EPSON L6160 or Canon mf230 atleast.
10 quick facts about AWS Lambda
Tags: aws, lambda
Published: 2020-11-15 20:17:22

---
title: 10 quick facts about AWS Lambda
published: true
tags: aws, lambda
canonical_url: https://tlakomy.com/ten-quick-facts-about-aws-lambda
---

Before we start - I'm working on [https://cloudash.dev](https://cloudash.dev), a brand new way of monitoring serverless apps 🚀. Check it our if you're tired of switching between 50 CloudWatch tabs when debugging a production incident.

<hr/>

1. By default there's a limit of 1000 concurrent lambda executions, this can be raised with a support ticket. There are companies that have this limit raised up to tens of thousands concurrent lambda executions.
2. There's a default limit of 75GB of code storage (so up to 10 React apps, lol) which can also be raised
3. It's possible to run Lambda functions on a custom VPC, which is useful when you need to work with RDS, EC2, containers etc. When using a custom VPC you should create a custom subnet for lambda functions to prevent issues when the function will scale massively
4. You get charged for the lambda execution time in 100ms blocks (so if your function takes 10ms to execute, you'll pay for 100ms)
5. With aliases you can run different versions of Lambda function with a different probability (for instance run version A 90% of the time and version B 10% of the time)
6. You can push failed async lambda function invocations to dead letter queue (for instance - SQS)
7. Pricing: 

First 1 million requests per month are free, afterwards you pay $0.20 per additional 1 million requests
- 400,000 GB seconds free per month, afterwards you pay $0.0000166667 for every GB second
- Example: **128MB of Memory x 30M executed per month x 200ms run time per invocation = $5.83**
8. Cold starts affect less than 1% of production workloads (they are much more common in development environments, since there is way less traffic). A duration of a cold start varies from less than 100ms to more than 1s. It's not possible to 'target' warm environments.
9. In order to reuse existing connections (and improve the performance of functions using http(s) request) use keep-alive property in order to reuse TCP connections on warm execution environments. More details: https://bit.ly/reuse-connection
10.  It's possible to use custom runtimes for Lambda (apart from Node, .NET, Python etc.) so if you **really** want to use Haskell you can do that

If you'd like to learn more I'd recommend:

- [Best practices for working with AWS Lambda functions](https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html)
- [Optimizing Lambda Performance for Your Serverless Applications](https://www.youtube.com/watch?v=FTCaOQJvG6Y)
- [Learn you some Lambda best practice for great good!](https://theburningmonk.thinkific.com/courses/learn-you-some-lambda) by [Yan Cui](https://twitter.com/theburningmonk)
- [Learn AWS Lambda from scratch on egghead.io](https://egghead.io/playlists/learn-aws-lambda-from-scratch-d29d?af=6p5abz)