Skip to content

Instantly share code, notes, and snippets.

View toransahu's full-sized avatar
💭
I may be slow to respond.

Toran Sahu toransahu

💭
I may be slow to respond.
View GitHub Profile
@toransahu
toransahu / extend_user_model_using_Custom_Model_Extending_AbstractUser.py
Created January 27, 2018 20:00
Django | Extend User Model | Extending User Model Using a Custom Model Extending AbstractUser
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
bio = models.TextField(max_length=500, blank=True)
location = models.CharField(max_length=30, blank=True)
birth_date = models.DateField(null=True, blank=True)
@toransahu
toransahu / duck_typing.py
Last active November 14, 2018 11:20
Duck Typing
"""
* EAFP: Easier to Ask Forgiveness than Permission
* Tag line definition: If an object can quack & fly, then its a duck.
* Do not worry about, if this object has this attribute or not, just try it inside try: block. If work then great, else handle the error.
"""
class Duck:
def quack(self):
print("Quack quack")
@toransahu
toransahu / DS.md
Last active November 28, 2018 19:35
DS.md

Data Structures Basic Data Structures

Stack (Array & Linked List Implementation)
Queue (Array & Linked List Implementation)
Linked List (Single, Double & Circular)
Lists

Tree Data Structures

@toransahu
toransahu / answer1.py
Last active February 15, 2018 16:41
GrabbnGo
from itertools import product
def get_string_comb():
alpha_list = [chr(i) for i in range(97, 123)]
for size in range(1, 10):
for s in product(alpha_list, repeat=size):
yield "".join(s)
@toransahu
toransahu / restful_viewset_based_view.py
Created April 12, 2018 06:07
Django REST framework VIEW Implementation Approach: Class Based + Single ViewSet Class (Inherits viewsets.ModelViewSet)
from rest_framework import viewsets
from .models import Blog
from .serializers import BlogSerializer
# Create your views here.
class BlogViewSet(viewsets.ModelViewSet):
"""
Using viewset instead of generic ListCreateAPIView & RetrieveUpdateDestroyAPIView.
#!/usr/bin/env python3.6.4
# coding="UTF-8"
__author__ = 'Toran Sahu <toran.sahu@yahoo.com>'
__copyright__ = 'Copyright (C) 2018 Ethereal Machines Pvt. Ltd. All rights reserved'
from rest_framework import viewsets, mixins
from .models import Job, JobEnquiry
from .serializers import JobSerializer, JobEnquirySerializer
#!/usr/bin/python3.6.4
# coding="UTF-8"
__author__ = 'Toran Sahu <toran.sahu@yahoo.com>'
__copyright__ = 'Copyright (C) 2018 Ethereal Machines Pvt. Ltd. All rights reserved'
from rest_framework.permissions import BasePermission, AllowAny
@toransahu
toransahu / model_with_custom_upload_to.py
Created April 14, 2018 11:49
Here we are providing dynamic path to upload_to attribute for saving the media file.
#!/usr/bin/env python3.6.4
# coding="UTF-8"
__author__ = 'Toran Sahu <toran.sahu@yahoo.com>'
__copyright__ = 'Copyright (C) 2018 Ethereal Machines Pvt. Ltd. All rights reserved'
from django.db import models
def directory_path(instance, filename):
@toransahu
toransahu / .editorconfig
Last active April 25, 2018 06:19
VIM dot files, configuration as Python IDE
# EditorConfig is awesome
# http://EditorConfig.org
root = true
# defaults
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8

Vim Cheatsheet

Disclaimer: This cheatsheet is summarized from personal experience and other online tutorials. It should not be considered as an official advice.

Global

:help keyword # open help for keyword
:o file       # open file
:saveas file  # save file as
:close        # close current pane