teleren/devto huggingface dataset:
How to test your Lambda made in Python locally with serverless
Tags: lambda, serverless, tutorial, python
Published: 2022-03-01 23:15:29

The idea of this tutorial is to quickly and practically demonstrate an example of how to test your lambdas locally


First your machine needs to have Node and Python already configured and then you will need to install serverless globally.

```bash
npm i -g serverless
```

**The basic structure of the project will be:**

```bash
.
├── handler.py
└── serverless.yml

```

**handler.py code**

```python
import json
import re


def lambda_handler(event, context):
    informedEmail = json.loads(event)['email']
    
    result = _validate(informedEmail)

    response = {
        'statusCode': 200,
        'body': result
    }

    return response

def _validate(email: str) -> str:
    emailRegex = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
    if(re.search(emailRegex, email)):  
       return "Valid Email"        

    return "Invalid Email"
    
```
The handler.py is basically a very simple code that receives an email in the body json is valid if it really is in the standard of an email through a simple regex

**serverless.yml code**

```yml
service: email-validator

provider:
  name: aws
  runtime: python3.8

functions:
  main:
    handler: handler.lambda_handler
```

The serverless.yml is the file where you define things like lambda region environment variables and profile used for aws testing.

Important points from our serverless.yml the `runtime` line  where we defined which python version used in the lambda and `handler` line where we reference the lambda entry point.

**Now how do we test our code?**

In your terminal of choice, run:
```bash
serverless invoke local --data '"{\"email\": \"test@example.com\"}"' --function main
```

Expected response when we provide a valid email

```json
{
    "statusCode": 200,
    "body": "Valid Email"
}
```

**Congratulations!!**

Now you know how to test your lambda locally without any problem
I’ve definitely coded… and coded…and still hung in there and coded..,
Tags: wecoded
Published: 2022-03-01 23:10:40

I’ve been a member of the dev community since its beginning and I’ve been a part of #shecoded since it began as well and I wanted to share a great story about the company that I work for: K16 Solutions. 
For the first time in many years believe that I am in a company that is open to everything and everyone. Their focus is on the talent that every person has without judging their gender (or their age for that matter) or anything else about them other than the fact that they have skills to contribute on the team.  It is the most honest employee - employer relationship I’ve ever had and I just want to send kudos out to K16 because they’ve worked really hard to make the company what it is but above and beyond that they are looking after the people who are a part of what they are.
groffstudio: A minimalist alternative to LaTeX and TeXstudio.
Tags: textprocessing, showdev, pascal
Published: 2022-03-01 23:02:17

## Preliminary remarks

As most of you already know, I am a strong advocate of simple solutions over complex tools that try to do everything. In this respect, it is only logical that in the course of my computer use I have also dealt with `groff`.

### `groff`?

`groff` - an amazingly good piece of software from the GNU project - is a free implementation of `troff`, which in turn is a successor to the `RUNOFF` tool first released in 1964 for the CTSS operating system. So unlike LaTeX, it is already very mature.

#### Advantages of `groff`

Unlike LaTeX, which (with a complete installation) takes up several gigabytes of disk space, `groff` is a rather compact software: a complete package, including all libraries, is less than ten megabytes. (I would like to mention here that there are now new alternative versions of `RUNOFF`, such as `neatroff`, but this is not relevant here).

