Skip to content

Instantly share code, notes, and snippets.

View vaibhav-jain's full-sized avatar
🏠
Working remotely @newpage solutions inc

vaibhav jain vaibhav-jain

🏠
Working remotely @newpage solutions inc
View GitHub Profile
@vaibhav-jain
vaibhav-jain / gist:7af5bb5ce4341fdb8e3a1af1ccb83ed3
Created March 6, 2017 06:36 — forked from rtorr/gist:3148833
No duplicate (case-insensitive) entries django model
from django.db import models
from django.db.models import Manager
from django.db.models.query import QuerySet
class CaseInsensitiveQuerySet(QuerySet):
def _filter_or_exclude(self, mapper, *args, **kwargs):
# 'name' is a field in your Model whose lookups you want case-insensitive by default
if 'name' in kwargs:
kwargs['name__iexact'] = kwargs['name']
del kwargs['name']
@vaibhav-jain
vaibhav-jain / gist:b8242404f796f490ac4c21259222ace0
Created November 19, 2016 11:30 — forked from fernandoaleman/gist:5083680
How to update VirtualBox Guest Additions with vagrant
# Start the old vagrant
$ vagrant init centos-6.3
$ vagrant up
# You should see a message like:
# [default] The guest additions on this VM do not match the install version of
# VirtualBox! This may cause things such as forwarded ports, shared
# folders, and more to not work properly. If any of those things fail on
# this machine, please update the guest additions and repackage the
# box.
@vaibhav-jain
vaibhav-jain / UniqueTogetherValidator.py
Created July 2, 2016 12:45
Django Rest Framework (DRF) Custom Unique Together Message
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
class SomeSerializer(serializers.ModelSerializer):
"""
Demostrating How to Override DRF UniqueTogetherValidator Message
"""
class Meta:
@vaibhav-jain
vaibhav-jain / timezone_field.py
Created June 9, 2016 17:59
TimeZone Field for DRF
import pytz
import six
class TimezoneField(serializers.Field):
def to_representation(self, obj):
return six.text_type(obj)
def to_internal_value(self, time_zone):
@vaibhav-jain
vaibhav-jain / 60-jetbrains.conf
Created May 31, 2016 05:20 — forked from SiegfriedEhret/60-jetbrains.conf
Inotify configuration for IntelliJ IDEA (PhpStorm, PyCharm, RubyMine, WebStorm). Create this file with e.g. `sudo vim /etc/sysctl.d/60-jetbrains.conf`
# Set inotify watch limit high enough for IntelliJ IDEA (PhpStorm, PyCharm, RubyMine, WebStorm).
# Create this file as /etc/sysctl.d/60-jetbrains.conf (Debian, Ubuntu), and
# run `sudo service procps start` or reboot.
# Source: https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit
#
# More information resources:
# -$ man inotify # manpage
# -$ man sysctl.conf # manpage
# -$ cat /proc/sys/fs/inotify/max_user_watches # print current value in use
from django.core.cache import caches
def get_request_cache():
return caches['default']
class RequestCacheMiddleware(object):
"""
Usage:
@vaibhav-jain
vaibhav-jain / gist:e7b3ce38277a7c73611d
Created January 12, 2016 09:00 — forked from machristie/gist:1073967
iframe Tweet Button example
<iframe id="tweet-button" allowtransparency="true" frameborder="0" scrolling="no"
src="http://platform.twitter.com/widgets/tweet_button.html?via=marcus_christie&amp;text=Replace%20Me&amp;count=horizontal"
style="width:110px; height:20px;"></iframe>
@vaibhav-jain
vaibhav-jain / boostrap-youtube-modal.js
Created December 7, 2015 16:57 — forked from jawinn/boostrap-youtube-modal.js
BOOTSTRAP 3.0 - Open YouTube Video Dynamicaly in Modal Window. Allow setting width and height.
// REQUIRED: Include "jQuery Query Parser" plugin here or before this point:
// https://github.com/mattsnider/jquery-plugin-query-parser
$(document).ready(function(){
// BOOTSTRAP 3.0 - Open YouTube Video Dynamicaly in Modal Window
// Modal Window for dynamically opening videos
$('a[href^="http://www.youtube.com"]').on('click', function(e){
// Store the query string variables and values
// Uses "jQuery Query Parser" plugin, to allow for various URL formats (could have extra parameters)
@vaibhav-jain
vaibhav-jain / git
Last active June 7, 2019 07:53 — forked from lttlrck/gist:9628955
Rename git branch
==============
git commands
==============
To rename branch
=================
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote