engine

Solve double minibufexplorer opened in VIM

31 Jan , 2012  

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 :

1
let g:miniBufExplorerMoreThanOne = 0

This will for miniBufExplorer into single window only. Another VIM configuration that may useful, taken from http://dotfiles.org/~joaoTrindade/.vimrc
More…

,

engine

Switch off ATI VGA in dual VGA with Intel on Ubuntu to solve overheat problem

30 Jan , 2012  

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 off ATI VGA will decrease heat problem in Ubuntu.

UPDATE: Try upgrade your BIOS. Several people have said they reduce heat by upgrading the BIOS.
http://h20000.www2.hp.com/bizsupport/TechSupport/SoftwareIndex.jsp?lang=en&cc=th&prodNameId=5086746&prodTypeId=321957&prodSeriesId=5086745&swLang=13&taskId=135&swEnvOID=4061#93211

First, check your dual VGA by :

1
lspci -vnnn | grep VGA

More…

,

Android

Build Android development in Ubuntu using Eclipse and Android SDK

30 Jan , 2012  

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 sure you have fast internet connection because we will download big files here.

This is steps How to build Android environment in Ubuntu using Eclipse and Android SDK.

1. Download and Install Android SDK
Android SDK contains API, Package Installation and Emulator. By Android wrapper in Eclipse, we can run and modify in Android SDK from Eclipse menu.

More…

,

system

Solve VIM NERDTree: 1 invalid bookmarks were read

30 Jan , 2012  

It’s little bit annoying if I see this error :

1
NERDTree: 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 :

1
rm -rf ~/.NERDTreeBookmarks

,

Server

How to Virtualbox Guest share wireless connection from host Ubuntu

30 Jan , 2012  

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 choose your wireless devices.
Then start your Virtual Machine and set cable connected on network icon.

,

Ubuntu

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

28 Jan , 2012  

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.

1
sudo apt-get install barry-util barrybackup-gui libbarry0

Then, you should plug your Blackberry via USB cable. Check if your Blackberry is detected by :
More…

,

engine

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

27 Jan , 2012  

Install VNC server in Ubuntu 11.10 Oneiric for remote-desktop is very easy. Here are the steps to install :

1
2
3
sudo apt-get install x11vnc
sudo x11vnc -storepasswd yourpasswordhere /etc/x11vnc.pass
sudo chmod 744 /etc/x11vnc.pass

Now you should edit your lightdm :

1
sudo vim /etc/lightdm/lightdm.conf
1
greeter-setup-script=/usr/bin/x11vnc -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes -noxdamage -rfbauth /etc/x11vnc.pass -forever -bg -rfbport 5900 -o /tmp/x11vnc.log

To run manually :

1
sudo x11vnc -rfbauth /etc/x11vnc.pass -o /var/log/x11vnc.log -forever -bg -rfbport 5900 -nomodtweak

or

1
sudo x11vnc -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes -noxdamage -rfbauth /etc/x11vnc.pass -forever -bg -rfbport 5900 -o /tmp/x11vnc.log

Happy remote desktop! 🙂

,

Django

How to filter distinct year or month queryset in Django models

25 Jan , 2012  

It simple to get distinct year / month using filter queryset in Django models. We can use dates. For instance:

Get unique year :

1
MyModel.objects.dates('created', 'year', order="DESC")

Get unique month :

1
MyModel.objects.dates('created', 'month', order="DESC")

Easy right ? 😀

,

Server

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

24 Jan , 2012  

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 :

1
2
3
4
5
6
7
8
9
10
11
12
13
/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:
 ssh depends on openssh-server; however:
  Package openssh-server is not configured yet.
