teleren/devto huggingface dataset:
AWESOME SAM
Tags: aws, awssam, sam, serverlessapplicationmodel
Published: 2022-09-28 15:21:16

The AWS Serverless Application Model (SAM) is an open-source framework for constructing serverless applications. It presents shorthand syntax to explicit functions, APIs, databases, and occasion supply mappings.

SAM builds upon CloudFormation carrier and CloudFormation Templates. So, it is an extension of AWS CloudFormation. 
SAM ONLY supports serverless services. If one want to create other resources, use CloudFormation in SAM template!

For installation- Follow [install SAM instructions](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) and [SAM Git Repo](https://github.com/aws/serverless-application-model)

![SAM Flow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5gb6tlpzyqglt6zsvd9.png)


**SAM Application**
Let's follow the popular [SAM example](https://github.com/aws/aws-sam-cli-app-templates/tree/master/python3.9/cookiecutter-aws-sam-hello-python) to create a Python Hello world Lambda function.
![SAM Application](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qmatafha3rq4ppueapun.PNG)

The SAM template
![SAM Template](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n7eqaiskslll5x1164x3.png)
As an extension of the Cloudformation templates, SAM templates will follow the same format. This means that we are able to use in the SAM templates the same references/structure that we use on Cloudformation. At the beginning of the above template file, the key difference with normal CloudFormation templates:

```
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
```

The Transform property tells CloudFormation how to handle the template, and allows you to use the SAM resource types.


**Build and Deploy**
Just run **sam build**
This compiles your source code and builds any dependencies that you have in the application. It then moves all the files into the .aws-sam/build folder so that they are ready to be packaged and deployed. It also updates the template.yml file accordingly.

**Test Application Locally**
The SAM CLI provides the sam local command to run your application locally. This internally uses Docker to simulate the execution environment of Lambda.

`sam local invoke "Hello" -e event.json`

Here you are invoking the function Hello using as the event source the mocked event.json file.

**Other Resources SAM Types**
AWS::Serverless::HttpApi — creates an HTTP API instead of a REST API (check here the diferences between both).
AWS::Serverless::LayerVersion — creates a Lambda LayerVersion with library or runtime code that is required by the lambda function.
AWS::Serverless::SimpleTable — creates a DynamoDB table that just covers the simple use case of a table with a single attribute primary key.
AWS::Serverless::StateMachine — creates an AWS Step Functions state machine to form complex workflows.
Laravel 9 - Prunable trait to automatically remove models from your database
Tags: laravel, php, webdev, programming
Published: 2022-09-28 14:48:52

You can use the **Prunable** trait to automatically remove models from your database. 

(ex.) You can permanently remove soft deleted models after a few days.
```
class ExampleClass extends Model
{
    use SoftDeletes;
    use Prunable;
    
    public function prunable()
    {
        // Files matching this query will be pruned
        return static::query()->where('deleted_at', '<=', now()->subDays(14));
    }
    
    protected function pruning()
    {
        // Remove the file from s3 before deleting the model
        Storage::disk('s3')->delete($this->filename);
    }
}
```

Add PruneCommand to your schedule (app/Console/Kernel.php)
```
$schedule->command(PruneCommand::class)->daily();
```
OSD600 Lab 3
Tags: opensource, cpp, beginners
Published: 2022-09-28 14:47:51

In this lab, I added to my SSG program ([SauSaGe](https://github.com/rudychung/SauSaGe)) in order to demonstrate the process of working with and merging parallel branches in a project. 

## What I added
I chose to add features to the existing Markdown parsing functionality of my program that allowed for replacing either a set of three dashes (---) or asterisks (***) with a horizontal rule \<hr> tag ([#13](https://github.com/rudychung/SauSaGe/issues/13)), as well as parsing of a set of backticks (`) to create a set of \<code> tags  ([#14](https://github.com/rudychung/SauSaGe/issues/14)). 

## The changes
I was fortunate enough that my code was modularized such that it was easy to add these two features in without disrupting the existing infrastructure. For the horizontal rule change ([b27e0b91](https://github.com/rudychung/SauSaGe/commit/b27e0b91274a422951fe592aa7574683b892aed2)), I used the existing infrastructure that was provided by [#10](https://github.com/rudychung/SauSaGe/pull/10) to create my own addition. For the code tag change ([03d7c91b](https://github.com/rudychung/SauSaGe/commit/03d7c91b72453987ffd9539a8a4185078d5226f5)), I again used the existing infrastructure this time provided by [#9](https://github.com/rudychung/SauSaGe/pull/9), that uses the regex library in C++ to perform token replacements while preserving the token contained between the two matched tokens. 

## Merging Changes
Merging was a relatively smooth process for the two branches I created, since there were no conflicts between the branches I was merging. In the previous lab however, I did deal with some conflicts having to reconcile code between [#9](https://github.com/rudychung/SauSaGe/pull/9) and [#10](https://github.com/rudychung/SauSaGe/pull/10), since they both added related features. These problems were compounded with the fact that I had some commits that I made which changed the file structure of my project, and altered parts of my code that were not pushed. This caused a whole bevy of problems that I had to reconcile while merging the two pull requests I received. 

## Lessons for the future
In the future, I will try to push any changes as soon as possible, especially if I am anticipating any pull requests. I will continue to try to keep my code modular as it greatly eases the process of merging changes from pull requests or otherwise to the main branch.
kafka consumer
Published: 2022-09-28 14:44:11

## 分配策略

1. range

8个partition，3个consumer：
`consumer 1: partition 1、partition 2、partition 3
consumer 2: partition 4、partition 5、partition 6
consumer 3: partition 7、partition 8 `


1. round robin

`consumer 1: partition 1、partition 4、partition 7
consumer 2: partition 2、partition 5、partition 8
consumer 3: partition 3、partition 6 `


1. 
sticky
Skype Personal integration with C#
Tags: help, csharp, winform, skype
Published: 2022-09-28 14:32:37

It's been weeks of searching everywhere but couldn't find any help and finally i'm posting my query here.

I'm not finding a way to integrate Skype Personal (Not Skype Business/Lync) in my c# application. I just want to receive Skype messages on my application from the skype installed on the machine. I have tried using Skype4com Library but it has discontinued and does not support the latest Skype and LYNC API also works only with Skype for business and same with Skype Web SDK as it does not work with Skype personal. I also tried the method to fetch the details through Skype local database but latest version of Skype doesn't store anything locally.

**Note: There are still some applications with Skype integration that I know but I don't know how they do that.**
Vite React Build Options - Rollup.js
Tags: vite, react
Published: 2022-09-28 14:12:56

My recent project in React Boostraped with Vite gave me a tough time. Mostly because it was my first time using Vite, of course l used it cos it's rendering speed. l came across an issue where l had to add OneSignalSDKWorker file `OneSignalWorker.js` in the root folder. In development it worked but not on production. This was because during build Vite ignored any file in the src and root folder that had no attribute/linkage to the project (to reduce size of the minified bundle).

I had to find a work around it. The first attemt was to use `rollup.js`. There are Build options for Vite in `vite.config.js` that can be changed [](https://vitejs.dev/config/build-options.html). Here's what l did with the rollup options: 

```
build: {
    rollupOptions: {
      input: {
        app: './index.html',
        'OneSignalSDKWorker': './OneSignalSDKWorker.js',
      },
      output: {
        entryFileNames: assetInfo => {
          return assetInfo.name === 'OneSignalSDKWorker' ? '[name].js' : 'assets/js/[name].js'
        }
      },
    },
  },
```
In the code block above we get our inputs. the app options is for the entry point and the second one is assigning a variable to the directory with the file. During build the file be placed in the dist root folder.

**Exception:** This works with .js files and other es build types.

For adding general files in the root folder, create a directory in src and name it public. You can now place all of your files into that folder. On build, all files will appear in the dist root directory.

Read up more on rollup.js [](https://rollupjs.org/guide/en/)
Cheers!
Algorithm part 5: Generate as many Binary number as you want
Tags: java, algorithms, problem, binarynumber
Published: 2022-09-28 14:05:54

Hello, Guys. Today i will show you how you can generate as many Binary numbers as you want.

I'll be using Java Language and Queue Data Structure.

Solution
```java
public String[] generateBinary(int n){
        String[] result=new String[n];
        Queue<String> queue=new LinkedList<>();
        queue.offer("1");
        
        
       for(int i=0;i<n;i++){
            String poll=queue.poll();
            String n1=poll+"0";
            String n2=poll+"1";
            result[i]=poll;
            
            queue.offer(n1);
            queue.offer(n2);
            
        }
        return result;
    }
```
Hope this helps you. Thank you ❤.
How to choose temporary email address?
Published: 2022-09-28 13:57:03

There are numerous [disposable email](http://tempmail.ink) services available today, and it can be hard to decide which one to choose. These are the key things to keep in mind when selecting the best [**temp email**](http://tempmail.ink) service.

**- Websites that don’t to register**
We use [**temporary mail**](http://tempmail.ink) to protect our privacy and convenience, so try to choose temporary mailboxes that do not require registration.

**- [Temp mail](http://tempmails.info) service easy to use**
If the temporary mailbox is too complicated, it will waste our time, so try to choose a simple and easy to use temporary mail service.

**- Ensure temp email address is anonymous**
Temporary mail must be anonymous,it's very important to us.

8 temp mail you can choose:

1 [10 minute mail](https://10-minutemail.com/) 
https://10-minutemail.com/

2 [temp mail](https://tempmail.ink) 
https://tempmail.ink

3 [temp mail](https://www.mailtemp.net/) 
https://www.mailtemp.net/

4 [temp mail](https://tempmails.info) 
https://tempmails.info

5 [10 min mail](https://email10min.net/) 
https://email10min.net/

6 [ten minutes mail](https://tenminutesmail.net/) https://tenminutesmail.net/

7 [10 min mail](https://10-minutemail.net) 
https://10-minutemail.net

8  [10 min mail](https://10-minutemail.org) 
https://10-minutemail.org
Terminal-based Battleship Game in Python3
Tags: python, gamedev, bash
Published: 2022-09-28 13:38:24

As part of my final project for the CS101 module of the computer science path in codecademy, I made a terminal-based battleship game in which you can play against the computer. The game is written in python3 and it was fun to make.

Each player (you and the computer) have a 7x7 grid to place their ships. There are 3 ships to place: Warship, Cruiser and Destroyer.

I have defined different classes for the main game objects, f.e. ship, grid, player. The computer player which I named HAL is a class that inherits from the player class. The game routine itself is a class named Battleship and it as a play function.

By making a game from the Battleship class HAL gets initialized and his ships get placed. By calling play() you as the player must enter your name and the starting point and alignments of your ships, so that they can be placed in your grid.

After all ships have been placed you and HAL take turns in shooting by giving a x-y-point to the shoot function of the Player class. Each player has also a shot list to keep track of his shots. If a ship is hit, the ship’s own hit attribute gets increased. The Ship class also provides an is_destroyed() function to check if a ship is destroyed. This is done by simply checking if the hit count is equal to the ship size. After each shot there is a check whether all enemy ships are down and the game is won. Each time you make an input, you can type „q“ of „Q“ to quit the game.

The game helped me to dive into python3 and I feel like there are still many ways to optimize the code and the game. F.e. I think it would be nice to have all the texts in one place and not distributed over the code. Maybe something like an TextHandler class that validates all inputs and prints out all texts. A restart function could also be nice.

If you are interested in trying the game you can find it here:
https://github.com/ptrick72/Battlehsip-Game.git

This is how the game looks like:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/35bdr0c7pxovddaolvfp.png)
Palindrome Number
Tags: javascript, python, algorithms, beginners
Published: 2022-09-23 20:33:59

Ooof! It's day 3 of the #I4G10DaysOfCodeChallenge and the question was to do a palindrome check on a number without first converting it into a string😪. Today's challenge was kind of tough for me, because I was familiar with first converting to a string to check for palindrome.

I was only able to solve the challenge with JavaScript this time. 
I first did a check to eliminate negative numbers and numbers that ended with zero.
![JavaScript Solution](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wf4a542gnyolkw6spoqx.png)

Then I used some kind of logic to reverse the number as long as the number is greater than zero. And checked if the initial number was equal to the reversed number, or if it was equal to the reversed number divided by 10 for odd numbers.

I would love if someone could put me through the logic for python.
Below is the link to the challenge 

https://leetcode.com/problems/palindrome-number/

Thank you❤️
New Course Alert
Tags: firebase, webdev, tutorial
Published: 2022-09-28 13:34:16

Hello all, 

I'm THRILLED to announce that my Firebase course is now live on Educative, Inc. This course took a lot of time to create, and I am extremely proud of it.

It truly was an exciting experience for me, and I thoroughly enjoyed working with the team at Educative Inc to create this course. It was also a huge learning opportunity for me as I found myself looking through Docker and tmux documentation multiple times, haha!

The course is tailored for beginner-intermediate Firebase developers and contains all you need to know to get started with Firebase. It comprehensively discusses Firebase services and demonstrates the usage and implementation of these services in a real-world application using Educative's in-app SPA widget. 

Kindly like, share, and recommend it to anyone who wants to learn Firebase! 

[Link to course](https://www.educative.io/collection/6586453712175104/4892772506533888)
Laravel 8 Class NumberFormatter Not Found
Tags: laravel, laravel8, errors, php
Published: 2022-09-28 13:34:04

In this article, we will see laravel 8 class 'numberformatter' not found. For numberformatter we need PHP 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0 and I have PHP 7 and intl still face numberformatter not found in laravel. class numberformatter not found in laravel 8 or class numberformatter not found in PHP just follow simple two solutions.

Let's see how to fix the laravel 8 class numberformatter not found.

> Solution 1:
 
You just need to enable this extension in php.ini by uncommenting this line.

```
extension=ext/php_intl.dll
``` 

> Solution 2:

In this step, we need to install PHP Intl Extension for it. So, let's open the terminal and run the below command.

```
sudo apt-get install php7.4-intl
```

To check the successful installation, run the command php -m. This should show the intl package in the list.
Algorithm part 4: Check if a string is palindrome or not
Tags: java, dsa, string, problem
Published: 2022-09-28 13:26:42

Hey, Guys. Today i am going to show you How you can check if a string is palindrome.

### what is palindrome?
Suppose you have a string `mom`. Now if you reverse this string you get `mom` again. So this is a palindrome string.

Solution
```java
public boolean isPalindrome(String str){
        char[] arr=str.toCharArray();
        
        int i=0;
        int j=arr.length-1;
        
        while(i<j){
            char temp=arr[i];
            arr[i]=arr[j];
            arr[j]=temp;
            
            i++;
            j--;
        }
        
        return str.equals(new String(arr));
    }
``` 
Hope this helps you. Thank you ❤.
Algorithm part 3 : Reverse a string using Stack
Tags: stack, java, string, problem
Published: 2022-09-28 13:23:06

Hey, Guys. Today i will show you how you can reverse a string using  stack.

In this problem we are given a single string and we have to reverse it using stack.

Solution
```java
public String reverse(String str) {
        Stack<Character> stack = new Stack<>();

        for (int i = 0; i < str.length(); i++) {
            stack.push(str.charAt(i));
        }

        char[] arr = new char[stack.size()];
        int i = 0;
        while (!stack.empty()) {
            arr[i] = (char) stack.pop();
            i++;
        }

        return new String(arr);

    }
```

Hope this helps you. Thank you ❤.
D3, why D3?
Tags: javascript, chart, webdev, beginners
Published: 2022-09-28 12:52:51

What if you want to create a chart that no one has ever used and only you know its functionality ,only you know it looks and you don't know its name, it is completely a new dish which you want to make. In this case what will you do? You can consider using d3.

**What is D3?**
Data Driven Documents, if you want to make charts in your application that are using dynamic data then d3 is the right choice. D3 serves you a lots of chart options to visualise data, you can customise your charts, can remove or add any functionality from your chart. D3 provides more flexibility and control as it directly manipulates the DOM.

**Why D3? Benefits of using d3**

Currently D3 is famous and has large community of users as compared to other libraries.

D3 is more than a normal visualisation library, it can help to create animations, diagrams and many more as it works with html, css and svg.

-> D3 helps us to **create customised charts**, unlike many other available charts libraries where we just use the given code template to create chart, these can be easy to use but comes with lots of restrictions as we'll not be able to modify the charts according to our need, we are just left with their chart design, as a result chart look and experience will be too common whereas, d3 does not provides us such templates, it provides us helper functions, these helper functions works at basic level like DOM selection, creating axis. Moreover d3 provides us the flexibility to create our own helper functions.
In short, only we define each and every thing in our graph while using d3, which helps us to make more customised charts.

-> In other chart libraries, while using a specific type of chart, the structure of the input data is already defined, so we are restricted to provide same structure of input data, whereas in d3 we can customise it as well.

->D3 is open source, large number of chart options are available, many examples are also available, large community and users as compared to others.

-> D3 can be easily used with other JS based frameworks like react, angular.

**Problems we can face while using d3:**

-> If you are new to d3 then you might find the syntax a bit confusing, but we have a solution for that too. 
Start by practicing the simplest chart or may be start by creating a simple square diagram using d3. Notice how d3 is manipulating DOM< how helper functions are working.
In [next blog](https://dev.to/modgil_23/let-us-understand-d3-4dk1) we'll try to understand working of d3 in simplest way.

Other chart frameworks are easy to use but as you know they come with lot of restrictions.

-> No doubt that d3 is compatible with JS based frameworks but sometimes you can face problems while using d3, just look if you are using the right version of d3 that is compatible with your JS framework.

Let me know your thoughts about d3 in comments and what library do you use for making charts in your applications?
COMBINE TWO TABLES
Tags: sql, database, datascience, beginners
Published: 2022-09-28 12:48:33

**Chalenge**
Write an SQL query to report the first name, last name, city, and state of each person in the Person table. If the address of a personId is not present in the Address table, report null instead.

Return the result table in any order.

Check [leetcode](https://leetcode.com/problems/combine-two-tables/description/) for more info.

**Approach**
In this challenge we are to write a SQL code to read data from two separate tables. let's review some basis of SQL and the SQL statements I  would use.

SQL is a language used to interact with the database. SQL stands for Structured  Query Language.

`select` clause tells the query what column to read from the data.

`from` clause tells the query what data to use

`join`clause tells query on additional table from which you would love to pull data

`on` clause specifies a logical statement to combine the table in from and join statement.

Now that we understand this basis, to solve this challenge, I wrote my query using `select` clause to the pull the  firstname, lastname, city and state column. I used the `from` clause to specify the table I want to pull data, then used the `join`clause to specify the other table I needed to pull data from and finally, `on` clause which I used to combine both tables in join.
q-google-map - Integrate google map in the Quasar 2, Vue 3 project using the Quasar extension - easy steps
Tags: vue, opensource, quasar2, github
Published: 2022-09-28 12:41:41

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xfnhw8bi597fi73r2mg.png)
Website - https://q-google-map.netlify.app/

Quasar Framework is a great UI framework that provides lots of ready-to-use components which are well tested on the web, iPad, mobile, and all devices.

q-google-map is a Quasar app extension written using Quasar 2 and Vue 3 to integrate Google Maps in any Quasar project. It works with Quasar 1.X as well as 2.X.

Demo and Documentation - https://q-google-map.netlify.app/
GitHub - https://github.com/mayur091193/q-google-map

To install the extension, use the below command:
```quasar ext add q-google-map```

To uninstall the extension, use the below command:
```quasar ext remove q-google-map```

In **quasar.conf.js**, add below:

```
...
build: {
  ...
  env:{
      options: JSON.stringify({
          load: {
            key: 'xxxxxxxxxxxxxxxxxxxxxx'
          },
          installComponents: true
      })
    },
  ...
},
...
```

Front-end code - HTML and script

```
<q-google-map :center="center"
              :zoom="zoom"
              style="width: 320px;height: 230px;">
</q-google-map>

data() {
    return {
      center: { lat: 20.7937, lng: 78.3629 },
      zoom: 4
    }
}
```

mayur091193@gmail.com