Add Printer to CentOS

 Before adding printer you need have the printer IP address
 Launch add printer wizard from command line: sudo system-config-printer
 New printer >> Give a name for the printer you want to add >>choose APPSocket/HP JetDirect in select connection >> put down the printer ip address in hostname field and leave port number at 9100 >> choose your printer type.

Add Network Printer to CentOS/Ubuntu

 Before adding printer you need have the printer IP address: you can print it out from the printer configuration


1. make sure CUPS is running in your system

[sourcecode language="bash"]
sudo /etc/init.d/cups start
[/sourcecode]


2. Launch add printer wizard from command line

[sourcecode language="bash"]
sudo su -
system-config-printer
[/sourcecode]


3. New printer >> Give a name for the printer you want to add >>choose APPSocket/HP JetDirect in select connection >> put down the printer ip address in hostname field and leave port number at 9100 >> choose your printer type.

4. select printer from database (HP)

5. model: since there is no support for my printer model HP4700 I choose Laserjet 4350 and Postscript as Driver option

Showing hisotry of your Linux commands

1. If you want to show wehen the command was issued:

$ export HISTTIMEFORMAT='%F %T '

$ history > file_name

2. Search the history using Control+R

 

Showing hisotry of your Linux commands

1. If you want to show wehen the command was issued:

$ export HISTTIMEFORMAT='%F %T '

$ history > file_name

2. Search the history using Control+R

 

Visit websense blocked sites?

Are you tied of the following message?

"Content blocked by your organization

Reason:

This Websense category is filtered: Explicitly Blocked."

If you answer yes, try to visit the site though here:

https://proxy1plus.appspot.com/


 

Visit websense blocked sites?

Are you tied of the following message?

"Content blocked by your organization

Reason:

This Websense category is filtered: Explicitly Blocked."

If you answer yes, try to visit the site though here:

https://proxy1plus.appspot.com/


 

Curious which verison of the CentOS you are running?

try typing uname -a in the command line

if you see

Linux XXXXXX 2.6.18-238.19.1.el5 #1 SMP Fri Jul 15 07:31:24 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

Then you are running 64 bit of CentOS.

Command cat /etc/redhat-release  will show you the version of theCentOS

Curious which verison of the CentOS you are running?

try typing uname -a in the command line

if you see

Linux XXXXXX 2.6.18-238.19.1.el5 #1 SMP Fri Jul 15 07:31:24 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

Then you are running 64 bit of CentOS.

Command cat /etc/redhat-release  will show you the version of theCentOS

Do not update the Creeky Ipad's firmware!

Do not update the Creepy Ipad's firmware!

Or you will probably enter the endless "recovery mode" loop. It happened to me one time before while I was updating the firmware.  And it happened again. I should never trust AP@LE. To get out the loop I have tried many ways I found online, however all most all of them do not work.

Try the following methods first if it happens to you.

Hold on booth home key and power key for at least 10 seconds, ipad will reboot. If you are lucky it will out of the recovery mode by doing so. ---Good for you.

The upper method works for me last time, but does not work this time. The only way works is do the following:

1. Uninstall old version of the iTunes and reboot your computer

2. Reinstall the most updated iTunes

3. Go to c:\ windows\system32\drivers\etc\ to locate the host file, delete the following two lines from the host file:

74.208.10.249 gs.apple.com
#127.0.0.1 gs.apple.com

4. Open iTunes and redo the recovery.

===============================

Unsuccessful methods:

Here are some others recommended to do with the "endless recovery mode":

1. Enter the DFU mode:

