teleren/devto huggingface dataset:
10- Django: create templates
Tags: webdev, django, python, programming
Published: 2023-01-24 07:10:32

--- series: Django a Python web framework ---

First, create a directory called templates in your polls directory. Django will look for templates in there.

In "Sublime Text": select polls> right click> New Folder> name it "templates"

Within the templates directory, create another directory called polls, and within that create a file called index.html.

Select polls folder inside templates folder> right click> New File> Save as: index.html

Then, put the following code in that template:
```
{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}
```

Then, update our index view in polls/views.py to use the template:
```
from django.http import HttpResponse
from django.template import loader

from .models import Question


def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    template = loader.get_template('polls/index.html')
    context = {
        'latest_question_list': latest_question_list,
    }
    return HttpResponse(template.render(context, request))

def detail(request, question_id):
    return HttpResponse("You're looking at question %s." % question_id)

def results(request, question_id):
    response = "You're looking at the results of question %s."
    return HttpResponse(response % question_id)

def vote(request, question_id):
    return HttpResponse("You're voting on question %s." % question_id)
```
Now, open http://127.0.0.1:8000/polls/ in your browser.

Inside polls directory in templates create datail.html and write following code in it:
```
<h1>{{ question.question_text }}</h1>
<ul>
{% for choice in question.choice_set.all %}
    <li>{{ choice.choice_text }}</li>
{% endfor %}
</ul>
```
Add a shortcut: get_object_or_404() to polls/views.py
```
from django.shortcuts import get_object_or_404, render

from .models import Question
# ...
def detail(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    return render(request, 'polls/detail.html', {'question': question})
```
To remove hardcoded URLs in templates, edite polls/index.html to: 
```
<li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li>
```
So, index.html should be like:
```
{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}
```

<p>If you like the content, please <a target="_blank" href="https://www.youtube.com/channel/UCpbWlHEqBSnJb6i4UemXQpA?sub_confirmation=1">SUBSCRIBE</a> to my channel for the future content</p>
9- Django: writing more views
Tags: webdev, django, python, programming
Published: 2023-01-24 07:07:41

--- series: Django a Python web framework ---

In our poll application, we’ll have the following four views:

Question “index” page – displays the latest few questions.
Question “detail” page – displays a question text, with no results but with a form to vote.
Question “results” page – displays results for a particular question.
Vote action – handles voting for a particular choice in a particular question.

Add mentioned views to polls/views.py
```
def detail(request, question_id):
    return HttpResponse("You're looking at question %s." % question_id)

def results(request, question_id):
    response = "You're looking at the results of question %s."
    return HttpResponse(response % question_id)

def vote(request, question_id):
    return HttpResponse("You're voting on question %s." % question_id)
```
Connet these new views into the polls/urls.py by adding the following path() calls:
```
from django.urls import path

from . import views

urlpatterns = [
    # ex: /polls/
    path('', views.index, name='index'),
    # ex: /polls/5/
    path('<int:question_id>/', views.detail, name='detail'),
    # ex: /polls/5/results/
    path('<int:question_id>/results/', views.results, name='results'),
    # ex: /polls/5/vote/
    path('<int:question_id>/vote/', views.vote, name='vote'),
]
```
To display the latest 5 poll questions in the system, edit polls/view.py to be:
```
from django.http import HttpResponse
from .models import Question


def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5] 
    output = ', '.join([q.question_text for q in latest_question_list])
    return HttpResponse(output)

def detail(request, question_id):
    return HttpResponse("You're looking at question %s." % question_id)

def results(request, question_id):
    response = "You're looking at the results of question %s."
    return HttpResponse(response % question_id)

def vote(request, question_id):
    return HttpResponse("You're voting on question %s." % question_id)
```
<p>If you like the content, please <a target="_blank" href="https://www.youtube.com/channel/UCpbWlHEqBSnJb6i4UemXQpA?sub_confirmation=1">SUBSCRIBE</a> to my channel for the future content</p>
8- Django: introducing admin
Tags: webdev, django, python, programming
Published: 2023-01-24 07:04:48

--- series: Django a Python web framework ---

