Skip to content

Instantly share code, notes, and snippets.

View jineshpaloor's full-sized avatar

Jinesh Panampattakunnath jineshpaloor

View GitHub Profile
@jineshpaloor
jineshpaloor / django_pdf.py
Last active December 17, 2015 21:39
django view to generate pdf file using report lab library
from django.http import HttpResponse
# imports for reportlab
import time
from reportlab.lib import colors
from reportlab.lib.enums import TA_JUSTIFY
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image,\
Table, TableStyle
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
>>> import os
>>> import pyPdf
>>> output = pyPdf.PdfFileWriter()
>>> files = ['a.pdf', 'b.pdf']
>>> pdf_path = '/home/jinesh/Documents/'
>>> for file in files:
... pdf = pdf_path + file
... f = open(pdf, 'rb')
... input = pyPdf.PdfFileReader(f)
@jineshpaloor
jineshpaloor / svn_tags.sh
Last active December 18, 2015 02:48
a simple step by step instruction to explain tagging in svn
# create a new local repo
$ svnadmin create /usr/local/svn/repos/test
# checkout the repo to make it working directory
$ svn checkout file:///usr/local/svn/repos/test
Checked out revision 0.
# create 3 folders 'trunk', 'tags', and 'branches'
$ cd test/trunk
$ echo 'Hello, World!' > hello.txt
@jineshpaloor
jineshpaloor / svn_ubuntu.sh
Last active December 18, 2015 03:48
how to set up a svn project on ubuntu server with trunk, tags, and branches.
# http://oliverdavies.co.uk/blog/2011/10/19/install-and-configure-subversion-svn-server-ubuntu
# http://odyniec.net/articles/ubuntu-subversion-server/
$ sudo mkdir /home/svn
$ sudo mkdir ~/ecomexpress
$ sudo svnadmin create /home/svn/ecomexpress -m 'initial project structure'
$ cd ~/ecomexpress
1
@jineshpaloor
jineshpaloor / date_range_query.py
Created June 19, 2013 09:49
django query making to get models objects in date range
def get_shipments_in_range(customer, date_on):
q = Q()
q = q & Q(shipper_id = int(customer.id))
dt = datetime.datetime.strftime(date_to, "%Y-%m-%d")
df = dt - datetime.timedelta(days=dt.day-1)
date_to = dt.strftime("%Y-%m-%d")
date_from = df.strftime("%Y-%m-%d")
q = q & Q(added_on__range=(date_from,date_to))
shipments = Shipment.objects.filter(q)
return shipments
@jineshpaloor
jineshpaloor / multiprocessing_log.py
Created June 26, 2013 05:15
wrapping class and a Pool subclass for logging errors
#reference: http://stackoverflow.com/a/7678125/846193
import traceback
from multiprocessing.pool import Pool
import multiprocessing
# Shortcut to multiprocessing's logger
def error(msg, *args):
return multiprocessing.get_logger().error(msg, *args)
@jineshpaloor
jineshpaloor / python_async.py
Created June 26, 2013 11:08
To run asynchronous process in python
os.system("nohup /usr/bin/python /home/path/billing.py arg1 arg2 arg3 > /dev/null & ")
@jineshpaloor
jineshpaloor / terminal.sh
Last active December 19, 2015 02:29
some useful random linux terminal commands
# to get the process details using pid
ps -p $PID -o pid,vsz=MEMORY -o user,group=GROUP -o comm,args=ARGS
$/proc/$PID/stat
# nohup - run a process even if we close the terminal. The below command will run
# the script(startbilling.py) with parameters ('20130601' '20130630'
# '/home/web/ecomm.prtouch.com/ecomexpress/static/uploads/billing/bill.xls')
# and write log to /home/jinesh/bill.log
$ nohup /usr/local/bin/python scripts/billscript/startbilling.py '20130601' '20130630' '/home/web/ecomm.prtouch.com/ecomexpress/static/uploads/billing/bill.xls' > /home/jinesh/bill.log &
@jineshpaloor
jineshpaloor / snippets
Created July 8, 2013 10:14
browser tricks
data:text/html, <html contenteditable>
data:text/html, <html contenteditable><style>body {color: #333; width: 960px; margin: 0 auto; display: block; height: 100%; font-size: 36px; padding: 20px;}</style></html>
data:text/html, <html><head><link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'><style type="text/css"> html { font-family: "Open Sans" } * { -webkit-transition: all linear 1s; }</style><script>window.onload=function(){var e=false;var t=0;setInterval(function(){if(!e){t=Math.round(Math.max(0,t-Math.max(t/3,1)))}var n=(255-t*2).toString(16);document.body.style.backgroundColor="#ff"+n+""+n},1e3);var n=null;document.onkeydown=function(){t=Math.min(128,t+2);e=true;clearTimeout(n);n=setTimeout(function(){e=false},1500)}}</script></head><body contenteditable style="font-size:2rem;line-height:1.4;max-width:60rem;margin:0 auto;padding:4rem;">
@jineshpaloor
jineshpaloor / date.py
Last active December 19, 2015 14:59
some experiments with date
>>> import datetime
>>> from django.utils.timezone import utc
>>> date_to = datetime.datetime(2013,05,07,tzinfo=utc)
>>> date_from = datetime.datetime(2013,05,05, tzinfo=utc)
>>> q = Q()
>>> q = q & Q(shipper=4)
>>> q = q & Q(inscan_date__gte=date_from, inscan_date__lte=date_to)
>>> sps = Shipment.objects.filter(q)