teleren/devto huggingface dataset:
Disable SQLModel foreign key constraint
Tags: python, sql, fastapi, tutorial
Published: 2023-03-06 05:50:35

When writing tests, you should follow the unit-of-work principle, which means separating data with each test. In Django, there is a method called `refresh_from_db` that can achieve this. 
However, in Flask or FastAPI, you need to implement it yourself. Here’s how to do it with SQLModel (a SQLAlchemy wrapper)

* conftest.py
```py
from sqlalchemy.orm import sessionmaker
from sqlmodel import Session, SQLModel

@pytest.fixture(autouse=True)
def refresh_database(db: Session):
    SQLModel.metadata.create_all(engine)

    yield

    db.close()
    SQLModel.metadata.drop_all(engine)
```
But if your SQLModel ORM includes foreign keys, creating or dropping all of them will result in a foreign key constraint issue.
```py
class Application(SQLModel, table=True):
    __tablename__ = 'applications'

    vendor_id: int | None = Field(default=None,
                                  nullable=True,
                                  # native support in SQLModel, will trigger fk constraint exception when create_all or drop_all
                                  foreign_key='vendors.id')
    category_id: int | None = Field(default=None,
                                    nullable=True,
foreign_key='categories.id')

    category: Optional['Category'] = Relationship(back_populates='applications')
    vendor: Optional['Vendor'] = Relationship(back_populates='applications')
```
As firstly mentioned, sqlmodel is a wrapper of sqlalchemy, it has parameters to pass sqlalchemy’s parameters via `sa_*`. 

SQLAlchemy can avoid this by using the `use_alter` flag.

```py
from sqlalchemy import Column, ForeignKey

class Application(SQLModel, table=True):
    __tablename__ = 'applications'

    vendor_id: int | None = Field(default=None,
                                  nullable=True,
                                  # use sa_* here, need to specific name when dropping column
                                  sa_column=Column(
                                      ForeignKey('vendors.id',
                                                 use_alter=True,
                                                 name='applications_vendor_id_fkey')))
    category_id: int | None = Field(default=None,
                                    nullable=True,
                                    sa_column=Column(
                                        ForeignKey(
                                            'categories.id',
                                            use_alter=True,
                                            name='applications_category_id_fkey')))

    category: Optional['Category'] = Relationship(back_populates='applications')
    vendor: Optional['Vendor'] = Relationship(back_populates='applications')
```
Then every thing works.
SELECT Statement
Tags: beginners, opengauss, sql
Published: 2023-03-06 03:38:23

The SELECT statement can be executed to retrieve data from a table or view. The result is stored in a result table, which is called a result set.

Serving as an overlaid filter for a database table, the SELECT statement filters required data from the table using SQL keywords.

**Syntax**

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

**Parameter Description**
**· SELECT list**
Specifies the name of a column in the table to be queried. The value can be a part of the column name or all of the column names. The wildcard (*) is used to represent all column names.

Column names can be expressed in the following formats:
· Manually input column names which are separated by commas (,)
· Columns computed in the FROM clause

**· FROM clause**

Specifies one or more source tables for the SELECT statement. The FROM clause involves multiple elements. The common elements are as follows:

**· table_name**

Specifies the name of a table or view. The schema name can be added before the table name or view name, for example, schema_name.table_name. The table name is the most common element.

**· subquery**

Performs a subquery in the FROM clause. A temporary table is created to save subquery results. For details, see Subqueries.

**· alias**

Gives a temporary alias to a table to facilitate the reference by other queries. For details, see Aliases.

**· join_type**

There are five types. For details, see JOIN.

**Examples**

**· Read all data from the customer_t1 table.**

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

**· Read the c_customer_sk and c_customer_id columns from the customer_t1 table.**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8xsrvgfco35ruvbg79ie.png)
Why JavaScript is so Popular?
Tags: javascript, programming, todayilearned, beginners
Published: 2023-03-06 05:25:03

Are you curious about why JavaScript has become one of the most popular programming languages to this day? If you've been programming for a while, you may have experienced a love-hate relationship with JavaScript at some point. I remember feeling this way when I first started programming back in 2014-2013. Python was my first love, and I just couldn't understand why people liked JavaScript so much. But fast forward to today, and all I do is write JS code. It's my go-to language, and I even write pseudo code in JS now. 
Today, we'll explore why JavaScript is still one of the most widely used programming languages and what makes it so popular among developers. Let's dive in!
        

1. **runs on browsers:** JS is the programming language that runs on browsers. So, It's a essential part of wed-development.
2. **Huge community and eco-system:** has huge community that builds library, framework and tools for the ecosystem. which makes development easier and faster for everyone.
3. **Versatility:** Not just web development, it can be used to build server-side, desktop applications and even mobile applications etc.
4. **Easy to learn:** it has low learning curve compared to other popular languages. simpler syntax and easy setup makes it more accessible for beginners.
5. **Constantly evolving:** it's a dynamic language, hence, constantly evolving and improving. new features and improvements are being added frequently. So, it's becoming more and more powerful.

