-
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
-
Switch off ATI VGA in dual VGA with Intel on Ubuntu to solve overheat problem
I have AMD Radeon HD 6470M which sometimes it make my laptop overheat until 90 C. Usually, it’s run on 70 C. This is because ATI Radeon run together with Intel VGA. By switch off VGA AMD Radeon, it decrease overheat from 70 C into 58 C. And my laptop not overheat anymore. Basically, turn […]
-
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 […]
-
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 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 […]
-
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 ? 😀
-
Manage auto login Ubuntu 2D or 3D user account in Ubuntu Oneiric
To manage user login in Ubuntu Oneiric 11.10 and choose what default Ubuntu desktop, first we go to “System Settings -> Account” and enable auto-login. Then, we can pick what default session for auto-login by editing “/etc/lightdm/lightdm.conf” : 1234[SeatDefaults] greeter-session=unity-greeter user-session=ubuntu-2d autologin-user=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: […]
-
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 […]
-
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 : […]
-
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
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
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 […]
-
Solve Fabric No handlers could be found for logger “ssh.transport” Fatal error: No existing session
After rebuild my ssh on Ubuntu Oneiric 11.10 Dekstop, suddenly my fabric give this error : 123No handlers could be found for logger "ssh.transport" Fatal error: No existing session
-
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(), […]
-
Convert month name into number & month number to month name in Python
Converting month by create dictionary of Month name is less efective. Here are how to convert month name into number in Pythonic way : 123from time import strptime month_name = ‘Jan’ month_number = strptime(month_name, ‘%b’).tm_mon
-
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!
-
Always use Reverse while accessing URL in Unit Test or Views Django
This note for me, that always use Reverse URL while accesing URL, make action or build URL. Using reverse will reduce your risk while developing Django applications. In this example, I will show how to use reverse url in Unit Testing with Client browser.
-
Create simple search page with custom pagination in Django 1.3
I will guide you to create simple search using Django 1.3 queryset and with pagination. Because lack of documentation, I hope this will help you figure out how to create search engine in Django 1.3. I will create search page with GET method. So, you should see your query parameters in URL. Here are to […]
-
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, […]
-
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
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 […]
-
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 […]
-
Have got name ‘Count’ is not defined when doing annotate query in Django?
When you got “NameError: name ‘Count’ is not defined” when doing annotate query. Remember to import Count from django.db.models. 123from django.db.models import Count q = Insurance.objects.annotate(Count(‘created’)) Somehow it’s missing in the Django documentation 🙂
-
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 […]
-
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 […]
-
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: 123http://localhost:8000/search/ http://localhost:8000/search/?q=<QUERY-HERE> http://localhost:8000/search/?q=Hello&page=2