teleren/devto huggingface dataset:
Direct download from Azure Blob storage using Content-Disposition header to set the filename
Tags: azure
Published: 2023-09-21 14:02:30

---
title: Direct download from Azure Blob storage using Content-Disposition header to set the filename
published: true
date: 2023-08-11 22:00:00 UTC
tags: Azure
canonical_url: https://mindbyte.nl/2023/08/12/direct-download-from-azure-blob-storage-using-contentdisposition-header-to-set-the-filename.html
---

For an application I m building, I store attachments on Azure in blob storage. This service is a relatively cheap and scalable solution for files that need to be retrieved again by others.

I have set the container to be a public one, and by generating random file names, I have some obfuscation so that iterating over them becomes complicated, but the URL is still sharable. These GUIDs also allow me to avoid name collisions as it is user input where I have no saying in what they upload.

But when you now want to retrieve the file, you get that random file name and not the original one it was uploaded with.

I can download the file to my server first and then return it with a correct name, but this will bring the additional IO to my system. I rather have people directly hit the Azure infrastructure.

Luckily you can set the `content-disposition` header. This header tells the client what to do with the file, like showing it inline or downloading it, and what the filename needs to be. This property is in there for some years, so you can set this directly using the SDK when you create a file:

```csharp
 var blobName = $"{cId}/{rId}/{Guid.NewGuid():N}.{extension}";
 
 BlobClient blobClient = containerClient.GetBlobClient(blobName);

 // Upload a byte[] to a blob
 await blobClient.UploadAsync(
 new MemoryStream(attachmentContent),
 new BlobHttpHeaders
 {
 ContentType = attachmentType,
 ContentDisposition = $"attachment; filename=\"{attachmentName}\""
 });

 string downloadUrl = blobClient.Uri.AbsoluteUri;

```

However, when I now used the public URL, I still got the long GUID-like name back, and the `content-disposition` header was missing. It appears that you need to specify the `x-ms-version: 2019-12-12` header as well. This is a bit annoying to set on a GET request in a browser as you cannot specify any headers, so we need to force the storage account to always use this version.

There is no easy dropdown in the portal, and as it is a once-off action, you can use the Cloud Shell (with Powershell) to do this:

```powershell
$ctx = New-AzureStorageContext -StorageAccountName name-of-storageaccount -StorageAccountKey your-access-key
Update-AzureStorageServiceProperty -ServiceType Blob -DefaultServiceVersion 2019-12-12 -Context $ctx

```

When you now fetch the file using the public url, you get the header included and as such the correct filename. But it took me some while to figure out that this is not the default behaviour of the storage account, so make sure to check the `DefaultServiceVersion`.
Day 803 : Reachin' 2 Much
Tags: hiphop, code, coding, lifelongdev
Published: 2023-08-11 21:37:38

_liner notes_:
- Professional : Today was a half day at work so I mostly responded to community questions, caught up with the engineering team, and worked on a demo project with some new features.

- Personal : Picked up some projects on Bandcamp and created the posts for the different social media sites I would post to the next day. Refactored some code in my side project to return some info from the back end to the front end depending on if the person is logged in and authorized. Also worked on some screens for pages of my side project. The designs are simple because at the end of the day, if someone else wants to spin up their own and want to customize it won't have to be reaching too much to try and figure out how to undo things.

![A field of tall grass on a hill in Scotland, United Kingdom with the sun setting behind a hill.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4b6of9pyrx27npdqs5f.jpg)

Since it was a half day, I took a nap and then started working on the radio show early and got a bunch of stuff done. I added new batteries to the recorder I use on the radio show to test it out and it worked! Great, don't need to be another one. About to finish up the radio show, eat dinner and work on my side project. Going to see if I can get the video elements showing up for the host. I've also been meaning to watch the new Dragon Ball Z movie so may end the night with that.

Have a great night and weekend!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube _2NzCWKcPaA %}
Mchezo - Specialists in sports, entertainment & gaming infrastructure
Published: 2023-08-11 21:20:37

Hi, I'm Ntoudi Mouyelo, Managing Director of Mchezo.

Mchezo owns Africa’s largest mobile gaming brand betPawa. Our focus is on amplifying potential in sports, talent, technological innovation, and responsible gaming. 

