<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Omkar Yadav on Medium]]></title>
        <description><![CDATA[Stories by Omkar Yadav on Medium]]></description>
        <link>https://medium.com/@omi10859?source=rss-1648f990e298------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*oYuyyz_b_ZyEDVjT.</url>
            <title>Stories by Omkar Yadav on Medium</title>
            <link>https://medium.com/@omi10859?source=rss-1648f990e298------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 02:02:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@omi10859/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Alternative Background Lines in Chartjs]]></title>
            <link>https://medium.com/@omi10859/alternative-background-lines-in-chartjs-a626ce4d3bcb?source=rss-1648f990e298------2</link>
            <guid isPermaLink="false">https://medium.com/p/a626ce4d3bcb</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react-charts]]></category>
            <category><![CDATA[background-color]]></category>
            <category><![CDATA[annotations]]></category>
            <category><![CDATA[chartjs]]></category>
            <dc:creator><![CDATA[Omkar Yadav]]></dc:creator>
            <pubDate>Wed, 11 May 2022 15:26:01 GMT</pubDate>
            <atom:updated>2022-05-11T15:26:01.228Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Using annotation for Changing Chartjs Background</em></p><p>We all know Chartjs is awesome with its little plugin module and all the customization options we get. So let&#39;s deep Dive into how to change the background to alternative lines shown in the picture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*bJz5yjL5AhVA76RfLqcsjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*b563uWGudzTx1-5RKVnbxw.png" /><figcaption>Before VS After</figcaption></figure><p>I will be using Reactjs and <a href="https://www.npmjs.com/package/react-chartjs-2">React-ChartJS-2</a> for building charts. We will be using annotation for changing the background. Let&#39;s install the package first</p><pre>npm install chartjs-plugin-annotation</pre><p>Register the plugin with chartJs, the below code can be added to your App.js</p><pre>import annotationPlugin from &quot;chartjs-plugin-annotation&quot;;</pre><pre>import {Chart} from &#39;chart.js&#39;;</pre><pre>Chart.register(annotationPlugin);</pre><p>Now the plugin has been registered with chartJs. Just Add annotation in plugin in options</p><pre>options: {<br>    plugins: {<br>        annotation: {annotations: background_annotation}<br>    }<br>}</pre><p>Annotation gives us the option to add things(Box, line, etc) in chartjs we will use that and add a box in the background of the chart. Code to add a box</p><pre>{<br>  type: &#39;box&#39;, #type of draw<br>  drawTime: &#39;beforeDraw&#39;, #this will decide background or foreground<br>  yMin: 5, #value min on y axis<br>  yMax: 10, #value max on y axis<br>  borderColor: &#39;rgb(242, 244, 248, 0.9)&#39;, #border color of the box<br>  borderWidth: 1, #boarder width for box<br>  backgroundColor: &#39;#F2F4F8&#39;, #colour of the box<br>}<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*kyF1RMGleMzVBIakhf17tg.png" /><figcaption>Output of code</figcaption></figure><p>Now, all we have to do is find values on the y-axis and plot a graph on the required interval. Adding code for that</p><pre>const inputRef = useRef(null);<br>const background_annotation= []</pre><pre>useEffect(() =&gt; {<br>if (inputRef &amp;&amp; inputRef[&#39;current&#39;]){<br>let y_axis = inputRef[&#39;current&#39;][&#39;scales&#39;][&#39;y&#39;][&#39;ticks&#39;]</pre><pre>y_axis.map((item, index) =&gt;{<br> if(index%2 == 0){<br>  if(index != y_axis.length-1){<br>    background_annotation.push({<br>      type: &#39;box&#39;,<br>      drawTime: &#39;beforeDraw&#39;,<br>      yMin: y_axis[index][&#39;value&#39;],<br>      yMax: y_axis[index+1][&#39;value&#39;],<br>      borderColor: &#39;rgb(242, 244, 248, 0.9)&#39;,<br>      borderWidth: 1,<br>      backgroundColor: &#39;#F2F4F8&#39;<br>    }<br>   )}}}<br>)}</pre><pre>const options = {<br>  plugins: {annotation: {annotations: background_annotation}<br>}</pre><pre># render/return <br>&lt;Line ref={inputRef} type={&quot;line&quot;} data={data} options={options} /&gt;</pre><p>Just like this, we can create more custom backgrounds if needed.</p><p>If you have any questions feel free to ask in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a626ce4d3bcb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Master-Slave DB In Django with PSQL]]></title>
            <link>https://medium.com/@omi10859/master-slave-db-in-django-with-psql-61dc10bff4c4?source=rss-1648f990e298------2</link>
            <guid isPermaLink="false">https://medium.com/p/61dc10bff4c4</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[mutidb]]></category>
            <category><![CDATA[master-slave]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Omkar Yadav]]></dc:creator>
            <pubDate>Thu, 09 Jul 2020 11:15:54 GMT</pubDate>
            <atom:updated>2020-07-09T11:15:54.890Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*Pv8BPPFc-wSUFmYnSEvYRQ.jpeg" /></figure><p>This is a way to reduce the load on one Database and distribute the load to more than one database. We use Master-Slave DB’s in which master DB is used to perform write operations while all the read operations are done from the slave database.</p><p>After each writes on Master we perform sync(sync operation) to all other slaves Databases and make sure that there is no difference between any databases and all the databases have the same data inside. Sync operation can be done with software(third party software like <a href="https://github.com/ankane/pgsync">pgsync</a> etc) or with PSQL <a href="https://www.postgresql.org/docs/9.1/high-availability.html">config</a> itself. There is a lag(time taken to sync all the database to each other) and the user can face some issues with the system to overcome that there are some open-source projects like <a href="https://github.com/jbalogh/django-multidb-router#pinningreplicarouter">django-multidb-router</a>. This helps solve problems, whenever a write operation is done on master DB some amount of time is taken to sync all the DB’s for that time all the read operations are done from the master itself(time is configurable in the package).</p><p>We can easily define multiple databases in Django settings like this:</p><pre>DATABASES = {</pre><pre>‘default’: {</pre><pre>‘NAME’: ‘app_data’,</pre><pre>‘ENGINE’: ‘django.db.backends.postgresql’,</pre><pre>‘USER’: ‘postgres_user’,</pre><pre>‘PASSWORD’: ‘s3krit’</pre><pre>},</pre><pre>‘slave-1’: {</pre><pre>‘NAME’: ‘slave_data’,</pre><pre>‘ENGINE’: ‘django.db.backends.mysql’,</pre><pre>‘USER’: ‘mysql_user’,</pre><pre>‘PASSWORD’: ‘priv4te’</pre><pre>}}</pre><p>After this, we can easily config Django for default database for only Write operations while slave-1 for only read operation like in the example below:</p><pre><br>    def db_for_read(self, model, **hints):<br>        &quot;&quot;&quot;<br>        Reads go to a randomly-chosen slave.<br>        &quot;&quot;&quot;<br>        if test_connection_to_db(&#39;master&#39;):<br>            return &#39;master&#39;<br>        return &#39;slave&#39;<br><br>    def db_for_write(self, model, **hints):<br>        &quot;&quot;&quot;<br>        Writes always go to master.<br>        &quot;&quot;&quot;<br>        if test_connection_to_db(&#39;master&#39;):<br>            return &#39;master&#39;<br>        return &#39;slave&#39;<br></pre><h3>Selection of slave DB’s</h3><p><strong>In Case We have multiple slave DB’s in place, there are two ways to select the slave DB for a read operation</strong></p><ul><li><strong>Choose Randomly</strong>: One way is to choose the slave DB randomly for the read operation.</li><li><strong>Choose more intelligently</strong>: The other way is to choose the slave DB is more intelligently where the decision can be made based on ping time or load on DB etc. There is an open-source library available to use for that <a href="https://pypi.org/project/django-pindb/">dajngo-pindb</a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61dc10bff4c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authentication, Routering and much more | ReactJS | Part-2]]></title>
            <link>https://medium.com/@omi10859/authentication-routering-and-much-more-reactjs-part-2-4fcecea1d233?source=rss-1648f990e298------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fcecea1d233</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-router]]></category>
            <dc:creator><![CDATA[Omkar Yadav]]></dc:creator>
            <pubDate>Wed, 29 May 2019 16:32:53 GMT</pubDate>
            <atom:updated>2019-05-29T17:11:20.548Z</atom:updated>
            <content:encoded><![CDATA[<h3>Authentication, Routers and much more | ReactJS | Part-2</h3><p>There we Goooo!!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FwpoLqr5FT1sY0%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FwpoLqr5FT1sY0%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FwpoLqr5FT1sY0%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="315" frameborder="0" scrolling="no"><a href="https://medium.com/media/481bcab67c71a0aaaadb42753472ce4a/href">https://medium.com/media/481bcab67c71a0aaaadb42753472ce4a/href</a></iframe><p>Don’t miss out part-1 in which i covered how to use Django-Rest-Framework to create basic authentication <a href="https://medium.com/p/f431963d745d/">https://medium.com/p/f431963d745d/</a></p><p>In the last part, we tried to create a backend using Django for our website with Login and signup APi Endpoints for users to create new accounts and to log in. Today we will be focusing on …..</p><ul><li><strong>Create Routers for our website</strong></li><li><strong>Making login page</strong></li><li><strong>Authentication Logic</strong></li><li><strong>Protected Routers</strong></li></ul><p>I will skip all the setup related stuff for ReactJs and consider you already have some basic knowledge about ReactJs.</p><p>Let’s Build a basic login form with other logics explained below</p><p><strong>login.js</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/704fb9823305c3523698481dc12c46ae/href">https://medium.com/media/704fb9823305c3523698481dc12c46ae/href</a></iframe><p><em>Starting with Taking input from user and saving that</em></p><p>We will be using states to save user input. we are using <strong>handleChange()</strong> that updates the value if the value is changed in login-form by a user. This is where magic is happing, this is a way to handle <em>multiple inputs</em> in one function.</p><pre>[event.target.name]: event.target.value,</pre><p><em>event.target.name</em> gives the value of name of input which we can define in HTML using <em>name=”something” </em>and <em>event.taget.value </em>will give its value. setState is used to updates value in state.</p><p>Now that we have saved user input’s, We will make a <em>POST </em>request to server with credentials, <em>‘</em><a href="https://www.npmjs.com/package/axios">axios</a>’ seems a nice library and we will be using that. Submit click is handled by <strong>handleSubmit(). </strong>If credentials are right server responds with <strong>TOKEN </strong>which is then used for any other requests to the server so we will save it in our <em>local storage of the browser </em>to do that we will use <a href="https://www.npmjs.com/package/local-storage">local-storage</a> using ls.set to save token.</p><p><strong>Redirecting to Home page</strong></p><p>Now, after token is saved we wish to redirect the page to home page, also I’m using ‘react-router-dom’ to managing routing stuff here.</p><p>I have used a new function redirect() inside which we are requesting a token from local-storage and when found will redirect to (‘/’) which is ‘Home’. This function is also called from <strong>componentDidMount() </strong>which is called immediately after component is mounted. so, if user is logged in already this will push to Home page.</p><p>Now Let’s create our main Routing logic</p><p><strong>App.js</strong></p><pre>import React from &#39;react&#39;;</pre><pre>import &#39;./App.css&#39;;</pre><pre>import Login from &#39;./pages/login&#39;;</pre><pre>import {Route,Switch} from &#39;react-router-dom&#39;;</pre><pre>import Register from &#39;./pages/register&#39;</pre><pre>import { PrivateRoute } from &#39;./api/isAuth&#39;</pre><pre>import Home from &#39;./pages/home&#39;</pre><pre><em>function</em> App<em>()</em> {</pre><pre>return (</pre><pre>  &lt;Router&gt;</pre><pre>    &lt;Switch&gt;</pre><pre>      &lt;Route path=&quot;/login&quot; component={Login} /&gt;</pre><pre>      &lt;Route path=&quot;/register&quot; component={Register}/&gt;</pre><pre>      &lt;PrivateRoute exact path=&quot;/&quot; component={Home}/&gt;</pre><pre>    &lt;/Switch&gt;</pre><pre>  &lt;/Router&gt;</pre><pre> );</pre><pre>}</pre><pre>export default App;</pre><p><strong>But what is <em>PrivateRoute</em>?</strong></p><p>As name suggest these would be like a private component and user have to be logged in to access these components. As you can see they are been imported from <em>‘./api/isAuth’ </em>so they much be<em> </em>user-defined components, let&#39;s see how to create them.</p><p><strong>isAuth.js</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/adfb4baa693e518194d3936129df2273/href">https://medium.com/media/adfb4baa693e518194d3936129df2273/href</a></iframe><p>we are again checking if Token is present in local-storage or now. If Token is not found user is redirected the login page.</p><p><strong>Resultssss…..</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*NCMR6xL0VgbARcxMkTOIwA.gif" /></figure><p>Now you can create a Registration page just like that.</p><p>I have covered a lot of things here which covers so many StackOverflow answers this whole thing took more than 1 day to understand andd guess what I personally hate react for now!.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fcecea1d233" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django-Rest-Framework | Authentication Mechanisms]]></title>
            <link>https://medium.com/@omi10859/django-rest-framework-authentication-mechanisms-f431963d745d?source=rss-1648f990e298------2</link>
            <guid isPermaLink="false">https://medium.com/p/f431963d745d</guid>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Omkar Yadav]]></dc:creator>
            <pubDate>Sat, 25 May 2019 11:04:26 GMT</pubDate>
            <atom:updated>2019-05-29T16:33:56.445Z</atom:updated>
            <content:encoded><![CDATA[<h3>Authentication Mechanisms | Django-Rest-Framework | Part-1</h3><h3>Deep into Authentication</h3><p>Holla Forks! I Hope summers are going well.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FwpoLqr5FT1sY0%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FwpoLqr5FT1sY0%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FwpoLqr5FT1sY0%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="315" frameborder="0" scrolling="no"><a href="https://medium.com/media/481bcab67c71a0aaaadb42753472ce4a/href">https://medium.com/media/481bcab67c71a0aaaadb42753472ce4a/href</a></iframe><p>Today we are going to talk about creating API’s using Django. I’m an absolute beginner and started learning about Django a few days back, so we will more focus on making things work rather than understanding how things are exacting working.</p><p>I was little amazed when I found out that <a href="https://www.django-rest-framework.org/">django-rest-framework</a> is a third-party library and not provided by Django itself. Did you know that??</p><p>Here I will skip all the installing part and setting up things (if you are facing a problem this could be [<a href="https://medium.com/backticks-tildes/lets-build-an-api-with-django-rest-framework-32fcf40231e5">helpful</a>]). Moving on there are some types of authentication that can be used with rest-framework we will be using <strong>Token based authentication. </strong>In that, a unique token is generated for every user which would be included in every request that a user makes, If you wish to learn more about on what is token based authentication etc. refer [<a href="https://www.django-rest-framework.org/api-guide/authentication/#tokenauthentication">here</a>].</p><p>First, we would need to change settings.py, Add these lines to include rest_framework classes for authentication this would be an override to normal Django classes.</p><p><strong>settings.py</strong></p><pre>REST_FRAMEWORK = {</pre><pre>    &#39;DEFAULT_AUTHENTICATION_CLASSES&#39;: (</pre><pre>    &#39;rest_framework.authentication.TokenAuthentication&#39;,),</pre><pre>    &#39;DEFAULT_PERMISSION_CLASSES&#39;: (</pre><pre>    &#39;rest_framework.permissions.IsAuthenticated&#39;,)}</pre><p>Here: <strong>IsAuthenticated </strong>class will be used to check the authentication status of the user.</p><p>And, you can create a new app to manage all the user model that will handle user authentication, registration etc or in some other app, I will leave that part to you.</p><p>Let’s create an API endpoint from which we can register new users.</p><pre>path<em>(</em>&quot;register/&quot;, UserRegistrationAPIView.as_view<em>()</em>, name=&quot;register_user&quot;<em>),</em></pre><p>Include this to your <strong>urls.py</strong>. Here <em>UserRegistrationAPIView </em>is a View which will handle all the registrations and endpoint would be <em>/register/</em></p><p><strong>Views.py</strong></p><pre><em>class</em> UserRegistrationAPIView(CreateAPIView):</pre><pre>    authentication_classes = ()<br>    permission_classes = ()</pre><pre>    serializer_class = UserRegistrationSerializer</pre><pre><em>    def</em> post<em>(</em>self, request, *args, **kwargs<em>)</em>:</pre><pre>        serializer = self.get_serializer<em>(</em>data=request.data<em>)</em></pre><pre>        serializer.is_valid<em>(</em>raise_exception=True<em>)</em></pre><pre>        self.perform_create<em>(</em>serializer<em>)</em></pre><pre>        user = serializer.instance</pre><pre>        token, created = Token.objects.get_or_create<em>(</em>user=user<em>)</em></pre><pre>        data = serializer.data</pre><pre>        data<em>[</em>&quot;token&quot;<em>]</em> = token.key</pre><pre>        headers = self.get_success_headers<em>(</em>serializer.data<em>)</em></pre><pre>        return Response<em>(</em>data, status=status.HTTP_201_CREATED,                         headers=headers<em>) .        </em></pre><p><strong>serializers.py</strong></p><pre>from rest_framework import serializers<br>from rest_framework.validators import UniqueValidator<br>from django.contrib.auth.models import User<br>from django.contrib.auth.hashers import make_password</pre><pre><em>class</em> UserRegistrationSerializer(serializers.ModelSerializer):</pre><pre>    email = serializers.EmailField<em>(</em>required=True,validators= . [UniqueValidator<em>(</em>queryset=User.objects.all<em>())</em>]<em>)</em></pre><pre>    username = serializers.CharField<em>(</em>max_length=32,validators=[UniqueValidator<em>(</em>queryset=User.objects.all<em>())</em>]<em>)</em></pre><pre>    password = serializers.CharField<em>(</em>min_length=4, max_length=100,write_only=True<em>)</em></pre><pre>    confirm_password = serializers.CharField<em>(</em>min_length=4, max_length=100,write_only=True<em>)</em></pre><pre><em>class</em> Meta:</pre><pre>    model = User</pre><pre>    fields = (&quot;id&quot;, &quot;username&quot;, &quot;email&quot;, &quot;password&quot;, &quot;confirm_password&quot;, &quot;date_joined&quot;)</pre><pre><em>    def</em> create<em>(</em>self, validated_data<em>)</em>:</pre><pre>        user = User.objects.create<em>(</em></pre><pre>        email=validator_data<em>[</em>&#39;email&#39;<em>]</em>,</pre><pre>        username=validator_data<em>[</em>&#39;username&#39;<em>]</em>,</pre><pre>        password=make_password<em>(</em>validator_data<em>[</em>&#39;password&#39;<em>]))</em></pre><pre>    return user</pre><pre><em>    def</em> validate<em>(</em>self, attrs<em>)</em>:</pre><pre>        if attrs.get<em>(</em>&#39;password&#39;<em>)</em> != attrs.get<em>(</em>&#39;confirm_password&#39;<em>)</em>:</pre><pre>        raise serializers.ValidationError<em>(</em>&quot;Those passwords don&#39;t match.&quot;<em>)</em></pre><pre>        return attrs</pre><p>We will have added checks like email should be unique along with username and password confirm password should be equal and should match.</p><p>If you are new to Django-rest-framework then serializers WTF is that</p><blockquote>Serializers allow complex data such as querysets and model instances to be converted to native Python datatypes that can then be easily rendered into JSON, XML or other content types. Serializers also provide deserialization, allowing parsed data to be converted back into complex types, after first validating the incoming data.</blockquote><p>In easy words, Serializers are used to convert the objects of the database in such a format that can be accessed using API’s.</p><p><strong><em>Q.) What is make_password()?</em></strong></p><p><strong><em>Ans.) </em></strong><em>make_password() is used to hash password which is very important. No one saves the password in plain text nowadays other than Facebook.</em></p><p>The registration endpoint is available to register new users in my case at</p><pre>localhost:8000/api/account/register/</pre><p>why not try it out, I will use postman to check my API</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*tV5wI1v5E6eoIt58WpJUDw.png" /></figure><p>All the checks are working: In image, it’s visible that I have only passed email-id which is not unique as some other user already using this email and other fields are empty. Now let’s try again with all details</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*qyetcwHmXcF9S-E3k8WI-A.png" /></figure><p>Holla, everything is working we have got <strong>token </strong>here we should store this is front-end and use this for all the requests that we want to make to access all endpoints.</p><h4>BUT BUT BUT <strong>What about login?</strong></h4><p>For login, the Mechanism would be to have an endpoint which will take username, password and return <strong>token. </strong>Every time user logout from front-end you will delete token from front-end.</p><p>So, For login django-rest-framework provide a function which can be used. Add this to your <strong>urls.py</strong></p><pre>from rest_framework.authtoken import views<br>urlpatterns = [<br>    url(https://medium.com/login/&#39;,%20views.obtain_auth_token)<br>]</pre><p>But, we should add one more thing that is deleting token after some time and create another to improve security. This library can be used to do that easily refer [<a href="https://github.com/JamesRitchie/django-rest-framework-expiring-tokens">here</a>].</p><p>That will do our login and registering but where is validation model?</p><p>Django-rest-framework provides some @permission_classes same as @login_required in Django here is a simple example:</p><pre>@api_view<em>(</em>[&#39;GET&#39;]<em>)</em></pre><pre>@permission_classes<em>(</em>(IsAuthenticated, )<em>)</em></pre><pre><em>def</em> ListUsers<em>(</em>request, format=None<em>)</em>:</pre><pre>    contete = {&#39;status&#39;:&#39;request permitted bro&#39;}</pre><pre>    return Response<em>(</em>contete<em>)</em></pre><p>api_view([‘GET’]) says that this function will only accept get requests.</p><p>permission_classes((IsAuthenticated, )) is used to check the authentication of the request if it’s authenticated it will provide or it will raise an error as:</p><pre>{<br>    &quot;detail&quot;: &quot;Authentication credentials were not provided.&quot;<br>}</pre><pre>OR</pre><pre>{<br>    &quot;detail&quot;: &quot;Invalid token.&quot;<br>}</pre><p>Yeaah!! We have created a simple login and signup end points along with authentication checks too.</p><p><em>Some points to keep in mind</em></p><ul><li>This is my approach to do this, there may be other ways which may be even better.</li><li>This blog post is written for people who already have a basic idea of Django and django-rest-framework.</li><li>I’m still in the learning phase and there may be some problems in code, please comment below so that I could fix them for others and for me.</li></ul><p>Thanks for reading I would be sharing more on Django-Rest-Framework and ReactJs, so don’t forget to follow this account.</p><p><strong>Part-2 is available here: </strong><a href="https://medium.com/@omi10859/authentication-routering-and-much-more-reactjs-part-2-4fcecea1d233"><strong>https://medium.com/@omi10859/authentication-routering-and-much-more-reactjs-part-2-4fcecea1d233</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f431963d745d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Automate | Python]]></title>
            <link>https://medium.com/@omi10859/lets-automate-python-162de7b0d6ff?source=rss-1648f990e298------2</link>
            <guid isPermaLink="false">https://medium.com/p/162de7b0d6ff</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[youtube]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Omkar Yadav]]></dc:creator>
            <pubDate>Mon, 17 Sep 2018 14:00:50 GMT</pubDate>
            <atom:updated>2018-09-17T14:03:32.536Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WdQst0NujrGzvGMQz37jfg.jpeg" /></figure><p>Holla Hackers,</p><p>Today we are going to talk about Automating things around you using python.</p><p>So, I guess most of you are already familiar with python if not this is a time to learn something new. Today we will talk more about how we can make our life easy with python, We will learn about automating things.</p><p><strong>What exactly is automation and what I’m talking about?</strong><br> <strong>Automation</strong> simply means making something do itself like you have a job to rename 100 files in a folder why do it yourself let computer help you <strong>[</strong>Here is the <a href="https://github.com/nitin42/Python-Automation/blob/master/project_7.py">code</a> for same<strong>]</strong>.</p><p><strong>Why python for automation?</strong><br> <strong>Python</strong> is a scripting language, and scripting languages that mean it need not get compiled and can be run on any system.<br> Python is open-source, very simple and has some great library’s that you can use to make your program easily.</p><h3>Ok, Let’s Do Some Coding….</h3><p>Today we will build a python script which can play youtube video on your browser if you pass a video title isn’t it cool?</p><p>Let’s get started….</p><p><strong>Step1: </strong>We need a youtube link (link to the video we want to play in browser):</p><p>For that, we will do a bit of <a href="https://en.wikipedia.org/wiki/Web_scraping">Web Scraping </a>using <a href="https://pypi.org/project/beautifulsoup4/">beautiful soup</a></p><p>Let’s search for something on youtube</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nJteIKU9-vZ3sM8n2KYLeQ.png" /></figure><p>nape we can do this from a url<br><a href="https://www.youtube.com/results?search_query=justin+bieber">https://www.youtube.com/results?search_query=justin+bieber</a></p><p><strong>Next:</strong></p><p>We just need to extract link of the first video</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2867f5704cb7ad1e3ced263cc053baca/href">https://medium.com/media/2867f5704cb7ad1e3ced263cc053baca/href</a></iframe><p>This will get the link of the Video now we just need to play that on the browser I would say you should try to do that yourself for help let me tell you there is a library that can help you <a href="https://docs.python.org/3/library/webbrowser.html">webbrowser</a> .</p><p>There is already a library that does the same and was publishes by me here. Hope you like and enjoy this tutorial.</p><p>Questions? Ask in comments below 🙂</p><p><em>Originally published at </em><a href="https://blog.omkar.site/lets-automate-python/"><em>blog.omkar.site</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=162de7b0d6ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native Zero To Hero | Part-1]]></title>
            <link>https://medium.com/@omi10859/react-native-zero-to-hero-part-1-f4c0b68155bb?source=rss-1648f990e298------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4c0b68155bb</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[techoxicated]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Omkar Yadav]]></dc:creator>
            <pubDate>Sun, 09 Sep 2018 18:28:05 GMT</pubDate>
            <atom:updated>2018-09-09T18:28:05.274Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*KEOO__DV3oBYvRuWJFZGxw.jpeg" /></figure><p>Hello,</p><p>Welcome to my new blog <a href="http://blog.omkar.site/">techOxicated.</a><br> I will try to keep posting at least one blog post every week so let’s go…</p><p>This post is a series of the blog post in which I will try to share my experience with <a href="http://facebook.github.io/react-native">react-native.</a></p><p>So, what exactly is react-native and why we should learn this 🤷🏻‍♂️</p><p>React native is a javascript framework for mobile development. Its an <a href="https://github.com/facebook/react-native">open source</a> project by <a href="http://facebook.com/">facebook</a>.</p><p>If you are familiar with web development react-native will be an easy task for you, and if know reactJs you are already a mobile developer 😉</p><p>React-native apps are native they are not hybrid, webapps and all that, but how exactly react-native do that React-native under the hood uses some state of the art technology to convert your javascript code to Java and XML for Android and Swift and C++ for iOS so you can use same code base to develop for both platforms ios and android and you can also use native code if you want, like for example, you want to develop some feature just for android go ahead its easy to do.</p><h3>How do we run/make apps in react native?</h3><p>Let’s suppose you are convinced and want to continue on how you can make apps using react-native.</p><p>Things you need to have</p><ul><li>Machine with 8Gb Ram</li><li><a href="https://nodejs.org/en/">Node.js</a></li><li><a href="https://facebook.github.io/watchman/">watchman</a></li><li>Android Studio/Xcode</li><li>python</li></ul><p>There is an easy way to install all that <a href="http://facebook.github.io/react-native/docs/getting-started.html">http://facebook.github.io/react-native/docs/getting-started.html</a> follow the link to know how you can set up all this on your machine</p><p>Let’s hope you done with setting up if not, search the web or you can ping 😉</p><p>open a terminal and write this:</p><p>react-native init AppName</p><p>this will create your project folder with all import files needed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*ru2PgYMsA5cKE6JvVDvtXg.png" /></figure><p>Files structure will be something like this</p><ul><li><strong>package.json</strong>: This file will have all dependencies for project</li><li><strong>index.js</strong>: Just like index.html index.js is an entry point for the project we don’t generally edit/update this file</li><li><strong>App.js: </strong>This is the file we need to change to get update App</li><li><strong>ios: </strong>This folder contains all ios code</li><li><strong>Android: </strong>This folder contains all android code</li><li>ignore all other for now</li></ul><h4>Where to run:</h4><p>You need to run an emulator or connect a physical device</p><p>After doing so you are ready to go (some steps are missing)</p><h4>Ready?</h4><p>Yes, you are now a mobile developer.</p><p>cd AppName</p><p>react-native run-ios //for ios</p><p>react-native run-android //for android</p><p>wait for a while and yeah its done good job!!</p><h4>Hello World</h4><p>Change App.js to</p><p><strong>import React, {Component} from ‘react’;<br>import {Platform, StyleSheet, Text, View} from ‘react-native’;</strong><strong>export default class App extends Component&lt;Props&gt; { render() { return ( &lt;View style={styles.container}&gt; &lt;Text style={styles.welcome}&gt;Welcome to React Native!&lt;/Text&gt; &lt;Text&gt;Hello World &lt;/Text&gt; &lt;/View&gt; ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: &#39;center&#39;, alignItems: &#39;center&#39;, backgroundColor: &#39;#F5FCFF&#39;, },</strong></p><p><strong>});</strong></p><p>Go to emulator and press command/ctrl + r to reload the code and boom!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*KeW483qFm3DdDmYMUZnyWA.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FR20voT6eqnc%3Fstart%3D74%26feature%3Doembed%26start%3D74&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DR20voT6eqnc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FR20voT6eqnc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/67675955cd317c49ff7722769b4a73e5/href">https://medium.com/media/67675955cd317c49ff7722769b4a73e5/href</a></iframe><p><strong>Still, Have Questions ask in the comments below. Thanks</strong></p><p><em>Originally published at </em><a href="https://blog.omkar.site/react-native-zero-to-hero-part-1/"><em>blog.omkar.site</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4c0b68155bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>