teleren/devto huggingface dataset:
Angular 11 Django CRUD PostgreSQL tutorial
Tags: angular, django, postgres, crud
Published: 2020-12-06 10:47:27

Tutorial Link: [Angular 11 Django CRUD PostgreSQL tutorial](https://ozenero.com/angular-11-django-crud-postgresql-example)

![Angular 11 Django CRUD PostgreSQL tutorial](https://ozenero.com/wp-content/uploads/2020/12/Django-Angular-11-Postgresql-crud.jpg)

In this tutorial, we show you Angular 11 Http Client & Django Server example that uses Django to do CRUD with PostgreSQL (including finder method) and Angular 11 as front-end technology to make request and receive response.

## Technologies
– Django 2.1
– Angular 11
– RxJS 6
– PostgreSQL 9.5

## Django Server

![Django Server](https://ozenero.com/wp-content/uploads/2020/12/Django-Angular-11-Rest-Api-PostgreSQL-Django-Server-Architecture.png)

With this system, we can use Angular Client to work with PostgreSQL Database via Django Server which has APIs:

1. GET api/customers/: get all customers
2. GET api/customers/[id]: get a customer by id
3. GET api/customers/age/[age]: find all customers by age
4. POST api/customers/: save a customer
5. PUT api/customers/[id]: update a customer by id
6. DELETE api/customers/[id]: delete a customer by id
7. DELETE api/customers/: delete all customers

## Angular 11 Client

The image below shows overview about Angular Components that we will create:

![Django Angular 11 Rest Api Postgresql – Angular Client Component](https://ozenero.com/wp-content/uploads/2020/12/Django-Angular-11-Rest-Api-Postgresql-Angular-Client-Component.png)

## Project Structure

There are several folders and files in our Django project:

![Django Project Structure](https://ozenero.com/wp-content/uploads/2019/03/django-angular-6-rest-api-postgresql-django-project-structure.png)

– customers/apps.py: declares CustomersConfig class (subclass of the django.apps.AppConfig) that represents our Django app and its configuration.
– gkzRestApi/settings.py: configures settings for the Django project, including INSTALLED_APPS list with Django REST framework and Customers Application.
– customers/models.py: defines Customer data model class (subclass of the django.db.models.Model).
– migrations/0001_initial.py: is generated by makemigrations command, includes the code to create the Customer model, will be run by migrate to generate PostgreSQL database table for Customer model.
– customers/serializers.py: declares CustomerSerializer class (subclass of rest_framework.serializers.ModelSerializer) for Customer instances to manage serialization to JSON and deserialization from JSON.
– customers/views.py: contains methods to process HTTP requests and produce HTTP responses (using CustomerSerializer).
– customers/urls.py: defines urlpatterns to be matched with request functions in the views.py.
– gkzRestApi/urls.py: defines root URL configurations that includes the URL patterns declared in customers/urls.py.

## Related posts

 [Django RestApis example – GET/POST/PUT/DELETE requests to PostgreSQL database](https://ozenero.com/django-restapis-postgresql-example-django-rest-framework-tutorial)
Advent of code - Day 5
Tags: javascript, typescript, adventofcode
Published: 2020-12-06 11:01:01

Are you participating in the [Advent of code](http://adventofcode.com) this year?

If you don't know what the advent of code is, it's a website where you'll find a daily challenge (every day it gets harder). It's a really fun event, you should participate!

I try to solve the exercises using either JavaScript or TypeScript and will share my solutions daily (with one day delay so no one can cheat!). I only share the solution for the second part.

For day #5, I starter with such complicated solutions... Took me a while to realise that this one was probably the easier we had to tackle since the beginning!

In the end, no need to do any binary operation. You just need to filter an array:
```js
const allIds = tickets.map((ticket) =>
  parseInt(
    ticket
      .split("")
      .map((char) => (char === "B" || char === "R" ? 1 : 0))
      .join(""),
    2
  )
);
const min = Math.min(...allIds);
const max = Math.max(...allIds);
const possibilities = Array.from(Array(max).keys()).slice(min);
const [seat] = possibilities.filter((p) => !allIds.includes(p));
```

Feel free to share yours in the comments!

________________________

Photo by [Markus Spiske](https://unsplash.com/@markusspiske?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText) on [Unsplash](https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText)
how does Entity Framework Core figure out where to get the connection string in .NET Core app?
Tags: csharp, dotnet, entityframeworkcore
Published: 2020-12-06 10:50:13

have you ever wondered how does EF Core finds the connection string even if you have decoupled the connection string from the Context class? 
# first in Asp.net Core :
what if your context class looks like this 
```
    public class ApplicationDBContext : DbContext
    {
        public ApplicationDBContext(DbContextOptions options):base(options){}

        public DbSet<Employee> Employees { get; set; }   
    }   
```
the proper way to put the connetion string is to put in a seperate file for example appsettings.json and we usually register the context class in the ConfigureServices
method in startup.cs like this

```
 public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<ApplicationDBContext>(
                dbContextOptions =>
                 dbContextOptions.UseMySql(Configuration.GetConnectionString("DefaultConnection"))); 
        }
```

EF core actually have a convention to follow to find the connection string, if we comment the CreateHostBuilder method EF will output this error 

```
Unable to create an object of type 'ApplicationDBContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
```

this means Entity looks for this method and figure out what is the name of the startup class in the UseStartup method and then figure out how to instantiate the Application context. 
# in console app

and if you are using a simple console App in .Net Core then and you dont create a constructor with parameters then  it simply looks for the OnConfiguiring method and looks for the connection string.
Git Bash Customization (on windows)
Tags: git, gitbash, shell
Published: 2020-12-06 10:45:27

# A simple Costumization tutorial

### Turn This : 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/99pazysxd9fyur4k9r5n.jpg)


### Into This (or any style):
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/nbmq3wvglc7mlv3zggab.jpg)

## The easy way
Go to bash settings by simply right-clicking and go to options menu. 
There you will find the "Looks" tab. 
You can play with the themes and properties to make it look the way you like. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/bbyz69rhyp7dvq78lxhq.jpg)

## The cool way
Using this method you can change some more things like the window title for example.

1. go to `C:\Program Files\Git\etc\profile.d\`
2. open `git-prompt.sh` as administartor in your favorite code editor. (I found an easy way, to open Powershell as administrator and then open vscode from there). 
 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mgyj9pdhuf8tus63qims.jpg)

In the file this is what you suppose to find:
 

```shell
PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]' # set window title
PS1="$PS1"'\n'                         # new line
PS1="$PS1"'\[\033[32m\]'               # change to green
PS1="$PS1"'\u@\h '                     # user@host<space>
PS1="$PS1"'\[\033[35m\]'               # change to purple
PS1="$PS1"'$MSYSTEM '                  # show MSYSTEM
PS1="$PS1"'\[\033[33m\]'               # change to brownish yellow
PS1="$PS1"'\w'                         # current working directory
```
The comments talk for themself... 

I change it to be :
```shell
PS1='\[\033]0;Git-Bash\007\]'  # set window title Git-Bash
PS1="$PS1"'\n'                 # new line
PS1="$PS1"'\[\033[32m\]'       # change to green
PS1="$PS1"'\u -> '             # user -> 
# removed  MSYSTEM
PS1="$PS1"'\[\033[33m\]'       # change to brownish yellow
PS1="$PS1"'\W'                 # current working Folder(not the whole path)
```

And, That's it!
Three things I am applying since I am programming (and you should too)
Tags: codenewbie, tips, career, motivation
Published: 2020-12-06 10:44:12

 [Originally posted on blog.accolades.dev]
(https://blog.accolades.dev/2020/11/01/three-things-i-am-applying-since-i-am-programming/)

Back in February 2019, I started my journey in programming. It was an incredible adventure up to this point, having all the tools and tutorials at hand and it was a trip with ups and downs.
I thought this week I’ll write about the most important things I’ll consider to advise people like me, juniors, that they recently started their coding adventure. As usual, I broke the information into parts, this time in three:

- Take notes;
- Apply the concepts; 
- Document your journey.

###Take notes!
Whether are handwritten notes or you are writing them on your device, take notes! Repeat the information by writing what you’ve just read or watched. It will remain engraved into your brain and you’ll have access to it at a later time. 
There are many ways of taking notes, not just writing, find the one that works for you, and use it. 
I am writing my notes in my Notebook and it’s beneficial, especially when I need to revisit concepts that I tend to not use for long. I am also using apps like Trello for cross devices. 

###Apply the concepts.
One of the best ways to test what you are learning is to apply. 
By applying, I mean building. Build projects, implement what you have learned. Even that it’s sometimes accompanied by struggle. Let me be blank: the struggle is part of the journey and it’s the part where you improve. 
Also, applying the concepts gives stability to fundamentals and builds a strong foundation on what you are learning. 
You can check my latest project here.

###Document your journey.
I know I recently said this, but again I am insisting on this topic. It’s important to document your adventure into coding. Go ahead, write a book if necessary! Sell it for 5$ or make a giveaway, but please document your path taken. You’ll thank yourself later.
One of the main benefits of documenting your journey is that you learn a lot while you are writing about the topic(s) you are studying and you don’t allow yourself to provide wrong information about it. You can record voice messages or paint on your Notebook, but this is a very important strategy to apply for growth. 

###Conclusion:
_Take notes_, benefits: the information remains engraved into your mind and you can revisit points you didn’t understand;
_Applying_ the concepts, benefits: you learn and you build a strong good foundation by practice; 
_Document your journey_ benefits: you study the topic before documenting it, you can’t afford to release wrong information.
 
That’s it for this week’s article. 
I am Luc and I like to think of myself that I am a 40+ of age teenager 🙂. 
Until next time, happy coding.

Connect with me on [Twitter] (https://twitter.com/accolades_dev) and on [LinkedIn](https://www.linkedin.com/in/luc-constantin/)
From 100% to 0% CPU with memoization
Tags: python, programming, tutorial, codequality
Published: 2020-12-06 10:43:12

I have followed the 30 first minutes of the freecodecamp training named [Dynamic Programing for Beginners – How to Solve Coding Challenges with Memoization and Tabulation](https://www.freecodecamp.org/news/learn-dynamic-programing-to-solve-coding-challenges/). 

The first part is about programming efficiency and timing but also about infrastructure resources.

The training shows Javascript examples, but I moved to Python ♥️

The code:

```python
def fib(n):
    if n == 0:
        return 0
    if n == 1:
        return 1
    return fib(n - 1) + fib(n - 2)

print('The first 50 fibonacci numbers are:')
print(','.join([str(fib(n)) for n in range(50)]))
```

It takes too many CPU resources and it doesn't even finish:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/uoy3461kbyqyd6ifhp1m.png)

Moving to:

```python
def fib(n, memo={}):
    if n in memo:
        return memo[n]

    if n == 0:
        return 0

    if (n <= 2):
        return 1

    memo[n] = fib(n - 1, memo) + fib(n - 2, memo)
    return memo[n]

print('The first 50 fibonacci numbers are:')
print(','.join([str(fib(n)) for n in range(50)]))
```

Takes less than a second to run and almost no CPU resorces:

```sh
real    0m0.156s
user    0m0.075s
sys     0m0.059s
```
EVOLUSI PERKEMBANGAN APLIKASI
Tags: softwarekomputer, aplikasiandroid, aplikasifullversion, aplikasigratis
Published: 2020-12-06 10:40:03

Source : https://www.toga-sarjana.club/

Aplikasi atau “Application” adalah Software komputer yang yang ditulis dalam suatu bahasa pemprograman sedemikian rupa yang dipergunakan untuk menjalankan perintah atau memanfaatkan kemampuan komputer untuk pekerjaan user. Dalam perjalanannya aplikasi ditemukan dalam proses sejarah yang cukup panjang.

Dalam sejarah perjalanan aplikasi sampai saat ini tidak luput dari Aljabar Boolean yang dikenal sebagai salah satu andalan semua software. Bolean sendiri menggunakan kode Binary Digit (Bit) yang terdiri dari dua angka yang bermakna (ON berarti benar, sedangkan OFF yang berarti salah).

Kekurangan boleon sendiri adalah konsep yang terlalu rumit sehingga kelompok Programmer sepakat untuk membentu suatu kelompok Bit yang terdiri atas 4 bagian. Kode binary digit dikelompokkan terdiri atas beberapa bit, yaitu :  4 Bit (Nible), 8 Bit (Byte), 2 Byte (Word) dan 32 Bit (Double Word).

Kelompok Kode Binary tersebut membantu software komputer pada berbagai tugasnya masing-masing, seperti merakit beberapa kode untuk menjadikan struktur instruksi. Struktur intruksi tersebut seperti, operasi logika, penyimpanan, transfer, bahkan sampai pada proses pembentukan kode baru yang dikenal pada saat ini yaitu Assembler. Kumpulan kode tersebutlah yang menjadi cikal bakal untuk penentuan pembuatan Aplikasi yang semakin berkembang.

Dalam sejarahnya, perkembangan aplikasi terdapat beberapa evolusi perangkat lunak yaitu :
1.	Era Pioner, merupakan perangkat lunak yang terdiri dari sambungan kabel antar beberapa bagian yang ada didalam komputer. Dalam era ini dikenal dengan sistem basis data sebagai pemisah antar program dan data.
2.	Era Mikro, Merupakan dimana dalam era ini ada pembagian perangkat lunak dibedakan menjadi sebagi berikut :

•	Aplikasi Sistem, Contohnya Windows, Machintosh Linux dan lainnya.

•	Software, Dikomputer sendiri Aplikasi di kategorikan beberapa jenis yaitu, Pertama Aplikasi pengola kata yang lebih dikenal dengan nama Microsoft Word, Kedua Aplikasi pengola angka seperti, Microsoft Excel dan Kalkulator, Ketiga Aplikasi pengola Data seperti Microsoft Access, Keempat Aplikasi pengola Grafis  yang sering digunakan sebagai pengeditan seperti Adobe Photoshop, Corel Draw, AutoCad dan lainnya.

Di era modern saat ini, fungsi aplikasi begitu luas dapat mengenal gambar, audio, video. Bahkan saat ini ada beberapa aplikasi yang tergolong canggih untuk mengsingkronkan antar beberapa perangkat baik itu Komputer, Tablet, dan Android dengan menggunakan Aplikasi yang semakin berkembang.

Jika anda tertarik untuk mendapatkan kumpulan aplikasi populer saat ini silahkan kunjungi website kami.
Solving day 6 of Advent of Code 2020 in JavaScript
Tags: challenge, adventofcode, javascript, video
Published: 2020-12-06 10:37:43

---
title: Solving day 6 of Advent of Code 2020 in JavaScript
published: true
description: JavaScript walkthrough of Advent of Code 2020 (day 6)
tags: challenge, AdventOfCode, javascript, video
series: Advent of Code 2020 in Javascript
---

{% youtube MzuagcMUVpU %}
Book: Introduction to Lambda Calculus by Henk Barendregt and Erik Barendsen
Tags: functional, lambda, math, science
Published: 2020-12-06 10:31:02

It briefly explains the foundation of Lambda Calculus. The descriptions are mathematically heavy. Some of the unexpected implications might be impressive. 

## For beginners: 
It might be a fascinating demonstration of how even the simplest programming concepts are powerful.

## For experienced:
It seems to be like a perfect initial step to learn the foundations of mathematics.
My First Javascript Application On Codecanyon
Tags: javascript, application, codecanyon, plugin
Published: 2020-12-06 10:29:55

I made a javascript plugin and upload it on codecanyon. This is a simple plugin. Digital clock for the website.

Features:
  # User/Beginner-friendly
  # Standered coding
  # Fully customizable
  # Support multiple instances on one page
  # Enable show/hide AM/PM
  # Style, Color, Font, Background, Border, Box Shadow, etc customizable
  # Enable/Disable year, month, week, date, minute, second, millisecond

Link: https://codecanyon.net/item/fully-customizable-digital-clock-javascript/29549094.

How is it?
Difference Between classList and className
Tags: javascript, html, classlist, classname
Published: 2020-12-06 10:26:15

We use classList and className on JavaScript DOM to manipulate classes from the element. These two DOM property has different use cases. Let's see what is the main difference between them.

## classList

* Using `classList`, you can add or remove a class without affecting any other classes the element may have.

* So this is helpful for adding additional classes to an element that contain other classes.

* `classList` has some handy methods like `toggle` and `replace`.

```
if (clicked) {
    button.classList.add('clicked');
} else {
    button.classList.remove('clicked');
}

```
Here if the button was clicked it will add the **clicked** class along with other classes the element may have and it will remove only the **clicked** class from the element.

## className

* If you use `className`, it will wipe out any existing classes while adding the new one (or if you assign an empty string it will wipe out all of them).

* Using `className` can be a convenience when you know this element will not use any other classes.  

```
if (clicked) {
    button.className = 'clicked';
} else {
    button.className = '';
}

```
In this case, `className` will wipe all the classes the element may have and add **clicked** class to it. The empty string('') will wipe all the classes.

## Conclusion

* My recommendation would be to use `className` whenever possible.

* Use `classList` when you need classList methods like toggle, replace, etc.
SVG - getTransformedPoint(point, element)
Tags: codepen, svg, transform, javascript
Published: 2020-12-06 10:07:06

---
title: SVG - getTransformedPoint(point, element)
published: true
tags: codepen, svg, transform, javascript
---

<p>When you get a Point from an SVG element you should take into account that the element can have gone through some transformations, like here where a CSS animation rotates the SVG Group in which the circle and the path are located.</p>

{% codepen https://codepen.io/netsi1964/pen/eYdZVob %}
Leetcode 101
Tags: computerscience, algorithms
Published: 2020-12-06 10:16:45

Hi, there are 5 different results that you will get while submitting a solution to [Leetcode](https://leetcode.com/problemset/all/?difficulty=Easy): 

1. compilation error: syntax error in your code because your code does not compile
2. runtime Exception: e.g. ArrayOutOfBoundsException, NullPointerException
3. wrong answer: your code may work for some unit test, but no for all test cases
4. [time limit exceeded (TLE)](https://dev.to/geyuqiu/leetcode-tle-explained-2eah)
5. accepted
Leetcode TLE explained
Tags: computerscience, algorithms
Published: 2020-12-06 10:15:40

Time limit exceeded (TLE) can be one of the most frustrating results when working on [hard problems on Leetcode](https://leetcode.com/problemset/all/?difficulty=Hard). 
 
Most of the easy and medium problems on Leetcode do not have any time constraints regarding how complex your algorithm should be, as long as you get all of the test cases right. However, you should make sure that your solution time complexity is somewhere between O(n^2) and O(n).

In my experience, we have a time constraint on hard problems that is between O(nlogn) and O(n). If you get a TLE, look at your algorithm and calculate the complexity. This means your algorithm should be at least faster than [merge sort](https://www.bigocheatsheet.com/). If you have any problems there, please take a look at these 2 books: [cracking the coding interview](https://www.amazon.com/Cracking-Coding-Interview-Programming-Questions/dp/0984782850) and [elements of programming interviews] (https://www.amazon.de/-/en/Adnan-Aziz/dp/1479274836)


If you have any questions, write me something :) 
And keep updated on my channel!
AoC: 2020 Day 06 AWK
Tags: adventofcode, awk
Published: 2020-12-06 10:11:35

⚠️ **SPOILER ALERT** ⚠️
This is a post with my solutions and learning from the puzzle. Don't continue reading if you haven't tried the puzzle on your own yet.

If you want to do the puzzle, visit [adventofcode.com/2020/day/6](https://adventofcode.com/2020/day/6).

# AWK

AWK is an useful tool in the command-line when processing text-files. It has it's own "programming language" which makes it quite powerful. 

## Prerequisite understandings

**Built-in variables:**
There are built-in variables in AWK. These are useful to know when doing more complex calculations. In this code I will use `FS` and `NF`.

- `FS`: Field seperator. It defaults to blank space " ".
- `NF`: Number of fields. A counter for number of fields in current line.

**No initialize required:**
You don't need to initialize variables in AWK. Running `var1++` is a valid statement. It will initialize `var1` to `0` and then add one. The same principle applies to arrays.

`array['X']++` initializes an empty array and then set the key-value. Will equal: `{ "X": 1 }`

**Structure:**

```
pattern1 { ACTIONS; }
pattern2 { ACTIONS; }
pattern3 { ACTIONS; }
```

The pattern is usually a regex for matching lines. For example: ` /name/ { print $1} `. There are two built-in patterns `BEGIN` and `END`. They run at the beginning and end of the program. They are good for initializing variables  and output results.

**Fetching fields:**
In an action the fields are accessed by `$1` notation. `$0` is the whole line. `$1` is the first field, `$2` is the second field and so on. It is allowed to use variables:
```
echo "Hello! My name is Christopher." | awk '{ i=5; print $i }'
# Output: Christopher.
```

## Solution

```AWK
BEGIN {
  # Field separator. Sets each character as an own field
  FS="" 
}
{ # Matches all lines.
  if (NF == 0){ # NF - Number of fields. 0 means empty line
    # Part 1
    total = total + length(group)

    # Part 2
    for(letters in group) {
      if (group[letters] >= person_count) {
        total2 += 1
      }
    }
    
    # Reset values
    delete group
    person_count = 0
  } else {
    person_count += 1
    for(i=1; i <= NF; i++){ # Iterate through fields
      group[$i]++ 
    }
  }
}
END {
  printf "Solution part 1: " total "\n"
  printf "Solution part 2: " total2 "\n"
}
```

Save this file as `06.awk` and then you can run it this way:
```bash
cat 06.input | awk -f 06.awk
```

# Good reads about AWK
* [https://ferd.ca/awk-in-20-minutes.html](https://ferd.ca/awk-in-20-minutes.html)
* [https://www.thegeekstuff.com/2010/01/8-powerful-awk-built-in-variables-fs-ofs-rs-ors-nr-nf-filename-fnr/](https://www.thegeekstuff.com/2010/01/8-powerful-awk-built-in-variables-fs-ofs-rs-ors-nr-nf-filename-fnr/)