To create an admin user, run the following command:
```
py manage.py createsuperuser
```
Enter any username, for example Azad and press enter. 
Then enter your email address, for example: azad977@gmail.com
Then create a password.
You should see:
```
Superuser created successfully.
```
Now, open a web browser and go to http://127.0.0.1:8000/admin/. You should see the admin’s login screen.
Try logging in with the superuser account you created in the previous step. 

To display poll app on the admin index page, open the polls/admin.py file, and edit it to look like this:
```
from django.contrib import admin

from .models import Question

admin.site.register(Question)
```

<p>If you like the content, please <a target="_blank" href="https://www.youtube.com/channel/UCpbWlHEqBSnJb6i4UemXQpA?sub_confirmation=1">SUBSCRIBE</a> to my channel for the future content</p>
7- Django: reate a new question and choices
Tags: webdev, python, django, programming
Published: 2023-01-24 07:01:42

--- series: Django a Python web framework ---
To invoke the Python shell, use this command:
```
py manage.py shell
```
Once you’re in the shell:
```
from polls.models import Choice, Question
```
Create a new Question.
```
from django.utils import timezone
q = Question(question_text="Rate this tutorial:", pub_date=timezone.now())
```

Save the object into the database. You have to call save() explicitly.
```
q.save()
```
Now it has an ID.
```
q.id
#1
```
Access model field values via Python attributes.
```
q.question_text
```
'Rate this tutorial:'
```
q.pub_date
```
datetime.datetime(2022, 5, 14, 15, 41, 26, 711723, tzinfo=datetime.timezone.utc)

Create five choices:
```
q.choice_set.create(choice_text='*', votes=0)
q.choice_set.create(choice_text='**', votes=0)
q.choice_set.create(choice_text='***', votes=0)
q.choice_set.create(choice_text='****', votes=0)
q.choice_set.create(choice_text='*****', votes=0)

q.choice_set.all()
```
LeetCode #101 Symmetric Tree with JavaScript
Tags: javascript, algorithms, leetcode
Published: 2023-01-24 06:48:52

Solutions to LeetCode's [101. Symmetric Tree] (https://leetcode.com/problems/symmetric-tree/description) with JavaScript.

**Follow up: Could you solve it both recursively and iteratively?**

## Solution 1: Recursive
```js
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
const isSymmetric1 = (root) => {
  const isMirror = (left, right) => {
    if (!left && !right) return true;
    if (!left || !right) return false;
    if (left.val !== right.val) return false;
    return isMirror(left.left, right.right) && isMirror(left.right, right.left);
  };
  return isMirror(root, root);
};
```
- Time complexity: O(n)
- Space complexity: O(n)

## Solution 2: Iterative BFS
```js
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
const isSymmetric2 = (root) => {
  const queue1 = [root.left];
  const queue2 = [root.right];

  while (queue1.length > 0 || queue2.length > 0) {
    const dequeued1 = queue1.shift();
    const dequeued2 = queue2.shift();

    if (!dequeued1 && !dequeued2) continue;
    if (!dequeued1 || !dequeued2) return false;
    if (dequeued1.val !== dequeued2.val) return false;

    queue1.push(dequeued1.left);
    queue1.push(dequeued1.right);
    queue2.push(dequeued2.right);
    queue2.push(dequeued2.left);
  }
  return true;
};
```
- Time complexity: O(n)
- Space complexity: O(n)

I used BFS to solve the problem with iteration.
Git Basic Commands That You Need For Regular Project Work
Tags: github, webdev, programming, productivity
Published: 2023-01-24 06:47:51

I am trying to list some commands above the work criteria. Check this below

### Git Initial Command:

```
1. git init
2. git status
3. git --version
4. rm -rf .git  //Remove git folder
5. git status -s
```

### Git Configuration Command:

```
1. git config --global user.name "username"
2. git config --global user.email "email"
3. git config --list
4. git config --global alias.last "log -p -1"  //Create alias for shortcut
```

### Git File Add Command:

```
1. git add .   //Stages new and modified file without deleted file
2. git add -A  //Stages all file
3. git add -u  //Stages modified and deleted file without new file
```

### Git Commit Command:

```
1. git commit -m "messeage"
2. git commit -a -m "message"  //Stage file commit without add
3. git commit --amend          //Change the last commit
```

### Git Commit Log Command:

