Month: January 2012

Solve double minibufexplorer opened in VIM

Solve double minibufexplorer opened in VIM

When using Minibufexplorer in VIM, I usually use Fuzzfinder for opening files. But, somehow, I see double minibufexplorer window every open more than 2 files. To solve this issue : 1let g:miniBufExplorerMoreThanOne = 0 This will for miniBufExplorer into single window only. Another VIM configuration that may useful, taken from http://dotfiles.org/~joaoTrindade/.vimrc

Build Android development in Ubuntu using Eclipse and Android SDK

Build Android development in Ubuntu using Eclipse and Android SDK

This is my first-time learning Android. I usually use Ubuntu for development which I use Ubuntu Oneiric 11.10 while write this articles. I have Python and PHP based before, so, migrate into Android will be wild and fun! So, to start develop Android in Ubuntu, I use Eclipse. Before you start read more, please make …

+ Read More

Solve VIM NERDTree: 1 invalid bookmarks were read

Solve VIM NERDTree: 1 invalid bookmarks were read

It’s little bit annoying if I see this error : 1NERDTree: 1 invalid bookmarks were read This is because NERDTreeBookmarks still keep the cache even bookmarks already deleted from VIM. To delete NerdTree cached in VIM is by : 1rm -rf ~/.NERDTreeBookmarks

How to Virtualbox Guest share wireless connection from host Ubuntu

How to Virtualbox Guest share wireless connection from host Ubuntu

I usually use LAN cable and share internet connection using NAT to Virtualbox client. But, I need to connect using Wireless int my Host and found NAT can’t works through this connection. So, share internet connection from wireless to Virtualbox guest, we should use “bridge-network”. Go Virtualbox Client Settings -> Network -> Bridge network and …

+ Read More

Blackberry as USB Modem connect into internet wvdial on Ubuntu with Barry

Blackberry as USB Modem connect into internet wvdial on Ubuntu with Barry

I have Blackberry Bold 9800 and Ubuntu 11.10 Oneiric. Also, I have two of indonesian internet cards called “Telkomselflash” and “Indosat Broadband”. Now, I will introduce you how to make Blackberry Bold as USB Modem and connect into internet using Barry and PPPD. First, you should install “Barry” packages in Ubuntu via apt-get or synaptic. …

+ Read More

How to setup VNC server for remote desktop in Ubuntu 11.10 Oneiric

How to setup VNC server for remote desktop in Ubuntu 11.10 Oneiric

Install VNC server in Ubuntu 11.10 Oneiric for remote-desktop is very easy. Here are the steps to install : 123sudo apt-get install x11vnc sudo x11vnc -storepasswd yourpasswordhere /etc/x11vnc.pass sudo chmod 744 /etc/x11vnc.pass Now you should edit your lightdm : 1sudo vim /etc/lightdm/lightdm.conf 1greeter-setup-script=/usr/bin/x11vnc -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes -noxdamage -rfbauth /etc/x11vnc.pass -forever -bg -rfbport 5900 -o …

+ Read More

How to filter distinct year or month queryset in Django models

How to filter distinct year or month queryset in Django models

It simple to get distinct year / month using filter queryset in Django models. We can use dates. For instance: Get unique year : 1MyModel.objects.dates(‘created’, ‘year’, order="DESC") Get unique month : 1MyModel.objects.dates(‘created’, ‘month’, order="DESC") Easy right ? 😀

Solve cannot create /etc/ssh/sshd_config: Directory nonexistent deleted ssh folder Ubuntu

Solve cannot create /etc/ssh/sshd_config: Directory nonexistent deleted ssh folder Ubuntu

Today I made mistake by deleting “/etc/ssh” folder manually. Then when I try to re-install openssh-server in Ubuntu Oneiric, it gave me several errors like this : 12345678910111213/var/lib/dpkg/info/openssh-server.postinst: 456: cannot create /etc/ssh/sshd_config: Directory nonexistent dpkg: error processing openssh-server (–configure):  subprocess installed post-installation script returned error exit status 2 dpkg: dependency problems prevent configuration of ssh: …

+ Read More

Max retries exceeded for url: in Requests Module Python Solved!

Max retries exceeded for url: in Requests Module Python Solved!

