Skip to content

Instantly share code, notes, and snippets.

@pankaj28843
pankaj28843 / parse_youtube_urls.py
Created Feb 26, 2012
Download multiple youtube videos at once
View parse_youtube_urls.py
# -*- 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']
@pankaj28843
pankaj28843 / api.py
Last active Dec 18, 2015
So, you want to create users using django-tastypie
View api.py
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 / app.js
Created Aug 6, 2013
Using SessionAuthentication of django-tastypie with AngularJS for POST/PUT/DELETE
View app.js
'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 / pnr-beep-beep.sh
Last active Dec 29, 2015
Go beep-beep-beep-beep-beep when Railway Chart is prepared for your PNR
View pnr-beep-beep.sh
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";
View xlsx-reader.js
(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/');
View app-services.js
(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);
};
@pankaj28843
pankaj28843 / profiler.py
Created Jan 6, 2014
Django view profiler - a decorator function to profile your code
View profiler.py
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()
View india-data-visualization-google-map.html
<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 / runinenv.sh
Created Jun 4, 2014
run a command inside virtualenv
View runinenv.sh
#!/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 / example.html
Last active Mar 9, 2017
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
View 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>