Warning: file_get_contents(http://www.prelovac.com/deploy.csv) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /accounts/giovannidimilia/www/dimilia.it/wp-content/plugins/wp-quick-deploy/wp-quick-deploy.class.php on line 437
Archive Coding | Giovanni Di Milia
Jan 28 2014

Pain with Bottle.py app and PyDev debugger

Giovanni

Since it took quite a bit of time for me to figure out the solution to this problem, I decided to write a quick reminder here.

I was working on a web application written in Bottle.py and everything was going smoothly until I decided to debug a function using the PyDev debugger in Eclipse.

Long story short there was no way to make the debugger work even if the same debugger was working perfectly fine in the unit tests.

After several tests I was able to understand that the PyDev debugger is incompatible with the option “reloader=True” of the bottle app.

So you can run your app in this way:

application.run(host=your_host, port=your_port, debug=True, reloader=True)

and it is wonderful because the app will reload by itself every time you change a python file,

but if you want to run the code in the PyDev debugger you need to start your app in this way:

application.run(host=your_host, port=your_port, debug=True)


Aug 3 2012

virtualenv and .bash_profile

Giovanni

Just a reminder… mostly for myself: 
the aliases set in .bash_profile are considered ALWAYS first, even if you are in a python virtualenv environment.

This means that if you have (like I do) an alias to a particular instance of ipython with the name “ipython” and in virtualenv you install ipython as well, if you simply type “ipython” the first (with all its libraries) will always be called!

 


Apr 3 2012

OS X Lion and MacPorts: how I made it work

Giovanni

Recently I received my new MacBook Air 13″ (sadly my old MacBook Aluminium is almost dead) and among all the problems I have with Lion probably the one I have with MacPorts is the most frustrating!

Someone can object with “why don’t you use Homebrew? It’s much better than Port because BLAH BLAH BLAH BLAH BLAH”, but I don’t care: I want Port working, not something else!

So after some searches around I found something that “magically” fixed everything.

The problem seems to be related to a missing setting after the installation of the Xcode. In particular the installation of the Xcode from the App Store (besides not installing by default the “Command line tools”) doesn’t set the “xcode_folder_path”.

To check if everything works it’s enough to run:

/usr/bin/xcodebuild -version

This gave me back:

xcode-select: Error: No Xcode folder is set. Run xcode-select -switch to set the path to the Xcode folder. Error: /usr/bin/xcode-select returned unexpected error.

Well, now the solution is clear! It’s enough to set the xcode_folder_path!

So I run:

sudo /usr/bin/xcode-select -switch /Applications/Xcode.app/Contents/Developer

where

/Applications/Xcode.app

is the path of the Xcode application installed through the App Store.

Now if you run again:

/usr/bin/xcodebuild -version

you will have

/usr/bin/xcodebuild -version Xcode 4.3.2 Build version 4E2002

All the Ports now should work! Well…. for me now they work!


Sep 2 2011

Python Code to validate ISBNs

Giovanni

I wrote this simple piece of code to validate ISBN strings and I publish it because I hope it can be useful for someone else.

 Python |  Copy the following code |? 
01
# Copyright (C) 2011, Giovanni Di Milia
02
#
03
# This program is free software: you can redistribute it and/or modify
04
# it under the terms of the GNU General Public License as published by
05
# the Free Software Foundation, either version 3 of the License, or
06
# (at your option) any later version.
07
# 
08
# This program is distributed in the hope that it will be useful,
09
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
# 
13
# You should have received a copy of the GNU General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
def is_valid_isbn(isbn):
17
    """ 
18
        Function that validates ISBNs
19
        Based on 
20
        http://en.wikipedia.org/wiki/International_Standard_Book_Number
21
        @author: Giovanni Di Milia
22
    """
23
 
24
    #I remove the valid hyphens in the code if they exist
25
    isbn = isbn.replace('-', '')
26
 
27
    #Validation of ISBN 10
28
    if len(isbn) == 10:
29
        try:
30
            checksum = str(11 - ((int(isbn[0])*10 + int(isbn[1])*9 +\
31
                                 int(isbn[2])*8 + int(isbn[3])*7 + \
32
                                 int(isbn[4])*6 + int(isbn[5])*5 +\
33
                                int(isbn[6])*4 + int(isbn[7])*3 +\
34
                                 int(isbn[8])*2) % 11))
35
        except ValueError:
36
            #if I fails it means that there are letters, so the ISBN is not valid
37
            return False
38
 
39
        if checksum == '11':
40
            checksum = '0'
41
        elif checksum == '10':
42
            checksum = 'X'
43
        if checksum == isbn[9]:
44
            return True
45
        else:
46
            return False
47
    #Validation of ISBN 13
48
    elif len(isbn) == 13:
49
        try:
50
            checksum = str(10 - ((int(isbn[0]) + int(isbn[1])*3 + \
51
                                  int(isbn[2]) + int(isbn[3])*3 +\
52
                                   int(isbn[4]) + int(isbn[5])*3 +\
53
                                    int(isbn[6]) + int(isbn[7])*3  +\
54
                                    int(isbn[8]) + int(isbn[9])*3 + \
55
                                    int(isbn[10]) + int(isbn[11])*3) % 10))
56
        except ValueError:
57
            #if I fails it means that there are letters, so the ISBN is not valid
58
            return False
59
 
60
        if checksum == '10':
61
            checksum = '0'
62
        if checksum == isbn[12]:
63
            return True
64
        else:
65
            return False
66
    else:
67
        return False
68