teleren/devto huggingface dataset:
Downloading a file from S3 using API Gateway & AWS Lambda
Tags: apigateway, s3, lambda, aws
Published: 2023-07-11 05:47:32


## Downloading a file from S3 using API Gateway & AWS Lambda

In my last post I showed how we can create and store a csv file in an S3 bucket. Let us now see how we can get the status of a request & get a downloadable link to the csv for completed requests.

**The Get Status lambda**

Under the src directory, create a new file called “get_status.py” with the below code -
{% gist https://gist.github.com/karthiks3000/d9cbddb0db022bedc482833948327dc4.js %}
Add the new file to Dockerfile -

![Dockerfile](https://cdn-images-1.medium.com/max/2000/1*-7JaAqIdOyVMCV-Q3qY_Vw.png)

Update the template.yaml file and add a new resource -
{% gist https://gist.github.com/karthiks3000/3330ff0572ab99edf03d3e7a912a9adf.js %}
**Testing locally**

We can test the endpoint locally, but before that we need to update the env.json and include the S3 bucket name -

![env.json](https://cdn-images-1.medium.com/max/2000/1*eOG6KyrZ3UgvBuVqHoTy5w.png)

Build and start the api locally -

    sam build
    sam local start-api --env-vars ./tests/env.json

You should see an output like -

![Console output](https://cdn-images-1.medium.com/max/2000/1*OZqRbnTZWmzYtOSnwy7szw.png)

Trigger a new request & grab the request id from the DB (since the post will fail without an SQS queue defined). Then test the get status call -

![postman](https://cdn-images-1.medium.com/max/4292/1*HVkU63Q2RBiYkCdc3pqHBA.png)

**Deploying the code**

Just like before, we need to specify an image repository for the new lambda function. Update the samconfig.toml file and add another item to the image_repositories list for GetStatusFunction -

    image_repositories = ["CreateFunction=541434768954.dkr.ecr.us-east-2.amazonaws.com/serverlessarchexample8b9687a4/createfunction286a02c8repo",
    "ProcessFunction=541434768954.dkr.ecr.us-east-2.amazonaws.com/serverlessarchexample8b9687a4/createfunction286a02c8repo",
    "GetStatusFunction=541434768954.dkr.ecr.us-east-2.amazonaws.com/serverlessarchexample8b9687a4/createfunction286a02c8repo"]

Deploy the code to aws -

    sam build
    sam deploy

The output should look like this -

![console output](https://cdn-images-1.medium.com/max/2000/1*dN7HKnhBXos0X23aoWjY9g.png)

Grab the get-status endpoint url and try making a request through postman for one of the completed orders from before -

![postman](https://cdn-images-1.medium.com/max/5588/1*864f8rDrPeAhEAKiTDlGKA.png)

Cmd+Click on the download_link to download the csv file from S3.

And thats it! The SAM CLI has enabled us to leverage infrastructure-as-code to deploy our entire architecture to any aws account within minutes!

**Source Code**

[Here](https://github.com/karthiks3000/serverless-arch-example) is the source code for the project created here.

Next: Part 7: AWS Lambda & ECR nuances
Writing a CSV to S3 from AWS Lambda
Tags: s3, lambda, serverless, aws
Published: 2023-07-11 05:41:39


## Writing a CSV to S3 from AWS Lambda

In the last post I explained how to scrape a url with selenium and extract the number of search results returned by google for a query string. Let us now see how to insert these results into S3 as a csv file.

**Setting up the S3 bucket**

Update the template.yaml file and add a new resource for the S3 bucket -

![template.yaml file](https://cdn-images-1.medium.com/max/2000/1*hghapdUyOmrvNu091TirLQ.png)

When defining the bucket we have specified a few additional properties -

* LifecycleConfiguration: This is optional, but I have set this so that my csvs are deleted after a day since I don’t want them lying around forever

* CorsConfiguration: In my use case I needed the objects in S3 to be available for download to anyone who has a pre-signed url. Because of this requirement I needed to specify a cors config that allowed any origin. Modify this as per your needs

Lets also define a global environment variable for the bucket name so that the lambdas have the name available to them -

![global env variables](https://cdn-images-1.medium.com/max/2000/1*0ecmtjxhenv_kqobvUIDWA.png)

We also need to ensure that the Process lambda has access to write to the S3 bucket. Add a new policy to the lambda properties -

![S3 policy](https://cdn-images-1.medium.com/max/2000/1*N8p291RDV1j0dko-oUvF9g.png)

Finally, update the Outputs -

![Outputs section](https://cdn-images-1.medium.com/max/2000/1*DvpU9vR-o0cHp1sOZahbmg.png)

Update the process.py file with the following code -
{% gist https://gist.github.com/karthiks3000/ebce00da833e30142939fb64749e0d46.js %}
***Note**: The update order status call for complete was also modified to include the csv file name*

**Deploying & Testing**

Unlike before, we are going to first deploy our changes to aws so that the S3 bucket gets created and then test our code.

    sam build
    sam deploy

You should see an output like this -

![Console output](https://cdn-images-1.medium.com/max/2000/1*Q06zHQQU52VQQhJm_wV-gw.png)

**Validate the changes**

To validate the changes, lets make another post call from postman to the prod api gateway -

![postman](https://cdn-images-1.medium.com/max/4172/1*G8e1ELUGu38OKkR1Mdx2Ew.png)

Now login to aws console and check the S3 bucket, you should see the csv file created -

![s3 bucket](https://cdn-images-1.medium.com/max/3092/1*TdPAMX23laCAV9T2l7PGQA.png)

Looking at the dynamodb table we can see that the file_location was also updated with the csv file name

![dynamodb table](https://cdn-images-1.medium.com/max/2418/1*Qb3_J5-tR9VMZa-laDi74A.png)

**Source Code**

[Here](https://github.com/karthiks3000/serverless-arch-example) is the source code for the project created here.

Next: Part 6: Downloading a file from S3 using API Gateway & AWS Lambda
Clojure Composers: Introduction
Tags: clojure, coding, learning, tutorial
Published: 2023-07-11 05:33:33

Over the next week or so, I'd like to talk about Clojure's _function composition_ functions in a series of small and focused posts: Clojure Composers.

Today, I'll just discuss some composer basics.

## About

Function composers provide us moulds with which we may create other functions. If we were to put this in mathematical terms, a function composer is a function `f(x)` that returns `g(y)`.

This is great for us because rather than writing something like this...

```clojure
(map #(some complicated (code %)) stuff)
```

...we can have a composer that looks like this...

```clojure
(defn complicator [f]
  (fn [thing] (some complicated (f thing))))
```

...then write this!

```clojure
(map (compliator code) stuff)
```

Giving us a clean way of hiding the ugly stuff behind the stuff we care about.

## Anatomy

There are a couple characteristics that apply to all composers, and I'll use Clojure's simplest composer, [`constantly`][constantly], as an example.

```clojure
(defn constantly [x]
  (fn [& args] x))
```

### Parameters

A composer will take one or more arguments, and use them in some way to build out a function. In the case above, `constantly` accepts only one parameter. However, other composers such as [`juxt`][juxt] or [`comp`][comp] can take any number of arguments.

If a composer takes zero arguments, then it should either be a constant or it depends on something externally from the function.

### Return Value

We can assume the return value will always be a function, which may have any arity (usually consistent with some defined pattern). Zero, one, two, infinite... In the example above, `constantly` always returns a function that accepts any number of arguments.

## Conclusion

While we can use composers just about anywhere, I find that they really shine in functions like `map`, `filter`, or `sort-by` where there is usually already some chaining of functions happening.

Which of these do you find easier to read?

```clojure
(map #(-> % :kills :confirmed) kittens)
(filter #(-> % :kills :confirmed zero?) kittens)
(sort-by (fn [{:keys [age weight]}] [age weight]) kittens)
```

```clojure
(map (comp :confirmed :kills) kittens)
(filter (comp zero? :confirmed :kills) kittens)
(sort-by (juxt :age :weight) kittens)
```

[constantly]: https://clojuredocs.org/clojure.core/constantly
[juxt]: https://clojuredocs.org/clojure.core/juxt
[comp]: https://clojuredocs.org/clojure.core/comp
CPWD and copy the path to clipboard! (For Mac Users)
Published: 2023-07-11 05:31:57

When I found that the instances of me copying the path of the current working directory has become huge, I wanted to make it a seamless task. There, I found the power of zsh.

> Just few step and you are good to go.

1. Open the `.zshrc` file in your terminal with the below command:

```zsh
open ~/.zshrc
```

2. Add this line to the end of the file:

```zsh
alias cpwd="pwd|pbcopy"
```

3. Save and Close the file.
4. You can close your terminal and open a new terminal to see the new changes.
5. Now, if you just enter `cpwd` you can copy the current path of the directory you are in to your clipboard.
6. Go ahead and paste in anywhere you want.

Glad that helped! See ya in another hack!
What is .map() ?
Tags: javascript, beginners
Published: 2023-07-07 15:24:20

# What are methods

Methods are certain functions meant to be used for specific, repeatable purposes in your code. For instance, instead of having to write your own function that makes a string's letters all uppercase repeatedly, you can just call this Javascript method called .toUpperCase() to do it for you every time you need to.

```
String.toUpperCase()
```

One of these methods, and arguably one of the most useful of them ,is called .map(). In order to understand .map() though, we need to understand what a Javascript array is first.

# What is an array ?
An array is an iterable group of items kept inside of a pair of square brackets

```
const my_array = [1,2,3,4,5]
```
Arrays are probably the most common type of data structure that programmers come across. If we're going to be dealing with large amounts f data, we would like the ability to organize them into groups that we can reference and manipulate. Thankfully, .map() allows us to do just that!

When we call the .map() function, we give it a callback function as an argument. This is a function that is going to take all of the items in the array as an argument, one at a time, until the function has gone through the entire array. 

```
const mapped_array = my_array.map(arrayItem => {console.log(arrayItem})
```

With this code, it would print the numbers 1-5 in the console, and would also console.log anything we decide to put in the array afterwards. 

```
(result)
1
2
3
4
5
```

Now that you know what .map() is, you are prepared to expand your ability to manipulate arrays in order to solve more complex problems than you could before. Good Luck!
An Exclusive Sneak Peek at the Future of Virtual Shopping
Tags: 3dvirtualstore, 3dstore
Published: 2023-07-11 04:46:17


## Introduction: 

[Virtual store](https://www.metadrob.com/) purchasing has been increasingly popular recently, offering customers a practical and engaging substitute for conventional brick-and-mortar shopping. The future of virtual store shopping holds enormous promise for changing how we shop as technology develops at a rapid rate. We will examine the fascinating developments and trends that lie ahead in the world of online store shopping in this special sneak peek.

## Enhancing Virtual Reality (VR) Experiences: 
Virtual reality has already created a stir in the gaming sector, but it is now set to transform how we shop. Put on a virtual reality headset and visualise yourself entering a store where you may peruse the aisles, grab items, and even try them on before making a purchase. A more immersive and interesting environment will be produced by improved VR experiences, bridging the gap between online and in-store buying.

Integration of Augmented Reality (AR): Augmented reality (AR) complements virtual reality by superimposing digital elements on the physical environment. Virtual store purchasing platforms will soon incorporate augmented reality (AR) technology, enabling buyers to see how things might appear in their homes or on their mobile devices.

## Personalized Recommendations and AI-powered Assistants: 

Thanks to improvements in artificial intelligence (AI), virtual store shopping will become more sophisticated and personalized. In order to offer highly customized recommendations, shopping platforms will use AI algorithms to analyze client preferences, purchase history, and behavior. Virtual assistants powered by AI will help customers navigate the virtual store, respond to questions, and make recommendations that are unique to them, simulating the assistance offered by actual store personnel.

## Social Shopping and Shared Experiences: 
Shopping has always had a social aspect, and [virtual store](https://www.metadrob.com/fashion) shopping will enhance this social connection even further. Platforms will introduce features that allow shoppers to interact with friends and family in real-time while exploring virtual stores together. Virtual shopping parties, where groups of people can shop and chat simultaneously, will become increasingly popular, making the shopping experience more enjoyable and sociable.

## Conclusion:
The future of [virtual store shopping](https://www.metadrob.com/fashion) is incredibly promising. With advancements in VR, AR, AI, and integration with offline shopping, consumers can look forward to a highly personalized, immersive, and convenient shopping experience. As the boundaries between the digital and physical worlds continue to blur, virtual store shopping will offer exciting opportunities for retailers to connect with customers and for shoppers to explore a world of endless possibilities. So get ready to step into a new era of retail, where virtual stores become a gateway to an extraordinary shopping adventure.
Sécuriser le contenu de votre compartiment S3 grâce aux Bucket policy.
Tags: security, aws, s3
Published: 2023-07-11 04:43:45

Ce article montre juste des pratiques simples et efficaces pour améliorer la sécurité des objets dans un compartiment AWS S3 en fonction d'un besoin précis.

Qu'est-ce que la politique de compartiment (**Bucket policy**) ?

> 
La politique de compartiment (Bucket policy) d'AWS S3, sert à sécuriser l'accès aux objets de vos compartiments, afin que seuls les utilisateurs disposant des autorisations et des règles d'accès appropriées puissent y accéder. Elle permet de contrôler qui peut accéder aux objets stockés dans le compartiment, comment ils y accèdent et quelles opérations ils peuvent effectuer sur ces objets.

Dans quel cas peut-on utiliser la politique de compartiment (bucket policy) sur AWS ?

Vous verrez quelques cas d'utilisation courants de la politique de compartiment sur AWS 


1. ***Accès entre comptes AWS***: Vous pouvez utiliser une politique de compartiment pour autoriser un autre compte AWS à accéder à des objets spécifiques dans votre compartiment S3. Cela peut être utile pour le partage de données entre différentes équipes ou services. 

2. ***Accès conditionnel***: Les politiques de compartiment permettent également de définir des conditions spécifiques pour l'accès aux objets. Par exemple, vous pouvez exiger que les demandes d'accès incluent un en-tête d'authentification particulier ou qu'elles proviennent d'un endroit spécifique.

3. ***Partage de contenu statique***: Si vous souhaitez héberger des fichiers statiques (par exemple, des images, des vidéos ou des fichiers HTML) pour un site web ou une application, vous pouvez utiliser une politique de compartiment pour permettre un accès en lecture à ces fichiers tout en restreignant ou en empêchant la modification ou la suppression par erreur. Ceci peut être utiliser pour des fichiers statiques sensibles.

4. ***Accès public restreint***: Vous pouvez utiliser une politique de compartiment pour limiter l'accès public à un compartiment S3 spécifique. Par exemple, vous pouvez configurer une politique pour autoriser uniquement certaines adresses IP ou plages d'adresses IP à accéder aux objets du compartiment, tout en refusant l'accès aux autres.

5. ***Intégration avec CloudFront***: Si vous utilisez Amazon CloudFront CDN pour distribuer du contenu en mode edge(le réseau mondial de serveurs en cache de CloudFront pour livrer des données aux utilisateurs finaux à partir d'emplacements géographiquement distribués), vous pouvez configurer une politique de compartiment pour travailler en conjonction avec CloudFront, en spécifiant des règles d'accès et de distribution pour vos objets.

Pour en savoir beaucoup plus sur ces différents cas d'usages avec des exemples [Voir le lien de la documentation d'AWS](https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies.html)
Praying Mantis: The Head Turner
Tags: facts, fact, amazingfact, animalfact
Published: 2023-07-11 04:27:52

Praying mantises are fascinating creatures that are sure to turn heads. They are predators that use their camouflage and sharp claws to ambush their prey.

Discoverybit shares valuable mind blowing facts, funny facts, did you know, and great facts. Follow us on our social media.

https://www.youtube.com/watch?v=N1jaXjjMgBs&ab_channel=DiscoveryBit
Short Ruby Newsletter - edition 50
Tags: ruby, news, published, newsletter
Published: 2023-07-11 03:52:37

Yesterday I published the 50th edition of [Short Ruby News](https://newsletter.shortruby.com/p/edition-50)

Here are some topics that you might find there: 

- 3 new Ruby projects launched that are worth checking out
- updates from Ruby conferences
- sample code of how to use Dry::Transaction
- performance comparison of passing blocks to method calls in Ruby
- How to copy data to a clipboard from Ruby REPL 
- Making a class inherit from Module as a way to generate a parameterized module dynamically
- Routing concerns example
- using `.tap` for debugging method chains
- a link to a PR discussing adding a new meta tag for AI-generated content
- a new Github Repo for docker-rails-example
- a lot of gem updates

And, like always, a good selection of articles, newsletters, talks, and screencasts, all published in the last week.

Read it all for free at [https://newsletter.shortruby.com/p/edition-50](https://newsletter.shortruby.com/p/edition-50)
Access modifier
Tags: java, oops, coding, devops
Published: 2023-07-11 03:49:11

In Java, are there clear rules on when to use each of access modifiers, namely the default (package private), public, protected and private, while making class and interface and dealing with inheritance?
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e1rligytai1wkuerolsm.jpg)

**Ans:**
**private** hides from other classes within the package. 
**public** exposes to classes outside the package. 
**protected** is a version of public restricted only to subclasses.

**For example**, if I have MyClass and I'm doing AnotherClass extends MyClass I will have access to all protected and public methods and properties from within AnotherClass. If I do MyClass myClass = new MyClass(); in AnotherClass somewhere - let's say the constructor - I will only have access to the public methods if it is in a different package. Note that if I do = new MyClass() { @Override protected void protectedMethod() { //some logic } }; it appears that I can access protected methods, but this kind of the same as extending it, but inline instead.
Vite environment variable's type casting/transforming
Tags: vite, typescript, development, env
Published: 2023-07-11 03:46:10

## Introduction

When developing a frontend app, we usually use environment variables(env) to store app's config, secret key,...And Vite, a popular development tool, also support env file, with Typescript supportted. But, all things we get from it is `string` and  we need to update `ImportMetaEnv`anytime we add new variable.

So, package `vite-env-caster` is published to solve these issues.

## Installation
Install package using `yarn` or `npm`:

**npm**
```sh
npm i @niku/vite-env-caster --save
```

**yarn**
```sh
yarn add @niku/vite-env-caster
```

Then add `EnvCaster` to you Vite's plugins.

```ts
// vite.config.ts
import EnvCaster from '@niku/vite-env-caster';

export default defineConfig({
  plugins: [
    EnvCaster({ /* options */ }),
  ],
});
```

## Usage

### Environment variable's type casting

Instead of `string`, you can use your `env` with it own type.

**Example:**

You have a file `.env` like this:

```
VITE_API_URL=http://example.com
VITE_DEFAULT_PAGE_SIZE=10
VITE_FACEBOOK_AUTH_ENABLED=false
VITE_ARRAY_EXAMPLE=[123,abc,def,456]
```

Then, you can import and use it's variables by import as a module (default `app-env`).

```ts
// src/main.ts
import appEnv from "app-env";

console.log(appEnv.VITE_API_URL) // "http://example.com"
console.log(appEnv.VITE_DEFAULT_PAGE_SIZE) // 10
console.log(appEnv.VITE_FACEBOOK_AUTH_ENABLED) // false
console.log(appEnv.VITE_ARRAY_EXAMPLE) // [123, "abc", "def", 456]
```

### Typescript support

To using `env` with **Typescript**, You just need to include it in your `tsconfig.json`. By default, file `env.d.ts` will be generated at root of project.

```json
{
  "include": ["env.d.ts"]
}
```

Then, you will get auto complete like this.

![Vite env caster](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ft2gejg1eu5xiiafsbbq.png)

## Conclusion

Thanks for reading, I hope that this post is useful to you.
艺术二维码产品 hysli.io
Published: 2023-07-11 03:06:21


## 背景
随着ControlNet模型的流行，最近国外有些大佬使用 Stable Diffusion配合ControlNet模型，生成了非常美丽的艺术二维码。偶然间发现国内有小伙伴，已经做出了艺术二维码的产品。[https://hysli.io/](https://hysli.io/)  


**UI真的很精美！**
![image.png](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e90ba26d13954e8d9904d5b1d521d2ff~tplv-k3u1fbpfcp-watermark.image?)

## 产品特性
- UI精美
- 操作简单
- 支持中文提示词
- 背景图锁定
- 支持二维码和图片艺术性自动调整

## 先入为主

大家可以感受一下，来自AI艺术二维码的震撼

![111111.jpg](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/98bedeaa0ebb494a9700daad4c20e239~tplv-k3u1fbpfcp-watermark.image?)

<br/>

![29621826184.jpg](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a8a41397139c45468948115c674877a0~tplv-k3u1fbpfcp-watermark.image?)

<br/>

![374166211755.jpg](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e4f09551e76b4af8aacbf910c2dcc1ba~tplv-k3u1fbpfcp-watermark.image?)

<br/>

![image (2).jpg](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/87c058f3fd3041b28969d1dd25426401~tplv-k3u1fbpfcp-watermark.image?)

<br/>

![image (3).jpg](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c9480d3d4e4c44bdb63cc3de929b93b3~tplv-k3u1fbpfcp-watermark.image?)

<br/>

![image (6).jpg](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/87ace50c10ee41d6ad3355028bcbccf9~tplv-k3u1fbpfcp-watermark.image?)



**大家可以尝试扫一下上面的艺术二维码图片，整个扫码过程非常顺畅**



## 使用教程


**1. 首先打开这个[网站](https://hysli.io/)**
![image.png](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e25828b2c4ca4801b1fa877aed60ec14~tplv-k3u1fbpfcp-watermark.image?)


**2. 然后进入「ArtQR 智绘二维码」**

![image.png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/067b5ab7ec7545f493836263f7d52083~tplv-k3u1fbpfcp-watermark.image?)



**3. 接下来，可以上传自己的二维码，也可以直接输入网址或者文本来直接生成二维码。**

![image.png](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/efdbc31d4de748b7bf93eaf090caf10f~tplv-k3u1fbpfcp-watermark.image?)


**4. 使用内置样式，进行绘制**

![image.png](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/6aec9ebd8df0476ea50d13d89b57308b~tplv-k3u1fbpfcp-watermark.image?)


**5. 使用绘画模式，进行绘制**

![image.png](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/ae5c0462e7874614a39389fb7b5ad27a~tplv-k3u1fbpfcp-watermark.image?)




**6. 如果出图效果不满意，可以重新绘制进行调整**

![image.png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/3999936533fa4308b0be73e64fdb478a~tplv-k3u1fbpfcp-watermark.image?)

<br/>

![image.png](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/7dc6cf95f8754151a365e913105e4ffa~tplv-k3u1fbpfcp-watermark.image?)


更多功能欢迎大家[体验❤](https://hysli.io/)