Saturday, December 17, 2011

Moved blog

I got interested in the jekyll project for generating static websites. As a test I have migrated my blog here.

Code paste

Use this service for pasting code with syntax highlighting and even test execution:
http://codepad.org

Saturday, November 26, 2011

How to make web2py faster

Avoid regenerating tables:
db = DAL('sqlite://storage.sqlite', migrate=runonce) 

Create indexes:
db.executesql('CREATE INDEX IF NOT EXISTS {table}_index ON {table} (id);'.format(table=table))

Compile byte code in admin

Serve static files direct from server

Move as much logic as possible from models into controllers and modules

Disable session if possible

Cache database queries and controller functions:
db().select(db.log.ALL, cache=(cache.ram, 60))


@cache(request.env.path_info, time_expire=5, cache_model=cache.ram)
def index():
pass

Friday, November 25, 2011

Let webfaction serve your static content

Create a static symbolic link application:
Name: web2py_static
App category: Symbolic link
App type: Symbolic link to static-only app
App doc: This creates a symlink from ~/webapps/ to the absolute path specified in the extra info field. 


Then in your website mount this at /static


Now requests to static files will be handled directly by webfaction and never reach your app.

web2py with uwsgi

I found Apache used too much memory so changed to uwsgi:

# build uwsgi
hg clone http://projects.unbit.it/hg/uwsgi
cd uwsgi
make -f Makefile.Py27
cd ..

# get web2py
wget http://www.web2py.com/examples/static/web2py_src.zip
unzip web2py_src.zip
cd web2py
# run web2py rocket server to setup password
python2.7 web2py.py
# set your password then kill the server
cp parameters_8080.py parameters_PORT.py
cd ..

# start uwsgi with 32 MB of memory, 24 threads, 1 process
./uwsgi/uwsgi --http=127.0.0.1:PORT --pythonpath /path/web2py --module wsgihandler -d /path/uwsgi.log -t 20 --async 24 --ugreen --limit-as 32 -r --no-orphans -M -p 1 --touch-reload /path/uwsgireload.txt --reload-on-rss 50
# reload server
touch /path/uwsgireload.txt

Thursday, November 24, 2011

How to determine what Linux is installed

Kernel version:

$ uname -r
2.6.18-238.12.1.el5PAE


Distribution name:

$ cat /etc/issue
CentOS release 5.7 (Final)


32 or 64 bit:

$ getconf LONG_BIT
32

Friday, November 18, 2011

How to create an image mosaic

For a birthday present I generated an image mosaic using the metapixel command.
Firstly get atleast 1000 images in [base_image_folder] and sub-directories. Then process the data with:  


metapixel-prepare --width=64 --height=96 -r [base_image_folder] [tmp_thumbnails_dir]


This processing will take a while. Then generate the mosaic with:


metapixel -w 48 -h 64 -s 8 --metapixel [image_pattern_for_mosaic] [output_image_file] --library [tmp_thumbnails_dir]


This should only take a few minutes. For different resolutions change the size flag.