Skip to main content

Posts

Monkey Patching Django Model Class

Django is shipped with some useful application, also there are lots of third party re-usable application written for Django. Sometime you need to modify or customize these applications(Models of application) to meet your software requirements. One of the usual solution is adding a Model class to have a one-to-one relationship with the third party Models. This solution has some disadvantages such as having more tables and classes which can highly adversely affect database performance, scalability and add more complexity to the software development.  I think of another solution to this problem. I used Django South along with monkey patching of third party Model classes. I added a field to Django user class. Here is a walk through over this approach. 1. Add an application: python manage.py startapplication userpatch 2. Add the following  code to add the new field to the user class from django.db import models from django.contrib.auth.models import User ...

Installing MS SQL Server driver on Ubuntu Linux

Although making a connection to SQL Server can be done using unixODBC and FreeTDS, it does not work with some collations on SQL Server 2008. Recently, Microsoft released an ODBC driver for Linux that works on 64-bit systems only. Installing the driver is tricky. I begin by installing the build-essential, which is required for compiling from source. Checkinstall can be installed if you want to add the following application to the package manager. $ sudo apt-get install build-essential  Download unixODBC-2.3.0  and Microsoft ODBC dirver  and extract. $ sudo wget ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.0.tar.gz $ tar xvf unixODBC-2.3.0.tar.gz $ wget http://download.microsoft.com/download/6/A/B/6AB27E13-46AE-4CE9-AFFD-406367CADC1D/Linux6/sqlncli-11.0.1790.0.tar.gz $ tar xvf sqlncli-11.0.1790.0.tar.gz  Install the unixodbc using the following commands: $ ./configure --disable-gui --disable-drivers --enable-iconv --with-iconv-char-enc=UTF8 --with-ico...

جستجوی املاک روی نقشه برای خرید و فروش و اجاره ، خانه و آپارتمان

دودوتا  وب سایت  جستجوی املاک آن لاین با قابلیت های بسیار زیاد از جمله جستجوی پیشرفته املاک روی نقشه و غربال سازی چند بعدی می با شد تمام امکانات این وب سایت رایگان است و کاربر می تواند مستقیما با آگهی دهنده و یا مالک در ارتباط باشد. این وب سایت تمام معاملات املاک از جمله فروش و خرید ، اجاره و رهن، معاوضه و پیش فروش را پشتیبانی می کند همچنین تمام انواع املاک  از جمله: آپارتمان، خانه، ویلا، زمین، مغازه دفتر کار و تمامی انواع مستغلات در دودوتا به طور مجزا قابل جستجو و طبقه بندی است.    اگر به دنبال خرید خانه یا آپارتمان ویا اجاره خانه هستید از طریق دودوتا به آسانی میتوانید ملک مورد نظر خود را با جستجو خرید خانه  از روی نقشه بیابید. اگر هم از اینترنت کم سرعت استفاده می کنید بهتر است از  خرید یا اجاره خانه  از روی لیست استفاده کنید. سپردن ملک و درج آگهی در دودوتا کاملا رایگان است. برای فروش آپارتمان و یا خانه می توانید به فروش خانه مراجعه کنید و  برای رهن و اجاره خانه  باید به  اجاره خانه   بروید .

Installing pyodbc on ubuntu

Installing pyodbc is straight forward but if  getting     "error: command 'gcc' failed with exit status 1"  when installing pyodbc, make sure you have installed  requirements  as below. sudo apt-get install unixODBC-dev g++ pip install pyodbc

Installing Python Imaging Library(PIL) on ubuntu

Install required packages sudo apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev python-dev Fixing the lib path sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib Install the PIL pip install pil If getting "ImportError: No module named PIL" on importing Image module also try from PIL import Image If not using virtualenv "$ sudo apt-get install python-imaging" will also install pil for the system.

Javascript Memoization Pattern

It happens sometime that you need to cache some data which has produced by a complex operation. Caching data helps you not to do repeat the complex operation. Caching the results of an operation is also known as Memoization. Followings are too example of this pattern. var setCache = function (param,val) {        setCache.cache[param] =val;        return setCache.cache[param];  }; setCache.cache={}; or you can just save the result of a function inside the  function: var setCache = function (param) {        if (!setCache.cache[param]){           var res;           //do the complex and heavy operation            //here and assign the  result to 'res'           setCache.cache[param] =res;        }        return setCache.cache[param]; }; setCache...