Archive

Archive for April, 2012

Setup Django

April 25, 2012 Leave a comment

OK, here’s the simplest way/setting for Django. I am using mac, but it should be similar for other linux.

First. Installing an official release.

  1. Download the latest release from download page.
  2. Untar the downloaded file (e.g. tar xzvf Django-X.Y.tar.gz, where X.Y is the version number of the latest release).
  3. Change into the directory created in step 2 (e.g. cd Django-X.Y).
  4. If you’re using Linux, Mac OS X or some other flavor of Unix, enter the command sudo python setup.py install at the shell prompt.

After install it, run python in the command line, and check:

import django
print django.get_version()

Second,  is to Configure your database and create your first app.

From the command line, cd into a directory where you’d like to store your code, then run the following command:

django-admin.py startproject mysite
Since you install it through command line, ‘django-admin.py’ should be in your system path. If you can not find it, try to find it in site-packages/django/bin, where site-packages is a directory within your Python installation. Consider symlinking to django-admin.py from some place on your path, such as /usr/local/bin.
The above command will create your first site like this:
mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

Now run the server by doing:

python manage.py runserver.

You will see somthing like this in your terminal:

Validating models...
0 errors found.Django version 1.4, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
 goto http://127.0.0.1:8000/,  cool, it works.  Please also note that MAC actually comes with a embedded Apache Server, you may like to check in details here.
Now you needs to configure you database. Edit mysite/settings.py. To make it as simple as possible, use sqlite3 ( it goes with python, so you don’t have to install additional packages) Change the ENGINE from ‘django.db.backends.‘ to ‘django.db.backends.sqlite3‘.
OK, you are now ready for creating your own models 🙂
Categories: Python, Web Tags: ,

Opencv Test on Xcode

April 19, 2012 1 comment

I pre-installed opencv (2.3.1) for python binding, but haven’t tried it out in Xcode. Here’s what I found that works on my Mac. I am using Xcode4.3, Mac Lion 10.7.3.

Just to clarify, I almost followed this link, which turns out working well for the example code.

– Make a new project and choose “Command Line Tool”, choose C++ as the type for the project. Xcode will automatically generate a main.cpp for you.

– Go to project setting, select all, among which search the “Header search path”, and add “/opt/local/include”

– Create a folder for your ‘framework’ on the left panel,  let’s say, name it as “opencv-Frameworks”, and right click it use “Add files to..”. You will going to add three files which are located at </opt/local/lib>. They are: libopencv_ml.2.3.1.dylib, libopencv_highgui.2.3.1.dylib, libopencv_core.2.3.1.dylib

– You don’t have to copy those items, but just an option 🙂

– Now, copy the demo code in the above link to your main.cpp, click build+run, you should see a pop up window like this:

– You can find a completed working project here.

Categories: MacOS, OpenCV Tags: ,

Make Rating Bar in Objective-C

April 19, 2012 Leave a comment
Instead of calling Google API to get the status shown on the meterbar, like this:
You can also use the NSLevelIndicator Class
Here’s several links:
Here’s an example creating start-rating:

I also find an overstack answer for the fancy bar that I have been looking for for a long time:
http://stackoverflow.com/questions/2015343/how-to-style-a-fancy-vertical-progressbar-correctly

Categories: Objective-C

An objc image processing package

April 17, 2012 Leave a comment

Here’s one that objective-C based image processing package.

Site for favicon.ico

April 17, 2012 Leave a comment

This is where you can make your ico file : http://www.favicon.cc/

Ico file is the icon that displays in the address bar of your web browser when you connect to a website.

Categories: Web

Fix Matplotlib MPLCONFIGDIR error

April 17, 2012 Leave a comment

When using Apache + python-cgi, I encounter this error:

<type ‘exceptions.RuntimeError’>: Failed to create /$dirstring$/common/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data 

An official explanation of MPLCONFIGDIR is here.

MPLCONFIGDIR This is the directory used to store user customizations to matplotlib, as well as some caches to improve performance. If MPLCONFIGDIR is not defined, HOME/.matplotlib is used by default.

It turns out that on my windows machine HOME/.matplotlib is now writable. Here’s a way to simply bypass this problem.

Find out the place where you first import matplotlib, right before it, set the $HOME dir to a temporary dir where it’s writable:

For example, I was importing matplotlib in an indirect way through “from scipy.cluster.vq import kmeans2“, so right before it, do

os.environ[‘HOME’] = r’C:\……\Apache2.2\htdocs\tmp’

from scipy.cluster.vq import kmeans2

Using Google Chart in Objective-C

April 14, 2012 1 comment

Google chart is a very nice tool where you can generate some very nice figures for your data. By calling their API, you could simply embed it into your web page or download the image for whatever you use. At their website, google includes some most commonly used ones, but some are missing such as meter bar. You could probably find others that fit your goal by just ‘googling’ 🙂

Here’s a code snip for how to use it in Objective-C. I use chf=bg,s,65432100 to make it a clear/transparent background.


- (UIImage *) getGoogleChartImage {

NSString* url=@"http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World&chf=bg,s,65432100";
NSString *myurl=[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:myurl] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

NSURLResponse* response;
NSError* error;
NSData *googleImageData=[NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];

NSLog(@"%@",error);
NSLog(@"%@",response);
NSLog(@"%@",googleImageData);

UIImage *googleImage = [[UIImage alloc] initWithData:googleImageData];
NSLog(@"Retrived Google Image Width: %f", googleImage.size.width);

return googleImage;
}