Fixing “cannot change locale (UTF-8)” error
I am trying new way to fix the annoying “cannot change locale (UTF-8)” error, this error usually show when you login from your OSX to a Linux machine:
Update Linux without a password
So you managed to login to your Ubuntu Linux machine with a password by using the magic of ssh keys, and you installed “apticron” to email you whenever their is a system update, you login to the system and issue the update command “sudo aptitude update” and “sudo” asks you about your password! not only it is annoying, it also can’t be automated, imaging you manage 10 servers and you have to type the password to update each machine! or you want to automate using some remote execution application like Fabric or Salt (I am Python fan, so I won’t mention Chef or Puppet here).
Best GIT cheat sheet
Click on each region to find out how to change its state: http://ndpsoftware.com/git-cheatsheet.html
الحذاء وطبق الكريستال
قصة للأطفال، تحكي عن حذاء جديد يتسخ من اول استخدام مما يجعله عرضة للسخرية من قبل صحن الكريستال.
بعد فترة يمل الطبق من السخرية ويبدأ الحديث مع الحذاء عن كيفية تعرضه للاتساخ، ويبدأ الحذاء بالحديث عن مغامراته اليومية خارج المنزل، وكيف انه يفيد صاحبه كل يوم.
بعد ما تشبعت مخيلة الطبق من مغامرات الحذاء اليومية بدأ يحس بمدى تفاهة حياته، وحاجته لان يكون مفيداً أكثر من الاستخدام النادر عند قدوم الضيوف.
My First Makefile
The following is a sample Makefile for simple project, here I am building a simple “Bloom Filter” library, and “main” program to use it.
The library will have the following files:
- hash.h and hash.c
- bloom.h and bloom.c
and we should get “libbloom.a” out of it.
The “main” program will use:
- main.c
- bloom.h
- libbloom.a
and we should get “main” executable. So our make file should look like this:
$ cat Makefile
CFLAGS=-Wall -O3
LDFLAGS= -L.
LDLIBS=-lbloom
CFLAGS += `pkg-config --cflags libpcre`
LDFLAGS += `pkg-config --libs libpcre`
OBJS=main.o other.o libbloom.a
BLOOM_OBJS=hash.o bloom.o
all: main libbloom.a
main: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
libbloom.a: $(BLOOM_OBJS)
ar rcs $@ $^
.PHONY: clean
clean:
-rm main libbloom.a *.o
Makefile use TAB not spaces for indentation.
Minimal Django Project: Part 2 … Flat Pages
In this step we will setup the Flatpage App, Flatpage allows you to create simple static pages from the Admin interface:
**mycms$ mkdir templates**
**mycms$ vi mycms/settings.py**
:
MIDDLEWARE_CLASSES = (
:
# Add Flatpage Middleware
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)
:
TEMPLATE_DIRS = (
:
'/Users/rayed/python/mycms/templates',
)
:
INSTALLED_APPS = (
:
# Add Flat Pages App
'django.contrib.flatpages',
:
)
:
**mycms$ vi mycms/urls.py**
:
# Your other patterns here
# SHOULD BE THE LAST RULE
urlpatterns += patterns('django.contrib.flatpages.views',
(r'^(?P<url>.*)$', 'flatpage'),
)
**mycms$ ./manage.py syncdb**
**mycms$ mkdir -p templates/flatpages**
**mycms$ vi templates/flatpages/default.html**
<!DOCTYPE html>
<html>
<head>
<title>{{ flatpage.title }}</title>
</head>
<body>
<h1>{{ flatpage.title }}</h1>
{{ flatpage.content }}
</body>
</html>
Now from the admin interface add a new page from “Flat pages” app, and you can view directly from the normal site.
Minimal Django Project: Part 1 … First Run
Update: Django 1.6+ don’t need any of these steps! it will work out of the box.
The following is the shortest way to create DB backed Django project, it uses SQLite as a backend, which make the setup very easy and fast.
I usually use for testing new Django modules or apps.
**$ django-admin.py startproject mycms**
**$ cd mycms**
**mycms$ chmod +x manage.py **
**mycms$ vi mycms/settings.py **
import os
PROJECT_ROOT = os.path.abspath(os.path.dirname(__name__))
:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': './mycms.db',
:
}
}
:
TIME_ZONE = 'Asia/Riyadh'
:
TEMPLATE_DIRS = (
PROJECT_ROOT + '/templates',
)
INSTALLED_APPS = (
:
'django.contrib.admin',
:
)
:
**mycms$ vi mycms/urls.py **
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
:
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
**mycms$ ./manage.py syncdb**
:
provide username, email, password for admin
:
**mycms$ ./manage.py runserver**
:
To access it from outside
:
**mycms$ ./manage.py runserver 0.0.0.0:8080**
To access it: Frontpage @ localhost Admin @ localhost
PostgreSQL: New Project Setup
For each new project that need PostgreSQL you should create its own user and its own DB, the following are the steps need for that.
Installation
$ sudo aptitude install postgresql
$ sudo aptitude install python-psycopg2 # For Django access
Require a Password
$ sudo vi /etc/postgresql/9.1/main/pg_hba.conf
:
#local all all peer
local all all md5
:
$ sudo service postgresql restart
Create Postgres User
$ sudo -u postgres createuser -P my_user
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
Create DB
$ sudo -u postgres createdb my_db -O my_user
Test It
$ psql -U my_user my_db
After login you issue any SQL statement, you should also try the following commands:
My Python and Django bookmarks
This a list of Django and Python websites I found useful, I hope you find it useful as well, and may be add to it in the comments:
- Django | Django documentation | Django documentation
- The Django Book
- Django Packages : Django Packages reusable apps, sites and tools directory
- 170+ Django conference videos | Equally True
- ubernostrum / django-registration — Bitbucket
- GoDjango.com – Going Through Django Screencasts
- Sourcefabric | Django Software Stack
- Drupal or Django? A Guide for Decision Makers | scot hacker's foobar blog
- <a HREF=“http://celeryproject.org/" “1335735065” >Homepage | Celery: Distributed Task Queue
- Haystack – Search for Django
- Ginger Tech Stack | Blog | Django Development | Lincoln Loop
- Django Best Practices — Django Best Practices
- 33 projects that make developing django apps awesome — elweb
- Brandon Konkle
- Django Advice / Steve Losh
- Auth tips and tricks
Japan Trip Photos
In October 2012 I visited Japan with my lovely family, overall Japan was great country to visit, and I will be writing more extensive post about my visit, mean while I hope you enjoy my photos.
read more