DFU mode as opposed to Recovery Mode, requires a bit of timing and can take practice so if at first you don’t succeed, don’t be afraid to keep trying.
  • Plug your iPhone, iPod touch, or iPad into your Mac or Windows PC and make sure iTunes is running.
  • Hold down both the Sleep Button (on top of your device) and the Home Button (on the front underneath the screen).
  • Keep them both held down from about 10 seconds. (If you see the Apple logo, you’ve held them too long and will need to start again.)
  • Let go of the Sleep Button but keep holding the Home Button for about 5 seconds. (If you see the “Plus into iTunes” screen than you held it too long and will need to start again.)
  • If the screen stays black, that’s it! Your iPhone, iPod touch, or iPad should now be in DFU mode.
2. Use TinyUmbrella, which requires you are able to enter the ipad's DFU mode:
  • Download TinyUmbrella (Fix Recovery) for iOS 4.3.x (Windows | Mac)
  • Download Zlib1.dll from here and place it in the same directory in which fixrecovery43.exe is present.
  • Launch iTunes and plug your iPhone into your PC or Mac via USB cable. Let iTunes run in background and use the following instructions to put your iPhone into DFU mode:
    • Hold down the Home+Power button simultaneously for 10 seconds.
    • After 10 seconds, release the Power button but keep holding the Home button until iTunes detects your iPhone into DFU mode.
    • Do not close iTunes. Let it run in the background.
  • Launch fixrecovery43.exe and wait while it kicks your iPhone out of recovery mode loop. Make sure you have an active internet connection because fix recovery will be needing to fetch DFU and firmware image from Apple servers. Whole process usually takes less than a minute.
3. Try using the Recboot and TinyUmbrella to kick you out of the recovery mode.

Do not update the Creeky Ipad's firmware!

Do not update the Creepy Ipad's firmware!

Or you will probably enter the endless "recovery mode" loop. It happened to me one time before while I was updating the firmware.  And it happened again. I should never trust AP@LE. To get out the loop I have tried many ways I found online, however all most all of them do not work.

Try the following methods first if it happens to you.

Hold on booth home key and power key for at least 10 seconds, ipad will reboot. If you are lucky it will out of the recovery mode by doing so. ---Good for you.

The upper method works for me last time, but does not work this time. The only way works is do the following:

1. Uninstall old version of the iTunes and reboot your computer

2. Reinstall the most updated iTunes

3. Go to c:\ windows\system32\drivers\etc\ to locate the host file, delete the following two lines from the host file:

74.208.10.249 gs.apple.com
#127.0.0.1 gs.apple.com

4. Open iTunes and redo the recovery.

===============================

Unsuccessful methods:

Here are some others recommended to do with the "endless recovery mode":

1. Enter the DFU mode:

DFU mode as opposed to Recovery Mode, requires a bit of timing and can take practice so if at first you don’t succeed, don’t be afraid to keep trying.
  • Plug your iPhone, iPod touch, or iPad into your Mac or Windows PC and make sure iTunes is running.
  • Hold down both the Sleep Button (on top of your device) and the Home Button (on the front underneath the screen).
  • Keep them both held down from about 10 seconds. (If you see the Apple logo, you’ve held them too long and will need to start again.)
  • Let go of the Sleep Button but keep holding the Home Button for about 5 seconds. (If you see the “Plus into iTunes” screen than you held it too long and will need to start again.)
  • If the screen stays black, that’s it! Your iPhone, iPod touch, or iPad should now be in DFU mode.
2. Use TinyUmbrella, which requires you are able to enter the ipad's DFU mode:
  • Download TinyUmbrella (Fix Recovery) for iOS 4.3.x (Windows | Mac)
  • Download Zlib1.dll from here and place it in the same directory in which fixrecovery43.exe is present.
  • Launch iTunes and plug your iPhone into your PC or Mac via USB cable. Let iTunes run in background and use the following instructions to put your iPhone into DFU mode:
    • Hold down the Home+Power button simultaneously for 10 seconds.
    • After 10 seconds, release the Power button but keep holding the Home button until iTunes detects your iPhone into DFU mode.
    • Do not close iTunes. Let it run in the background.
  • Launch fixrecovery43.exe and wait while it kicks your iPhone out of recovery mode loop. Make sure you have an active internet connection because fix recovery will be needing to fetch DFU and firmware image from Apple servers. Whole process usually takes less than a minute.
