Django – combine two querysets

I had to get a list of accounts that either had some activity going around. Activity could be varying, e.g. has active deployments or quotes being exchanged, and therefore getting data from two different models. Here’s how I managed to merge the querysets together:

from itertools import chain
from django.db.models import Q

active_deal_accounts = Deal.objects.filter('account_id').distinct()
active_installation_accounts = Installation.objects.filter(Q(|
active_deal_results = Account.objects.filter(id__in=active_deal_accounts)
active_installation_results = Account.objects.filter(id__in=active_installation_accounts)
results = list(chain(active_deal_results, active_installation_results))

More info on StackOverflow article

Install VMware tools on a debian machine

How to install VMware tools on a debian machine.

   * apt-get upgrade
   * apt-get update
   * VSphere:  Edit the settings of the VM and click on "CD/DVD drive 1".   Click the "Connected" box at the top of the window and say OK.   Then return to the SSH session.
   * which gcc
   * which make
       NOTE:  If you don't get a path to gcc & make back when you invoke the "which" commands, those tools are not installed and must be:
   * apt-get install make gcc
   * Determine what kernel you're using:    uname -r
   * apt-get install linux-headers    (I'm not specifying a version of linux-headers because by leaving it off, apt-get will return a list of linux-kernel packages):
       NOTE:  This will give you a list of packages to install.   Look for one that has your kernel version in
           it (i.e.: I chose linux-headers-2.6.32-5-686 because both the kernel version AND architecture matched).   
   * Install the matching version:   apt-get install linux-headers-2.6.32-5-686
   * cd /usr/local/src
   * wget
       NOTE:  If you get an error "wget" doesn't exist, install it:   "apt-get install wget"
   * apt-get -f install dpkg-dev
   * dpkg -i build-essential_11.6_i386.deb    (this replaces build-essential 11.5 with 11.6)
   * VSphere:  Right-click on the VM, go to Guest -> Install/Upgrade VMWare Tools
   * mount /dev/cdrom  /media/cdrom0    (/dev/cdrom points to /dev/sr0)
   * cd /media/cdrom0
   * cp VMwareTools-8.6.0-425873.tar.gz /tmp
   * cd /tmp
   * tar -zxvf VMwareTools-8.6.0-425873.tar.gz
   * cd /tmp/vmware-tools-distrib
   * perl
       NOTE:   Follow all the prompts.    I have went through this entire procedure twice now on brand-spanking new Debian machines and just accepting all defaults has worked each time.
   * Remove the VMWare Tools tar-ball and un-packed files.   
   * cd /tmp
   * rm -rf  VMwareTools*  vmware-tools-distrib        (this removes the tar-ball and un-packed files - no need for them any longer).
     NOTE:   The installation script automatically un-mounts the virtual CDROM/DVD drive.

Find Linux distribution name/version

The lsb_release command displays certain LSB (Linux Standard Base) and distribution-specific information. Type the following command:

lsb_release -a

Sample outputs:

No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 6.0.2 (squeeze)
Release:	6.0.2
Codename:	squeeze

Install openssh-server on debian

I installed the latest openssh-server on debian with the following command:

apt-get install openssh-server

I was able to connect to the ssh server but wasn’t able to login via root account. After the 3rd password attempt, I would get the following message:
Permission denied (publickey,password).
The default configuration doesn’t allow root ssh access via password. In order to do that I had to replace the following lines in the file /etc/ssh/sshd_config:

PermitRootLogin without-password
#PasswordAuthentication yes

with the below lines:

PermitRootLogin yes
PasswordAuthentication yes

Installing Perl Modules

Here’s how I was able to add Perl modules. Login as root to do this:

Login to the perl shell

perl -MCPAN -e shell

On the perl shell, type install followed by the module name, e.g.
cpan[1]> install LWP::Protocol::https
cpan[1]> install JSON
cpan[1]> REST::Client

Salesforce Query – Filter by Date

I was trying to get records from Salesforce modified within the last day. But kept running into exceptions where SF would complain that data must be of type datetime and must not be enclosed within quotes which was weird. But here’s how I was able to set the datetime without quotes and execute the query:

SELECT Accellion_Net_Subscription_Revenue__c,AccountId,Amount,CampaignId,CloseDate,Company_Size__c,CreatedDate,Deployment_ID__c,Id,LastModifiedDate 
FROM Opportunity 
WHERE LastModifiedDate >=2016-03-09T00:00:00Z 
ORDER BY LastModifiedDate ASC 

PHP – Get log file location

Based on the php version, the error log file may be available at separate locations. Here’s a nice way to find out the location of the log file. Execute the following command on your command prompt:

php --info | grep error

The error_log variable will point to the destination of log file.