As for LaTeX, there are also macro packages for `groff`, which is mainly used for creating man pages, for writing letters, CVs and so on. Especially [mom](http://www.schaffter.ca/mom/mom-01.html) stands out here, which is optimised for writing books. On the website of `mom` - macro packages in `groff` always begin with an "m", since you call them up via `groff -m...` - you can also see the pleasantly compact and quite readable syntax of `groff`, which I personally consider at least equal to LaTeX.

#### Disadvantages of `groff`

Until recently, there were countless graphical interfaces for LaTeX, such as AuCTeX and TeXstudio, but none for `groff`. Because I was bored the other day, I changed that.

## groffstudio

`groffstudio` is a simple tool for Windows and unix-like systems developed in Free Pascal and LCL - i.e. with the free IDE [Lazarus](https://www.lazarus-ide.org) - with the purpose of making the use of `groff` as user-friendly as possible. It requires a working installation of `groff`. (Since this is somewhat more difficult under Windows, the Windows version includes a function to download `groff`).

A preview function does not (yet?) exist, but simply compiling a `groff` document into PostScript or PDF is already possible without any problems. A screenshot of the current version of `groffstudio` is attached to this article.

### Links

* [`groffstudio` website](https://groff.tuxproject.de)
* [Fossil repository](https://code.rosaelefanten.org/groffstudio)
 * [GitHub mirror](https://github.com/dertuxmalwieder/groffstudio)

## Help wanted

I wrote `groffstudio` in about four days. Naturally, my own free time and access to as many platforms as possible are limited. However, I was generous 😏 enough to make `groffstudio` free software under the terms of the CDDL-1.1 license.

So if you want to help me improve the software, please get in touch with me and I'll probably grant you commit access to the repository.

## Comments?

I sadly still cannot answer here on DEV because the staff hates me 😉, but feel free to ping me [on Twitter](https://twitter.com/tux0r) or send patches or something. Thank you for reading!
What is my current Tailwind CSS breakpoint?
Tags: css, tailwindcss
Published: 2022-03-01 22:56:27

When you're designing your site and fiddling around with which Tailwind CSS classes should apply starting at each breakpoint, mobile (the default), `sm:`, `md:`, and beyond, it can be very handy for your browser to tell you definitively what breakpoint is currently active.

![breakpoint-lg](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5rw6eyxheueh3if96gnr.png)

![breakpoint-mobile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i34mwt8taws6qgj04ed6.png)

Create a partial/fragment/component with the following HTML, which uses the `sticky z-50 top-2 left-2` classes to ensure your little badge always appears in the top left corner.

```html
<div class="sticky z-50 top-2 left-2 max-w-xs text-gray-900 bg-gray-50">
  <p class="p-2 text-xs">
    Breakpoint:
    <span class="sm:hidden">mobile</span>
    <span class="hidden sm:inline md:hidden">sm</span>
    <span class="hidden md:inline lg:hidden">md</span>
    <span class="hidden lg:inline xl:hidden">lg</span>
    <span class="hidden xl:inline 2xl:hidden">xl</span>
    <span class="hidden 2xl:inline 3xl:hidden">2xl</span>
    <span class="hidden 3xl:inline 4xl:hidden">3xl</span>
    <span class="hidden 4xl:inline">4xl+</span>
  <p>
</div>
```

Next, in your most outer layout, inject this partial/component when the current page's parameters include `dev=1` or similar, near the top of the `<body>` tag.

For example, in Ruby on Rails you might put the following inside your `application.html.erb`:

```html
<%= render "shared/sticky_panel" if params[:dev].presence %>
```

Want to try it out? It's currently live to the public at <https://app.rcrdshp.com/?dev=1>.
Bash script to log and restart docker container based on cpu usage
Tags: docker, bash, linux
Published: 2022-03-01 22:51:50

I wrote this post to share with you one job experience that I had to live with recently, one problem I had and my temporal solution to this problem.
I'm new in this tech world, I will be grateful if any of you have some improvement recommendations and very pleased if this post it's useful for someone else.
A few mounths ago in my company we discovered that some Docker container was having problems with CPU usage. Out of nowhere the CPU usage of that container was increasing abruptly. So while the dev team was searching for the code error, I implemented a temporary solution. I made one script to log all cpu usage every 5 seconds:

```bash
#!/bin/bash
logs=/var/log/process_name.log
container_name=container_name

while :
do
  # Get a variable with the cpu usage for a specific container
  var=`docker stats --no-stream --format "{{.CPUPerc}}" $container_name`
  length=${#var}

  if (( $length==0 )); then
     echo "Container ${container_name} does not exist"
     echo "$(date +'%d-%m-%Y %H:%M') | Container $container_name does not exist" >> $logs
  else
    # CPU usage in number
    percent="${var[@]::-4}"

    echo "Actual cpu usage: ${percent}"

    # Save actual CPU usage in file
    echo "$(date +'%d-%m-%Y %H:%M') | ${percent}" >> $logs
  fi
  sleep 5

``` 

After that I created a supervisor config to run this process:

```bash
[program:process]
command=/opt/scripts/script.sh
autostart=true
autorestart=true
stderr_logfile=/var/log/process.err.log
stdout_logfile=/var/log/process.err.log
```

Then I wrote a script to restart the problematic container, based on the logs of the previous script:

```bash
#!/bin/bash
container_name=container_name
logs_evaluated_lines=5
logs=/var/log/process_name.log
max_cpu=90

while :
do
    # Lines in file
    num=$(wc -l < $logs)

    counter=0

    # For 'logs_evaluated_lines' lines in logs increase counter if cpu is greater than 100%
    for ((index=$num;index>=$num-$logs_evaluated_lines+1;index--))
    do
    value=$(sed "${index}q;d" $logs)
    percent=$(echo $value | cut -c 20-)
    #echo $percent
    if (( $percent >= max_cpu )); then
    #    echo 'mayor'
        counter=$((counter+1))
    #  else
    #    echo 'menor'
    fi
    done

    echo "$(date +'%d-%m-%Y %H:%M') | Logs up to 100%: ${counter}"
    echo "$(date +'%d-%m-%Y %H:%M') | Logs lines analyzed: ${logs_evaluated_lines}"
    if (( $counter == $logs_evaluated_lines )); then
        echo "$(date +'%d-%m-%Y %H:%M') | CPU Full usage";
        echo "$(date +'%d-%m-%Y %H:%M') | Restarting Container"
        docker restart $container_name
        echo "$(date +'%d-%m-%Y %H:%M') | Container Restarted"
        echo "$(date +'%d-%m-%Y %H:%M') | Container Restarted" >> $logs
    else
        echo "$(date +'%d-%m-%Y %H:%M') | CPU Usage OK"
    fi
    echo "$(date +'%d-%m-%Y %H:%M') |"
    sleep 5
done
```

This script evaluate 'logs_evaluated_lines' lines in log and restarts the container if the count is upper 'max_cpu' variable
IMac that slow – is that normal?
Tags: askdifferent, imac, normal, slow
Published: 2022-03-05 04:22:14

---
title: IMac that slow – is that normal?
published: true
date: 2022-03-01 22:22:18 UTC
tags: AskDifferent,IMac,normal,slow
canonical_url: https://stackallflow.com/ask-different/imac-that-slow-is-that-normal/
---

I have a iMac Retina4K from the end of 2015 with 3.1GHz Quad-Core i5 and 8GB DDR3 on 21″ with a second monitor attached, and a HDD-disk. macOS is Catalina and I am running Firefox, Adobe InDesign and Adobe Illustrator most of the time. Since I upgraded to Catalina my Mac is soooo slow that starting up in the morning until anything really runs (i.e. I am able to click on an app) takes up to 10 minutes with no applications opened yet.

Opening up Illustrator works in 6 of 10 times, else it just freezes. If opened it does work okay though. Firefox freezes also on a regular basis. I never open up more then 3 applications at the same time, have no widget etc running and I got hundreds of gigabyte diskspace left.

I get it, that this isn’t the newest device but shouldn’t the OS and some really simple task like opening up a browser be “there” in less then 5 minutes?

My question though is a different one: If I’d set up/reinstall the Mac completely new with Catalina (as I am bound by Creative Cloud to it) should that speed up my described routine or is the current scenario just what I can expect from the combination of that hardware/software combination?

## Accepted Answer:

You can use Activity Monitor (in /Applications/Utilities) to see what processes are taking the most CPU and Memory, and monitor disk input and output. This may help to identify what is causing the slowness.

However, the most likely cause (in the absence of any other info) is the presence of an internal mechanical hard drive, either by itself or as part of a ‘Fusion’ drive.

Mechanical hard drives are much slower than modern ‘solid state’ SSDs. If your Mac has to ‘swap’ memory data to and from the disk, then this will slow things down dramatically. Also, the drive is at the end of its useful lifespan, and may show signs of failing.

While taking an iMac apart to replace the drive may be of moderate difficulty, you would do better to use an external SSD. Old Thunderbolt 2 enclosure are harder to find these days, but even a USB3 SSD will be faster.

Apple continued to install hard drives in iMacs for many years after it was using SSDs in its other Macs. So, in reply to the question ‘is this normal for an iMac’, the answer is sadly, yes.

#IMac #slow #normal

The post [IMac that slow – is that normal?](https://stackallflow.com/ask-different/imac-that-slow-is-that-normal/) appeared first on [Stack All Flow](https://stackallflow.com).
Disable smooth fading when changing brightness of MacBook Pro Screen?
Tags: askdifferent, brightness, changing, disable
Published: 2022-03-05 04:22:18

---
title: Disable smooth fading when changing brightness of MacBook Pro Screen?
published: true
date: 2022-03-01 22:32:14 UTC
tags: AskDifferent,brightness,Changing,disable
canonical_url: https://stackallflow.com/ask-different/disable-smooth-fading-when-changing-brightness-of-macbook-pro-screen/
---

I’m on a late 2013 15″ MacBook Pro with Retina Display.

Is there any way of disabling/enabling whether the display smoothly fades when the brightness keys are hit (F1 to lower, F1 to raise)? On my old computer, a late 2008 MacBook, it just snapped to the new brightness if I changed it in system preferences or used the Function Keys shortcut.

I want to do this because I am in a small theatre, and when I run light cues off my computer that black out the stage, I want it to snap to near-zero brightness, as opposed to the higher brightness I need to have it set to when the lights are up to prevent the screen from being washed out. I am setting the brightness via applescript.

## Accepted Answer:

#Disable #smooth #fading #changing #brightness #MacBook #Pro #Screen

The post [Disable smooth fading when changing brightness of MacBook Pro Screen?](https://stackallflow.com/ask-different/disable-smooth-fading-when-changing-brightness-of-macbook-pro-screen/) appeared first on [Stack All Flow](https://stackallflow.com).
Let's talk web2 vs web3
Tags: web3, web2, blockchain
Published: 2022-03-01 22:23:44

The web was first created in 1989 by [Tim Berners-Lee](https://en.wikipedia.org/wiki/Tim_Berners-Lee), who wanted to create a global communication tool that would allow different computer systems to connect easily, read and save documents and at that time the internet was mostly used for academic and government purposes. This was the first iteration of the internet, the version of the internet most of us know today is web2,with web3 creeping into mainstream and with this introduction of web3,people are increasingly interested in the way,it will change the web as we know it.That is why companies like [Nestcoin](https://nestcoin.com/) and [Zuri](https://zuri.team/) are empowering developers especially in Africa with the relevant skills and knowledge to be part of those that will change the face of the web by creating programs centered on blockchain and web3 with the [Blockgames](https://blockgames.gg/) as its first program.
Web2 is the version of the internet dominated by companies that provide services in exchange for your personal data while web3 in contrast refers to decentralized apps that run on the blockchain,these applications allow anyone to participate without monetizing their personal data.so you may ask,what.s is web3 bringing to the table?here are some of the benefits of web3

- Anyone who is in the network has permission to use the service-in other words,permission isn't required.

- No one can block you or deny you access to the service

- Payments are built in viz the native tokens,e.g ether

## Let's make practical comparisons between web2 and web3

- In web2, it is centralized and anyone can be censored whereas web3 is decentralized thus can not be censored as control is not controlled by an individual or companies.

- Payment services may decide to not allow payments for certain reasons or type of work but with web3 payment applications require no personal data and can't prevent payments.

- In web2,servers may have down time,be hacked and personal data breached or lost but web3 servers can't have downtime and cannot be hacked. 
This is not an exhaustive list since we are still scraping the surface of web3,however every phase of the internet has its limitations and web3 is not excluded

- Scalability: Transactions are slower on web3 compared to web2 because of the decentralized nature of web3.

- User Experience: Interacting with web3 applications would require extra steps,software and education,this could be a hurdle for its adoption

- Accessibility: The lack of integration in modern web browsers make web3 less accessible to most users when compared to web2.

- Cost: building and developing on web3 can be quite expensive when compared with web2 because it cost money to put a code on the blockchain.

However as more people get to know and learn more about this phase of the internet,the challenges of web3 will be overcome,interested in this new phase,you are still early,join [Blockgames](https://blockgames.gg/) and kick start your blockchain development journey.
Google Chrome Developer Tools – Part 2
Tags: debugging, javascript, technology
Published: 2022-03-21 08:24:22

---
title: Google Chrome Developer Tools – Part 2
published: true
date: 2022-03-01 22:15:57 UTC
tags: Debugging,JavaScript,Technology
canonical_url: https://bugfender.com/blog/google-chrome-developer-tools-part-2/
---

This is the second part of the Google Chrome Developer tools article. In this post we will share show you more of the new Developers Tools that Google has added to Chrome. Remember that Google Chrome Dev Tools is a set of powerful tools that help developers to build better webs.

If you haven’t done it yet, you can read [the first article of the series](https://dev.to/bugfenderapp/google-chrome-developer-tools-part-1-jjk).

## Console Panel

Learn how to use Google Chrome Console Panel to improve your app and test things when you are building your website.
{% embed https://www.youtube.com/watch?v=32aWB2TSHJM %}

## Payload Tab

If you are building a website and you are doing requests to a server, you can use the Payload Tab to see what information you are sending to it, so you can debug any query that fails.
{% embed https://www.youtube.com/watch?v=i--pY6P4iH4 %}


## Sync Settings

If you work on multiple computers, you might want to synchronize all your Google Chrome settings between them. Learn how to do it on the next video.
{% embed https://www.youtube.com/watch?v=IUiN1_4RCS8 %}

## Where To Go From Here…

I hope you found the article insightful! In this first article, we have covered another 3 of the new Dev Tools, if you want to learn more about all the tools offered by Google Chrome, you can check [the first article of the series](https://dev.to/bugfenderapp/google-chrome-developer-tools-part-1-jjk) or you can check the official Google Chrome link:

[https://developer.chrome.com/docs/devtools/](https://developer.chrome.com/docs/devtools/)

Or you can wait for our last article to learn about another set of tools. Stay tuned!
First three steps done
Published: 2022-03-01 22:10:59

https://alteeno-crc.s3.us-east-2.amazonaws.com/testSite.html
![To be improved...](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40l7oojwuz127s804tjd.png)
 

I cleared the S3 section of my Udemy course and managed to get this really barebones resume up. Pretty cool so far! I may continue more today to get it running with HTTPS. The course slowly put things together but I think I could've just went to one 5 minute section and got it over with. But, its probably good to learn about versioning, encryption, and policies.
IPhone – How to view (not download) iPhone pictures on a Mac screen?
Tags: askdifferent, download, iphone, mac
Published: 2022-03-05 04:21:56

---
title: IPhone – How to view (not download) iPhone pictures on a Mac screen?
published: true
date: 2022-03-01 22:02:18 UTC
tags: AskDifferent,download,iPhone,Mac
canonical_url: https://stackallflow.com/ask-different/iphone-how-to-view-not-download-iphone-pictures-on-a-mac-screen/
---

I have an iPhone 5 with various photos.  
 I have a Mac desktop running OS X Yosemite.

Is there a way to view a fullscreen slideshow of the photos on the Mac display? I don’t want to download the photos, just flip through them for display on the big screen.

## Accepted Answer:

Apple’s mandated solution would be to wait for the photos to upload to your Photo Stream or iCloud Photo Library, then start a slideshow in iPhoto or Aperture.

Alternatively, you could make your Mac into an AirPlay receiver using a 3rd party app such as AirSquirrel’s [Reflector](https://stackallflow.com/reference/aHR0cDovL3d3dy5haXJzcXVpcnJlbHMuY29tL3JlZmxlY3Rvci8=). This one is paid, but I’m not aware of any free equivalent.

#IPhone #view #download #iPhone #pictures #Mac #screen

The post [IPhone – How to view (not download) iPhone pictures on a Mac screen?](https://stackallflow.com/ask-different/iphone-how-to-view-not-download-iphone-pictures-on-a-mac-screen/) appeared first on [Stack All Flow](https://stackallflow.com).