3. Try using the Recboot and TinyUmbrella to kick you out of the recovery mode.

Linux find and replace text within all files within a directory



There is a fast way to replace all the occurrences of one world within a certain directory including subdirectory by using a one line Linux code (by using Perl):



find /path/to/start/from/ -type f | xargs perl -pi -e 's/old_word/new_word/g'





REMEMBER ALWAYS BACKUP BEFORE DOING SOMETHING
If you want to do word replacement using the vim
:%s/search/replace/g                     whole file
:2,12s/search/replace/g                 from line 2 to line 12

Linux find and replace text within all files within a directory



There is a fast way to replace all the occurrences of one world within a certain directory including subdirectory by using a one line Linux code (by using Perl):



find /path/to/start/from/ -type f | xargs perl -pi -e 's/old_word/new_word/g'





REMEMBER ALWAYS BACKUP BEFORE DOING SOMETHING
If you want to do word replacement using the vim
:%s/search/replace/g                     whole file
:2,12s/search/replace/g                 from line 2 to line 12

Install a new version of the Python on CentOS without overwriting the system's python installation

Install a new version of the Python on CentOS without overwriting the system's python installation
** You have to decide where to install it based on your needs. If you want to run web server later using this copy of the Python, you may not want to install it in your home directory. Most popular place to go is /opt/.
The default Python comes with the CentOS is version 2.4 which can not meet the requirements of some programs. Here is an instruction of installing a separate newer version of the Python on CnetOS.
Prepare the source code
  1. cd
  2. wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
  3. tar –zvxf Python-2.7.2.tgz
  4. cd Python-2.7.2
  5. configure python so it will not overwriting the system’s default python
    ./configure –prefix= /usr/local/opt/python2.7 --with-threads --enable-shared
1)     --enable-shared is required if you are going to install mod_wsgi. Or you have to rebuild the python library.
2)        However, if you choose –enable-shared parameter you may encounter error while you are trying to install pscopg2. The error message is "ld cannot find lpython2.7". Here is a solution to that:
$ cd /usr/lib64
$ sudo ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 libpython2.7.so.1.0
   $ sudo ln -s libpython2.7.so.1.0  libpython2.7.so

  1. make and install
  $ make
 $ make install
Now you have successfully installed a fully functional copy of the python library. In order to use it you can do some configuration for this version of the python.
  1. add the following line to user’s .bashrc to create an alias, so you do not need reboot to start using the alias
    alias python='/usr/local/opt/python2.7/bin/python'
2.  Make a symbolic link in the /usr/bin folder:
    $ ln –s /usr/local/python2.7/bin/python /usr/bin/python2.7
3. to make a permanent change then you can run the following as root:
     ln -f /usr/local/python2.7/bin/python /usr/local/bin/python
  1. Configure ld to find your shared libs:
a. create file opt-python2.7.conf under /etc/ld.so.conf.d folder
b. add /usr/local/python2.7/lib into the created file
c. run $ sudo /sbin/ldconfig

After the installation of the new versions of the Python you might need to install the setuptools and pip to work with this version of the Python:
1. Install setuptools
a.         cd
b.        wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e
c.        tar -zvxf setuptools-0.6c11.tar.gzll
d.        cd setuptools-0.6c11
e.        python2.7 setup.py build  ###here use the newly installed python to make sure you are installing it for it
f.        python2.7 setup.py install

     2 Install pip

        Follow the same operation process for installing setuptools.  After installing the pip you may want to make a symbolic link for it in the /usr/bin folder
sudo ln –s /usr/local/python2.7/bin/pip /usr/bin/pip2.7









Reference:

1. Thanks http://thebuild.com/blog/2009/10/17/wordpress-to-djangopostgresql-part-3-installing-apache-python-2-6-psycopg2-and-mod_wsgi/ for tips on overcoming the errors while installing the psycopg2 by link thelibraries to /usr/lib64.

2. http://blog.hackedexistence.com/mediatemple-centos-5-5-ve-server-build-django-1-3-python-2-7-mysql-5-5-php-5-3

Install a new version of the Python on CentOS without overwriting the system's python installation

** You have to decide where to install it based on your needs. Most popular place to go is /opt/.

1. Install epel (extra packages for enterprise linux). This will add the epel repo to yum and give us a running start at some normally unavailable packages. It also provides some updates to existing repo packages:

To install EPEL follow this link: http://b2ctran.wordpress.com/2013/03/08/enable-epel-repository-on-centos/

2. Preinstall dependencies: development tools, ssl and zlib and some other packages which will be needed by python
$ yum -y groupinstall 'Development Tools'
$ yum -y  install openssl-devel zlib zlib-devel
$ yum install -y gdbm-devel sqlite-devel tk-devel ncurses-devel bzip2-devel readline-devel db4-devel

3. Prepare python2.7 source code

$ cd
$ wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
$ tar –zvxf Python-2.7.2.tgz
$ cd Python-2.7.2

Configure the Modules/Setup.dist to enable the gzip and readline support by uncomment the associated entries.
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib –lz
#readline realine.c -lreadline –ltermcap

4. configure python so it will not overwriting the system’s default python
./configure –prefix= /opt/python2.7 --with-threads --enable-shared

1)--enable-shared is required if you are going to install mod_wsgi. Or you have to rebuild the python library.
2) However, if you choose –enable-shared parameter you may encounter error while you are trying to install pscopg2.

The error message is "ld cannot find lpython2.7".

Here is a solution to that:

$ cd /usr/lib64
$ sudo ln -s /opt/python2.7/lib/libpython2.7.so.1.0 libpython2.7.so.1.0
$ sudo ln -s libpython2.7.so.1.0 libpython2.7.so

5. make and install

$ make
$ sudo make install

6. Now we need to update BASH so that it knows about the new shared libraries that we have put on the system.

$ sudotouch /etc/ld.so.conf.d/opt-python2.7.conf
add put /opt/python2.7/lib in the created file
$ sudo /sbin/ldconfig

7. install setuptools and pip:

$wget https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
$sudo sh setuptools-0.6c11-py2.7.egg

if you encounter python2.7 could not found error, the following will probably fix it:
$ sudo ln -s /opt/python2.7/bin/python  /usr/bin/python2.7

After installing easy_install you can install pip: sudo /opt/python2.7/bin/easy_install pip

Configure mod_wsgi with Apache for running Django project

Part One Install mod_wsgi and make necessary configuration

1. Install mod_wsgi

[sourcecode language="bash"]
#http://code.google.com/p/modwsgi/downloads/list
wget http://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
tar -zvxf mod_wsgi-3.4.tar.gz
cd mod_wsgi-3.4
#here must define which python to use
#make: *** [mod_wsgi.la] Error 1
./configure --with-python=/opt/python2.7/bin/python
make
sudo make install
[/sourcecode]

if you encounter an error during configure, "checking Apache version... ./configure: line 1704: apxs: command not found"
make sure you have development package of httpd (apache) installed on your machine.

[sourcecode language="bash"]
yum install httpd-devel.x86_64
[/sourcecode]

2. Configure httpd to load mod_wsgi

[sourcecode language="bash"]
#create file mod_wsgi.conf under /etc/httpd/conf.d
sudo vim /etc/httpd/conf.d/mod_wsgi.conf
#save the following line to mod_wsgi.so file
LoadModule wsgi_module modules/mod_wsgi.so
#restart the httpd service
sudo /etc/init.dhttpd restart
[/sourcecode]

