teleren/devto huggingface dataset:
Handle PostgreSQL ObjectInUse Error
Tags: database, postgres
Published: 2021-06-11 01:42:03

I had a need to be able to handle table partition management. Unfortunately the particular framework + ORM I'm using just will not handle it. So I decided to use a PostgreSQL trigger function to handle creating, updating, deleting of table partitions based on trigger actions against a tracking table.

Super cool, right?

Not so much when pytest is running and everything you do is a monstrous transaction. I wanted to flow to be like this:
1. Create a partition.
2. Insert some records
3. Delete the records by dropping the correct containing partition.

Works great in autocommit mode. Transactionally, it'll stomp those operations flat **if** you use deferred foreign key constraints (which my app database is loaded with). You end up with some variation of this error (as reported by python and psycopg2):
```
psycopg2.errors.ObjectInUse: cannot DROP TABLE "reporting_awscostentrylineitem_daily_summary_2017_01" because it has pending trigger events
CONTEXT:  SQL statement "DROP TABLE reporting_awscostentrylineitem_daily_summary_2017_01 ;"
PL/pgSQL function trfn_partition_manager() line 359 at EXECUTE
```

Holy cow! If you've forgotten that you have deferred constraints (as I did) you'll have about 15 minutes of panic before you realize that there is actually a simple answer for this. You can set all or a specified set of constraints to IMMEDIATE for the current transaction. The easy, big-hammer form of this is:
```sql
SET CONSTRAINTS ALL IMMEDIATE;
```
But please take a few minutes to [read the docs](https://www.postgresql.org/docs/12/sql-set-constraints.html). This forced the deferred constraint triggers to fire and allowed me to execute the DDL for ALTER, TRUNCATE, DROP on the affected table partition.

What a lifesaver!

Hope this helps someone out there.
Change filenames
Tags: bash, linux
Published: 2021-06-11 04:06:08

If you want to change filenames with given a prefix and do it in all inner folders, its little bit problem so this problem can solve easily with find sed and awk programs but I want to show a way just some script.

Lets define a deep first search algorithm for folders and get filenames.
{% gist https://gist.github.com/rytsh/0c3cbb436a37a3439b4abcc76ce8df00 %}

After that goes to deep folder, first searching files with regular expressions (Added asterix to code due to passing asterix cause passing all filenames to function) and executing that filename with our `${2}` given function.

```sh
[[ -n ${2} ]] && (${2} ${file})
```

Good, now can prepare change filename function and give it to this script. As you see `${file}` will be our first argument `${1}`.

```bash
function changeFileName() { mv $(pwd)/${1} $(pwd)/_${1}; }
export -f changeFileName
```

Ok than,
```bash
./check.sh .scss changeFileName
```

Now I added prefix underscore for all my related files in all folders.
A Query, if you will...
Tags: mediaqueries, beginners, css
Published: 2021-06-11 03:57:57

So here's a query for you: Do you know about **media queries**?

If you don't, I'd like to take a moment today to introduce you to them.
__________
###<center>So, what exactly *is* a media query?</center>

Basically, a media query is something used in CSS to set certain rules conditionally. Media queries are super useful if you want to make your page/project responsive (fitting to various screen sizes).

We define media queries by using the `@media` rule. Frequently, we see if used in the following way:
```
@media screen and (max-width: 1025px){
     // conditional CSS goes here
}
```
*where it says `max-width` may appear a little differently (ie. `min-width`, etc.)*

Media queries can be super helpful if you want something to only appear in a desktop view or perhaps appear differently in a mobile view. An example of that would be having a button that does not display on mobile devices/screens smaller than 812px:
```
@media screen and (max-width: 812px){
     button { display:none; }
}
```

**BONUS** If you have been following along with my blog posts and have been using styled-components, you can use media queries in the following way:
```
const ConditionalBackground = styled.div`
     background-color: #ff6b35;
     @media screen and (max-width: 960px){
          background-color: #15b7d7;
     }
`
```
________
###<center>So why is this important?</center>
Like I said, media queries are super helpful for formatting your design to fit various screen types. Nowadays, so many people use mobile devices to surf the web or check out apps. If you want people to want to use your applications, it will certainly be to your benefit to make sure that what they see is what you intend.

If you're still reading, here's a final query for you: **what are you waiting for?!** Go give it a shot!
Calculator
Published: 2021-06-11 03:56:04

Hello there! As I continue to progress in my programming journey, I decided to learn something new. As a quick flashback, I started off with basic python projects and then learnt about DBMS with SQL and Python mySQL. So, I decided to now move onto the user interface side by learning about Flutter.

Flutter is one of the latest user interface programming languages created by Google and I found this introductory course by The Net Ninja on Youtube quite useful.
<a https://www.youtube.com/playlist?list=PL4cUxeGkcC9jLYyp2Aoh6hcWuxFDX6PBJ>Intro to Flutter</a>
They go through the basics of Dart programming and the creating of basic functions and widgets on the application.

Thereafter, I decided to use my newfound knowledge to create a Calculator App. I ran my code to display it on Google, which gives us the capabilities to see what phone users will see. I then experimented with designs, colors, display, buttons and came up with a calculator -shape app for which pressing the buttons will show text on the screen.

The came the part about evaluating the equation. I did that in another function and evaluated the text using the _eval_ function which I created using a simple algorithm. I separated the string into 2 on the either side of the sign. Used the _eval_ function on them. Returned the values and then calculated the final equation. I then displayed in the text form on the screen.

This experience was fun and enriching as I learnt about stateful and stateless widgets and designing apps in general.
My super mart
Published: 2021-06-11 03:37:40

After learning about and experimenting with Databases in the previous project. I decided to go next level with a project that requires more tables in my database. After some research online, I decided to make my very own super mart managed on a database.
In this database, I will be managing, customer interactions, item handling and price management.

Let us first talk about item handling. So, I first created a table *seller_details* to store the details about the vendors from whom I was going to purchase my items from. For example, I may purchase breads from Raj's Bakery. So, I will store their name, phone, email and address...just as I did in my contact book project.
Then, I created a table of *stock_type* that will store all the types of items I will store in my shop like oranges, apples, bananas, milk, etc. I also created a table that stored details of all the items I had in my store like the name _Beautiful Bananas_, their quantity, their sale and purchase prices, etc. .

Then, I had to look into customer management so I created the tables *customer_details* and *customer_purchase_details*. The first table stored details of my customers like name, phone, email and address... just as I did in my contact book project. The cutomer_purchase_details stored all the transactions they had made. They stored the item bought, the quantity and the price they paid.

Finally, I created a table for my income management that stored the details of all the income I had made.

Overall, in this project I learnt about database handling, SQL syntax and how to connect python to sql.
Better Django Hasher
Tags: django, github, template, tutorial
Published: 2021-06-11 03:34:23

Django support multiple password hash algorithm, however two hash that it support but not come out of the box are Argon2 and Bcrypt. This post will show how we can make for a better Django Password hasher our project. 

## Installing Argon2 Library

We can install the Argon2 library as follow 
```
pipenv install django[argon2]
pipenv lock -r > requirements.txt
```

## Update Settings

in your settings.py just add the following line

```python
PASSWORD_HASHERS = [
    'django.contrib.auth.hashers.Argon2PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
    'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
]
```
That's it and now your password is being hash with a much better password hasher.

## End

With just 2 simple steps, your user password is being hash with a better password hasher. Why not just implement this in your project, as you got nothing to loose and so many to gain.
Artificial Intelligence and Microchips: A Revolutionary Step in Drug Discovery
Tags: ai
Published: 2021-06-11 03:24:00

<p>3Brain AG recently announced the development of a new technology that integrates microchips and artificial intelligence. The revolutionary duo has the potential to fundamentally alter how drug candidates are selected in the preclinical stage. This increases their chances of success.<br><br>Preclinical studies are deemed to be the most critical for identifying safety and efficacy concerns promptly. Despite numerous advancements in drug delivery, it frequently fails due to limited drawbacks in preclinical tests on animal models. Another significant disadvantage is that drugs that work successfully in animals often fail to work in humans.<br><br>To address the pervasive problems associated with drug delivery, new biotechnologies are being introduced. New biotechnologies that mimic and perform similarly to human stem cells are considered viable alternatives to animal models.</p>
<p>These structures are created using a combination of artificial intelligence and microchips and consist of cell culture and organoid assays that can be used as drug testbeds. These cell-based assays are transforming the process of drug development.</p>
<h2>The Disruption of the Traditional: A Transition from the Traditional to the Biotechnological</h2>
<p>Medical experts and physicians have expressed dissatisfaction with traditional drug delivery methods. Due to several limitations, conventional methods of drug delivery were unable to act across a wide bandwidth. Standard plastic multi-well plates are transformed into intelligent devices with multi-core processing power from a sustainability and cost perspective. These devices are programmable and can be updated regularly.</p>
<p>The ultimate goal is to accelerate the delivery of cures for diseases, thereby increasing readiness. This can be described as a significant and necessary disruption of the established paradigm while preserving cost-effectiveness and sustainability.</p>
Code Smell 78 - Callback Hell
Tags: javascript, node, oop, tutorial
Published: 2021-06-11 03:06:33

*Processing an algorithm as a sequence of nested callbacks is not clever.*

> TL;DR: Don't process calls in a callback way. Write a sequence.

# Problems

- Readability

- Hard to debug.

- Complexity

# Solutions

1. Change callbacks to sequence calls.

2. Extract repeated Code

3. Refactor.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/110f803da03a27f4024ebbce97154307)
```javascript
var fs = require('fs');

var fileWithData = '/hello.world';  
fs.readFile(fileWithData, 'utf8', function(err, txt) {  
    if (err) return console.log(err);

    txt = txt + '\n' + 'Add Data!';
    fs.writeFile(fileWithData, txt, function(err) {
        if(err) return console.log(err);
        console.log('Information added');
    });
});
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/90622aea76933ddedea1fd344dbe4751)
```javascript
var fs = require('fs');

function logTextWasAdded(err) {  
    if(err) return console.log(err);
    console.log('Information added');
};

function addData(error, actualText) {  
    if (error) return console.log(error);

    actualText = actualText + '\n' + 'Add data';
    fs.writeFile(fileWithData, actualText, logTextWasAdded);
}

var fileWithData = 'hello.world';  
fs.readFile(fileWithData, 'utf8', addData);  
```

# Detection

This problem shines at the naked eye. Many linters can detect this complexity and warn us.

# Tags

- Readability

- Complexity

# Conclusion

Callback Hell is a very common problem in programming languages with futures or promises.

Callbacks are added in an incremental way. There's no much mess at the beginning.

Complexity without refactoring makes them hard to read and debug.

# Relations

{% post https://dev.to/mcsee/code-smell-06-too-clever-programmer-37lb %}
 
* * *

> There are two ways to write code: write code so simple there are obviously no bugs in it, or write code so complex that there are no obvious bugs in it.

_Tony Hoare_
 
{% post https://dev.to/mcsee/software-engineering-great-quotes-26ci %}

* * *

This article is part of the CodeSmell Series.

{% post https://dev.to/mcsee/how-to-find-the-stinky-parts-of-your-code-1dbc %}
Day 385 : Feeling Good
Tags: hiphop, code, coding, lifelongdev
Published: 2021-06-10 22:46:48

_liner notes_:
- Professional : Got help from the team on how to download a recording I made from a demo to help with a community question. The recording proved that the demo worked the way the user wanted. Felt good. While working on the question, I found a small typo in the documentation. A boolean had quotes around it, so I just removed it and made a PR. Had a pretty cool meeting with the Artificial Intelligence team and talk about what they are working on. Some cool stuff in the future. Got on a video call with a team mate to test out some functionality. Also had a quick team meeting. Pretty productive day.

- Personal : Last night, I worked on getting modals to show up with different information depending on what was clicked. Also got the Twitter and Github login working and when someone logs in, the UI changes.

![A path covered in brown leaves going thorough a green forest in Speulderbos, Netherlands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oyc71z717137pewxiu6v.jpg)

So, I definitely took a nap after work. haha Feeling pretty good right now. I want to get more info on the user like username that isn't saved when a person logs in, but it is available right after the user logs in, so I'll add it then. Going to get that working and the section where people can sign up to do lightning talks during the breaks.

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube 25BP-eioBG4 %}
🔥 Datatypes in JavaScript
Tags: javascript, datatypes
Published: 2021-06-11 02:57:06

☑️ What are Datatypes ? 

It defines the category for data which will be stored in a variable 

☑️ Types of Datatypes ? 

a. Primitive
b. Object/Reference

☑️ Primitive Datatypes ?

The datatypes which hold only single value at a time is called Primitive Datatype

Example: number, Boolean, character, String, null, undefined

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

☑️ Object/Reference Datatypes ?

The non-primitive datatypes are called object based/reference data types

Ex: Arrays, Objects itself. 

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vcv5brvu993w48a8at58.png)
How to Configure Git Username and Email Address
Tags: github, git, bitbucket
Published: 2021-06-11 02:51:09


Git is a distributed version control system that’s being used by most software teams today. The first thing you should do after installing Git on your system is to configure your git username and email address. Git associate your identity with every commit you make.

Git allows you to set a global and per-project username and email address. You can set or change your git identity using the `git config` command. Changes only affect future commits. The name and email associated with the commits you made prior to the change are not affected.

## Setting Global Git Username and Password

The global git username and password are associated with commits on all repositories on your system that don’t have repository-specific values.

To set your global commit name and email address run the `git config` command with the `--global` option:

```
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"
```

Once done, you can confirm that the information is set by running:

```
git config --list
```

```
user.name=Your Name
user.email=youremail@yourdomain.com
```

The command saves the values in the global configuration file, `~/.gitconfig`:

~/.gitconfig

```
[user]
    name = Your Name
    email = youremail@yourdomain.com
```

You can also edit the file with your text editor, but it is recommended to use the `git config` command.

## Setting Git Username and Password for a Single Repository

If you want to use a different username or email address for a specific repository, run the `git config` command without the `--global` option from within the repository directory.

Let’s say you want to set a repository-specific username and email address for a stored in the `~/Projects/myapp` directory. First, switch the repository root directory:

```
cd ~/Projects/myapp
```

Set a Git username and email address:

```
git config user.name "Your Name"
```

Verify that the changes were made correctly:

```
git config --list
```

```
user.name=Your Name
user.email=youremail@yourdomain.com
```

The repository-specific setting are kept in the `.git/config` file under the root directory of the repository.

## Conclusion

The Git username and email address can be set with the `git config` command. The values are associated with your commits.
How to list all SSL certificates issued by Certbot and how to delete one in Ubuntu
Tags: ubuntu, ssl, certbot
Published: 2021-06-11 02:45:04

If you are using Let’s Encrypt Certbot to issue SSL certificates for your site and want to display a list of all your SSL certificates.

You can run the following if your server is using certbot.

`certbot certificates`

![List all SSL certificates issued by Certbot in Ubuntu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqsd0xdgunwl28tkqtrb.png)

To delete a Let’s Encrypt SSL certificate that is on your server run the following.

`certbot delete`

and choose the number that correspond to the site you want to delete the SSL certificate for.

![Delete SSL certificates issued by Certbot in Ubuntu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwszxzztaec49749av63.png)
Useful Git commands that may save your life
Tags: git, command, guthub, useful
Published: 2021-06-11 02:41:30

Git commands aren't always easy. If they were, we would have these commands at our disposal. They would be super helpful for performing everyday tasks like creating or renaming a git branch, removing files, and undoing changes.

In this post, I’m focusing on major git commands that gets all (almost) your work fulfilled.

## How to undo the most recent local commits in Git?

You can run

```bash
$ git reset HEAD~1
```

You can even undo your commit but leave your files and your index:

```bash
$ git reset --soft HEAD~1
```

If you want to permanently undo the commit and you have cloned some repository:
To get commit id:

```bash
$ git log
```

```bash
$ git reset --hard <commit_id>

$ git push origin <branch_name> -f
```

## How to undo a public commit?

You can just run

```bash
$ git revert HEAD
```

## How to delete a Git branch locally and remotely?

- Deleting local branch

```bash
$ git branch -d <branchname>
```

- Deleting remote branch

```bash
$ git push origin --delete <branch>
```

## How to revert to a particular commit?

To revert to a particular commit you'll need a commit id. To get a commit id just run

```bash
$ git log
```

Then copy the commit id you want to rever back to. And then run:

```bash
$ git revert <commit-id>
```

## How Undo a git stash?

You can just run:

```bash
$ git stash pop
```

and it will unstash your changes.

In case you want to preserve the state of files (staged vs. working), use

```bash
$ git stash apply --index
```

## How to undo 'git add' before commit?

You can undo `git add` before commit with

```bash
$ git reset <file>
```

**To unstage all due changes**

```bash
$ git reset
```

## How to rename a local Git branch?

```bash
$ git branch -m <oldname> <newname>
```

- To rename current branch

```bash
$ git branch -m <newname>
```

## How to discard unstaged changes in Git?

- For all unstaged files

```bash
$ git checkout -- .
```

- For a specific file

```bash
git checkout -- path/to/file/to/revert
```

**Note**: -- here to remove argument ambiguation.

## How to delete all tags from a Git repository?

To delete remote tags simply do:

```bash
$ git tag -l | xargs -n 1 git push --delete origin
```

and then delete the local copies of tag:

```bash
$ git tag | xargs git tag -d
```

## Conclusion

I hope this post saved your time and life. If you liked the post, feel free to share it to help others find it!

You may also want to read <a href="https://pratapsharma.io/getting-started-with-git/" target="_blank">Getting Started with Git - A beginner's guide</a>

You may also follow me on <a href="https://www.linkedin.com/in/prataps22/" target="_blank">LinkedIn</a> and <a href="https://twitter.com/Pratap2210" target="_blank">Twitter</a>.

💌 If you’d like to receive more tutorials in your inbox, you can sign up for the newsletter [here](https://pratap.substack.com).
Top 5 DEV Comments from the Past Week
Tags: bestofdev
Published: 2021-06-11 02:25:46

---
title: Top 5 DEV Comments from the Past Week
published: true
description: 
tags: bestofdev 
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nvjh80kv1nr41sw6wxke.png
---


_This is a weekly roundup of awesome DEV comments that you may have missed.  You are welcome and encouraged to boost posts and comments yourself using the **[#bestofdev](/t/bestofdev)** tag._


[Becoming a successful developer](https://dev.to/krowser/how-to-become-a-successful-developer-4h2g) is a long, complicated process. Thanks for adding to the conversation, @valeriavg !

{% devcomment 1f71g %}


No one's a fan of [endless online courses](https://dev.to/dragosgn/7-steps-to-become-an-expert-software-engineer-without-endless-online-courses-or-waiting-for-years-m8j), and neither is @keskyle17 ! Thanks for the tip, here!
{% devcomment 1f57c %}


This is a great post on [websites to practice frontend skills](https://dev.to/codewell/7-websites-to-practice-your-frontend-development-skills-54de) - thanks @lostgirljourney for adding another to the list!
{% devcomment 1f62m %}

A [togglable dark mode theme](https://dev.to/sbrevolution5/creating-a-toggleable-dark-mode-theme-ned) is such a cool feature. Thanks to @ianwijma for helping make the idea a reality!
{% devcomment 1f4l5 %}

[JavaScript tip](https://dev.to/techygeeky/top-20-javascript-tips-and-tricks-to-increase-your-speed-and-efficiency-283g) fans, this article is for you!! Thanks for the additional bit of insight here, @martinmuzatko!
{% devcomment 1f7oh %}


See you next week for more great comments ✌
June 10th, 2021: What did you learn this week?
Tags: weeklylearn, discuss, weeklyretro
Published: 2021-06-11 02:15:11

It's that time of the week again. So wonderful devs, what did you learn this week? It could be programming tips, career advice etc.

<center>

![Image of the brain](https://media.giphy.com/media/ojmB7lOn3VUU8/giphy.gif)
</center>

Feel free to comment with what you learnt and/or reference your TIL post to give it some more exposure.

{%tag todayilearned %}

And remember, if something you learnt was a big win for you, then you know where to drop it as well.👇👇🏻👇🏼👇🏽👇🏾👇🏿

{%link https://dev.to/devteam/what-was-your-win-this-week-4oa2 %}

<center>

![Little kid making a fist as if to say "Yes!"](https://media.giphy.com/media/6brH8dM3zeMyA/giphy.gif)
</center>