We’re dedicated to being a key stakeholder in the journey of taking the African sports entertainment industry to new heights. Mchezo, with the betPawa brand, promotes regulated gaming across the continent. We believe this is the surest way to ensure consumer protection, responsible gaming, and local revenue generation for the benefit of consumers and citizens.

https://mchezo.rw
[SOlVED] FileExistsError: [WinError 183] Cannot create a file when that file already exists
Tags: python, developer, coding, help
Published: 2023-08-11 20:40:50

## welcome everybody 🙂🖐
Today I am going to share with you how to handel FileExistsError

This problem occurs when you create a file or folder that already exists
In this example
I created a folder named test
The first time I run the code, there is no problem
But in the second case, the problem occurs because of the repetition of the same thing, which is to create the folder that already exists

```python

import os
os.mkdir('test')

```

Suppose you want to save a text file in the test folder
But the folder does not exist
So you will create it first
Then save the file
But the next time a FileExistsError problem will occur because you repeat the same step, which is creating the folder
To solve this problem you should use **try**
In this code I have solved the problem in a simple way

```python

import os

def save_file():
    f = open('test/file.txt', 'w')
    f.write('this is test')

try:
    save_file()
except Exception as e:
    os.mkdir('test')
    save_file()

```

**Now we're done**
Don't forget to like and follow 🙂
Returning Responses from Asynchronous Calls: A Multilingual Guide
Tags: javascript, webdev, beginners, api
Published: 2023-08-11 20:33:51

`Asynchronous `calls are fundamental in modern programming, enabling efficient handling of tasks that might take time, such as network requests or file operations. However, getting the `response `from these `asynchronous `calls might be puzzling for newcomers. In this guide, we'll explore how to return responses from asynchronous calls in different programming languages: `JavaScript`, `Python`, `Node.js`, `C#`, `PHP`, `Ruby`, and `Go`. Let's dive in with comprehensive code examples.

## 1. JavaScript (Node.js and Browser):

In `JavaScript`, you can use promises to handle `asynchronous `operations. Here's an example using fetch for `HTTP requests`:

![javascript](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1jqne9v2o0o2h2x32w7.png)

## 2. Python:

`Python `uses the `async `and await keywords for asynchronous operations. Here's an example using the aiohttp library for asynchronous `HTTP requests`:


![python](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wm02gtug8v81k0l0mvv4.png)

## 3. Node.js:

In `Node.js`, you can use the util.promisify method to handle `asynchronous `operations using promises. Here's an example using the fs module for file operations:

![Nodejs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vg8x3fenocjwxkb3smmq.png)

## 4. C#:

C# uses the `async `and await keywords for asynchronous operations. Here's an example using `HttpClient `for` HTTP requests`:


![csharp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/06ahw3xcua4bmy2jkac1.png)

## 5. PHP:

`PHP `supports asynchronous operations through libraries like `ReactPHP`. Here's an example using Guzzle for asynchronous HTTP requests:

![php](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e7jguz9yrof6uk13z3v7.png)

## 6. Ruby:

`Ruby `has built-in support for `asynchronous `programming using fibers and libraries like `async `or `async-http`. Here's an example using the `async `gem for `asynchronous `HTTP requests:


![ruby](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7kruostez4t5kdo8p21.png)

## 7. Go:

`Go `has built-in support for concurrency using goroutines and channels. Here's an example using the http package for asynchronous` HTTP requests`:

![Go](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/czirt2dwtzibrj0enhxk.png)

![Go](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bje0itftzke68rzox41x.png)

## Conclusion:

`Asynchronous `programming is crucial for efficient application development. By mastering how to return responses from asynchronous calls in various programming languages, you'll be better equipped to handle complex tasks without blocking your program's execution. These comprehensive examples in `JavaScript`, `Python`, `Node.js`, `C#`, `PHP`, `Ruby`, and `Go `demonstrate how to retrieve results from asynchronous operations, ensuring smooth execution and maintaining responsiveness in your applications.
UTF-8 grapheme clusters
Tags: unicode, utf, raku
Published: 2023-08-11 20:14:17

Grapheme cluster is a sequence of code points that should be treated as single unit when processed.

The most famous grapheme cluster is CRLF line break.