dpkg: error processing ssh (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 openssh-server
 ssh
E: Sub-process /usr/bin/dpkg returned an error code (1)

More…

,

Python module

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

23 Jan , 2012  

Updated!
Thanks to @_palsu which give me the right way of proxy usage in urllib :

1
result = 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 :

1
Max retries exceeded for url: ....

After a few minutes debugging, I know the problem coming from invalid proxy usages. So, when I use requests module with proxy like this :
More…

,

Django

How to add class attribute in Forms modelform Django 1.3

23 Jan , 2012  

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 :

forms.py

1
2
3
4
from django import forms

class YahooParse(forms.Form):
    url = forms.URLField(widget=forms.TextInput(attrs={'class': 'xlarge'}))

This will generate form like this :

1
<input type="text" name="url" class="xlarge" id="id_url">

,

Django

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

23 Jan , 2012  

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 :

1
2
3
4
5
PROJECT
  |____APP
  |___ settings.py
  |___ static
  |___ templates

Now, we should configure static in “settings.py” :
More…

,

Django

How to install SVN into Aptana 3 Studio in Ubuntu Oneiric

20 Jan , 2012  

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

1
sudo apt-get install libsvn-java

More…

,

configuration

Aptana delete all my files because SVN failure

20 Jan , 2012  

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 have backup 1 day ago. If you curious why this happen, it because subversive plugin. So, I recommend you to use subeclipse for Eclipse or Aptana.

If you need the installation Guide, just follow this link :

How to install SVN in Aptana

,

engine

Solve Fabric No handlers could be found for logger “ssh.transport” Fatal error: No existing session

18 Jan , 2012  

After rebuild my ssh on Ubuntu Oneiric 11.10 Dekstop, suddenly my fabric give this error :

1
2
3
No handlers could be found for logger "ssh.transport"

Fatal error: No existing session

More…

,

Python module

How to sort dictionary by keys or by values in Python

17 Jan , 2012  

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 :

1
2
sort_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:

1
sorted(a.items())

by value:

1
sorted(a.items(), key=lambda x: x[1])

Want more detailed explanation? Open your python console.
First, we define a dictionary :
More…

,

Python module

Convert month name into number & month number to month name in Python

17 Jan , 2012  

Converting month by create dictionary of Month name is less efective. Here are how to convert month name into number in Pythonic way :

1
2
3
from time import strptime
month_name = 'Jan'
month_number = strptime(month_name, '%b').tm_mon

More…

,

Django

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

17 Jan , 2012  

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 :

1
2
3
4
5
6
7
8
9
TEMPLATE_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",
    "django.contrib.messages.context_processors.messages",
    "django.core.context_processors.request",
)

More…

,

Django

How to redirect page based on referer page in Django 1.3

17 Jan , 2012  

Sometimes you need to redirect into referered page (eg: delete action) in Django 1.3. To do that, it simply by :

1
2
3
from django.shortcuts import redirect

return redirect(request.META.get('HTTP_REFERER', None))

Straight-foward about redirecting by meta referer in Django 1.3!

,

Django

Always use Reverse while accessing URL in Unit Test or Views Django

17 Jan , 2012  

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. More…

,

Django

Create simple search page with custom pagination in Django 1.3

17 Jan , 2012  

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 do.

urls.py

1
url(r'^search/$', 'search', name='search'),

More…

,

Django

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

17 Jan , 2012  

So, you have field that contains insurer, agent name. For instance:

1
2
3
4
5
6
7
Insurer  | 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, disticnt doesn’t make unique result by field. If you want distinct by field, then you should use values and disticnt together. Eg :
More…

,

Django

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

17 Jan , 2012  

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

1
STATIC_THEME = '/static/theme'

More…

,

Django

Nested application inside apps sub-folder in Django 1.3

17 Jan , 2012  

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 :

1
2
3
4
5
PROJECT
  |_______ sub-folder
             |____ __init__.py
             |____ YOUR_APPLICATION_HERE_1
             |____ YOUR_APPLICATION_HERE_2

Remember, you must create “__init__.py” inside sub-folder which it will threat all python inside as one module packages. To achieve this, we can do in 2 ways. First, by editing your “manage.py” : More…

,

Django

How to create POST Form in Django 1.3 without CSRF problem

15 Jan , 2012  

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 Forgery, or when Django’s CSRF mechanism has not been used correctly. For POST forms, you need to ensure:

The view function uses RequestContext for the template, instead of Context.
In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.

You’re seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed.

You can customize this page using the CSRF_FAILURE_VIEW setting.

More…

,

Django

Have got name ‘Count’ is not defined when doing annotate query in Django?

13 Jan , 2012  

When you got “NameError: name ‘Count’ is not defined” when doing annotate query. Remember to import Count from django.db.models.

1
2
3
from django.db.models import Count

q = Insurance.objects.annotate(Count('created'))

Somehow it’s missing in the Django documentation 🙂

,

Django

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

13 Jan , 2012  

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 several data-loss scenarios, including rolled-back transactions and fields on different models referencing the same file. In Django 1.3, when a model is deleted the FileField’s delete() method won’t be called. If you need cleanup of orphaned files, you’ll need to handle it yourself (for instance, with a custom management command that can be run manually or scheduled to run periodically via e.g. cron).

More…

,

Django

Example how to use django-pagination in Django 1.3

11 Jan , 2012  

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from django.shortcuts import render_to_response
from django.core.paginator import Paginator, InvalidPage, EmptyPage

def index(request):
    plan = Plan.objects.all()
    paginator = Paginator(plan, 5)
   
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1
   
    try:
        fp = paginator.page(page)
    except (EmptyPage, InvalidPage):
        fp = paginator.page(paginator.num_pages)

    return render_to_response('myapp/index.html', {'mydata': fp})

More…

,

Django

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

11 Jan , 2012  

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:

1
2
3
4
http://localhost:8000/search/
http://localhost:8000/search/?q=<query -HERE>
http://localhost:8000/search/?q=Hello&page=2
</query>

More…

,