teleren/devto huggingface dataset:
Setting Up Django Rest Framework
Tags: programming, django, drf, python
Published: 2020-11-27 22:06:27

### Django Rest Framework (DRF)

Django framework is a powerful toolkit for building web API's

its comes with many interesting features which include: 

- a web_browsable_api
- serialization that supports ORM

an API(application programming interface) gives us data when requests are sent to it.

this data is usually in the form of JSON(JavaScript Object Notation). 

> yes, it is not only for javascript

Django rest framework(DRF) helps us customize the requests handling and the outputs down to status codes.

to install it Django and python is required

```
python -m venv env
```

- to create a virtual environment

```
pip install django
```

- install django

```
pip install djangorestframework Markdown django-filter
```

- install django rest framework

```
django-admin startproject api
```

- start a django project

- change directory to api/api

- open settings.py

- under installed apps

- add the following lines to the end of the list

```
"rest_framework",
"rest_framework.authtoken"

```
change directory to the root api

```
python manage.py migrate
```

```
python manage.py runserver
```
Difference between for and foreach in php
Tags: php, programming, webdev
Published: 2020-11-27 21:58:16

loops are used to enable code reusability, I mean if you need certain lines of code to be executed repeatedly you should use loops to reduce line of code. our topic of discussion is the difference between For loop and for each loop in PHP, let’s explore both one by one in detail.

#For loop:
For loop is the most desired and best option when it is known in advance that how many times your script needs to be executed. 

