Friday, October 10, 2014

Javascript : Sorting with locale (German Language Sorting)

Javascript's .sort() will work only on English.

So sorting languages like German, French having some special characters in addition to english alphabets is not possible with .sort of javascript.

For array
 var arr = ["Übelkeit", "Veränderte Geschmacksempfindung", "Veränderte Geschmacksempfindung", "Ödem (Schwellung)", "Nasenbluten"] 

normal sorting using

arr.sort(function(a, b) 
{
     if (typeof a === 'string' && typeof b === 'string')
         return (a > b) ? 1 : ((a < b) ? -1 : 0); }); 
}

will sort like this.

["Nasenbluten", "Veränderte Geschmacksempfindung", "Veränderte Geschmacksempfindung", "Ödem (Schwellung)", "Übelkeit"] 

But in german Ü = U and the order is Ü < ü < U < u .
also for similar letters.

A small mode to the actual sorting will solve this.
using localeCompare

arr.sort(function(a, b) 
{
    if (typeof a === 'string' && typeof b === 'string')
        return a.toLowerCase().localeCompare(b.toLowerCase()); 
});

["Nasenbluten", "Ödem (Schwellung)", "Übelkeit", "Veränderte Geschmacksempfindung", "Veränderte Geschmacksempfindung"]

Happy :) ?

Saturday, September 28, 2013

Open Shift Django Basic

My 1 week research on various Paas ended at open shift.
I was a fan of heroku. Some pros of  openshift are 3 gears instead of 1 single dyno
and each gear have a 512MB memory, 1GB local storage than read only file system.
So a total of 1.5GB Ram and 3GB storage :)

Now coming to django to openshift

install rhc using

sudo gem install rhc

create an open shift app using

rhc app create APPNAME python-2.7 -s

-s is for auto scaling

edit setup.py

nano APPNAME/setup.py

uncomment the line install_requires=['Django==xxxxxxx
and change it according to the required django version if its 1.5.1

install_requires=['Django==1.5.1']

save and exit

git commit -am 'Initial commit'
git push


django app should be put in side wsgi

cd wsgi
django-admin.py startproject PROJECTNAME


edit the file application

nano application

delete the contents and paste the new contents

#!/usr/bin/python
import os, sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'PROJECTNAME.settings'
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi',
    'PROJECTNAME'))

virtenv = os.environ['APPDIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.6/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')

try:
    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
    pass

#
# IMPORTANT: Put any additional includes below this line.  If placed above this
# line, it's possible required libraries won't be in your searchable path
#
from django.core.handlers import wsgi
application = wsgi.WSGIHandler() 


Now push the changes

cd ..
git add .
git commit -a -m "Project Creation"
git push 


Wait for push to finish,

One drawback of openshift is the time take to restart an app after a change is pushed.

Sunday, September 01, 2013

Django FastCgi with Nginx

When Launching a  django app, Configuring an nginx virtual host is the most tedious thing. I never can write a configuration with out fiddling with it for a day.

So I descided to write a script for it to auto manage it,

Clone my git hub repo https://github.com/abhisheklalnediya/djangonginx

copy the StartServer.sh to the app directory
specify the port for nginx as the first argument
eg :
$ StartServer.sh 8011

What it does is:
1. Start django in fasctcgi
2. Generate an nginx virtual host configuration file
3. Reloads nginx
4. Happy :) ?

Saturday, May 12, 2012

Bug:Freezing gnome-shell after some work hours

A bug on Gnome shell,
when Gnome shell is used for some time, about an hour or more, i t hangs,
the mouse does not hangs.

So its the problem with gnome-shell.

Bug reported on redhat bugzill is availiable at bugzilla.redhat.com.

So for those guys this is really an annoying thing, there is a temporary solution  .



Go to tty1 by pressing

Ctrl + Alt + F1

Now login using user name and password, (Number pad doesn't work here)

On successful login

pkill gnome-shell

Now go back to GUi by

Ctrl + Alt + F7