Noodlecode parody of spaghetti code

Month: February 2010 (page 2 of 3)

Roundtable Plus S2 Ep. 261

Roundtable Plus S2, Episode 261, Jan 11 2010, from KBS World

Continue reading

Batch image resize

To mass resize image files, you need ImageMagick

yum install ImageMagick

To resize:

cd image-folder/
mogrify -resize 800px *.jpg

Note: 800px is the width, it’ll keep the aspect ratio of the image



Deploy Turbogears 2.1 on Fedora

(Update: Using Fedora 16)

Install mod_wsgi for apache

yum install mod_wsgi

Edit apache config: (/etc/httpd/conf/httpd.conf)

ServerName hostname:80

Workaround for mod_wsgi 2.x in Fedora, move this line:

Include conf.d/*.conf

… to below these lines:

User apache
Group apache

Add this to the end of the config file: (/etc/httpd/conf.d/wsgi.conf)

<IfModule mod_wsgi.c>
  WSGISocketPrefix /var/run/wsgi

Using TG2 demo app from the previous post (HelloWorld), create apache config file for this app: (/etc/httpd/conf.d/HelloWorld.conf)

Listen 8080
NameVirtualHost *:8080

<VirtualHost *:8080>

  ServerAdmin [email protected]
  ServerName hostname
  ErrorLog logs/hostname-error_log
  CustomLog logs/hostname-access_log common

  Alias /images/ /var/www/HelloWorld/images/
  Alias /css/ /var/www/HelloWorld/css/
  Alias /javascript/ /var/www/HelloWorld/javascript/

  WSGIDaemonProcess HelloWorld threads=10 processes=3
  WSGIProcessGroup HelloWorld
  WSGIScriptAlias / /var/www/HelloWorld/HelloWorld.wsgi

  <Directory /var/www/HelloWorld>
    Order deny,allow
    Allow from all


Create directory for static contents (do these as root):

mkdir -p /var/www/HelloWorld/python-eggs

Create wsgi script for apache to launch this app: (/var/www/HelloWorld/HelloWorld.wsgi)

import os, sys, site
appname = 'HelloWorld'
prev_sys_path = list(sys.path)
site.addsitedir('/usr/local/pythonenv/%s/lib/python2.6/site-packages' % appname)
new_sys_path = []
for item in list(sys.path):
    if item not in prev_sys_path:
sys.path[:0] = new_sys_path
sys.path.append('/usr/local/turbogears/%s' % appname)
from pkg_resources import working_set, Environment
env = Environment('/usr/local/pythonenv/%s' % appname)
distributions, errors = working_set.find_plugins(env)
for dist in distributions:
os.environ['PYTHON_EGG_CACHE'] = '/usr/local/turbogears/%s/python-eggs' % appname
from paste.deploy import loadapp
application = loadapp('config:/usr/local/turbogears/%s/production.ini' % appname)

Move TG2 public folder to static contents folder:

cp -r HelloWorld/helloworld/public/* /var/www/HelloWorld
chown -R apache.apache /var/www/HelloWorld

Move TG2 app to application folder:

mkdir -p /usr/local/turbogears
cp -r HelloWorld/ /usr/local/turbogears/

Create production config file of the app:

cd /usr/local/turbogears/HelloWorld
cp development.ini production.ini

Set debug to false: (/usr/local/turbogears/HelloWorld/production.ini)


Set permission:

chown -R apache.apache /usr/local/turbogears

Finally, restart apache:

service httpd restart

Now, browse to http://localhost:8080

Thunderbird calendar + WebDAV


Users synchronize their calendar in Thunderbird with calendar server (WebDAV) on Fedora

Install Thunderbird & calendar plugin:

yum install thunderbird thunderbird-lightning

Install apache + mod dav:

yum install httpd mod_dav_svn

Calendars will be stored in /home/webmaster/calendar. Make sure to chmod 755 /home/webmaster

Setting up apache:


<IfModule mod_dav.c>
  Alias /calendar /home/webmaster/calendar
  <Directory /home/webmaster/calendar>
    DAV On
    Options +Indexes
    AuthType Basic
    AuthName "Calendar Authentication"
    AuthUserFile /home/webmaster/calendar.htpasswd
    <LimitExcept GET OPTIONS>
      require valid-user
    Order allow,deny
    Allow from all
<Directory /home/webmaster/calendar>
  AuthUserFile /home/webmaster/calendar.htpasswd
  AuthName "Calendar Authentication"
  AuthType basic
  require valid-user

Create user & password:

htpasswd -cb /home/webmaster/calendar.htpasswd username password

Create calendar directory & set permission:

mkdir /home/webmaster/calendar
chown -R apache /home/webmaster/calendar

Test the new configuration:

touch calendar.ics
cadaver http://localhost/calendar
put calendar.ics

Refer /var/log/httpd/error_log if there’s any error. Always check folder permission.

Create new calendar for Thunderbird (calendar name: Personal):

touch Personal.ics
cadaver http://localhost/calendar
put Personal.ics

Launch Thunderbird

  1. Events & Tasks > Calendar (or Ctrl+Shift+C)
  2. File > New > Calendar
  3. ‘On the network’
  4. ‘iCalendar (ICS)’, location: http://localhost/calendar/Personal.ics
  5. Enter username & password (in /home/webmaster/calendar.htpasswd)

Create new event for the new calendar

Turbogears 2.1 on Fedora

This post shows how to install Turbogears2 (TG2) in a Python virtual environment. (Update: Using Fedora 14)

Install required software:

yum install python-setuptools python-virtualenv

PostgreSQL dependencies (needed by PyGreSQL)

yum install gcc postgresql-devel

For MySQL backend, dependencies:

yum install gcc mysql-devel

Install TG2 in virtual env: (as root)

mkdir -p /usr/local/pythonenv
virtualenv --no-site-packages /usr/local/pythonenv/HelloWorld

Activate virtual env:

source /usr/local/pythonenv/HelloWorld/bin/activate

Install PostgreSQL database components: (in virtualenv, as root)

easy_install PyGreSQL
easy_install psycopg2

Install TG2.1: (in virtualenv, as root)

easy_install -i tg.devtools
easy_install -i Genshi
easy_install tw.jquery

Start developing TG2 app:

Note: Another way to add dependencies – edit, add package name to ‘install_requires’ variable. For MySQL, add ‘MySQL-python’

Activate virtualenv first (as regular user – ‘webmaster’)

source /usr/local/pythonenv/HelloWorld/bin/activate

Create TG2 app:

paster quickstart HelloWorld

Install required packages for this new app: (in virtual env, as root)

cd HelloWorld/
python develop

Make sure to use new PostgreSQL DSN format: (development.ini)

postgresql://username:[email protected]:port/databasename

Populate database (as regular user, refer HelloWorld/helloworld/

paster setup-app development.ini

Launch TG standalone server

paster serve --reload development.ini

… and start coding / debugging at http://localhost:8080

To change default URL address: (development.ini)

host =
port = 5000

Turbo + Gear

PostgreSQL on Fedora

PostgreSQL (Update: Using Fedora 14)

Install PostgreSQL & phpPgAdmin (web-based Postgres administration)

yum install postgresql postgresql-server phpPgAdmin

Initialize database

service postgresql initdb

Start PostgreSQL service

service postgresql start

Create password for user ‘postgres’ (in the system)

passwd postgres

Login as user ‘postgres’

su - postgres

Create password for user ‘postgres’ (in the database)

psql -d template1
alter user postgres with password 'password';

Exit psql shell:


Let Postgres allow authentication using password: (/var/lib/pgsql/data/pg_hba.conf)

# "local" is for Unix domain socket connections only
local   all         all                               md5
local   all         all                               ident
# IPv4 local connections:
host    all         all          md5
host    all         all          ident
# IPv6 local connections:
host    all         all         ::1/128               md5
host    all         all         ::1/128               ident

md5 – allow authentication using password
ident – authentication as system user

Restart PostgreSQL

service postgresql restart

Enable service:

chkconfig postgresql on


Create phpPgAdmin by copying from original config file: (/usr/share/phpPgAdmin/conf)


Allow login from phpPgAdmin: (/usr/share/phpPgAdmin/conf/

$conf['extra_login_security'] = false;

Apache setting, add your IP address to allow access to the application (/etc/httpd/conf.d/phpPgAdmin.conf)

Allow from

Reload httpd. Open phpPgAdmin (http://localhost/phpPgAdmin). Login as ‘postgres’

Add new user: (PostgreSQL > Roles > Create role)


Create role (user) ‘webmaster’, inherits privileges from user ‘postgres’ & allow login

Create database: (PostgreSQL > Database > Create database)


Create database ‘helloworld’ using Unicode encoding

Grant permission on database: (PostgreSQL > helloworld > Privileges > Grant)


User ‘webmaster’ is granted ‘All privileges’

Check connection & configuration

psql -h localhost helloworld webmaster

Install Fedora as server

This installation exclude desktop environment, therefore it uses only command line interface. (Update: Based on Fedora 14)

During installation of Fedora, for software set, select ‘Minimal’, then choose to ‘Customize Now’. In customization section, for ‘Servers’ category, select only servers that you need: Web Server, PostgreSQL; then for ‘Base System’ category, select ‘Administration Tools’

Post installation configuration:

Set SELinux to ‘permissive’ (/etc/sysconfig/selinux)


Enable / disable certain services:

chkconfig [servicename] on|off

Disable: NetworkManager, firstboot, pcscd, cups (unless you connect this server with a printer), sendmail (unless you want to send e-mail using it)

Enable: httpd, mysqld, network

Note: We use ‘network’ instead of ‘NetworkManager’ to manage internet connection

Edit network interface: (/etc/sysconfig/network-scripts/ifcfg-eth0)


Restart the server

init 6

After restart, update the system:

yum install yum-fastestmirror yum-presto -y
yum update -y

X-less Fedora server on VBox


Add new user (‘webmaster’):

adduser webmaster
passwd webmaster

Install vim (CLI text editor):

yum install vim-enhanced

Install new fonts in Gnome

Create folder .fonts on home directory

mkdir ~/.fonts

Move your *.ttf and *.otf to that folder

mv *.ttf ~/.fonts

‘Reload’ Gnome desktop

fc-cache -f -v

Gnome window compositing

Gnome >= 2.22 has its own window compositing. To enable:

gconftool-2 -s --type bool /apps/metacity/general/compositing_manager true

To disable, set ‘true’ to ‘false’


Without window compositing


With compositing. See the drop shadow on app window and opacity on terminal window

Kara – Lupin

Kara’s 3rd Mini Album, Lupin

Continue reading

Older posts Newer posts

Copyright © 2017 Noodlecode