In the last decade, JavaScript has become incredibly popular, largely due to its large community, versatility, and beginner-friendly nature. As web development became a more popular career choice with the growth of the internet, andJavaScript's popularity grew with it.
My new blog post
Published: 2023-03-06 05:15:33

**Exciting news📢!**
I'm releasing a brand new blog today. Can you guess the topic? Comment them👇 and stay tuned for the big reveal.

In the meantime, check out my other blogs on #Hashnode and make sure to follow me for more tech goodness. 

https://hashnode.com/@yashdev9274

#blogging #tech
Randy Letang | Randy Delbert Letang | The Ultimate Solution For BioEnergy Solutions
Published: 2023-03-06 05:04:15

Today **[Randy Letang](https://www.slideshare.net/RandyDelbertLetang/what-everyone-is-saying-about-randy-letang-highly-viral-name-in-usa)** is truly a phenomenon. Today, every news paper, media or social media channel wants to get every single update about Randy Letang. This is because he has provided solutions in bioenergy field which are beneficial for the environment. In 2023, Randy will rank as the most popular term searched on internet which can be used to identify people who are experts in Bioenergy.
https://randydelbertletang.wordpress.com/
https://randydelbertletang.wixsite.com/randy-delbert-letang/post/here-randy-letang-explain-renewable-energy-benefits-that-will-brighten-your-future-or-health
https://www.reddit.com/user/randydelbertletang/
https://www.behance.net/randydelbertletang
https://whatech.com/companies/global-heavy-industry-manufacturing/tools/randy-letang-randy-delbert-letang
https://hashnode.com/@randyletangbio
https://randydelbertletang.weebly.com/journal/who-is-randy-letang-within-2-3-years-renewable-energy-like-biofuel-will-be-the-top-trends
Signal vs Noise
Tags: productivity, discuss, community, todayilearned
Published: 2023-03-06 04:51:58

##What is signal?
**Signal** is a term used to describe **important information**. Anything that is not signal should be considered **noise**, which is the opposite of signal.

I recently took a couple weeks off work, and while sifting through various emails when I returned, I started to notice a pattern of noise vs signal. Noise being emails that didn't hold any significant information. They were marked as read and discarded, while anything that was deemed signal was moved to a "to do" email folder that I would later dig into. Most of the time emails may not fall exactly in one bucket or another, but it's important practice to start noticing what is providing value and what isn't. Remove recurring emails or updates that you don't find yourself using, they create the mental overhead we are calling noise.

It also makes one consider when we communicate how much of what we **output** is noise vs signal.

##The goal is to be as high signal as possible. 
When you speak, people will start to listen, because what you say is valuable. If you are constantly sending out noise, it may get lost in a sea of other noisy messages.

For example, am I including the right people on the email? An update on a project might be signal to some recipients and noise for others. The key is to be conscious of what you are sending and how it will be interpreted. 

##How can I be more high signal?
Some ways I've found to be high signal in emails is to highlight action items, and clearly define (if possible) who is responsible for the specific ask. Outlook allows you to tag individuals in your active directory, which is a very handy tool for this practice.

Signal is not only reserved for written communication, we see it in all sorts of mediums. When someone is presenting in a meeting for example, are they highlighting the most important information or draining a powerpoint slide? 

##Say less
My #1 tip for being more high signal is to **say less**. Often in meetings we spend a few minutes justifying our reasoning before making our point, to hopefully bring along others to our way of thinking. Instead I tend to make my point and elaborate if there are questions.

It's generally easy to identify incoming noise, but orders of magnitude more difficult to be conscious of the noise we are outputting. If you have any tips or tricks for being more high signal, please comment and share below!
Top YouTube Channels Front-End Developers Should Follow
Tags: webdev, beginners, programming, tutorial
Published: 2023-03-06 04:51:27

1. Traversy Media[Traversy Media](https://www.youtube.com/@TraversyMedia): Covering a wide range of topics, including HTML, CSS, JavaScript, React, and more.
2. Dev Ed[Dev Ed](https://www.youtube.com/@developedbyed): focusing on modern web development with tutorials and projects.
3. DesignCourse[DesignCourse](https://www.youtube.com/@DesignCourse) - Covering front-end design and development with HTML, CSS, JavaScript, and more.
4. Kevin Powell[Kevin Powell](https://www.youtube.com/@KevinPowell) - Focusing on CSS with tutorials, projects, and challenges. 
5. Net Ninja[Net Ninja](https://www.youtube.com/@NetNinja) - Covering web development with tutorials on HTML, CSS, JavaScript, React, and more.
6. FreeCodeCamp[FreeCodeCamp](https://www.youtube.com/@freecodecamp): Offering tutorials and challenges for learning web development, including front-end technologies.
7. CSS Tricks[CSS Tricks](https://www.youtube.com/@realcsstricks): Offering tutorials and articles on CSS and front-end development
8. Academind[Academind](https://www.youtube.com/@academind): Focusing on web development with tutorials on front-end and back-end technologies.

If you have any questions, you can write me on [Twitter](https://twitter.com/binatenoor).

Read more: [Freelancing](https://techbinate.com/category/freelancing/), [Internet](https://techbinate.com/category/internet/), [Digital Marketing](https://techbinate.com/category/digital-marketing/), [Health & Fitness](https://techbinate.com/category/health-fitness/)
HOW TO STUDY BETTER
Tags: productivity, career, beginners, leadership
Published: 2023-03-06 04:30:00

NOTE
**Quality of work = time spent * focus**

Correct Inputs -> **Beneficial Outputs**
- Eat healthy
- Sleep well
- Drink water
- Go outside + get sunlight 
- Exercise regularly 

Less Distractions = **Focused State**  
- Make the tasks that distract you as difficult to do as possible 
- Phones
- Drawing equipment 
- Family 
- Television 


**_Important Details _**

- Grades are a byproduct of how high the quality of work is
- Chase the system that produces the most efficient workflow, and the results follow 
- Consistency and Focus are the two most important factors  
- Track when you enter a flow state after a study session to notice patterns 
- Create habits of entering “study flow” consistently 
- Write down beforehand when you’re planning to study and for how long
- Create a reward system

stay focus * stay calm * Hustle Everyday
🦆 From API to scheduled offline copies with DuckDB on Kaggle ♾️
Tags: datascience, kaggle, python, api
Published: 2023-03-06 04:20:02

## ❔ About

While I was working on [`endoflife.date`](https://endoflife.date/) integrations, the need for offline copy started to raise:

{% github https://github.com/endoflife-date/endoflife.date/issues/2530 %}

After some various attempts, I finally found a [Kaggle](https://www.kaggle.com/) based solution.

I wanted the data to:

- 👐 Be easy to share
- ✅ Rely on the official API
- 🔁 Up-to date (without any effort)
- 🔗 Easy to integrate with third party products
- 🧑‍🔬 Be deployed on a datacentric/datascience platform
- 🤓 Show source code (Open Source)
- 🚀 Be easily extensible

Therefore I created a [Notebook](https://www.kaggle.com/getting-started/270972) that does the following things once a week: 

1. **Queries** the API
2. **Load & store** data in a DuckDb database
3. **Export** resulting database in `sql` an `csv`
4. **Export** database a [`Apache Parquet`](https://parquet.apache.org/) files

## 🧰 Tools

All you need is Python and DuckDB `json` functions:

{% embed https://duckdb.org/docs/extensions/json.html %}

## 🎯 Result

As you can see, for now, the only input is the [API](https://endoflife.date/docs/api):


[![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jleq47jjipmcfb7pt08m.png)](https://www.kaggle.com/code/adriensales/endoflife-date-offline-copy/input)

... while we have fresh output files:
[
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vh9ytr3667o3b9yirdk2.png)](https://www.kaggle.com/code/adriensales/endoflife-date-offline-copy/output)

[![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gr31atneecbvhqxpv9da.png)](https://www.kaggle.com/code/adriensales/endoflife-date-offline-copy/)


## 🗣️ Conclusion

Finally I delivered the following solution to the community:

{% github https://github.com/endoflife-date/endoflife.date/issues/2633 %}
Today I learned... (TIL) - Week 2
Published: 2023-03-06 04:11:39



In week two, I learned about both hard and soft skills:

---

#### Soft Skills
- [SMART Goals](https://www.youtube.com/watch?v=YvnKWwbVTPk&t=33s&ab_channel=JamesRosseau%2CSr.)
- [Personal Branding](https://www.youtube.com/watch?v=Ix2W1m6ZuR4&ab_channel=MakedaAndrews)
- [Having a better LinkedIn profile](https://www.linkedin.com/business/sales/blog/profile-best-practices/17-steps-to-a-better-linkedin-profile-in-2017)

---

#### Hard (Technical) Skills 
  - Ruby Basics from Treehouse
- ***"for" loop vs "each" loop:***
The variable used to iterate in the for loop, exist outside the for loop. While in other iterators they exist only inside the block of code that's running.
  - Mac shortcuts and tricks 
  - Running Ruby locally
JavaScript Data Types
Tags: javascript, beginners, programming, writing
Published: 2023-03-06 04:10:01

Data Types refer to the types of data that can be stored in a [variable](https://dev.to/lenacodes/javascript-variables-3p1g). They include primitive and non-primitive data types.

The primitive data types are:

String
Number
Boolean
Undefined
Null
Symbol
The non-primitive data type is:

An object can be an array, function, date , object and Regex (Regular expression).

The major difference between the primitive and non-primitive data types is that in primitive data types, only one value can be stored while more than one value can be stored in the non-primitive type.

For the purpose of this post, we will only focus on string, number, boolean, undefined and null.

## String

A group of characters surrounded by single quotes (‘’), double quotes(“”), backticks or String() method.

```javascript
let str1 = 'String in single quote.';
let str2 = "String in double quote.";
let str3 = `String in backticks.`;
let str4 = String('Creating a string with String().');
```

## Number

The number can be an integer (positive or negative), a floating point value, exponential value, Infinity or Nan (not a number).

```javascript
const num1 = 1; // Positive integer
const num2 = -10; // Negative integer
const num3 = 24.3; // Floating point value
const num4 = 10e2; // Exponential value: 10*100
const num5 = 5 / 0; // Infinity
const num6 = 'hello' * 5; // Nan
let num7 = Number(10);
Num7 = Number(5);
```

## Boolean

This is a logical data type that has two values `true` and `false`. It can be used for comparison of [variables](https://dev.to/lenacodes/javascript-variables-3p1g) or to check a condition.

```javascript
let checker = true;
const a =5, b = 9;
if (a < b) {
  // if a is less than b
  checker = true;
}
else {
  checker = false;
}
a == b; // a is equal to b returns false
a != b; // a is not equal to b returns true
```

## Undefined

This type of data is a variable where the variable has been declared but remains undefined. A value has not been assigned.

```javascript
let firstName; // Declaration
console.log(firstName); // Undefined
firstName = 'John'; // Assign the string John
console.log(firstName); // John
```

## Null

The null data type refers to a value that means the value is absent or empty.

```javascript
let x = null;
console.log(x) // null
```
If this was helpful to you, would appreciate if you like this post and share.

Thank you for reading.
Git Explained by a dump person
Tags: git, beginners, productivity
Published: 2023-03-06 03:46:12

What is Git?

According to Wikipedia, Git is a distributed version control system that tracks changes in any set of computer files, usually used for coordinating work among programmers collaboratively developing source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows.

That explanation is so technical. Okay, let me explain intuitively. Imagine your project code is like a tree.


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

<br>

**Okay, let's dig deeper!**

Creating a new project is like when we plant a new tree.

![Little tree](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2ew5lz9aqnzsnu1ip0p.png)

For the first couple of commits, the Branch feature is not mandatory. Because we're not building complex features yet, We could commit straight to the main. 

Tree's growing, the same as to our project. When our project gets bigger and more complex, for safety reasons, It would be good for us to use a ***git branch***. 

`Crete a new specific branch → work on the branch → merge the branch to the main.`

after the branch is merged into the main, The branch will become unused, I call it a dead-branch. So it's good for us to cut ( delete ) the unused branch, to make our tree looks aesthetic.

![Git explanation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e3erop8kh0h2z5ygmajp.png)

preference

[https://en.wikipedia.org/wiki/Git](https://en.wikipedia.org/wiki/Git)
1539. Leetcode Solution in cpp
Published: 2023-03-06 03:38:05

======================================================
#Description:
Given an array arr of positive integers sorted in a strictly increasing order, and an integer k.

Return the kth positive integer that is missing from this array.

 

Example 1:

Input: arr = [2,3,4,7,11], k = 5
Output: 9
Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5th missing positive integer is 9.
Example 2:

Input: arr = [1,2,3,4], k = 2
Output: 6
Explanation: The missing positive integers are [5,6,7,...]. The 2nd missing positive integer is 6.
 

Constraints:

1 <= arr.length <= 1000
1 <= arr[i] <= 1000
1 <= k <= 1000
arr[i] < arr[j] for 1 <= i < j <= arr.length

====================================================
#Solution:


```cpp
class Solution {
 public:
  int findKthPositive(vector<int>& arr, int k) {
    int l = 0;
    int r = arr.size();

    // find the first index l s.t. nMissing(l) = A[l] - l - 1 >= k
    while (l < r) {
      const int m = (l + r) / 2;
      if (arr[m] - m - 1 >= k)
        r = m;
      else
        l = m + 1;
    }

    // the k-th missing positive
    // = A[l - 1] + k - nMissing(l - 1)
    // = A[l - 1] + k - (A[l - 1] - (l - 1) - 1)
    // = A[l - 1] + k - (A[l - 1] - l)
    // = l + k
    return l + k;
  }
};

```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/kth-missing-positive-number/