```
$ raku -e '"\r".chars.say' # CR (carriage return)
1

$ raku -e '"\n".chars.say' # LF (line feed)
1

$ raku -e '"\r\n".chars.say' # CRLF
1 # still 1 character

$ raku -e '"\r\n".codes.say'
2

$ raku -e '"\r\n".NFC.say'
NFC:0x<000d 000a> # does not compose
```

Unlike composition, sequence of code points does not produce another code point as a result. Grapheme cluster <u>has length of 1 but original code points remain unchanged</u>.

**Why?**

Concept of grapheme clusters is used for rendering and editing purposes. For example when your cursor is before grapheme cluster and you press right arrow it should move to the end of grapheme cluster. And notice that your text editor does just that! If you have CRLF line endings set and press right arrow at the end of the line it goes to beginning of the new line right away. It does not go to beginning of current line (carriage return) first and then to lower line (line feed). Does not require pressing arrow two times, even if you jump over two code points.

Same for text selection - grapheme cluster should be selected as single unit.

Although some editors are not so strict about it.

**Properties**

For better visualization let's use something more... visible. Like `กำ` - Thai `KO KAI` and `SARA AM` characters, that also form grapheme cluster.

- Graphemes in cluster can not be separated:

```
$ raku -e '.say for "ab".comb'
a
b

$ raku -e '.say for "กำ".comb'
กำ
```

