For example, if you can't get man pages for pthread_create,
(Some blogs recommend you to install glibc-doc, but it wouldn't work.)
just do 'sudo apt-get install manpages-posix-dev'
Wednesday, October 21, 2009
Tuesday, August 18, 2009
Using autocomplete plugin of jQuery with django
1. Download jQuery auto complete plugin here.
2. Unzip it.
3. Copy below files from the unzipped onto your javascript directory.
5. If you want to activate auto complete onto the html tag with id 'qwerty', add following code onto your js code area.
$(document).ready(function(){
$("#qwerty").autocomplete{
'/ajax/autocomplete',
{multiple: true, multipleSeparator: ', '}
);
});
6. Setup urls.py so that it can handle '/ajax/autocomplete' with ajax_autocomplete module.
7. in views.py, make ajax_autocomplete module like,
def ajax_autocomplete(request):
if request.GET.has_key('q'):
# Write your code here (search dictionary or db, etc..)
# And put it onto res (separated with '\n').
return HttpResponse(res)
return HttpResponse()
8. Done. Have fun :)
2. Unzip it.
3. Copy below files from the unzipped onto your javascript directory.
- jquery.autocomplete.css
- jquery.autocomplete.js
- jquery.bgiframes.min.js
- jquery.dimensions.js (from jquery.com)
5. If you want to activate auto complete onto the html tag with id 'qwerty', add following code onto your js code area.
$(document).ready(function(){
$("#qwerty").autocomplete{
'/ajax/autocomplete',
{multiple: true, multipleSeparator: ', '}
);
});
6. Setup urls.py so that it can handle '/ajax/autocomplete' with ajax_autocomplete module.
7. in views.py, make ajax_autocomplete module like,
def ajax_autocomplete(request):
if request.GET.has_key('q'):
# Write your code here (search dictionary or db, etc..)
# And put it onto res (separated with '\n').
return HttpResponse(res)
return HttpResponse()
8. Done. Have fun :)
Tuesday, August 4, 2009
MSN proxy with ssh using Pidgin
If your company blocked MSN port and you have accessable server out of your company, use it as a proxy with ssh -D option.
Set tunnel with '>ssh -D 1234 yourserveraddress.com'.
(You can use any port number instead of 1234.)
Set proxy option in your pidgin.
Host : localhost
Port : 1234
That's all. Have fun.
Set tunnel with '>ssh -D 1234 yourserveraddress.com'.
(You can use any port number instead of 1234.)
Set proxy option in your pidgin.
Host : localhost
Port : 1234
That's all. Have fun.
Monday, August 3, 2009
Using django - Accounts
Django auth system is in django.contrib.auth.
(Included in INSTALLED_APPS as a default)
Login page
You can use default django login handler.
<urls.py>
urlpatterns = patterns('',
...
(r'^login/$', 'django.contrib.auth.views.login')
<eof>
You need to make a template for login page.
<templates/registration/login.html>
<form methos='post' action='.'>
<label for='id_username'>Username : </label>
{{ form.username }}
<br>
<label for='id_password'>Password : </label>
{{ form.password }}
<br>
<input type='hidden' name='next' value='/'/>
<input type='submit' value='Login'/>
</form>
<eof>
User objects methods
Logout
<views.py>
from django.http import HttpResponseRedirect
from django.contrib.auth import logout
def logout_page(request):
logout(request)
return HttpResponseRedirect('/')
<eof>
<urls.py>
...
(r'^logout/$', logout_page),
...
<eof>
(Included in INSTALLED_APPS as a default)
Login page
You can use default django login handler.
<urls.py>
urlpatterns = patterns('',
...
(r'^login/$', 'django.contrib.auth.views.login')
<eof>
You need to make a template for login page.
<templates/registration/login.html>
<form methos='post' action='.'>
<label for='id_username'>Username : </label>
{{ form.username }}
<br>
<label for='id_password'>Password : </label>
{{ form.password }}
<br>
<input type='hidden' name='next' value='/'/>
<input type='submit' value='Login'/>
</form>
<eof>
User objects methods
- is_authenticated()
- get_full_name()
- email_user(subject, message, from_email=None)
- set_password(raw_password)
- check_password(raw_password)
Logout
<views.py>
from django.http import HttpResponseRedirect
from django.contrib.auth import logout
def logout_page(request):
logout(request)
return HttpResponseRedirect('/')
<eof>
<urls.py>
...
(r'^logout/$', logout_page),
...
<eof>
Friday, July 10, 2009
Using django - database
Django seldom uses SQL. It uses python class to access DB.
Pros. You can apply one code to various types of DB.
In django database,
- Data type is equal to table.
- Class member is like a table field.
Designing data model
Create data type(table) in ur sampleapp/models.py
<models.py>
from django.db import models
class SampleTable(models.Model):
fieldA = models.IntegerField(unique=True)
<eof>
Like IntegerField, there are also pre-defined field.
- TextField, DateTimefield, EmailField, URLField, FileField
Creating data type
Check if you activated your application in settings.py.
<settings.py>
INSTALLED_APPS = (
...
'sampleproject.sampleapp',
)
<eof>
Do DB sync
> ./manage.py syncdb
You can see which SQL were generated with,
> ./manage.py sql sampleapp
Note that it generate 'id' field automatically when it makes table.
Using DB Shell
Like we use database console to execute SQLs in terminal,
django also has shell.
> ./manage.py shell
>>> from sampleapp.models import *
>>> record = SampleTable(fieldA=123)
>>> record.fieldA
123
>>> record.save()
>>> records = SampleTable.objects.all()
>>> firstRecord = SampleTable.objects.get(id=1)
>>> record.delete()
Like above, you can create a record, save it into DB, get all records or single one, access by id and delete it.
Note that until you save(), it just remain only in memory.
User data model
'User' data model is already built in.
>>> from django.contrib.auth.models import User
>>> User.objects.all()
User has many attributes like username, email and password.
Pros. You can apply one code to various types of DB.
In django database,
- Data type is equal to table.
- Class member is like a table field.
Designing data model
Create data type(table) in ur sampleapp/models.py
<models.py>
from django.db import models
class SampleTable(models.Model):
fieldA = models.IntegerField(unique=True)
<eof>
Like IntegerField, there are also pre-defined field.
- TextField, DateTimefield, EmailField, URLField, FileField
Creating data type
Check if you activated your application in settings.py.
<settings.py>
INSTALLED_APPS = (
...
'sampleproject.sampleapp',
)
<eof>
Do DB sync
> ./manage.py syncdb
You can see which SQL were generated with,
> ./manage.py sql sampleapp
Note that it generate 'id' field automatically when it makes table.
Using DB Shell
Like we use database console to execute SQLs in terminal,
django also has shell.
> ./manage.py shell
>>> from sampleapp.models import *
>>> record = SampleTable(fieldA=123)
>>> record.fieldA
123
>>> record.save()
>>> records = SampleTable.objects.all()
>>> firstRecord = SampleTable.objects.get(id=1)
>>> record.delete()
Like above, you can create a record, save it into DB, get all records or single one, access by id and delete it.
Note that until you save(), it just remain only in memory.
User data model
'User' data model is already built in.
>>> from django.contrib.auth.models import User
>>> User.objects.all()
User has many attributes like username, email and password.
Thursday, July 9, 2009
Using django - beginning
Installing
> sudo apt-get install python-django
Start project
> django-admin startproject sampleproject
Then, directory sampleproject is created.
You can run test server using manage.py in the directory.
You can set details using setting.py.
You can set urls using urls.py
Setting DB(ex. SQLite)
Edit setting.py.
- Set DATABASE_NAME, DATABASE_ENGINE
Then create DB.
> ./manage.py syncdb
- Chose if you will set superuser account.
Run server
> ./manage.py runserver
Check it with url 'http://localhost:8000/'
(8000 is default.)
Create application
In one project, you can have several web-applications. Django calls it as applications.
Create with commands,
> ./manage.py startapp sampleapp
Directory sampleapp is then generated.
Application is recommended to be designed with MVC model.
In sampleapp directory,
You can define http request handler function in the file views.py
Implementing handler
Example,
<views.py>
from django.http import HttpResponse
def main(request):
output = "<html>Welcome!</html>"
return HttpResponse(output)
<eof>
'request' has many informations about current requests.
<urls.py>
from sampleapp.views import *
...
urlpatterns = patterns('',
(r'^$', main)
)
<eof>
In 'r'^$', r means regular expression, ^ is first of uri and $ stands for the last.
So it means '/' actually. Function main has been set as a handler for '/' above.
Now, check your first page with browser using 'http://localhost:8000/'. Good job!
Regular expressions
You can use expressions like below
. ^ $ * + ? | [a-z] \w \d
\w means alphabet or '_'
\d means one letter digit.
> sudo apt-get install python-django
Start project
> django-admin startproject sampleproject
Then, directory sampleproject is created.
You can run test server using manage.py in the directory.
You can set details using setting.py.
You can set urls using urls.py
Setting DB(ex. SQLite)
Edit setting.py.
- Set DATABASE_NAME, DATABASE_ENGINE
Then create DB.
> ./manage.py syncdb
- Chose if you will set superuser account.
Run server
> ./manage.py runserver
Check it with url 'http://localhost:8000/'
(8000 is default.)
Create application
In one project, you can have several web-applications. Django calls it as applications.
Create with commands,
> ./manage.py startapp sampleapp
Directory sampleapp is then generated.
Application is recommended to be designed with MVC model.
In sampleapp directory,
You can define http request handler function in the file views.py
Implementing handler
Example,
<views.py>
from django.http import HttpResponse
def main(request):
output = "<html>Welcome!</html>"
return HttpResponse(output)
<eof>
'request' has many informations about current requests.
<urls.py>
from sampleapp.views import *
...
urlpatterns = patterns('',
(r'^$', main)
)
<eof>
In 'r'^$', r means regular expression, ^ is first of uri and $ stands for the last.
So it means '/' actually. Function main has been set as a handler for '/' above.
Now, check your first page with browser using 'http://localhost:8000/'. Good job!
Regular expressions
You can use expressions like below
. ^ $ * + ? | [a-z] \w \d
\w means alphabet or '_'
\d means one letter digit.
Wednesday, July 8, 2009
Disable firefox disk cache
Enter about:config in search bar.
set browser.cache.disk.enable as "false"
set browser.cache.disk.enable as "false"
set browser.cache.disk.capacity as "0"
set browser.cache.memory.capacity (ex. 14336 (256M))
Subscribe to:
Posts (Atom)