Part two: make necessary configuration in /etc/httpd/conf/httpd.conf
In this part of the configuration we are using the Apache VirtualHost to host the django project.
1. Configure apache to serve VirtualHost:

[sourcecode language="text"]
# a. add one more port for listening by Apache which will be specifically used for virtual host:
Listen 8081
# b. uncomment NameVirtualHost *:80 and change the port number from 80 to the port number you defined in step (a), which is 8081 in my case
[/sourcecode]



2.  Add the following configuration for virtual host:
[sourcecode language="text"]
ServerName virtual name of your server
ServerAdmin your email address
DocumentRoot /srv/www/...../cmsdj/
WSGIScriptAlias / /srv/www/..../cmsdj/apache/django.wsgi
Order allow,deny
Allow from all
ErrorLog /srv/www/..../cmsdj/logs/error.log
CustomLog /srv/www/..../cmsdj/logs/access.log combined
[/sourcecode]

3. Create django.wsgi file under your app folder
The detail path to your wsgi file is in the upper virtual host configuration file:

[sourcecode language="text"]
/srv/www/...../cmsdj/apache/django.wsgi
[/sourcecode]

The content of this file:

[sourcecode language="python"]import os
import sys
path = '/srv/www/foodborn.nctr.fda.gov/' #do not add the project folder name to this path
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'cmsdj.settings'
os.environ['PYTHON_EGG_CACHE'] = '/srv/www/foodborn.nctr.fda.gov/.python-eggs'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
[/sourcecode]

4.  Check your project’s urls.py file to make sure that you are using the full path to the models you are importing and in the urls maps:

[sourcecode language="python"]
a. (r'^$', 'core.views.index') is not the full path since you are omitting the name of the project, which should be changed to (r'^$', 'cmsdj.core.views.index'),
b.  “from core import views”  is not the full path, you need add project name “from cmsdj.core import views”
[/sourcecode]

Part Three: serving the admin files
Make sure your project’s settings.py file contents this sentence:

[sourcecode language="bash"]
ADMIN_MEDIA_PREFIX = '/media/'
[/sourcecode]

Then you run the following command to collect all the static files needed by admin models into the project admin folder.

[sourcecode language="bash"]
python manage.py collectstatic
[/sourcecode]

References:
1. http://blog.perplexedlabs.com/2008/11/10/setup-python-25-mod_wsgi-and-django-10-on-centos-5-cpanel/
2. https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#module-django.contrib.staticfiles
3. https://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

Configure mod_wsgi with Apache for running Django project

Part One: prepare the environment
 1. Download source code of modwsgi from http://code.google.com/p/modwsgi/downloads/list
 2. Unpack the downloaded package tar -zvxf package_name
 3. Enter the unpackaged folder, run. /configure 
 4. if you encounter an error, make sure you have development package of httpd (apache) installed on your machine.
 to install the development package of Apache, run yum install httpd-devel.x86_64 
 5. re-run $./configure
 6. $ make
 7. sudo make install
 8. create file mod_wsgi.conf under /etc/httpd/conf.d, ans add th efollowing line to the file you created:
 LoadModule wsgi_module modules/mod_wsgi.so
 9. restart the httpd service: sudo /etc/init.dhttpd restart
10. make clean

 Part two: make necessary configuration in httpd.conf file located in /etc/httpd/conf/
 In this part of the configuration we are using the Apache VirtualHost to host the django project.
 1. Configure apache to server VirtualHost:
 a. add one more port for listening by Apache which will be specifically used for virtual host:
 Listen 8081
 b.  uncomment NameVirtualHost *:80 and change the port number from 80 to the port number you defined in step (a), which is 8081 in my case
 2.  Add the following configuration for virtual host:
 <VirtualHost *:8081>
    ServerName virtual name of your server
    ServerAdmin your email address
    DocumentRoot /srv/www/...../cmsdj/
    WSGIScriptAlias / /srv/www/..../cmsdj/apache/django.wsgi
    <Directory /srv/www/..../cmsdj/apache>
      Order allow,deny
      Allow from all
    </Directory>
    ErrorLog /srv/www/..../cmsdj/logs/error.log
    CustomLog /srv/www/..../cmsdj/logs/access.log combined
</VirtualHost>
3. Create django.wsgi file under your app folder
 The detail path to your wsgi file is in the upper virtual host configuration file:
 /srv/www/foodborn.nctr.fda.gov/cmsdj/apache/django.wsgi

The content of this file:
import os
import sys
path = '/srv/www/foodborn.nctr.fda.gov/' #do not add the project folder name to this path
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'cmsdj.settings'
os.environ['PYTHON_EGG_CACHE'] = '/srv/www/foodborn.nctr.fda.gov/.python-eggs'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

4.  Check your project’s urls.py file to make sure that you are using the full path to the models you are importing and in the urls maps:
  a. (r'^$', 'core.views.index') is not the full path since you are omitting the name of the project, which should be changed to (r'^$', 'cmsdj.core.views.index'),
b.  “from core import views”  is not the full path, you need add project name “from cmsdj.core import views”

Part Three: serving the admin files
 Make sure your project’s settings.py file contents this sentence:
 ADMIN_MEDIA_PREFIX = '/media/'
  Then you run the followingcommand to collect all the static files needed by admin models into the project admin folder.
 python manage.py collectstatic

 
References:
1.      http://blog.perplexedlabs.com/2008/11/10/setup-python-25-mod_wsgi-and-django-10-on-centos-5-cpanel/
2.      https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#module-django.contrib.staticfiles
3.      https://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/






Bypass views to render a static page/template in Django Project

 Django project

Bypassing views to render a static template, add this line in "urls.py". For example "About Us" page could be:
(r'^about', 'django.views.generic.simple.direct_to_template', {'template': 'path/to/about_us.html'}),


** please note you have to save the about_us.html into template folder of your project.

Bypass views to render a static page/template in Django Project

 Django project

Bypassing views to render a static template, add this line in "urls.py". For example "About Us" page could be:
(r'^about', 'django.views.generic.simple.direct_to_template', {'template': 'path/to/about_us.html'}),


** please note you have to save the about_us.html into template folder of your project.

Use Django-registration with Django project

1. Donwload django-registration

2. un-tar the file and copy the regostration folder into your django project as an app

3. set up the settings.py by adding the 'registration' into the INSTALLED_APPS = ()

4. also adding the followings to the settings.py file:
  • ACCOUNT_ACTIVATION_DAYS = 7
  • EMAIL_HOST = 'localhost'
  • DEFAULT_FROM_EMAIL = 'WEBMASTER@LOCALHOST'
  • LOGIN_REDIRECT_URL = '/'
4. mkdir /project_root/templates/registration/

5. copy templates files into the registration folder made in  step 4. You can download the templates files hereat https://github.com/vladimir-webdev/django-registration-templates



Has not finished yet....

Use Django-registration with Django project

1. Donwload django-registration

2. un-tar the file and copy the regostration folder into your django project as an app

3. set up the settings.py by adding the 'registration' into the INSTALLED_APPS = ()

4. also adding the followings to the settings.py file:
  • ACCOUNT_ACTIVATION_DAYS = 7
  • EMAIL_HOST = 'localhost'
  • DEFAULT_FROM_EMAIL = 'WEBMASTER@LOCALHOST'
  • LOGIN_REDIRECT_URL = '/'
4. mkdir /project_root/templates/registration/

5. copy templates files into the registration folder made in  step 4. You can download the templates files hereat https://github.com/vladimir-webdev/django-registration-templates



Has not finished yet....

Datatable static image not found on the server

When you use ```datatables.min.css``` and ```datatables.min.js``` locally, instead of datatables CDN, you may have encountered that ```sort...