teleren/devto huggingface dataset:
Fibonacci sonlari | C++ boshlang'ich
Tags: cpp, uzbek, beginners, dasturlash
Published: 2022-04-01 10:41:45

### Fibonacci
- `n` - fibonacci soni `n-1` va `n-2` fibonacci sonlari yig'indisiga teng.
- dastlabki 2 ta fibonacci sonlar `0` va `1` ga teng.

> Dastlabki 10 ta fibonacci sonlarni hisoblab chop etadigan dastur tuzing.

```cpp
int a = 0, b = 1, c = a + b;
cout << a << " " << b << " " << c << " ";
```
- yuqorida dastlabki 3 ta fibonacci sonlar hisoblab chop etilgan


Keyingi fibonacci sonni hisoblab topish uchun so'ngi ikkita fibonacci sonlar `b` va `c`ni qo'shish kerak.

Lekin bu usul optimal kod emas, chunki yuqoridagi algoritm `reusable` emas. Ya'ni yuqoridagi algoritmni qaytarish orqali keyingi fibonaccini topib bo'lmaydi.

Quyidagi kodga qarang:
```cpp
b = c;
a = b;
c = a + b;
cout << c << " ";
```

Yuqoridagi kod optimal algoritm. Keyingi fibonaccini topish uchun yuqoridagi kodni shunchaki *copy/paste* qilish kifoya.

#### Barcha kod
```cpp
int a = 0, b = 1, c = a + b;
cout << a << " " << b << " " << c << " "; // dastlabki 3 ta fibonacci

b = c;
a = b;
c = a + b;
cout << c << " ";   // 4-fibonacci

b = c;
a = b;
c = a + b;
cout << c << " ";   // 5-fibonacci


b = c;
a = b;
c = a + b;
cout << c << " ";   // 6-fibonacci


b = c;
a = b;
c = a + b;
cout << c << " ";   // 7-fibonacci

b = c;
a = b;
c = a + b;
cout << c << " ";   // 8-fibonacci

b = c;
a = b;
c = a + b;
cout << c << " ";   // 9-fibonacci

b = c;
a = b;
c = a + b;
cout << c << " ";   // 10-fibonacci
```

## Yoqqan bo'lsa ❤️ bosing ☺️.
Getting Started with the Blazor Range Slider Component
Tags: blazor, webdev, csharp, dotnet
Published: 2022-04-01 10:38:04