```
1. git log
2. git log -p -2
3. git log --stat
4. git log --pretty=oneline
5. git log --pretty=short/full
6. git log --pretty=format:"%h 00 %ae"
7. git log --since=2.days/weeks/months/years
```

### Git Branch Command:

```
1. git branch
2. git branch `branchName`
3. git checkout `branchName`
4. git merge `branchName`                 //Branch must be master
5. git branch -v
6. git branch --merged
7. git brach --no-merged
8. git branch -d `branchName`             //Locally deleted
9. git push origin --delete `branchName`  //Deledted on github
10. git checkout -b "branchName"          // Create brach and switch to the created branch
```

### Git Compare Command

```
1. git diff `fileName`           //Difference tracked file code between last commit file to now
2. git diff --staged `filename`  //Difference Stages file code between last commit file to now
3. git reset `fileName`          //Stages file to unstages file
4. git checkout `fileName`       //Clear file to last commit
5. git checkout -f               //For all file
6. git rm --cached `fileName`    //Tracked file to Untracked file
```

### Git Command For Github

```
1. git remote add origin `url`
2. git remote rm origin
3. git push -u origin master
4. git pull origin master
5. git remote -v
6. git clone `url`
```

### Git Extra Command

```
1 .gitignore
2. git rm `fileName`
3. git mv `fileName1` `fileName2`  //Change the filename & fileName2 is changed name.
```
**NOTE:** If you don't understand any command, find out on Google. This way you can learn about git commands properly and have a crystal clear idea on git commands. Keep exploring.
LinkedIn Learning Free Lifetime Access!!!
Tags: webdev, javascript, beginners, tutorial
Published: 2023-01-24 06:39:32

https://bit.ly/3Dn1RbX
Library Card: 21901805167321
PIN: 280591

🎁LinkedIn Learning Lifetime Access 

➡️ Login Here : Click Here (https://bit.ly/3Dn1RbX)

📱Details 

➡️Library Card : 21901805167321 

➡️PIN: 280591

🚨Note : Do Not Change Any Details In Account 

For more resources like this, subscribe to my youtube channel:https://www.youtube.com/channel/UCdMBvHugZtN_FZ6oh8L5BHA 

I'll be sharing more
"Git Like a Pro: Learn the Essential Commands for Effective Version Control"
Tags: git, beginners, opensource, github
Published: 2023-01-24 06:20:37

Git is a version control system that allows developers to keep track of changes made to their code over time. It is widely used for software development and can be used for any type of project where tracking and managing changes is important.

Here are some common Git commands:

**git init**: Initializes a new Git repository in the current directory.
**git clone [repository]**: Clones an existing repository to the local machine.
**git status**: Shows the current status of the repository, including which files have been modified and which branch you are currently on.
**git add [file]**: Adds a file to the staging area, preparing it to be committed.
**git commit -m "[message]"**: Commits the changes in the staging area with the specified message.
**git push [remote] [branch]**: Pushes the local changes to a remote repository.
**git pull [remote] [branch]**: Fetches and merges changes from a remote repository.
**git branch**: Lists all branches in the repository.
**git branch [branch-name]**: Creates a new branch with the specified name.
**git checkout [branch-name]**: Switches to the specified branch.
**git merge [branch-name]**: Merges the specified branch into the current branch.
**git log**: Shows a log of all commits in the repository.

These are just a few of the many Git commands available, but they are some of the most commonly used and are a good starting point for learning Git.
Shallow Copy vs Deep Copy JS & Reference Part-2🚀
Tags: javascript, webdev, tutorial, programming
Published: 2023-01-24 06:16:43

This post is continuation of the last post.

In last post we were discussing _What is Reference_ and done with assign by value. Now we discuss furthur.

Table of content

1 Primitive Data type
2 Non-primitive data type
3 What is Reference
4 Shallow copy
5 Deep Copy

## What is Reference

**Assign by reference**

> When a non-primitive data type like array, objects or function assign to a variable and that variable point to a address of the data type is called assign by reference. We can say that non-primitive data type is basically a collection of primitive data type. Show get access to all that primitive values collectively an address is assign to the variable.
See the example below for clarification.

```js
const student = {
  name: 'Sid',
  class: 'KG',
  subject: 'JS',
  marks: '100'
}
console.log(student);
/* output ->
name:"Sid"
class:"KG"
subject:"JS"
marks:"100"
*/

const studentCopy = student
console.log(studentCopy);
/* output ->
name:"Sid"
class:"KG"
subject:"JS"
marks:"100"
*/

//will change the name for both variables
studentCopy.name = 'Alic'
console.log('student -> ',student,'studentCopy =>', studentCopy);
/* student->
name:"Alic"
class:"KG"
subject:"JS"
marks:"100"

studentCopy ->
name:"Alic"
class:"KG"
subject:"JS"
marks:"100"
*/
```
 
Observe the above code, a object has been created names student and it has some info about the student which is primitive data type. This data saved collectively in an object having a address on which the variable student is referencing to.

Student is assign to studentCopy variable .These two variables are pointing to the same address. If there's any change in the values it will reflect in both variables.

Suppose this as a match broadcasting live on multiple screens all at once.

**Source**
[stackoverflow](https://stackoverflow.com/questions/23436437/why-can-i-change-a-constant-object-in-javascript#:~:text=This%20is%20because%20you%20cannot,the%20value%20of%20the%20address.&text=Save%20this%20answer.,-Show%20activity%20on)

[medium](https://codeburst.io/explaining-value-vs-reference-in-javascript-647a975e12a0)

[medium](https://medium.com/@naveenkarippai/learning-how-references-work-in-javascript-a066a4e15600)

[dev.to](https://dev.to/amansethi00/shallow-copy-vs-deep-copy-in-javascript-11d6)

Thanks to @amanse
to be continue...
How to sort an array of objects by a property value in Typescript
Published: 2023-01-24 06:15:12

In TypeScript, you can use the Array.prototype.sort() method to sort an array of objects by a property value. The sort() method takes a comparator function as its argument, which should return a negative, zero, or positive value depending on the order in which the elements should be sorted.

Here's an example of how you can use the sort() method to sort an array of objects by a property called "name":

```
interface Person {
    name: string;
    age: number;
}

let people: Person[] = [
    { name: "Uzeyr", age: 33 },
    { name: "Ozcan", age: 28 },
    { name: "Ali", age: 30 }
];

people.sort((a, b) => {
    if (a.age < b.age) {
        return -1;
    }
    if (a.age > b.age) {
        return 1;
    }
    return 0;
});

console.log(people);
// Output: [{ name: "Ozcan", age: 28 }, { name: "Ali", age: 30 }, { name: "uzeyr", age: 33 }]
```

In the example above, we defined an interface Person to represent the objects in the array, and created an array of objects that implement the Person interface. We then called the sort() method on the people array and passed in a comparator function that compares the "name" property of two objects and returns a negative, zero, or positive value depending on their relative order. The sort() method then sorts the array in place based on the values returned by the comparator function.

You can use the same approach to sort an array of objects by any property. Just replace "name" with the name of the property you want to sort by, and adjust the comparator function accordingly.

It's important to notice that the sort() method sorts the array in place, meaning it modifies the original array and doesn't create a new one.
Retrieving 6-Month Data from MySQL using SQL Query
Published: 2023-01-24 06:12:23

A simple mysql command to see records that have been processed in the last 6 months

```
SELECT * FROM records
WHERE date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH);

```

This query uses the CURDATE() function to get the current date, and then subtracts 6 months from it using the DATE_SUB function. The result is used as the lower bound for the date column in the WHERE clause, ensuring that only records with a date within the last 6 months will be selected.
Secret affair of Node.js - Environment Variables.
Tags: env, node, environmen
Published: 2023-01-24 06:04:44

So today I am presenting you guys **"Secret affair of Node.js - Environment Variables"**


When you build a Node.js application you want them to run everywhere. This could be on your colleagues’ computers, internal company servers, cloud servers, or inside of a container (maybe using Docker).
This is the time when we use **environment variables**.

Environment variables are a fundamental part of developing with Node.js, allowing your app to behave differently based on the environment you want them to run in. Wherever your app needs configuration, you use environment variables. And they’re so simple, they’re beautiful!

Today, this post will help you create and use environment variable in your Node.js application.

---

Example of using ENV:

`
// server.js
const port = process.env.PORT;
console.log('Your port is ${port}');
`

Create a file named server.js and put the above code in the file. Now when you run this file you will see a message "Your port is undefined".
This is because there isn't any enviornment variable right now.

So for that we create a File name `.env`.

Create the .env file in the root of your app and add your variables and values to it.

```
NODE_ENV=development
PORT=8626
# Set your database/API connection information here
API_KEY=**************************
API_URL=**************************
```


**Remember Your .gitignore File**

A `.env` file include many security related data, so you better put this file into gitignore.
Open or create .gitignore file and add 
`
.env
`
anywhere in the file.

Now install `Install dotenv from npm`

`npm install dotenv`

Now read the env data like this

`
// server.js
console.log('Your port is ${process.env.PORT}'); // undefined
const dotenv = require('dotenv');
dotenv.config();
console.log('Your port is ${process.env.PORT}'); // 8626
`

Now run your code
`node server.js`.

This is it, now you can use any variable like this

`process.env.Variable`.

GoodBye :)
Hire Dedicated UI UX Web Designer
Tags: ux, design, hiring, webdev
Published: 2023-01-24 05:55:27

InfiRaise provides models to [hire web designers](https://www.infiraise.com/develop/web-app-development/) to create compelling designs for business impact. Our dedicated website designers have prolific knowledge in the field of website design and are committed to delivering the best design solutions possible.

We assist companies, online e-commerce stores, small businesses, and individuals from various verticals to enhance brand value and build a lasting online presence to hire a dedicated UI UX web designer. Our dedicated graphic and website designers have demonstrated proficiency in HTML, XHTML, and CSS, as well as other web design resources and applications.

## Benefits of hiring a dedicated UI UX web designer:

- Rapid Access to Designer
- Different successful methods of emerging and getting promoted in the world of e-business.
- Costs Scalable to Demand
- An attractive online presence to draw higher traffic.
- Flexible Hiring Models
- Maintenance cost saving.
- Fully infrastructure with hardware and software.
- Transparent Cost Model
- Facilitating you to hire on the basis of hours, months, etc.
- Corporate Identity Design
- A rise in ROI and efficiency using the top hi-tech efforts and designs.
- Modern website designing tools that will take your web presence to the fore from your competitors.
- Direct control over the design with result-oriented outcomes.

## Why select InfiRaise?

- Talented, trained, and dedicated web designing resources
- Exact implementation as per your specialized vision and concept
- Graphics, Photoshop, XHTML/CSS tools proficiency
- Unique and eye-pleasing Corporate Identity designs
- Monthly and hourly packages as per your convenient
- Service through complete involvement and direct control

We are one of the best tools from where you can [hire a dedicated UI UX web designer](https://www.infiraise.com/hire/hire-ui-ux-designer/) in India. With complete dedication and a commitment to serve until our clients are satisfied, we provide an exclusive range of services to all our clients. Some of our most sought-after exclusive web design services are as follows:

- Custom community website design
- Custom Website Design
- Blog website design
- Custom Website Redesign
- Static Web Design
- WordPress Website Design
- PHP Website Design
- Magento Website Design
- Zend Website Design
- Dynamic Website Design
- Website Design Upgrade
- Website Design Maintenance and Support

Article Source: https://www.infiraise.com/hire-dedicated-ui-ux-web-designer/
Next.js issue
Tags: nextjs, webdev, javascript, node
Published: 2023-01-24 05:44:27


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

I got the above error as I run dev command in terminal shown in my browsers. But same issue was not displayed at other desktop's browsers.

I have used next.js 13.1 version with latest node.js version.
5- Django: database setup
Tags: webdev, python, django, programming
Published: 2023-01-24 05:43:17

--- series: Django a Python web framework ---

Open up PollProject/settings.py. By default, the configuration uses SQLite.

Inside PollProject/settings.py, set TIME\_ZONE to your time zone. For example, in my case, it is: `TIME_ZONE = 'Asia/Baghdad'`

To create the tables in the database we run the following command:

```plaintext
py manage.py migrate
```

<p>If you like the content, please <a target="_blank" href="https://www.youtube.com/channel/UCpbWlHEqBSnJb6i4UemXQpA?sub_confirmation=1">SUBSCRIBE</a> to my channel for the future content</p>