Thursday, May 29, 2014

Download youtube videos without any plugin or application

This is very simple technique to download the youtube videos without any software support or plugin in browser.

step 1: copy the url of video.
ex: https://www.youtube.com/watch?v=ulE2CbvCCG0
step 2: Omit the part 'https://www.' from url and  add 'ss' instead of it in url.
ie, ssyoutube.com/watch?v=ulE2CbvCCG0
step 3: Reload the browser.

0 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

Friday, May 23, 2014

Barcode in RML Reports

Barcode in rml report:
<barCode code="code128" quiet="9" fontName="Times-Roman" barWidth="2.00" fontSize="350" alignment="CENTER">[[ o.reg_no ]]</barCode>

0 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

Wednesday, May 21, 2014

Install VirtualBox in Ubuntu

To install virtualbox in ubuntu:
sudo apt-get install virtualbox-ose

0 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

Install nautilus-open-terminal in Ubuntu

To get 'Open in Terminal' in right button option in Ubuntu, need to install nautilus-open-terminal.

command:
sudo apt-get install nautilus-open-terminal

0 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

Tuesday, May 20, 2014

Generate random numbers in Python

Python random module helps to generate random numbers.
We can generate this in three ways
  • randint(a, b)
  • uniform(a, b)
  • random()
randint(a, b) : returns a random integer number in the range [a, b]
uniform(a, b) : returns a floating point number in the range [a, b]
random() : returns a floating point number in the range [0, 1]

>>> import random
>>> a = random.randint(1,99)
>>> a
77
>>> b = random.uniform(1,999)
>>> b
766.6455229055509
>>> c = random.random()
>>> c
0.6372421095384033
>>>

0 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

Convert PDF to JPEG Python

Convert pdf file to image file using 'PythonMagick' in Python. PythonMagick provides object oriented bindings for the ImageMagick Library. You can dowload PythonMagick

Ex:
>>> import PythonMagick
>>> pdf = 'Invoices.pdf'
>>> p = PythonMagick.Image()
>>> p.density('600')
>>> p.read(pdf)
>>> p.write('test_image.jpg')
>>>

5 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

Date in Python and its Conversion

Current date in Python using 'time' module

>>> import time
>>> time.strftime("format")
Ex:
>>> import time
>>> time.strftime("%d-%m-%Y")
'20-05-2014'
>>> time.strftime("%d-%m-%Y %H:%M:%S")
'20-05-2014 12:17:51'
Current date in Python using 'datetime' module

>>> import datetime
>>> now = datetime.datetime.now()
>>> now
datetime.datetime(2014, 5, 20, 12, 19, 16, 547221)
>>> now.year
2014
>>> now.month
5
>>> now.day
20
>>> now.hour
12
>>> now.minute
19
>>> now.second
16
>>> now.microsecond
547221
>>>
Change date format using time module

syntax:
time.strftime('required format', time.strptime('date data', 'source format'))
Ex:
>>> import time
>>> d1 = time.strftime('%d-%m-%Y', time.strptime('2014-05-10', '%Y-%m-%d'))
>>> d1
'10-05-2014'
>>>
Convert date to datetime using datetime module

Ex:
>>> from datetime import datetime
>>> d1 = datetime.strftime(datetime.strptime('2014-05-10', '%Y-%m-%d'), "%Y-%m-%d 00:00:00")
>>> d1
'2014-05-10 00:00:00'
>>> d2 = datetime.strftime(datetime.strptime('2014-05-10', '%Y-%m-%d'), "%Y-%m-%d 23:59:59")
>>> d2
'2014-05-10 23:59:59'
>>> d1, d2
('2014-05-10 00:00:00', '2014-05-10 23:59:59')
>>>

0 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

Monday, May 19, 2014

Generate random password in Python

To generate random password in Python

import string
import random
from random import sample

def create_password(self):
        """
        create a random password
        """
        rand = string.ascii_letters + string.digits
        length = 8
        passwd = ''.join(sample(rand, length))
        return passwd

Ex:
>>> import string
>>> import random
>>> from random import sample
>>> rand = string.ascii_letters + string.digits
>>> length = 8
>>> passwd = ''.join(sample(rand, length))
>>> passwd
'8fK6ZR0q'
>>>

0 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

Add spaces between lines in RML reports OpenERP

In OpenERP, the rml repots generates will omit the white spaces between lines. So in order to maintain the white spaces between lines needs to modify the base code in openerp report module or modify the rml syntax.

Solution 1:

=== modified file 'openerp/report/render/rml2pdf/trml2pdf.py'
--- openerp/report/render/rml2pdf/trml2pdf.py    2012-07-16 07:52:17 +0000
+++ openerp/report/render/rml2pdf/trml2pdf.py    2012-07-19 10:16:33 +0000
@@ -743,6 +743,8 @@
                 style.__dict__.update(extra_style)
             result = []
             for i in self._textual(node).split('\n'):
+                if len(i.strip()) == 0:
+                    i = '<font color="white"> </font>'
                 result.append(platypus.Paragraph(i, style, **(utils.attr_get(node, [], {'bulletText':'str'}))))
             return result
         elif node.tag=='barCode':

Solution 2:

Replace <para></para> with <xpre></xpre> in rml file.

ex:
<xpre style="terp_default_9">[[ format(o.note or '') ]]</xpre>

0 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

Number of days between two dates/ date differences in Python

To find the number of days between two given dates or to find the difference between two dates in Python. This function generally needs in many case in most of the program.

from datetime import datetime

def days_between(d1, d2):
    d1 = datetime.strptime(d1, "%Y-%m-%d")
    d2 = datetime.strptime(d2, "%Y-%m-%d")
    return abs((d2 - d1).days)

Example:

>>> from datetime import datetime
>>> d1 = '2014-05-10'
>>> d2 = '2014-05-05'
>>> d1 = datetime.strptime(d1, "%Y-%m-%d")
>>> d2 = datetime.strptime(d2, "%Y-%m-%d")
>>> no_of_days = abs((d2 - d1).days)
>>> no_of_days

0 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

Remove duplicates from a list in Python

The python built in function 'set()' helps to remove the duplicates from a list.

consider an example:
>>> list1 = [1, 2, 3, 1, 2, 5, 6, 7, 8]
>>> list1
[1, 2, 3, 1, 2, 5, 6, 7, 8]
>>> set(list1)
set([1, 2, 3, 5, 6, 7, 8])
>>> list(set(list1))
[1, 2, 3, 5, 6, 7, 8]
>>>

0 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

Page Number in RML Report

To show the page number in rml report:

<drawString x="4.5cm" y="27.35cm"><pageCount/></drawString>

To show the page number in such a format 'page 1 of 3' :
<drawString x="9.5cm" y="0.2cm"> Page: <pageNumber/> of </drawString>
<drawString x="10.6cm" y="0.2cm"><pageCount/></drawString>

1 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

 
Twitter Facebook RSS YouTube Google
© 2014 | Distributed and Designed By Jasad Moozhiyan