Skip to content

Instantly share code, notes, and snippets.

View jerinisready's full-sized avatar
💭
A catalyst of Change

JK jerinisready

💭
A catalyst of Change
View GitHub Profile
@jerinisready
jerinisready / gist:1bcc5ca615765d76058860293c3144ec
Created May 13, 2018 10:54 — forked from thraxil/gist:3123935
django project git pre-commit hook
#!/usr/bin/env python
import os
import re
import subprocess
import sys
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)')
CHECKS = [
@jerinisready
jerinisready / .git_commands
Last active May 21, 2018 15:49
This is how to remove any large files form git history! This is adviced only after proper backup of your repository!
git filter-branch --index-filter 'git rm --cached --ignore-unmatch <file_path_or_pattern>' --tag-name-filter cat -- --all
git push origin --force --all
<style>
.classWithShadow{
-moz-box-shadow: 1px 1px 2px grey, 0 0 25px lightgrey;
-webkit-box-shadow: 1px 1px 2px grey, 0 0 25px lightgrey;
box-shadow: 1px 1px 2px grey, 0 0 25px lightgrey;
}
</style>
<!doctype HTML>
<head></head>
<div class="shadowclass">
@jerinisready
jerinisready / django_bootstrap_models.py
Created June 5, 2018 20:52
Sample Django Form To add Bootstrap's Form Control class to every field.
class BootstrapMixinForm(forms.ModelForm):
"""
Sample Django Form To add Bootstrap's Form Control class to every field.
"""
def __init__(self, *args, **kwargs):
super(BootstrapMixinForm, self).__init__(*args, **kwargs)
for myField in self.fields:
self.fields[myField].widget.attrs['class'] = 'form-control'
@jerinisready
jerinisready / reset_javascript_element.js
Created June 8, 2018 07:05
Sometimes we require to reset a canvas when we want to replace the graph with another set of data. that time simply resigning may cause issue, we can reomove and recreate elements for that purpose
function reset_element(element_id, element_type){
var child = document.getElementById(div_id);
var parent = child.parentElement;
var new_child = document.createElement(element_type);
parent.removeChild(child);
new_child.setAttribute('id', div_id);
parent.appendChild(new_child);
}
// <span id="my_canvas_id"></span>
@jerinisready
jerinisready / django_api_detail_view.py
Last active June 20, 2018 07:01
APIDetailView Django Rest Framework / DRF Detail View With pk
class APIDetailView(APIView):
authentication_classes = (CsrfExemptSessionAuthentication, BasicAuthentication)
http_method_names = ('get', )
serializer_class = ModelSerializer
def get(self, request, pk, **kwargs):
obj = Chapter.objects.get(id=pk)
serializer = ModelSerializer(obj, context={"request": request})
return Response(serializer.data, status=status.HTTP_200_OK)
@jerinisready
jerinisready / load_image_to _model.py
Created July 2, 2018 11:23
If you want to download and save an image from an external url, this snippet might help you!
from django.core.files import File
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.core.files.temp import NamedTemporaryFile
from newspaper import Article
import requests
from myapp.models import Blog, Category, Tags
__author__ = 'jerinisready'
@jerinisready
jerinisready / login_required_mixin_over_drf.py
Last active July 2, 2018 15:14
A Quick Login Required Mixin For Django Rest Framework
from rest_framework.response import Response
import rest_framework.views
class APIView(rest_framework.views.APIView):
""" A Quick Login Required Mixin For Django Rest Framework """
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated():
return Response({'error': 'Please Authenticate to continue'}, status=405)
return super(self.__class__, self).dispatch(request, *args, **kwargs)
@jerinisready
jerinisready / python_builtin_similarity_checker.py
Last active July 12, 2018 22:33
Here is a builtin python package to view the similarity of the text forked from stackoverflow [https://stackoverflow.com/a/17388505/9662240]
__author__ = """https://stackoverflow.com/a/17388505/9662240"""
from difflib import SequenceMatcher
def similar(a, b):
return SequenceMatcher(None, a, b).ratio()
"""
>>> similar("Apple","Appel")
0.8
@jerinisready
jerinisready / make_all_blocks_equiheight.js
Created July 18, 2018 05:53
How to make All Blocks Equal height with JS. **[ Courtsy: Unknown ]**
$(document).ready(function(){
$('.height-outer').each(function(){
var highestBox = 0;
$('.equilheight', this).each(function(){
if($(this).height() > highestBox) {
highestBox = $(this).height();
}
});
$('.equilheight',this).height(highestBox);
});