Skip to content

Instantly share code, notes, and snippets.

@pankaj28843
pankaj28843 / example.html
Last active March 9, 2017 17:45
A hack to open links in new window or parent in a published Google Doc which is embedded as iframe. Demo at https://cdn.rawgit.com/psjinx/1f2317a50eb2b506ed84/raw/example.html
<!DOCTYPE html>
<html>
<head>
<title>psjinx's Resume</title>
</head>
<body>
<iframe id="google-doc-iframe" srcdoc="" style="height: 1050px; margin: 0 auto;" align="middle" frameborder="0" width="100%" height="100%" scrolling="no">
</iframe>
@pankaj28843
pankaj28843 / runinenv.sh
Created June 4, 2014 09:25
run a command inside virtualenv
#!/bin/bash
VENV=$1
if [ -z $VENV ]; then
echo "usage: runinenv [virtualenv_path] CMDS"
exit 1
fi
. ${VENV}/bin/activate
shift 1
echo "Executing $@ in ${VENV}"
exec "$@"
@pankaj28843
pankaj28843 / india-data-visualization-google-map.html
Created May 3, 2014 07:34
India data visualization google map
<html>
<head>
<script type='text/javascript' src='http://www.google.co.in/jsapi'></script>
<script>
google.load('visualization', '1', {
'packages': ['geomap']
});
google.setOnLoadCallback(drawMap2);
@pankaj28843
pankaj28843 / profiler.py
Created January 6, 2014 12:21
Django view profiler - a decorator function to profile your code
import hotshot
import os
import time
from django.conf import settings
import tempfile
try:
PROFILE_LOG_BASE = settings.PROFILE_LOG_BASE
except:
PROFILE_LOG_BASE = tempfile.gettempdir()
(function(undefined) {
// Get angular app
var app = angular.module("App");
app.factory("XLSXReaderService", ['$q', '$rootScope',
function($q, $rootScope) {
var service = function(data) {
angular.extend(this, data);
};
(function(undefined) {
'use strict';
// Check if dependecies are available.
if (typeof XLSX === 'undefined') {
console.log('xlsx.js is required. Get it from https://github.com/SheetJS/js-xlsx');
return;
}
if (typeof _ === 'undefined') {
console.log('Lodash.js is required. Get it from http://lodash.com/');
@pankaj28843
pankaj28843 / pnr-beep-beep.sh
Last active December 29, 2015 10:19
Go beep-beep-beep-beep-beep when Railway Chart is prepared for your PNR
while true;
# echo date/time
date;
do
# make a post request to Indian Railways PNR Enquiry page and search for "CHART NOT PREPARED"
if curl --silent -X POST -d "lccp_pnrno1=$1&submitpnr=Get+PNR+Status" http://www.indianrail.gov.in/cgi_bin/inet_pnrstat_cgi.cgi | grep "CHART PREPARED"
then
# Chart prepared :)
echo "Chart prepared. \n\n";
@pankaj28843
pankaj28843 / app.js
Created August 6, 2013 06:10
Using SessionAuthentication of django-tastypie with AngularJS for POST/PUT/DELETE
'use strict';
angular.module('App', ['ng', 'ngCookies', 'ngResource']);
angular.module('App').run(function($rootScope, $http, $cookies) {
$http.defaults.headers.common['X-CSRFToken'] = $cookies.csrftoken;
});
@pankaj28843
pankaj28843 / api.py
Last active December 18, 2015 03:59
So, you want to create users using django-tastypie
from django.contrib.auth.models import User
from django.contrib.auth.hashers import make_password
from tastypie.authentication import (
Authentication, ApiKeyAuthentication, BasicAuthentication,
MultiAuthentication)
from tastypie.authorization import Authorization
from tastypie.resources import ModelResource
from tastypie import fields
@pankaj28843
pankaj28843 / parse_youtube_urls.py
Created February 26, 2012 18:00
Download multiple youtube videos at once
# -*- coding: utf-8 -*-
from BeautifulSoup import BeautifulSoup
input_file = file('input.txt')
soup = BeautifulSoup(input_file.read())
for a in soup.findAll('a'):
if 'watch?v=' in a['href']:
print 'http://www.youtube.com'+a['href']