[Raku](https://raku.org/) note: Function `comb` is complementary to better known cousin `split`. Instead of saying what is the separator it says what should be extracted. Without params it extracts array of characters. But we can be explicit:

```
$ raku -e '.say for "กำ".comb: /./'
กำ
```

Which also gives another clue, that in UTF-8 aware regular expressions grapheme cluster is indeed matched as single character:

```
$ raku -e 'say "กำ" ~~ /./'
｢กำ｣
```

- Graphemes in cluster can not be flipped:

```
$ raku -e '"ab".flip.say'
ba

$ raku -e '"กำ".flip.say'
กำ  # same
```

I'm mentioning it explicitly to emphasize difference with composition, where combining characters could be given in any order.

**Memorization trick**

If you still cannot grasp/remember difference between composition and clusters think of Mortal Kombat:

![MK vanilla logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kyq31ztul9n2stbckykp.png)

- Grapheme cluster = _combo_. Each punch and kick is visible on their own, but they form an uninterruptible chain.
- Composition = _fatality_. Individual punch and kicks are not shown, but whole sequence produces a new move instead.

**Coming up next:** [Sorting and collation](https://dev.to/bbkr/utf-8-sorting-and-collation-p35).
Dev Links launch
Tags: productivity, extensions
Published: 2023-08-11 20:14:10

Hi there👋. I present you 🚀**Dev Links**. An open source browser extension that allows you to find useful tools for developers and designers, helping you to increase your productivity and keep you focused.


![Dev Links main view](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tjcmlikh7tj7f6ox3nd8.png)

With this extension you will have a list of tools ready for you to browse. All tools are seperated by categories, so you can find fast what you wish. 

Dev Links allows you to select your favorite links for quick access.

You can contribute with more links to the project in its repository. The repo of Dev Links is [this](https://github.com/R0land013/dev-links).

## Downloads
- You can download DevLinks for Chrome, Opera and Brave [here](https://chrome.google.com/webstore/detail/dev-links/eogoekcejgaaaodjgbhnlpmccdmboapb).
- For Firefox you can get the extension [here](https://addons.mozilla.org/en-US/firefox/addon/dev-links/).
- Dev Links will be publicly available for Edge soon.

Support Dev Links in [Product Hunt](https://www.producthunt.com/posts/dev-links-2) so it can reach more persons.
Laravel Pint: Easy-to-use Code Style Fixer For Artisans
Tags: laravel, codestyling, laravelpint
Published: 2023-08-11 20:09:00

---
title: Laravel Pint: Easy-to-use Code Style Fixer For Artisans
published: true
description: Laravel Pint: Easy-to-use Code Style Fixer For Artisans
tags: Laravel, CodeStyling, laravelPint
canonical_url: https://ariaieboy.ir/blog/13-laravel-pint-easy-to-use-code-style-fixer/
---
For Laravel developers, having a standardized code style for each project is crucial.

It makes the code more readable and gives the entire project a uniform look.

However, adhering to these guidelines while focusing on writing code can be challenging.

Thankfully, code-style fixers like Prettier in the JS ecosystem and PHP-CS-Fixer in PHP exist to take care of this issue.

But installing and configuring these tools can pose a challenge.

That's where Laravel Pint comes in - it provides a pre-configured PHP-CS-Fixer for use in Laravel projects.

To install it, run the command `composer requires laravel/pint --dev` in your Laravel project.

Then, to fix your Laravel project file styles, run the `./vendor/bin/pint` command.

Laravel Pint is highly customizable, and you can configure it to suit your needs with a JSON config file.

It also uses pre-existing rules from PHP-CS-Fixer in your configuration, making it a more straightforward and uncomplicated option.

The default configuration works for most Laravel projects, making Laravel Pint a must-have code-style fixer for Laravel developers.
Thoughts on: Time-traveling Ruby Logger
Tags: ruby
Published: 2023-08-11 19:37:45

I've been thinking a lot about application context, the core things that our application knows: the current user, the instance it's running on, details about the request. 

Pretty often we know all of the context right up front and the beginning of a request, but sometimes we don't figure out this context until later in the request. Sometimes this is annoying. It might be nice to log things details of the request along with the userID at the beginning of a request, but we don't actually know the userID right at the beginning. Or we might want to log more details of the processing, but only if the request errors later on. 

I like the ideas in: [Time-traveling Ruby Logger](https://prefab.cloud/blog/ruby-logging-time-travel/)

I wonder if there are other ways to extends this thinking. The buffer is a bit like a promise queue that will get called later with more information. I'm curious if this gets other peoples' thoughts flowing too.
How trying to make pocket calculators do complex maths accidentally invented modern computing
Tags: youtube, calculators, computinghistory, electronics
Published: 2023-08-11 19:17:02

---
title: How trying to make pocket calculators do complex maths accidentally invented modern computing
published: true
date: 2023-08-11 19:02:46 UTC
tags: YouTube,Calculators,ComputingHistory,Electronics
canonical_url: https://ncot.uk/how-trying-to-make-pocket-calculators-do-complex-maths-accidentally-invented-modern-computing/
---

What happens when you set out to build a pocket calculator? Well in this case it turns out you also accidentally invent desktop computers, and spawn a bunch of CPUs that are still being used today.

Follow along as we go through the thoroughly bizarre story of how trying to do complex maths and fit it in our pockets lead directly to the machine you’re using right now to watch this video, which you should totally watch, now. Go on, click it.

{% embed https://www.youtube.com/embed/aGCt2G4FdHs %}

Calculators were originally like computers – huge boxes that required care and maintenance and sat firmly on a desk plugged into the wall. Today everyone wants to own a smartphone, back then everyone wanted a pocket calculator.

The story of trying to cram a whole shoebox of electronics into a pocket involves dodgy corporate dealings, people starting their own companies and deciding that while calculators were nice, being able to program them would be even better.

Part of the difficulty of building a calculator is working out how to understand the maths the operators were entering. A basic four function calculator can be thought of as a simple state machine, but once we get to doing scientific functions or longer multi stage formulae. And this is where a technique known as [Reverse Polish Notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation) comes in.

Back then computers were too low powered to cope with parsing text and checking for dumb human things like missing brackets or maths that made no sense. So we had to do that for them.

The history of how the modern computer came to be is pretty interesting. There’s a fascinating explanation on[this website](https://www.computerworld.com/article/2532590/forgotten-pc-history-the-true-origins-of-the-personal-computer.html), which was then turned into an equally fascinating book that you should go and read. Here’s a link to the [Google Books version](https://www.google.co.uk/books/edition/_/idTeAAAAQBAJ?hl=en&gbpv=1&pg=PT102), but the real thing is better to read.

<!-- YARPP List -->
### Related posts:

1. [DIY Solar – is it worth it?](https://ncot.uk/diy-solar-is-it-worth-it/ "DIY Solar – is it worth it?")
2. [Why the 1880 US Census lead to the invention of the computer](https://ncot.uk/why-the-1880-us-census-lead-to-the-invention-of-the-computer/ "Why the 1880 US Census lead to the invention of the computer")
3. [Upgrading My Atari ST to 4MB](https://ncot.uk/upgrading-my-atari-st-to-4mb/ "Upgrading My Atari ST to 4MB")
exit vim
Tags: vim, scor32k, linux
Published: 2023-08-11 19:24:44


## We will discuss 4 method to get out of VIM
---

### Method 1

1. click-> `Esc`
2. click-> `:` 
3. click-> `w`
4. click-> `q`
5. click-> `Enter`

<img src="https://imgur.com/PABrjD9.png" width="400px" height="200px" alt="img"/>

### Method 2
1. click-> `Esc`
2. click-> `:`
3. click-> `x`
4. click-> `Enter`

<img src="https://imgur.com/UyveLyz.png" width="400px" height="200px" alt="img"/>

### Method 3

If you just want to exit without saving the content

1. click-> `Esc`
2. click-> `q`
3. click -> `!`
4. click-> `Enter`
<img src="https://imgur.com/kVDFZEe.png" width="400px" height="200px" alt="img"/>

### Method 4

<img src="https://media1.giphy.com/media/FXGoDrsgrNLj2/giphy.gif?cid=ecf05e47yue0xbqelirlyzg5h0ng1p9kz38yypwc4lmd3wnd&ep=v1_gifs_search&rid=giphy.gif&ct=g" alt="throw"/>

haha! this one is most important.

---

If the article helps you, leave a like, follow, or anything 🙂.  
You can follow me on [LinkedIn](https://www.linkedin.com/in/abhishekpathak32/), [GitHub](https://github.com/scorcism), [Dev.to](https://dev.to/scorcism) and [hashnode](https://scorcism.hashnode.dev/).

**Bye**
One Punch Man Workout App + Source Code
Tags: react, opensource, motivation, webdev
Published: 2023-08-11 19:04:51

In early January, my cousin asked me to join him doing the One Punch Man workout for a month. It was new to me, but essentially, it involves 100 push-ups, 100 sit-ups, 100 squats, and a 10km run every day. It’s kind of a controversial training method, but I committed for one month (without the running part 😅).

After a few days, the process of documenting my reps with pen and paper became quite cumbersome. The urge to *create an app for this* became incredibly strong; maybe you know this feeling too.

I ran `npx create-react-app` and started hacking, the lines of code flowed like a waterfall from my fingertips. And after a second session the next day, the app did its job and I have been using it ever since.

The app can easily be hosted on a simple static file host as all data is stored in the browsers Local Storage. For these kind of projects I love to use https://surge.sh/. It provides a simple CLI interface that lets you publish a static website with a single command.

Isn’t it great that we now have the tools to do stuff like this? And so fast? It reminded me how much I love the Web, JavaScript and React.

The app is not 100% done yet, I would have liked to have a calendar at the bottom where you can see check marks for each completed day. And maybe a setting with some checkboxes where you can set which of the exercises to track (for example, if you want to opt out of the 10km running).

You can try the app right now in your browser:
https://one-punch-man-workout.surge.sh/

If you want to see how it works or even contribute with a pull request, you can find the source code on my GitHub: https://github.com/receter/one-punch-man-workout

Not every project needs to be the next unicorn, creating small projects and finishing them is really refreshing.

Let me know about your last small project in the comments.
an amazing python library to make colored text
Published: 2023-08-11 18:49:34

## welcome everybody 🙂🖐

Today I am going to share with you the best library for text coloring in Python

install colored `pip install colored`

Now I will make a background for the text
you have 255 color for use

**colored.bg(255)** The background color will change to white


```python

import colored

print(colored.stylize('This is text to test ', colored.bg(255)))

```

if you want to change text color use **colored.fg(50)** in **colored.stylize**

```python
import colored

print(colored.stylize('This is text to test ', colored.fg(50)))

```

There is also a great feature in this library
You can control the color of the text and the background together


```python
from colored import Back, Fore, Style

print(f'{Back.RGB(225, 225, 255)}{Fore.red} this is text{Style.reset}')

```
**Back** is an class thats containe on amazing functions that help you to set color such as  **RGB() function** and you can  choise color 
like this **Back.white** directly
the same feature in **Fore** class

Now we're done
Don't forget to like and follow 🙂