This video will get you started with the Syncfusion [Range Slider component](https://www.syncfusion.com/blazor-components/blazor-range-slider) in a Blazor WebAssembly application. You will learn about basic functionalities: binding values, applying ranges, formats, tooltips, ticks, and limits. You will also see how to customize the Range Slider using CSS classes. 

Product Overview: https://www.syncfusion.com/blazor-components/blazor-range-slider

Download an example from GitHub: https://github.com/SyncfusionExamples

Refer to the following documentation to learn about the Blazor Range Slider component: https://blazor.syncfusion.com/documentation/range-slider/getting-started

Check out this online example of the Blazor Range Slider component: https://blazor.syncfusion.com/demos/range-slider/default


{% youtube UeSbfQtK-5I %}
[ Database ] - SQLAlchemy "or_" function
Tags: database, sql, sqlalchemy, python
Published: 2022-04-01 10:17:00

진행중인 프로젝트에서 이번에 검색 기능을 추가하기로 했다.
쉽게 상품이 있는데, 한글과 영어로 된 이름이 모두 상품 테이블에 각 컬럼별로 존재한다.

보통 검색기능을 구현할 때, sql에서는 like 구문으로, orm는 종류가 다양하지만 보통 like나 filter와 같은 메소드로 값을 전달해서 데이터를 추출하곤 한다.

하지만 내가 오늘 구현하고 싶었던 기능은, 어떠한 키워드로 검색을 했을 때
한글 이름과 영어 이름 컬럼에서 모두 해당 키워드가 존재하는지 검색 후 값을 가져오고 싶었다.

상품 모델을 `Product`라 하고, 필드명이 `name`이라고 하나만 존재하고,
상품의 이름으로 검색을 하고싶다면 우리는 orm을 다음과 같이 작성할 수 있다.

```python
# "db" is "<class 'sqlalchemy.orm.session.Session'>"
# "name" is variable from Query Parameter

db.query(Product).filter(
    Product.name.like(f"%{name}%")
).all()
```

그런데 만약, name이라는 하나의 컬럼이 아닌, 한국어와 영어로 이름을 모두 가지고 있는 상품이라면 컬럼은 `kor`,`eng`로 나뉠 수 있고 한 번에 두 가지의 컬럼을 모두 검색하고 싶다면 다음과 같이 sqlalchemy에서 or_이라는 함수를 가져와 사용하면 된다.

```python
# "db" is "<class 'sqlalchemy.orm.session.Session'>"
# "name" is variable from Query Parameter

from sqlalchemy import or_

db.query(Product).filter(or_(
    Product.kor.like(f"%{name}%"),
    Product.eng.like(f"%{name}%"),
)).all()
```

이렇게 해주면 "나이키" 와 "Nike"이라는 이름을 가진 상품이 있을 때,
Query Parameter에 name으로 "이", "나이", "i", "ik", "ike" 등등
한글과 영어로 구분지을 필요 없이 검색을 할 수 있다.
> 물론 검색 필터로 **`f"%{name}%"`**이라고 주었기 때문에 가능한 것이다.
서비스에 따라 **`%`**를 잘 활용하도록 하자.

만약에 일본어의 이름도 추가하고 싶어서 jp라는 컬럼까지 추가했고, 해당 컬럼까지 조회하고 싶다면 or_ 함수에 **`Product.jp.like(f"%{name}%")`** 인자를 추가해주면 된다.

```python
# "db" is "<class 'sqlalchemy.orm.session.Session'>"
# "name" is variable from Query Parameter

from sqlalchemy import or_

db.query(Product).filter(or_(
    Product.kor.like(f"%{name}%"),
    Product.eng.like(f"%{name}%"),
    Product.jp.like(f"%{name}%"),
)).all()
```
Github optimal cron for twitter posting
Tags: github
Published: 2022-04-01 10:13:42

Hi all

Working on a FREE online [staking and rewards crypto rates comparator](https://stakingcrypto.io), I wanted to tweet stuff based on the data I collect. For example, an increase of a rate, or a new coin.

For this, when I retrieve the data, I populate a mongo collection with the text I want to share and the destination network (mainly twitter and reddit).

I also made a whole framework to have different variations of texts and, of course, markdown version (for reddit) and text version (for twitter)
 
Now, with this collection filled, I wanted to tweet those informations on the best schedule possible, as Buffer does.

To do this, I discovered Github Actions cron functionality.

```
name: optimal-cron-for-twitter

on:
  schedule:
    - cron: '58 17 * * MON'
    - cron: '49 17 * * MON'
    - cron: '32 13 * * TUE'
    - cron: '58 17 * * TUE'
    - cron: '49 21 * * TUE'
    - cron: '32 13 * * WED'
    - cron: '58 17 * * WED'
    - cron: '49 21 * * WED'
    - cron: '32 13 * * THU'
    - cron: '58 17 * * THU'
    - cron: '49 21 * * THU'
    - cron: '32 13 * * FRI'
    - cron: '58 17 * * FRI'
    - cron: '49 21 * * FRI'
    - cron: '32 13 * * SAT'
    - cron: '58 17 * * SAT'
    - cron: '49 21 * * SAT'
    - cron: '32 13 * * SUN'
    - cron: '58 17 * * SUN'
    - cron: '49 21 * * SUN'

jobs:
  cron:
    runs-on: ubuntu-latest
    steps:
      - name: optimal-cron-for-twitter
        run: |
          curl --request POST \
          --url 'https://stakingcrypto.io/api/cron/optimal-cron-for-twitter' \
          --header 'Authorization: Bearer ${{ secrets.CRON_APP_KEY }}'


```

This basically will, every perfect time for posting, get back one tweet and post it to my twitter account [@stakingcryptoio](https://twitter.com/stakingcryptoio).

Github cron is setup for the GMT timezone and I adapted the best times for New York.

What about you, what schedule do you use to post on twitter optimally?
LeetCode Streak Challenge - Day 1/30 - Reverse list
Published: 2022-04-01 10:00:45

I have decided to keep up a 30 day streak on LeetCode starting today. The idea is to be consistent, so I will start with 2 problems per day.

**Problem 1: Reversing a list**

Today's daily challenge question was about reversing lists. This topic has been discussed to death in many forums already. But I have found that trying to reproduce what I learnt/read, helps increase the retain the piece of information for longer in memory. Also I want to try and keep notes for each problem I solve so that I can revisit them later.

There are different ways to go about reversing a list in Python:

1. `list.reverse()` - 
    * Reversing is done in place - It does not create a new object and reverse it. Instead it modifies the original copy.
    * The function does not return the modified list. We cannot assign the returned value of the function to a variable. The return value is `None`.
    * [Another term for operating in place is side-effect](https://stackoverflow.com/questions/45050704/operate-by-side-effect#:~:text=It%27s%20a%20little%20confusing%20that%20the%20operation%2Din%2Dplace%20is%20called%20a%20%22side%20effect%22%2C%20when%20in%20this%20case%20it%27s%20the%20whole%20point%20of%20the%20method%3B%20but%20%22side%20effect%22%20is%20a%20general%20term%20for%20operations%20that%20mutate%20an%20object%2C%20rather%20than%20(or%20in%20addition%20to)%20producing%20a%20new%20object). 
    * Time complexity - O(n) where n is the number of elements in the list. 
    * Space complexity - O(n). 
2. `reversed(list)` - 
    * It returns an iterator that allows traversing the list in reverse order. 
    * We can call a list on the returned iterator to get the reversed list. 
    * Any changes to the original list will impact the iterator because the iterator points to the same list and not a copy.
    * Time complexity - O(n) where n is the number of elements in the list. 
    * Space complexity - O(n). 
3. Swap the first element with the last, the second element with the second last, and so on. 
    * Time complexity - O(n).
    * Space complexity - O(n).
4. Slicing
    * list[start:stop:step]. The default value of step is one, which allows the slicing to extract items from start to stop-1 from left to right. Setting the step to -1 returns the objects in reverse order. 
    * It returns a reversed copy of the list. 
    * Time complexity - O(n).
    * Space complexity - O(n).
5. Loops
    * We can loop through the list in reverse order and copy each element to a new list. Needless to say, this is not in place.
    * Time complexity - O(n).
    * Space complexity - O(n).


For methods 4 - 5, we can also use recursion. In this case, the Space complexity will include the Stack space which will be O(n). The maximum number of elements present in stack will be the size of the list, n.
Conditional validation of form fields using Yup
Published: 2022-04-01 09:46:09

---
title: Conditional validation of form fields using Yup
published: true
description: How to enable or disable validation on Formik form fields based on certain conditions in Yup.
tags: 
//cover_image: https://direct_url_to_image.jpg
---

I had a form where I needed to enter the `passphrase` if it was required and make it optional if it wasn't required. While validating the field using Yup I needed a way to conditionally change the validation logic for the field. For this, we need to use the `when()` function from Yup which allows us to change the validation logic applied to a field based on some conditions. 

Sample code:
```javascript
<Formik
      initialValues={initialValues}
      validationSchema={Yup.object({
        passphrase: Yup.string().when([], {
          is: () => passwordRequired && !showMessage,
          then: Yup.string().required("Passphrase is required"),
          otherwise: Yup.string().notRequired(),
        }),
      })}
>
  {/* ... */}
</Formik>
```

References: 
1. [Yup docs on when() function](https://github.com/jquense/yup#schemawhenkeys-string--string-builder-object--values-any-schema--schema-schema)
2. [SO post with good answers](https://stackoverflow.com/q/59058714/7358595)
Alibaba Cloud Infrastructure Guide for AWS Professionals
Tags: database, nosql, aws
Published: 2022-04-01 09:43:16

Please find full read at:
https://resource.alibabacloud.com/whitepaper/alibaba-cloud-infrastructure-guide-for-aws-professionals_4651?key=

**Database Service Highlight**

1. DATA WAREHOUSE
2. NOSQL DATABASE
3. RELATIONAL DATABASE
4. UTILITY & TOOLS

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7z2r019s3wr22c4tltq.png)
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0nfehw7usjuicn2s9lrt.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iaxf092rxaikuh7e6mux.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fjmlndlesjfccldii5kc.png)
Solidity: external vs. public & memory vs. calldata vs. storage
Tags: solidity, ethereum, optimization
Published: 2022-04-01 08:30:30

It is written in many places how these things are. But what not easy to decide **when to use which of them**, as it needs a deeper understanding to choose. 

So I want to note the quick heuristic methods to choose these. 


## Public vs. External 

TL;DR;
> So if you know the function you create only allows for external calls, go for `external`. It provides performance benefits and you will save on gas.

Basically, `public` means it can be `external` or `internal`, the compiler need additional work for the public function. With the `external` only, it allows arguments to be read directly from `calldata`, saving the copying step.

Easy read here: 
- https://gus-tavo-guim.medium.com/public-vs-external-functions-in-solidity-b46bcf0ba3ac
- https://ethereum.stackexchange.com/a/19391/76945

## Memory vs. Calldata vs. Storage

TL;DR;
> - use `calldata` when you only need read-only data, avoiding the cost of allocating memory or storage.
> - use `memory` if you want your argument to be mutable.
> - use `storage` if your argument will already exist in storage, to prevent copying something into storage over into memory unnecessarily.

Ref: 
- [Easy example on why storage over memory](https://ethereum.stackexchange.com/a/123692/76945)

## To research more

I am still not sure why most of the OpenZeppelin libs choose to use `memory` over `calldata`, although they don't mutate them. For example: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol#L179
This Week in Python
Tags: python
Published: 2022-04-01 09:33:49

**Fri, April 1, 2022**

This Week in Python is a concise reading list about what happened in the past week in the Python universe. 

## Python Articles


- [Time Series Forecasting with Ploomber, Arima, Python, and Slurm](https://www.kdnuggets.com/2022/03/time-series-forecasting-ploomber-arima-python-slurm.html) – Take a raw `.ipynb` notebook that does time series forecasting with Arima, modularize it into a Ploomber pipeline, and run parallel jobs on Slurm.
- [Implementing an Azure IoT Device Using Python](https://dev.to/chrisdinhnz/implementing-an-azure-iot-device-using-python-412g) – In this blog post the focus will be on creating a couple of Azure IoT devices using the Python Device SDK.
- [Setting up a basic Django project with Poetry](https://builtwithdjango.com/blog/basic-django-setup) – In this tutorial, we will go through the process of setting up the most basic Django project that we will be using for other posts and tutorials.
- [Validate JSON Documents in Python using Pydantic](https://blog.couchbase.com/validate-json-documents-in-python-using-pydantic/) – This article shows you how to validate your JSON documents against a specified schema using the popular Python library pydantic.
- [How to Make the Most of Pydantic](https://towardsdatascience.com/how-to-make-the-most-of-pydantic-aa374d5c12d) – Explore techniques for data contract validation, higher interoperability with JSON Schemas, and simplified data model processing.

## Projects

- [py-dynacli](https://github.com/BstLabs/py-dynacli) – cloud-friendly Python library for converting pure Python functions into Linux Shell commands
- [perflint](https://github.com/tonybaloney/perflint) – Python Linter for performance anti patterns
- [UltraDict](https://github.com/ronny-rentner/UltraDict) – Shared, streaming Python dict
- [python-cheatsheet](https://github.com/gto76/python-cheatsheet) – Comprehensive Python Cheatsheet
- [recommenders](https://github.com/microsoft/recommenders) – Best Practices on Recommendation Systems


{% embed https://twitter.com/bascodes/status/1509788654067240960 %}
Opening large files (>2GB) in Windows
Published: 2022-04-01 09:31:17

---
title: Opening large files (>2GB) in Windows
published: true
description: How do you open a very large text/log file in Windows
tags: 
//cover_image: https://direct_url_to_image.jpg
---

Once I had to go through an unusually large log file which was around 2GB. I am a regular Notepad++ user but it couldn't handle the file. In addition to opening the file I also needed to search around the file for keywords like Error or Exception. I found [klogg](https://klogg.filimonov.dev/) to be just the right tool for me. It allows for viewing as well searching for words within the large text file easily.

If you're looking for other editors please go through [this](https://stackoverflow.com/a/159537/7358595) answer.
Optimize your Blog with 7 steps
Tags: seo, news, performance, blog
Published: 2022-04-01 09:30:02

Blogging has become the forgotten blessing of the digital marketing world. The reason why I say this is because of the simple fact that blogs have been forgotten by businesses online. Studies show that 60% of businesses have blogs and 65% of them have not updated their blogs in the past year. Why is this happening? Well, the answer is, most bloggers are not aware of the simple ways to optimize their blogs and make them more Search Engine appropriate.

This is my message to all the writers and entrepreneurs out there. Instead of forgetting about blogs, learn the little tricks and optimize them wisely.

Here are 7 simple ways to optimize your blog.

**1)** **Do a thorough Research on Keywords:**

The strongest weapon which helps win the **SEO** war is Keywords. Everything comes down to playing with the correct keywords in the correct places. If you notice, your blog might already have a few keywords. But it would not hurt to know what the keywords you should be using are. Take the help of Google AdWords Keyword Tool, Moz Toolbar, Buzzsumo, etc. to improve your keyword game.

**2)** **Look around the SERP:**

Let me ask you a question right now. When you are looking into any topic, do you look around the search engine result page (SERP)? Some might be nodding their heads replying with a yes. But the majorities have their guilty face on. Before taking the help of some fancy keyword tools, take a look around the SERP. It provides you with a lot of related keywords at the end of the page. It also shows you single-liner questions which have the related keywords you are so desperately looking for.

**3)** **Choose your post Title wisely:**

Of course, your **Blog** has a Title. But do you include the main keywords in the title of your blog? That’s right! Include the focus keyword in your Title and you will win the game by 30%.

**4)** **URL should contain Keywords:**

Never thought URLs should be given a thought while writing and uploading blogs right? If you include your focus keyword in the URL it helps you in your SEO ranking majorly.

**5)** **Don’t forget about your headings:**

Every blog will have only 1 H1 heading but many H2, H3, H4, H5 headings. Try to include related keywords in the headings. But make sure to avoid keyword stuffing. You will get penalized by Google.

**6)** **Optimize the image as well:**

Yes! You read that right. The images that accompany your blog should be tagged with Keywords as well. Fill out the alternate text field with a small description filled with keywords.

**7)** **Use internal links in your blog:**

Some love and acknowledgment have never been harmful. Mentioning other bloggers in your article is also considered good blogging etiquette. Plus, there are chances of being mentioned in someone else’s blog as well. 

So roll up your sleeves and put your thinking caps on and start writing. Remember, these simple points, and be sure to see the results. Finally, enjoy blogging.
Most common MIME types
Published: 2022-04-01 09:23:44

---
title: Most common MIME types
published: true
description: A list of most common MIME types for web and beyond.
tags: 
//cover_image: https://direct_url_to_image.jpg
---

I was looking for a way to validate the MIME types of uploaded files. For this I needed a list of most common MIME types for files. Below is a list of links to the resource.

1. [MDN Common MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types)
2. [IANA All Media Types](https://www.iana.org/assignments/media-types/media-types.xhtml)
3. [SO question with some useful answers](https://stackoverflow.com/questions/4212861/what-is-a-correct-mime-type-for-docx-pptx-etc)
How to ignore an already tracked *.log file in git
Published: 2022-04-01 09:15:51

---
title: How to ignore an already tracked *.log file in git
published: true
description: Ignore an already tracked *.log file in git
tags: 
//cover_image: https://direct_url_to_image.jpg
---

I faced this issue the other day. I didn't put `*.log` file in the `.gitignore` file earlier.

The problem: I had already committed a few log files before and so it was already in the git. When I added the git ignore rule for excluding log files it wasn't removed automatically. Turns out for files already checked into git, we first need to untrack those files before we add the rules for ignoring those files.

Command for untracking the file:
```bash
git rm --cached FILENAME
```

Reference: https://stackoverflow.com/questions/4308610/how-to-ignore-certain-files-in-git
LEMP and LAMP stack? 🤔
Tags: webdev, webs, php
Published: 2022-04-01 08:35:34

**DECK** marketplace provides you with LEMP and LAMP stack.

What are **LEMP** and **LAMP**?

- **L-** Linux Operating System
- **E-** Nginx Server
- **A-** Apache HTTP Server
- **M-** MySQL Database
- **P-** PHP
So **LEMP** and **LAMP** stack are both a set of open-source software developers can use to run websites and web applications.

And with **DECK**, it's a click of a button you can have it for your project.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vbf2nq6j0do45rtzsl9u.png)

[Try DECK today](https://get-deck.com/) 💕.

If you find this article helpful please share and follow us on [Twitter](https://twitter.com/deckdevstudio).
Adding Git autocomplete to PowerShell (Windows)
Published: 2022-04-01 09:01:41

---
title: Adding Git autocomplete to PowerShell (Windows)
published: true
description: Adding Git autocomplete to PowerShell
tags: 
//cover_image: https://direct_url_to_image.jpg
---

In order to get bash like git autocomplete in Powershell, install the posh-git package.

1. Fulfill the conditions mentioned in the prerequisite:
https://github.com/dahlbyk/posh-git#prerequisites
 a. Make sure PowerShell version greater than 6 is installed.
 b. Make sure git is installed and in the PATH.
 c. Make sure the script execution policy is set to `RemoteSigned` or `Unrestricted`.

2. In PowerShell execute: 
```powershell
PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force
```

3. Add posh-git to PowerShell profiles by either running `Add-PoshGitToProfile -AllHosts` or add it to the profiles file located at: `C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1` (Create the file if it doesn't exist).


References: 
* https://github.com/dahlbyk/posh-git
* https://git-scm.com/book/en/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-PowerShell