Skip to content

Instantly share code, notes, and snippets.

View mushfiq's full-sized avatar

Mushfiq mushfiq

View GitHub Profile
@mushfiq
mushfiq / authentication.py
Last active December 29, 2015 22:17
DRF custom authentication class for access key based auth checking.
from rest_framework import authentication
from rest_framework import exceptions
from apps.newspaper.models import Subscriber
class AccessKeyAuthentication(authentication.BaseAuthentication):
def authenticate(self, request):
access_key = request.GET.get("access_key", None)
if not access_key:
@mushfiq
mushfiq / cors.py
Last active October 7, 2015 14:34
python decorator for bottle framework to enable CORS to an endpoint.
from bottle import Bottle,response
def allow_cors(func):
""" this is a decorator which enable CORS for specified endpoint """
def wrapper(*args, **kwargs):
response.headers['Access-Control-Allow-Origin'] = 'example.com' # * in case you want to be accessed via any website
return func(*args, **kwargs)
return wrapper
@mushfiq
mushfiq / gplaces_api_client.php
Last active August 29, 2015 14:17
This gist has a sample API call using PHP Google places API client.
<?php
require_once 'googleplaces.class.php';
$googlePlaces = new GooglePlaces(array(
'apiKey' => "YOUR_API_KEY"
));
$query['query'] = "Burger in Berlin";
$places = $googlePlaces->getLocationsByTextSearch($query);
$decoded_data = json_decode($places, true);
import nltk
import random
class Categorizer(object):
def __init__(self, categories):
self.categories = categories
def prep_seed(self, content):
"""Convert seed content into nltk.Text"""
raw = nltk.clean_html(content)
import os
import sys
from getpass import getpass
import gdata.docs.service
import gdata.spreadsheet.service
'''
get user information from the command line argument and
@mushfiq
mushfiq / JSDateTOJavaDateConversion
Last active December 27, 2015 17:49
A sample java demo for js datetime to java date conversion
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
*
* @author mushfiq
*/
public class JSDateTOJavaDateConversion {
node_modules/*
*.data
node_modules/*
@mushfiq
mushfiq / crawlPyCentral.py
Last active December 20, 2015 21:29
An example of using super in python
import requests
from BeautifulSoup import BeautifulSoup
class crawlPyCentral(object):
def __init__(self, url='http://pythoncentral.org/'):
self.url = url
def getSoup(self):
response = requests.get(self.url)
db.$cmd.sys.unlock.findOne();