teleren/devto huggingface dataset:
Define Custom Query Sets in Model Managers for Code Reuse
Tags: python, django, database
Published: 2022-04-16 10:49:00

Django provides a great way to query your database with few lines of code and without writing SQL. However, there are some cases when you'll find yourself repeating the same piece of code logic in a project.🥶

## Problem

Let's say we've added a new field to a model to create a `public_id` based on `uuid4`.

```python
class Product(models.Model):
    public_id = models.UUIDField(db_index=True, unique=True, default=uuid.uuid4, editable=False)
```

Basically, this `public_id` will be used instead of the `id` of an object to perform CRUD actions. 
Suppose that a user makes a request to retrieve a specific object in the database. 
A solid logic will look like this:

```python
public_id = kwargs.get("public_id")
try:
    product = Product.objects.get(public_id=public_id)
except ObjectDoesNotExist:
    raise Http404("Product does not exist")
```
Simple logic right here, until you are adding other models to your project that use the same `public_id` field and you find yourself repeating the same piece of code logic.

## Solution

Custom model managers allow developers to write extra methods for a model.

Returning to the example, let's create a custom `Manager` class for the `Product` model.

```python
class ProductManager(models.Manager):
    def get_object_by_public_id(self, public_id):
        try:
            instance = self.get(public_id=public_id)
            return instance
        except ObjectDoesNotExist as e:
            raise e

class Product(models.Model):
    public_id = models.UUIDField(db_index=True, unique=True, default=uuid.uuid4, editable=False)

    objects = ProductManager()
```

And when retrieving an object, the code will simply be:

```python
public_id = kwargs.get("public_id")

product = Product.objects.get_object_by_public_id(public_id)
```

If you have other models in the database, let's suppose a `Shop` model or a `User` model with also a `public_id` field. We can write an `AbstractManager` class.

```python
class AbstractManager(models.Manager):
    def get_object_by_public_id(self, public_id):
        try:
            instance = self.get(public_id=public_id)
            return instance
        except (ObjectDoesNotExist, ValueError, TypeError) as e:
            raise e

class ShopManager(AbstractManager):
    pass

class ProductManager(AbstractManager):
    pass

class Product(models.Model):
    public_id = models.UUIDField(db_index=True, unique=True, default=uuid.uuid4, editable=False)

    objects = ProductManager()

class Shop(models.Model):
    public_id = models.UUIDField(db_index=True, unique=True, default=uuid.uuid4, editable=False)

    objects = ShopManager()

product = Product.objects.get_object_by_public_id(public_id)
shop = Shop.objects.get_object_by_public_id(public_id)
``` 
🚀🚀🚀

You can learn more about managers in the official documentation of [Django](https://docs.djangoproject.com/en/4.0/topics/db/managers/).



*Article posted using [bloggu.io](https://bloggu.io). Try it for free.*
FIX: replaceAll() is not a Function In JavaScript
Tags: javascript, programming, node, alternative
Published: 2022-04-16 10:44:29

## Why this error?
You will get error something like this: TypeError: replaceAll is not a function while using replaceAll() function because whatever version of node js or browser does not support this function.

replaceAll method was added es2012 or es12 so if you are using ECMAScript version below 12 then definitely you will see this error as there is not implementation for replaceAll in earlier versions.

## How To Fix thee Issue?​
As a workaround for this problem, you can use replace() method with a regular expression that has the global (“g”) flag set which had a strong support for all ES version and browsers.

Lets try with an example:

Below example will replace all whitespaces(” “) with hyphen “-“.

```
function testReplace(sentence) {
  return sentence.replace(/[" "]/g, "-");
}

console.log(testReplace("This is Test"));
```

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

## What if you need to use replaceAll() at multiple places?
Alternatively, You can create a function which will resemble the behavior of replaceAll() method.

Like in this example:

```
function someFunction(blogName) {
  return **replaceAll**(blogName, /[" "]/g, "-");
}


function replaceAll(sentence, regx, replaceBy) {
  return sentence.replace(regx, replaceBy);
}

console.log(someFunction("This is my blog"));
```

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

Now you are good to use replaceAll() method anywhere but with different implementation. Note that we are passing 3 parameters to our replaceAll() method which is different than the actual replaceAll() method but both will give desired output.

## Conclusion
There is no implementation of replaceAll() present in version of ECMAScript12 that’s why we get this error. To fix this, we had a workaround which will use replace() method to do exact thing which replaceAll() does.

> Please do share your feedback and experiences in the comments section below

If you found this article useful, please share it with your friends and colleagues!❤️

Follow me on ⤵️
🌐 [LinkedIn](https://www.linkedin.com/in/shivam-prakash-pawar/)
Hire odoo partner Vs odoo freelancer
Published: 2022-04-16 10:43:59

Hire odoo partner Vs odoo freelancer

Why hire developers for customizing odoo ERP?

[Hiring odoo developers](https://www.cybrosys.com/hire-odoo-developer/) benefit the user in many different ways. Whenever the user has a specific need that he/she needs to implement  in the odoo software for better user experience ,a developer has to be hired who can understand the actual need of the customer and has the experience to implement it in the Odoo software by making changes to the code.

Hiring a odoo freelancer vs the merits of hiring an Odoo partner

Odoo developer freelance services are available throughout the web but is it really the best option for your firm ? Does the experience of a freelancer really affect the output of the product handed down to the user ? Even though Odoo partner services are priced on the high side, does it give a better result than hiring a freelancer ?

These are all the doubts while choosing a developer to customize your Odoo software to suit your company’s needs. The truth is there is a huge difference in this segment.

An odoo freelance developer does not have any kind of organizational support and is not available 24x7 for support. Freelancing is a paycheck based service where the obligation ends once the fee is paid. The quality of the service provided will be questionable. Domain experience of the freelancer is limited when compared to that of an odoo partner. An important factor to be noted is that the confidentiality of the client information is questionable.

Even though the price for hiring a odoo partner is on the higher side when compared to an odoo freelancer , it provides the client with a wide variety of services like 24x7 support , reliable and experienced personnel , after support available and the experience of the developers in handling a client request , ensures the confidentiality of information.

Therefore hiring an odoo partner is always best when compared to a freelancer and for the best results in odoo software customization.
Lắp đặt giàn phơi thông minh Duy Lợi, Hoà Phát giá rẻ
Published: 2022-04-16 10:31:17


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q47rvixu7s5h7f142vru.jpg)Lắp đặt giàn phơi đồ thông minh Hoà Phát, Duy Lợi ... giá rẻ, chất lượng, bảo hành 2 năm. Lắp đặt lưới an toàn, bat che nắng mưa, cửa lưới chống muỗi
Địa chỉ : quận Bình Tân, TP.Ho Chi Minh
Phone : 0903852049
Website	https://sieuthiduyloi.com/
URL Seo 1	https://sieuthiduyloi.com/products/luoi-an-toan-ban-cong/
URL Seo 2		https://sieuthiduyloi.com/danh-muc-sp/gian-phoi-thong-minh/
URL Seo 3		https://sieuthiduyloi.com/danh-muc-sp/cua-luoi-chong-muoi/
URL Seo 4		https://sieuthiduyloi.com/danh-muc-sp/gian-phoi-quan-ao/
URL Seo 5		https://sieuthiduyloi.com/danh-muc-sp/gian-phoi-thong-minh-hoa-phat/
URL Seo 6		https://sieuthiduyloi.com/danh-muc-sp/luoi-an-toan/
Social:
https://twitter.com/gianphoiduyloi
https://www.pinterest.com/gianphoiduyloi/_saved/
https://www.twitch.tv/gianphoiduyloi/about
https://www.linkedin.com/in/gianphoiduyloi/
https://gianphoiduyloi.tumblr.com/
https://flipboard.com/@gianphoiduyloi
https://gab.com/gianphoiduyloi
https://gianphoiduyloi.netboard.me/
Software developer vs Web Developer
Tags: webdev, programming, discuss, career
Published: 2022-04-16 10:05:06

You might be a person new to programming, trying to find a job, or you might be deciding if you want to get started with either option. 

Whatever the reason, I am here to help you choose whether Software development or Web Dev is right for you. So without further ado, let's get started!

## Software Development Pros/Cons

Pros:

1. Slightly higher paying
2. Don't necessarily need internet access

Cons:

1. Might need to use harder programming languages
2. Harder compared to web dev to get started with

Note that all comparison above is compared with web development. 

## Web Development Pros/Cons

Pros:

1. Get To Use JavaScript
2. More online resources

Cons:

1. Need internet access
2. Not as well paid (Compared to software dev)

All comparisons are compared with software dev.

## Final Statements

No matter your choice, you'll get to enjoy a good work life style with either options, as long as you try your best. 

Thank you for you time, and wish you all the best of luck!
What Russia's invasion mean for developers
Tags: news, discuss, career, webdev
Published: 2022-04-16 09:48:58

I agree, Russia's invasion isn't the most ideal event in the century. However, this event is especially causing damage at the tech industry. Here's how.

## The Splinternet

The splinternet is a theory of the internet being divided, according to the splinternet theory, each country would have it's own internet, breaking the whole point of the internet. 

With Russia's invasion, Putin would likely cut Russia off the global internet, because Putin want's to keep the invasion a secret.

After that, Putin would likely create it's own internet that is 7/21 monitored by his officers. That really isn't something we want for Russia. 

## Customers

5% of my personal customers are from Russia. With Russia's invasion, the number has lowered to less than 1 percent. I am not sure how it got to this, but I am sure this isn't a coincidence.

5% is a lot for a company, so this war isn't great for big companies that have customers from Russia.

## Conclusion

Customers or even the internet is not important compared to the greater cost the war has brought us. The deaths of thousands of people, both Ukrainians and Russians.
How to Change Spring Boot Default Port?
Tags: springboot, tutorials
Published: 2022-04-23 16:33:16

---
title: How to Change Spring Boot Default Port?
published: true
date: 2022-04-16 09:01:04 UTC
tags: SpringBoot, #tutorials
canonical_url: 
---

The Spring Boot framework provides the default embedded server (Tomcat) to run the Spring Boot application. It runs on port 8080. It is possible to change the port in Spring Boot.

If you want to change the default port you have several options. But using `application.properties` option is recommended to overwrite default values.

To override the default port, we need to specify `server.port` property in application.properties file.

#### Changing Default Port in Spring Boot

In the `application.properties` file, we can set a custom port number for the property server.port

```
server.port = 9090
```

In the application.yml file, you can find as follows −

```
server: 
    port: 9090
```

#### Running Spring Boot in Random Port

In the `application.properties` file, we can set a random port number for the property `server.port`

```
server.port = 0
```

In the `application.yml file`, you can find it as follows −

```
server: 
   port: 0

```

**Note** − If the server.port number is 0 while starting the Spring Boot application, Tomcat uses the random port number based on the availability.

#### Using Command-Line Arguments

We can also set the server port using the java command line argument as follows.

```
java -jar spring-boot-app.jar --server.port=8009
```

or by using the equivalent syntax:

```
java -jar -Dserver.port=8009 spring-boot-app.jar
```

The post [How to Change Spring Boot Default Port?](https://stacktips.com/tutorials/spring-boot/how-to-change-spring-boot-default-port) first appeared on [Stacktips](https://stacktips.com).
Unpin apps from Windows 11 Start Menu
Tags: software, misc
Published: 2022-04-16 08:10:02

---
title: Unpin apps from Windows 11 Start Menu
published: true
date: 2022-04-16 07:46:38 UTC
tags: software,misc
canonical_url: https://siderite.dev/blog/unpin-apps-from-windows-11-start-menu/
---

Installing Windows 11 is a trip. Not only does it comes with its own idea on how your taskbar and start menu should look and feel without giving you even the options Windows 10 had, but it also brings so much wisdom by telling you what applications you should use most. Like every single Microsoft Office app, plus the Office loader. Meanwhile, the apps you pinned are stuck at the end of the list. You have to scroll to get to them!

Easy to fix, you might think, so you right-click on the apps expecting to get an option to unpin and you do, and you get a loading prompt and then the menu closes and... nothing happens. Like at all. Even loading the app would have been a better result.

It turns out **the answer is to press the Shift key and right click the items** , only then you get a reasonable menu that gives you the option to unpin. No such luck as being able to enter an edit mode by pressing long, so you have to unpin every single useless thing from there until you get to the few things you actually want to use without, you know, pressing the Start key and then typing what you want.

Ugh! Every generation of designers out there becomes more and more idiotic. In the near future I am sure they will reach the conclusion that the entire digital experience of humanity can be condensed into a tridimensional metaverse infinite scroll and remove any other option.
Introducing Heapland - Universal interface for data services
Tags: opensource, devops, cloud, productivity
Published: 2022-04-16 08:24:51

## The Problem
We as backend developers, must have faced situations, where the data we're working with, is stored in all over the place like -  VMs, databases, file systems, object storages and messaging infrastructure and logs. 

## The Solution

To clean up this mess, I created and open sourced [Heapland](https://github.com/heapland/heapland) to provide an unified interface to browse file system, query databases and watch message streams.

The first release (v0.1.0) gives you the following features

- Browse, upload, delete files in Amazon S3
- Browse tables, save and execute queries against popular databases - MySQL, Postgres and MariaDB.

Head over to the [Github](https://github.com/heapland/heapland) repository to know more.
Using Scope to improve Code readability.
Tags: laravel
Published: 2022-04-16 08:01:41

Laravel Query Scope is one of my favorite feature and its the one that I use extensively as it helps to keep code clean and make it more readable.

Let's suppose we have the following Code in Controller which fetches all the Posts which are active.

```
Post::query()
    ->where('active', 1)
    ->get();
```

A very simple query with one where clause. Let's convert this where Clause to a Scope. We will go to Post Model and will create a method. We will call it `scopeActive`. The method name must being with `scope`. It will have Eloquent\Builder passed to it automatically. So we will define our method like below:

```
public function scopeActive( $query ) 
{
    return $query->where('active', 1);
}
```

We can now use utilize this Scope and our Controller Code will become as below:

```
Post::query()
    ->active()
    ->get();
```

We can now use our `active` scope anywhere in our code and Laravel will automatically convert it into query. Not a big improvement, you might say, but let's look at the following example where we need to get Active Posts which are created between 2 dates.

```
Post::query()
    ->where('active', 1)
    ->whereBetween('created_at', [
        $startDate . ' 00:00:00',
        $endDate .' 23:59:59'
    ])
    ->get();
```

Let's create a scope for this. We will call it `scopeBetween` and it will accept 2 parameters, `$startDate` and `$endDate`.

```
public function scopeBetween($query, $startDate, $endDate)
{
    $endDate .= ' 23:59:59';
    return $query->whereBetween('created_at', [
        $startDate,
        $endDate
    ]);
}
```

And now we can change our Controller Code as below:

```
Post::query()
    ->active()
    ->between($startDate, $endDate)
    ->get();
```

If we compare this, our code is much more readable and a lot of noise has been removed. And we are starting to see the benefit of using Scopes.

Let us have another scenario where we want to retrieve active  Posts created during Last Month. Our Code without Scope would look like below:

```
Post::query()
    ->where('active', 1)
    ->whereBetween('created_at', [
        Carbon::now()->startOfMonth()->subMonthNoOverflow(),
        Carbon::now()->subMonthNoOverflow()->endOfMonth()
    ])
    ->get();
```

Now let us define a Scope as follows:

```
public function scopeLastMonth($query)
{
    $startDate = Carbon::now()->startOfMonth()->subMonthNoOverflow();
    $endDate = Carbon::now()->subMonthNoOverflow()->endOfMonth();

    return $query->whereBetween('created_at', [
        $startDate,
        $endDate
    ]);
}
```

And our Code which uses the above scope becomes:

```
Post::query()
    ->active()
    ->lastMonth()
    ->get();
```

As you can see, we can encapsulate our complex or repeating conditions within the scope. We can give a meaningful name to our Scopes. And then use those scopes in our code which drastically improves the readability of our code.
Enjoy Programming-Themed Humor? Here's today's daily developer joke!
Tags: jokes, dailydeveloperjokes
Published: 2022-04-16 08:00:01

---
title: "Enjoy Programming-Themed Humor? Here's today's daily developer joke!"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1259a6b60d2.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit._

<!--
Joke text:
What's the best tool for automatically ignoring long email threads about tech buzzwords?

"Block-chain"
 -->
My Swags
Tags: dev, swags, gear
Published: 2022-04-16 07:36:11

Hello, Dev's... 😊
This is an awesome collection of my developer swags...

![swag image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zknb0jcwzvc9lab5q5po.jpg)

![swag image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/al22w7uz4wqv0zl55u4t.jpg)


![swag image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f1fvkbhuuo34ucr3ab47.jpg)
![swags](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3uow5vyyio94fbmvcgs.jpg)

![swags oct 22](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/72xz6tri5yqbe82ta6r7.jpg)
Beginners journey: programming with python 0.
Tags: python, beginners, tutorial, programming
Published: 2022-04-16 07:22:01

Starting your journey as a programmer with the python programming language, probably suggested by a friend, family member, or just plain curiosity, welcome to my blogging channel which I would be uploading once a week. Be sure to start tuned and not miss the next update.
But first,
**_What is python programming language?_**

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

Python is one of the most user-friendly high-level programming languages which is easy to use and can be used in several different areas such as data science, data analysis, machine learning, web development, and so on.

**_Why python?_**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ohz9v8eglqjlfn00tk3w.jpg)
Python has been present for about 31 years now and its use is widely recognized in several companies and organizations. Based on the linked-in job posting in US and Europe, python programming experts are one of the most required in companies and businesses.






So what now?
Interested? Stay tuned and find out more 
Next week we begin officially 
Starting with a simple "Hello, world" statement
See you there.
My Journey into Software Development
Tags: beginners, webdev, java
Published: 2022-04-16 01:37:54

My journey began in the 6th grade in the year 2000 there was an after-school program that summer that allowed those students without a computer at home to learn how to utilize computers. The instructor hosting this class was a computer science major who previously worked in the field of computers and technology for a while and decided to instead teach kids math in elementary schools. This is when I first learn what HTML was. Writing a few lines in the Netscape browser. I was amazed at what a few lines of code could do like bring pages with information to life by formatting text and images to give us something so cool.



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


Fast forward to the year 2014 where again after a hard long life, I stumbled into programming in the form of a book written by Barry Burd (Java for Dummies) I fell in love with the language by reading books and watching tutorials on YouTube by a channel named mybringback (Travis). I also stumbled into the Team-Treehouse website where I wrote my first application for android with the help of their Android development track, later monetizing it and making a cool 5 grand. I was astonished how such a simple app could generate over 100k downloads and bring back so much revenue I used the money towards a new laptop to help continue on my journey.




![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lrc2gp9qsg6mumnruz1.gif) 

I am now enrolled in FlatIron Bootcamp it is very challenging and demanding but I have learned a lot in the last few weeks that will help in my pursuit of a software developer job. I am currently learning JavaScript and other technologies like HTML, CSS, and Ruby to form what is known as a FullStack Web Developer. After completion of this program, I plan to develop open-source software and as well work for a technology company that has great values and goals.
*-
Tags: orod, varansi
Published: 2022-04-16 06:58:19

A root canal is a treatment to repair and save a badly damaged or infected tooth.Pediatric dental care is also served by orodental clinic. at reasonable prices in Varanasi. Treat your teeth with painless and hygiene procedure with Dr. Praveen Kumar Do visit on our official website or contact at +91-9935614326 


Our treatments
https://bit.ly/3uZSgCQ
https://bit.ly/3je7f6F
https://bit.ly/3NRzRRj
https://bit.ly/3ujfjt8
https://bit.ly/38FPyeh