Updated! Thanks to @_palsu which give me the right way of proxy usage in urllib : 1result = requests.get(url, proxies={‘http’: ‘http://33.33.33.11:8118’}) Requests module help me much in creating crawlers. But somehow it throw me an error : 1Max retries exceeded for url: …. After a few minutes debugging, I know the problem coming from invalid …

+ Read More

How to add class attribute in Forms modelform Django 1.3

How to add class attribute in Forms modelform Django 1.3

Usually we use forms.py and create class Form to generate form and pass it into views.py. As usual, we need to customize form in ModelForm for instance, we need to add class attribute. So, we can use Widget to solve this problem. Here are how to customize and add class attribute into form Django : …

+ Read More

How to setup static folder files in Django 1.3 for development server

How to setup static folder files in Django 1.3 for development server

We can create centralized static folder in PROJECT path and accessed it as “/static/” using development server. To achieve this, you should create “static” folder inside PROJECT folder (not APP folder). Eg : 12345PROJECT   |____APP   |___ settings.py   |___ static   |___ templates Now, we should configure static in “settings.py” :

How to install SVN into Aptana 3 Studio in Ubuntu Oneiric

How to install SVN into Aptana 3 Studio in Ubuntu Oneiric

There are lack documentation how to install Subeclipse in Aptana Studio 3. Also, I recommend you choose subeclipse than subversive because I have bad experience with subversive in Aptana before. So, here are steps you need to make SVN in Aptana : 1. Install lib-svn Java in Ubuntu 1sudo apt-get install libsvn-java

Aptana delete all my files because SVN failure

Aptana delete all my files because SVN failure

I use Aptana Studio 3 and Subversive as SVN connector. After checkout some SVN repository, I got that it was failed process. There no confirmation or something alert, but suddenly all my files in the pointed folder was deleted. Yes, it entirely deleted and not in Trash. I just luck have a Gitosis repository which …

+ Read More

How to sort dictionary by keys or by values in Python

How to sort dictionary by keys or by values in Python

Usually dictionary have sorted by keys. But sometimes it got messy un-sorted dictionary because using dict.update() or while adding new dict. You can sort it by keys using : 12sort_dict = [x for x in messy_dict.iteritems()] sort_dict.sort(key=lambda x: x[0]) # sort by key Neat Way by Mr. Kholid : by key: 1sorted(a.items()) by value: 1sorted(a.items(), …

+ Read More

How to set flash message in Django 1.3 and show into another page

How to set flash message in Django 1.3 and show into another page

Set flash message like notification, error or something information and show into another page is quite easy in Django 1.3. If you don’t use render() or RequestContenxt, then you should enable message Middleware in settings.py : 123456789TEMPLATE_CONTEXT_PROCESSORS = (     "django.contrib.auth.context_processors.auth",     "django.core.context_processors.debug",     "django.core.context_processors.i18n",     "django.core.context_processors.media",     "django.core.context_processors.static",   …

+ Read More

How to redirect page based on referer page in Django 1.3

How to redirect page based on referer page in Django 1.3

Sometimes you need to redirect into referered page (eg: delete action) in Django 1.3. To do that, it simply by : 123from django.shortcuts import redirect return redirect(request.META.get(‘HTTP_REFERER’, None)) Straight-foward about redirecting by meta referer in Django 1.3!

How to filter objects and get unique data by field using distinct in Django 1.3

How to filter objects and get unique data by field using distinct in Django 1.3

So, you have field that contains insurer, agent name. For instance: 1234567Insurer  | Agent ======== | ===== Tommy    | AXA Joko     | CommonWealth Falcon   | CommonWealth Sumito   | Wilis Tarno    | AXA You want to search unique agent in the database. Then you can use values and distinct. Remember, …

+ Read More

How to pass constant custom variable in settings.py into templates and views Django 1.3

How to pass constant custom variable in settings.py into templates and views Django 1.3

We may create custom constant variable in settings.py, eg : MEDIA_URL, STATIC_THEME, THEME_URL, etc. Then, we need to access this settings.py varible from Views and templates. Then here are what should we do : Accessing custom variable in settings.py from views We should import settings and use getattr(). For instance : settings.py 1STATIC_THEME = ‘/static/theme’

Nested application inside apps sub-folder in Django 1.3

Nested application inside apps sub-folder in Django 1.3

Sometimes we need to nesting applications using sub-folder inside apps of Django. To be able run application in Django using sub-folder, then we can approach this with two ways. For instance, you projects have sub-folder apps like this : 12345PROJECT   |_______ sub-folder              |____ __init__.py         …

+ Read More

How to create POST Form in Django 1.3 without CSRF problem

How to create POST Form in Django 1.3 without CSRF problem

Creating form with POST, doing validation and process the input is easy in Django 1.3. But, seems a lot of people facing this CSRF problem : Forbidden (403) CSRF verification failed. Request aborted. Reason given for failure: CSRF token missing or incorrect. In general, this can occur when there is a genuine Cross Site Request …

+ Read More

Automatically delete file in filefield Django 1.3 when object / record deleted

Automatically delete file in filefield Django 1.3 when object / record deleted

Deleting a model records in Django 1.3 doesn’t followed with delete associated files in FileField. As explained on Django 1.3 CHANGELOG releases : In earlier Django versions, when a model instance containing a FileField was deleted, FileField took it upon itself to also delete the file from the backend storage. This opened the door to …

+ Read More

Example how to use django-pagination in Django 1.3

Example how to use django-pagination in Django 1.3

Django-pagination is great module which ease for creating pagination pages. Usually, we make query to get data from database. Then on templates, we iterating the variable that contains data. Because large of data, we want it get paginate. Using default Django pagination will take several codes, eg : views.py: 123456789101112131415161718from django.shortcuts import render_to_response from django.core.paginator …

+ Read More

How to modify page and custom get variable parameters in Django 1.3 pagination

How to modify page and custom get variable parameters in Django 1.3 pagination

Sometimes in Django pagination, we want to adding custom variable in pagination URL. For instance, we want to build search page which need to paginate the results. In URL, it should be have “/search/?q=QUERY/” and “/search/QUERY&page=PAGE_NUMBER”. Eg: 1234http://localhost:8000/search/ http://localhost:8000/search/?q=<query -HERE> http://localhost:8000/search/?q=Hello&page=2 </query>