Skip to content

Instantly share code, notes, and snippets.

View a1Gupta's full-sized avatar

Ashish Gupta a1Gupta

View GitHub Profile
@a1Gupta
a1Gupta / middleware.py
Created December 25, 2015 17:24 — forked from mindlace/middleware.py
Add user created/modified to every model
"""Add user created_by and modified_by foreign key refs to any model automatically.
Almost entirely taken from https://github.com/Atomidata/django-audit-log/blob/master/audit_log/middleware.py"""
from django.db.models import signals
from django.utils.functional import curry
class WhodidMiddleware(object):
def process_request(self, request):
if not request.method in ('GET', 'HEAD', 'OPTIONS', 'TRACE'):
if hasattr(request, 'user') and request.user.is_authenticated():
user = request.user
@a1Gupta
a1Gupta / post-merge
Created February 7, 2016 04:32 — forked from sindresorhus/post-merge
git hook to run a command after `git pull` if a specified file was changed. In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed. Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
@a1Gupta
a1Gupta / gist:e0076d65b627a168e682641bc8d0ebc2
Last active January 22, 2017 16:57 — forked from marcgg/gist:733592
Regex to get the Facebook Page ID from a given URL
# Matches patterns such as:
# https://www.facebook.com/my_page_id => my_page_id
# http://www.facebook.com/my_page_id => my_page_id
# http://www.facebook.com/#!/my_page_id => my_page_id
# http://www.facebook.com/pages/Paris-France/Vanity-Url/123456?v=app_555 => 123456
# http://www.facebook.com/pages/Vanity-Url/45678 => 45678
# http://www.facebook.com/#!/page_with_1_number => page_with_1_number
# http://www.facebook.com/bounce_page#!/pages/Vanity-Url/45678 => 45678
# http://www.facebook.com/bounce_page#!/my_page_id?v=app_166292090072334 => my_page_id
# http://www.facebook.com/my.page.is.great => my.page.is.great

Keybase proof

I hereby claim:

  • I am a1Gupta on github.
  • I am a1gupta (https://keybase.io/a1gupta) on keybase.
  • I have a public key whose fingerprint is C954 0359 FF43 7EC3 4CAA 9867 9AE8 AA8C C3E1 3762

To claim this, I am signing this object:

@a1Gupta
a1Gupta / Images
Last active February 11, 2017 08:22
# Identify blank/broken image
try:
file = cStringIO.StringIO(urllib.urlopen(user.profile_pic.url).read())
img = Image.open(file)
except:
print "broken image"
def queryset_iterator(queryset, chunksize=1000):
'''''
Iterate over a Django Queryset ordered by the primary key
This method loads a maximum of chunksize (default: 1000) rows in it's
memory at the same time while django normally would load all rows in it's
memory. Using the iterator() method only causes it to not preload all the
classes.
Note that the implementation of the iterator
does not support ordered query sets.
'''
@a1Gupta
a1Gupta / 0_reuse_code.js
Created July 1, 2017 12:35
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console