syntax and example of for loop:
```
<?php 
//this is the syntax
for (initialize the counter; test the counter; increment/decrement the counter) {
  script that needs to be executed for iteration;
}
//example 
for ($i=5; $i>=0;$i--)
{
echo "number in decreasing order:$i <br>";
}
?>
```
#Foreach loop
Foreach loop is an ideal choice for Arrays and it works in key and value pairs. The foreach loop executes an array of data with a pair of keys and values up to the last element of the array. besides that, it is used to implement associative arrays and to extract data from the database.[Read more](https://www.kodlogs.com/blog/2353/difference-between-for-and-foreach-in-php)
How to Remove a Substring from a String in Python?
Tags: python, programming
Published: 2020-11-27 21:56:19

A substring is a chain of sequential characters inside a bigger string. Removing a substring from a fixed of strings deletes this substring from every detail within the set.Use str.replace() inside a for-loop to get rid of a substring from all strings in a fixed set of strings.

Use **str.replace(old, new)** with new as "" to remove substring old from str.
```
_string = "programming"

new_string = a_string.replace("ing", "")


print(new_string)

Output

programm
```

Use **str.replace()** in a for-loop to remove a substring from all elements in the set. Add each modified string to a new set.
```
string_set = {"learning", "enjoying", "programming"}

new_set = set()


for a_string in string_set:

    new_string = a_string.replace("ing", "")

    new_set.add(new_string)


print(new_set)

Output

{'enjoy', 'learn', 'programm'}
```
Use a set comprehension for a more compact implementation.
```
string_set = {"learning", "enjoying", "programming"}

new_set = {x.replace("ing", "") for x in string_set}


print(new_set)

Output

{'enjoy', 'learn', 'programm'}
```

###Warning
sets are an unordered collection of items. Performing set comprehensions does not preserve the original ordering.

##Remove a prefix from a string
Is there a fashionable manner to remove a substring from the start of a string?  Replacing the string root withinside the given course rigorously ought to update later occurrences as well, successfully returning nonsense, because the feedback pointed out. I could propose to update the start of the string properly: 

`import re end result = re.sub(r'^' + re.escape(root), '', course)`
This manner you keep away from each error loops.

Starting in Python 3.9 , you could use :
[Read more](https://www.kodlogs.com/blog/2377/how-to-remove-a-substring-from-a-string-in-python)
How to Return Index of item in list on Python?
Tags: python, programming, oop
Published: 2020-11-27 21:51:57

The **index()** technique returns the index of the required element within the list.

##The syntax of the list index() technique is:

**list.index(element, start, end)
list index() parameters**

The **list index()** technique can take a most of 3 arguments:   

     element - the detail to be searched    
    start (optional) - begin looking from this index
     end (optional) - seek the detail as much as this index

##Return Value from List index()   

     The index() technique returns the index of the given element within the list.   
     If the element isn't found, a ValueError exception is raised.

**Note:** The index() technique most effectively returns the primary prevalence of the matching element

```
# vowels list
vowels = ['a', 'e', 'i', 'o', 'i', 'u']

# index of 'e' in vowels
index = vowels.index('e')
print('The index of e:', index)

# element 'i' is searched
# index of the first 'i' is returned
index = vowels.index('i')

print('The index of i:', index)
```

###Output

`The index of e: 1
The index of i: 2`

[Read more](https://www.kodlogs.com/blog/2380/how-to-return-index-of-item-in-list-on-python)
Polishing and Usability - Building SaaS #69
Tags: python, django, views
Published: 2020-11-26 18:10:43

{% youtube GnOcVBmqYKU %}

In this episode, we polished some parts of the application. Now that my first customer is using the app regularly, the feedback is coming in rapidly. We worked to fix some of the issues that she found.

The first issue that I tackled dealt with ambiguity about a course's relationship to a school year on the course's detail page. I fixed this issue by displaying the grade level on the course page to provide all the details. This change makes it clear what grade level the course is connected to. This is useful because courses in the school year could have the same name (e.g., "Math").

The next issue that we worked on was related to the ordering of data on the schedule pages. The schedules pages showed information for each student in the school. This was broken for a couple of reasons:

1. The order of students may not match the order     of grade levels.     That leads to a mismatch     when looking at the school year     versus looking at the schedule view. 2. The schedule would show students     even if they weren't enrolled     in the school year.

I fixed the daily and weekly schedule views by changing the logic from looping over all the students to looping over all the enrollments for a school year. This change corrected both of the problems that were present in the view.

After changing that in two place, I observed the common implementation that was duplicated in two views. Because of the duplication, we did some refactoring to extract that logic into a shared method on the `Student` model.

At the end of the stream, as I cleaned up the code to prepare to commit it, we cleaned up some test code based on some observations about how the tests behaved with the new code.
Design Systems for Devs: Typography
Tags: design, systems, css, scss
Published: 2020-11-27 21:51:51

What's good Dev.to community!


## Intro
My name is Chris Porter and I'm a design engineer. I specialize in coding for design systems. 

I would love to share my Type system as my first post. It's a system that I've built and used for many of my Jamstack websites. 

[Download the Type System](https://www.madebyporter.com/journal/2020/designsystems-type/)

## How it's built?
The main gist is using classes to set styles. This allows you to reuse styles in many different ways. Want to use `<H1>` styles on a `<p>` tag? Use `.h1`. It's curated and written in SCSS, using variables, mixins and extends to keep type systems consistent and scalable. I've borrowed and refactored code I've found via tutorials, trial and error, etc.

## Let me know!
Check it out and let me know if you have any questions or feedback. I would love to hear from you.

[Download the Type System](https://www.madebyporter.com/journal/2020/designsystems-type/)
Finding the percentage hackerrank solution
Tags: python, programming
Published: 2020-11-27 21:45:51

I suggest that you avoid looking for the solution to HackerRank problems at all costs, as it will be detrimental to your development as a programmer.

The thing is, you won&rsquo;t always have the option to look for the solution to a problem once you&rsquo;re working as a software engineer&mdash;it&rsquo;s perfectly permissible to look things up as you work, but it&rsquo;s unlikely that you&rsquo;ll find the exact solution to the problem you&rsquo;re working on on Google. Instead, you need raw problem-solving skills and technical proficiency, which you won&rsquo;t develop if you&rsquo;re constantly leaning on other people for the final answer.

Instead of searching for specific solutions to specific problems, seek out the principles behind entire categories of solutions by putting the problem aside and finding resources that will increase your theoretical knowledge.[Read more](https://www.kodlogs.com/blog/2410/finding-the-percentage-hackerrank-solution)
Remove duplicate characters in a string javascript
Tags: javascript, programming, webdev
Published: 2020-11-27 21:44:55

In this post, we will see how to remove duplicate or repeating elements from an array in JavaScript . For this, we will not limit ourselves to arrays with simple data types; but also object arrangements.

Explained in another way, what we will do is:

* See how to remove repeated primitive data (string, integer, boolean, etc.) from arrays in JavaScript
* Eliminate repeating objects, either based on a property or by comparing them in depth.
Let's go there.

#Remove array duplicates, with simple data:
Let's first see how to remove duplicates from an array but when they are not objects. There are many ways, you can use the one you want but I recommend the one that uses sets.

These methods work for strings, numbers, and Booleans.
##Method 1: Filtering array
**NOTE** This method has better compatibility with older browsers.
The first way is by doing a filter; which filters an array and returns a new one with the elements that have passed the filter.

Knowing this, we can filter an array, on the condition that this value is not repeated in it. And how do we know if that value already exists? we use indexOf, which returns the index of the first element that matches the search in an array.

In this case, only if the current index (in the filter) is equal to the index returned by the function, we let the value pass.

Explained in other words, we only let the value pass if it is the first time it appears, if not, we discard it because it already existed previously.

The code looks like this:
[Read more](https://www.kodlogs.com/blog/2428/remove-duplicate-characters-in-a-string-javascript)
Check if a string contains special characters java
Tags: java, oop, programming
Published: 2020-11-27 21:39:00

In this article, you will learn how to check special characters present in a string. I am going to explain simply about the string class methods used to check special characters without using regex.

#Approach
* In order to check the non- alphanumeric characters in any given string, I am using a  basic approach without any regex class.
* In the example, I have taken a demo input with some special characters in it to make you understand that my code works well.
* I have also taken the specialcharacters in a string because we need to find the special characters in a string.
* By using for loop I have cross-checked each and every character in the given string with all the specialcharcaters string.
* If it contains a special character, then it returns an output statement that the given string has a special character in it.
* Else it checks for the condition whether the character index value equals to the total string length, then it indicates zero special characters in the string. [Read more](https://www.kodlogs.com/blog/2624/check-if-a-string-contains-special-characters-java)
What is the 100DaysOfCode challenge and how does it work?
Tags: 100daysofcode, programming
Published: 2020-11-27 21:33:42

# # 100DaysOfCode
## Have you heard about 100DaysOfCode?

[100DaysOfCode](https://www.100daysofcode.com/) is a challenge that many programmers are eager to do, with it you have more productivity, increase your knowledge, your experience and with that you learn good practices in code creation and everything

## How it works ?

To start participating in the challenge, you first have to plan what you can do during these 100 days that is productive, you have to set aside at least 1 hour of your day to be able to put your planning into practice, when you complete the Estimated time you will have to post on a social network proving that you have completed that day and that you are participating in a spectacular challenge.

## What can I do ?
 
This challenge can be done in several ways, such as:

1. Study a new language
2. Deepen in a language that you already have a little command of
3. Make articles about some features that you think are important in programming that other people know, among other things.

## Is it difficult to participate in this challenge?

No, it is not difficult, you simply choose something of your choice, the theme is free, you just need the time necessary to be able to complete each day.

## Two Main Rules

1. Code at least one hour every day for the next 100 days.
2. Tweet your progress every day with the hashtag # 100DaysOfCode.

[Learn more about the rules](https://www.100daysofcode.com/rules/)

# Commitment

If you commit yourself publicly to the challenge, if you decided to start, then go to the end and don't give up on anything, be responsible and graduating every day for your effort.


[Link to group on whatsapp](https://chat.whatsapp.com/K2P9q0a6O1YFQ47c5gFkBh)
Difference b/w C++ and Visual C++.
Tags: cpp, programming
Published: 2020-11-27 21:32:12

C++ is a programming language, it is an enhanced and advanced version of programming language C. C++ is a general-purpose for OOP language. We can use C++ on many platforms. Visual C++ is an IDE i.e., Integrated Development Environment product provided by well known multinational company Microsoft. It is used for developing projects in different languages.

#Difference between C++ and Visual C++
Down below we are going to take look at C++ and Visual C++. We will learn what is the difference between them and what are the uses of them in the programming industry. C++ and Visual C++ are two different things yet they sound the same. Hope you will find this article helpful.

##C++
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fl2esp34t6d9baiw1udw.jpg)
C++, an extension of C, developed by Bjarne Stroustrup in 1979 at Bell Laboratory. C++ is a high-level object-oriented programming language. It uses a compiler to convert code written in a high-level language into machine language.[Read more](https://www.kodlogs.com/blog/261/difference-b-w-c-and-visual-c)
How to insert Hindi text in MySQL database using php?
Tags: sql, mysql, php, webdev
Published: 2020-11-27 21:29:17

In this article, we will learn how we can insert data in Hindi font using the php and MySQL. In the first step, we will create a database with the name of “Hindi fonts” and also create a database table with the name “User”. The table will contain the two columns id and name. In the second step, we will insert the name in Hindi format and then we will fetch the data from the database and then display it in the HTML table.

#Create database
```
CREATE DATABASE hindi_fonts

          CHARACTER SET utf8

         COLLATE utf8_general_ci;

USE hindi_fonts;

CREATE TABLE “user (

   ‘name’ varchar(255) COLLATE utf8_general_ci NOT NULL

)
```
##Index.php

```
<!DOCTYPE html>

<html>

<head>

               <title></title>

               <meta charset="UTF-8">

</head>

<body>

<?php

if(isset($_POST['submit']))

{

               $conn= mysqli_connect("localhost","root","password","hindi_fonts");

               mysqli_set_charset($conn,'utf8');

               $query= "INSERT INTO user(`name`)VALUES ('".$_POST['name']."');";

               $result= mysqli_query($conn,$query);



}

?>

<form method="post" action="">

<input type="text" name="name">

<input type="submit" name="submit">

</form>

</body>

</html>
```
[Read more](https://www.kodlogs.com/blog/318/how-to-insert-hindi-text-in-mysql-database-using-php)
typeerror: object(...) is not a function in Javascript
Tags: cpp, oop, programming
Published: 2020-11-27 21:20:30

In javascript browsers use javascript engine to execute the javascript code and to show errors in the console, those errors help in improving the performance of the website.
This article discusses the error “typeerror: object(...) is not a function” via example.

#Example
```
<body>
    <a href="javascript:;" id="test">hello</a>
</body>

<script type="text/javascript">
    document.getElementById("test").addEventListener("click", function () {
      test()
    }, false)
    function test() {
      var postTypes = new Array('hello', 'there')   
      (function() { alert('hello there') })()
    }
</script>
```

##Cause
Here the programmer forgot to include semicolon 
I know sometimes we don't have to include semicolons in our javascript program. But javascript requires semicolons, the thing is javascript engines insert semicolons for us on the line where it is possible.
Similarly in the above code
`var a = new B(args)(stuff)()`

[Read more](https://www.kodlogs.com/blog/2062/typeerror-object-is-not-a-function-in-javascript)
Shell (e.g. Bash) users before coming to Windows Terminal - which shell do you use?
Tags: discuss, windows
Published: 2020-11-27 21:19:14

Do you use PowerShell or `cmd.exe`? Or something else, like Git-bash or WSL?

How do you learn commands? PS and `cmd.exe` have different commands.

Some of commands I need are

- `which` => `Get-Command`
- `head` (I don't need `cat`) => `gc log.txt | select -first 5`
Terminating With Uncaught Exception of Type Std
Tags: cpp, oop, programming
Published: 2020-11-27 21:08:56

The above error means that the programmer tried to index into a string using an index that is not valid. An index means an array of related data stored under a single variable or variables of the same type stored in one file type. 

#Cause

When the loop is testing the conditions that have been set and find that the index is not a group type of array of others in the system, the index will be out of range.

 **See below:**
`y equals source.size()                     assume y is not a valid index,`

**so temp.at(y) throws std::out_of_range. **
Based on the above example, if the string length is “n” the valid indices will be 0 through n-1. Thus, string ‘n’ will be out of range when used and the above error will occur. 

##Solution
The possible way to solve the error will be to ensure that the indices declared are within the range of the index array. 
Another way to navigate through is to use size_t instead of unassigned long when dealing with sizes so that the long integers can be truncated to allow the index fit in the arrays defined in the system. [Read more](https://www.kodlogs.com/blog/1999/terminating-with-uncaught-exception-of-type-std)
- Cyber Muse - 音楽投稿アプリをリリースしました！（個人開発）
Tags: react, reactnative, ios, android
Published: 2020-11-27 21:07:51

# 初めに

音楽投稿アプリを開発しました！

ウェブサイト： 

https://cyber-muse.com

Apple Store:

https://apps.apple.com/app/id1511131064
Google Play:

https://play.google.com/store/apps/details?id=com.front_music

開発言語は[React](https://ja.reactjs.org/)と[React Native](https://reactnative.dev/)を使用しています。

開発から運用まで全て個人で行っています。~~開発から運用まで大変だったことなど色々書いていきたいと思います。~~

# React & React Nativeについての所感
気づけばReactを書き始めてから1年ぐらいがたってしまいました。Reactを学ぶきっかけとなったのはアルバイトです。それまではフロントエンドについてはあまり興味がなく、[Python](https://www.python.jp/)をよく書いていました。バイト先ではReact(JS)がメインだったので面接に受かってから学び始めました。バイトの頻度は週二回1日8時間くらいでした。
### React
Reactは個人的にすごく書きやすい。個人的にhtml内のscriptの中やUIとは独立したjsファイルにjsを書くのが嫌いだったので。見にくくないですか？
Reactでつまづくとすれば、それはstateという概念だ。hooks周辺を理解するのは難しい。
useEffectについてひたすら調べまくりました。正直日本語でこれ以上に分かりやすい記事は他にないと思う。
https://iqkui.com/ja/a-complete-guide-to-useeffect/
あとは例外的ではあるがファイルアップロード関係かな。バイト先では[GraphQL](https://graphql.org/)というバックエンドとフロントを繋ぐものを使用していたのだが、これに使えるファイルアップローダーの無さといったらもう。そもそもGraphQLを通してファイルアップロードするのもどうかと思うんだが。バックエンドで[Prisma](https://v1.prisma.io/docs/1.34/get-started/01-setting-up-prisma-new-database-JAVASCRIPT-a002/)とか[Docker](https://www.docker.com/)とか使ってたからしゃあなしか？
今回バックエンドについては特にかくつもりないので割愛します。
とまぁこんな感じでReactに慣れてきたらReact Nativeも書くようになりました。

### React Native
 React Nativeで一番大変なのはコードを書く以前の準備だと思います。モバイルアプリの開発はSimulatorをたてた状態で行わないといけませんが、慣れないうちはこれが大変です。iOSで言えばpodあたりやXcodeの設定をしっかり把握していないとビルドが失敗します。バイト先はアプリの運用をしていたので、既に完成されているものをビルドしなければいけません。ビルド時間は5~10分くらいかかっていました。ですので、慣れていないと後少し!!というところでビルドが失敗したりしてドツボにハマったりします。
　という感じで僕のモバイルアプリ開発の始めは苦しむことが多かったですが、今はiOSもAndroidもできているのでいいかなという感じです。
　そう、これがReact Nativeの利点だと僕は思う。ネイティブ言語でiOSとAndroidの開発をしようと思ったら、swiftやjavaの両方を学ばなければいけないからだ。React Nativeを使えば、多少の差があることは確かだがUIでいじる必要があることはほとんどない。ビルドの仕方とリリースの仕方を学べばそれでいい。多少の差に言及しておくとそれはアプリ内でファイル操作をする時だ。写真を選択したり、アップロードしたり。知らないとバグって、は？ってなる。　
 
最後にReact NativeのUIについて述べる。UIはオープンソースのコンポーネントが色々あって便利だと思う。が、React Nativeのバージョンの違いとかで役に立たなかったりするやつがあるから注意。githubのReleasesのlatestが2年前とかのやつには手を出さないのが無難だ。あとは、cssのflexの有り難みがすごくわかる。キーワードはflexDirection, justifyContent, alignItemsだ。この３つがあれば画面が綺麗に整う。

所感の割りには色々書きすぎたと思うが以上がReact Nativeに関する正直な感想だ。

# ウェブサイトのアニメーションについて
実は最近ウェブサイトをアップデートしてアニメーションを取り入れた。
https://cyber-muse.com
このウェブサイトのアニメーションは全て[react-spring]("https://www.react-spring.io/)というモジュールを使用している。
https://www.react-spring.io/
このモジュールにスクロールの制御を加えると僕が作ったウェブサイトぐらいは作れるという感じで紹介しておこう。

# 終わりに
初めの文章に取り消しせんが付いている通りです。
ReactとReact Nativeについて述べただけになってしまいました。

**React**と**React Native**を使えばこういうウェブサイトやアプリが作れる！！という参考になればいいと思います。

ウェブサイト： https://cyber-muse.com
Apple Store: https://apps.apple.com/app/id1511131064
Google Play: https://play.google.com/store/apps/details?id=com.front_music
How to make a list in java?
Tags: java, oop, programming
Published: 2020-11-27 21:06:09

In this article, we will Explain How to Create, Initialize, and Print List in Java. I also Explaining the List with Complete Example Code
This blog will introduce you to the data structures 'list' which is one of the basic structure in a Java interface Collection.
Java list is the order of elements in accordance with the command. List interface java.util package is one that implements the objects of the ordered sequence in a particular mode called List.s ATesting in Software Testing_

Just like arrays, elements of the list can also be accessed using an index with the first index starting from 0. This index shows the specific elements of the index 'i' ie it is the element i away from the beginning of the list.
Some characteristics of the Java list includes:
• The list can have duplicate elements.
• This list can also have a 'zero' element.
• List supports the generic you can have a generic list.
• You can also have a mix of objects (objects of different classes) in the same list.
• List always maintain insertion order and allows the positional access.
What You Will Learn: [Event]
List In Java
The Java List interface is a sub-type of a Java interface Collection. This is a standard interface that inherits the Java Collection interface.
Given below is a list of Java class diagram interface.

[Read more](https://www.kodlogs.com/blog/2173/how-to-make-a-list-in-java)