Working with Drupal

Working with Drupal

The last couple of weeks have been very exciting as I've managed to migrate two websites (www.onecoursesource.com and www.technicaltrainingresources.com) that were created in Drupal and helped to build a new one in Drupal (www.missionbaymassage.com).  In the last year, I've been doing more and more with PHP programming directly on our company's Point Of Sale system.  At first, I found that working with Drupal was confusing, as what thought would be a web page file was really just an entry in the Drupal database.  

What Got Me Started

The Fedora server that I set up several years to run postfix/dovecot/squirrelmail/ftp/http for our two company domains was at end-of-life for software updates, so we needed to upgrade.  Rather than actually upgrading, a new server was installed, and I was tasked with making the new server do everything that the old server was doing.

How I Fixed Problems


Drush is the Drupal shell.  It gives you an awesome amount of power to work with Drupal.  You can use it to perform updates, download and install modules and themes.  You can do backups and restores.  It also allows you to execute PHP and SQL code for troubleshooting, and more.  I highly recommend this tool for managing a Drupal installation.

Download drush and install it.  drupal.org does keep files for the release of drush, but the project is now maintained at github in the repository: https://github.com/drush-ops/drush

There is documentation available at http://docs.drush.org/ and specifically for installation for English users at http://docs.drush.org/en/master/install/

Start by executing the following commands (the exact file name may vary):

wget http://ftp.drupal.org/files/projects/drush-7.x-5.9.tar.gz  
echo $PATH

Examine the output of the PATH directories listed for an optimal one where you have write permission
In my case, I was limited to my home directory/bin, so I executed -C option with the name of my home directory:

mkdir ~bin
tar -xvf  drush-7.x-5.9.tar.gz -C ~/

Next, create the links to the executables in the directory where you have write permission:

ln -s ~/drush/drush ~/bin/drush
ln -s ~/drush.php ~/bin/drush.php

Now, you can use drush, but before you execute it, you should change to directory where drupal is installed.  In a few of my sites this is /usr/share/drupal, but in this example for HostGator, it is ~/public_html. In order to use drush, cd to the directory where drupal is installed:

cd ~/public_html

If you successfully executed drush, then you can see all the sub commands available:
Execute a drush command. Run `drush help [command]` to view command-specific help.  Run
`drush topic` to read even more documentation.

Global options (see `drush topic core-global-options` for the full list):
 -d, --debug                               Display even more information, including    
                                           internal messages.                          
 -h, --help                                This help system.                           
 -ia, --interactive                        Force interactive mode for commands run on  
                                           multiple targets (e.g. `drush @site1,@site2 
                                           cc --ia`).                                  
 -n, --no                                  Assume 'no' as answer to all prompts.       
                    The absolute path to your PHP intepreter,  
                                           if not 'php' in the path.                   
 -p, --pipe                                Emit a compact representation of the        
                                           command for scripting.                      
 -r , --root=                  Drupal root directory to use (default:      
                                           current directory).                         
 -s, --simulate                            Simulate all relevant actions (don't        
                                           actually change the system).                
 -l ,             URI of the drupal site to use (only needed  
 --uri=           in multisite environments or when running   
                                           on an alternate port).                      
 -v, --verbose                             Display extra information about the         
 --version                                 Show drush version.                         
 -y, --yes                                 Assume 'yes' as answer to all prompts.      

Core drush commands: (core)
 archive-dump (ard,    Backup your code, files, and database into a single file.       
 archive-backup, arb)                                                                  
 archive-restore       Expand a site archive into a Drupal web site.                   
 cache-clear (cc)      Clear a specific cache, or all drupal caches.                   
 cache-get (cg)        Fetch a cached object and display it.                           
 cache-set (cs)        Cache an object expressed in JSON or var_export() format.       
 core-config (conf,    Edit drushrc, site alias, and Drupal settings.php files.        
 core-cron (cron)      Run all cron hooks in all active modules for specified site.    
 core-execute (exec,   Execute a shell command. Usually used with a site alias.        
 core-quick-drupal     Download, install, serve and login to Drupal with minimal       
 (qd)                  configuration and dependencies.                                 
 core-requirements     Provides information about things that may be wrong in your     
 (status-report, rq)   Drupal installation, if any.                                    
 core-rsync (rsync)    Rsync the Drupal tree to/from another server using ssh.         
 core-status (status,  Provides a birds-eye view of the current Drupal installation,   
 st)                   if any.                                                         
 core-topic (topic)    Read detailed documentation on a given topic.                   
 drupal-directory      Return path to a given module/theme directory.                  
 help                  Print this help message. See `drush help help` for more         
 image-flush           Flush all derived images for a given style.                     
 php-eval (eval, ev)   Evaluate arbitrary php code after bootstrapping Drupal (if      
 php-script (scr)      Run php script(s).                                              
 queue-list            Returns a list of all defined queues                            
 queue-run             Run a specific queue by name                                    
 search-index          Index the remaining search items without wiping the index.      
 search-reindex        Force the search index to be rebuilt.                           
 search-status         Show how many items remain to be indexed out of the total.      
 self-update           Check to see if there is a newer Drush release available.       
 shell-alias (sha)     Print all known shell alias records.                            
 site-alias (sa)       Print site alias records for all known site aliases and local   
 site-install (si)     Install Drupal along with modules/themes/configuration using    
                       the specified install profile.                                  
 site-reset            Reset a persistently set site.                                  
 site-set (use)        Set a site alias to work on that will persist for the current   
 site-ssh (ssh)        Connect to a Drupal site's server via SSH for an interactive    
                       session or to run a shell command                               
 test-clean            Clean temporary tables and files.                               
 test-run              Run tests. Note that you must use the --uri option.             
 updatedb (updb)       Apply any database updates required (as with running            
 usage-send (usend)    Send anonymous Drush usage information to statistics logging    
                       site.  Usage statistics contain the Drush command name and the  
                       Drush option names, but no arguments or option values.          
 usage-show (ushow)    Show Drush usage information that has been logged but not sent. 
                        Usage statistics contain the Drush command name and the Drush  
                       option names, but no arguments or option values.                
 variable-delete       Delete a variable.                                              
 variable-get (vget)   Get a list of some or all site variables and values.            
 variable-set (vset)   Set a variable.                                                 
 version               Show drush version.                                             
 watchdog-delete       Delete watchdog messages.                                       
 (wd-del, wd-delete)                                                                   
 watchdog-list         Show available message types and severity levels. A prompt will 
 (wd-list)             ask for a choice to show watchdog messages.                     
 watchdog-show         Show watchdog messages.                                         
 (wd-show, ws)                                                                         

Runserver commands: (runserver)
 runserver (rs)        Runs a lightweight built in http server for development. 

Field commands: (field)
 field-clone           Clone a field and all its instances.                         
 field-create          Create fields and instances. Returns urls for field editing. 
 field-delete          Delete a field and its instances.                            
 field-info            View information about fields, field_types, and widgets.     
 field-update          Return URL for field editing web page.                       

Project manager commands: (pm)
 pm-disable (dis)      Disable one or more extensions (modules or themes).           
 pm-download (dl)      Download projects from drupal.org or other sources.           
 pm-enable (en)        Enable one or more extensions (modules or themes).            
 pm-info (pmi)         Show detailed info for one or more extensions (modules or     
 pm-list (pml)         Show a list of available extensions (modules and themes).     
 pm-refresh (rf)       Refresh update status information.                            
 pm-releasenotes       Print release notes for given projects.                       
 pm-releases (rl)      Print release information for given projects.                 
 pm-uninstall          Uninstall one or more modules.                                
 pm-update (up)        Update Drupal core and contrib projects and apply any pending 
                       database updates (Same as pm-updatecode + updatedb).          
 pm-updatecode (upc)   Update Drupal core and contrib projects to latest recommended 

SQL commands: (sql)
 sql-cli (sqlc)        Open a SQL command-line interface using Drupal's credentials. 
 sql-connect           A string for connecting to the DB.                            
 sql-create            Create a database.                                            
 sql-drop              Drop all tables in a given database.                          
 sql-dump              Exports the Drupal DB as SQL using mysqldump or equivalent.   
 sql-query (sqlq)      Execute a query against the site database.                    
 sql-sync              Copy and import source database to target database. Transfers 
                       via rsync.                                                    

User commands: (user)
 user-add-role (urol)  Add a role to the specified user accounts.                   
 user-block (ublk)     Block the specified user(s).                                 
 user-cancel (ucan)    Cancel a user account with the specified name.               
 user-create (ucrt)    Create a user account with the specified name.               
 user-information      Print information about the specified user(s).               
 user-login (uli)      Display a one time login link for the given user account     
                       (defaults to uid 1).                                         
 user-password (upwd)  (Re)Set the password for the user account with the specified 
 user-remove-role      Remove a role from the specified user accounts.              
 user-unblock (uublk)  Unblock the specified user(s).                               

Other commands: (make)
 make                  Turns a makefile into a working Drupal codebase.  
 make-generate         Generate a makefile from the current Drupal site. 

What Kept Me Going

It was frustrating and difficult to migrate the existing websites because I was not involved in creating them.  My girlfriend was frustrated at the same time that the company hosting her website was not responsive to her requests.  I had been reluctant to create a website for my girlfriend, as I was not wanting to have to be the one who would have to be responsive to all of her requests.

I had reached a tipping point.  I decided that if I helped my girlfriend create a new site in Drupal, then I might have a better understanding of the whole framework.  I was right!  While my girlfriend still has plenty of requests, gradually I'm teaching her how to use Drupal (and HTML) to solve them on her own.  


Reset Samsung 3D BluRay Player

  1. Power on your Blu-ray player and tune your TV to the input where the Blu-ray player is connected. For example, if the Blu-ray player is connected to HDMI 1 press the TV input/source/line button to tune your TV to HDMI 1.
  1. Remove any disc from the player and then press and hold theStop button on the front of the player, not the remote, for about 8 seconds or until the front display reads ‘SETUP’. 'Resetting all settings to default values...' is displayed on your TV screen as the Blu-ray player powers off and resets.
  1. The Blu-ray player is automatically powered on after the reset and the select Language screen is displayed.




HTML 5 is just the continuing evolution of content presented on the Internet. It adds some new elements, and obsoletes others, but it isn't a radical change from earlier versions. The W3C lists these differences.


There are two different standards of HTML 5.  Web Hypertext Application Technology Working Group (WHATWG) publishes what is called a "Living Standard" and was created in response to the slow pace of progress by the World Wide Web Consortium (W3C).


To distinguish a document as HTML 5, the first thing contained in that document should be:
<!DOCTYPE html>

New Semantic Elements

The following are new elements added to HTML 5 to better organize content with meaning:
article, aside, footer, header, nav, and section. Instead of using meaningless div elements to divide up the document, these elements should be logically used.

New Input Elements

There are many new input element types, email and number.

New Editing Elements

To represent text added later use ins and text that should be removed use del elements.

New Audio

New Video

New Canvas

Presentational Markup

It is better to separate the presentation of the text from the text itself by using CSS. This helps to make the document smaller, easier to maintain, and easier accessibility.

HTML5 removes presentational markup language with the exception of the and i which are now intended to represent text that is stylistically different. Of course, as shown above most browsers will render them bold or italic, but it is recommended to use a class, so that CSS can be used to define alternative styles.


Current standard is ECMAScript 5.1 (ES5)
ECMAScript 6 is under development (ES6)
Remember to avoid side-effects:

  • Objects are assigned by reference.
  • Primitives are assigned by value.
  • All function arguments are passed by value
  • Variables declared with var have a function level scope 
  • Variables declared with let will have a block level scope in ES6

Primitives include:

  • numbers
  • strings
  • null
  • undefined
  • true
  • false

Vulnerabilities to Avoid

Cross site scripting (XSS) - Not validating user input. If combined with a database, may be used to SQL injection.

Cross site request forgery (CSRF) - If origin headers are not validated from forms or other user specific tokens embedded in forms, then they may be posted from other sites, often without the user's knowledge.

Clickjacking - pages should check if they are being "framed" with an iFrame by comparing the window object with top.

Do's and Don'ts


  • Start with base functionality and use progressive enhancement and graceful degradation
  • Use a layered architecture separating HTML, JavaScript and CSS. 
  • Use a library like jQuery or Dojo to ease platform and browser differences
  • Use well-known design patterns
  • To ensure events fire for specific elements to run a script, the script should be attached directly to the element.


  • Pollute the global namespace 
  • Modify the Object class prototype
  • Pass strings, use functions to pass to setTimeout and setInterval 
  • Use document.write 
  • Use reserved JavaScript keywords:
    • break do instanceof typeof
    • case else new var
    • catch finally return void
    • continue for switch while
    • debugger function this with
    • default if throw
    • delete in try
  • Use future reserved JavaScript keywords:
    • class enum extends super
    • const export import
  • Use future reserved JavaScript keywords in a strict context:
    • implements let private public yield
    • interface package protected static

Advanced Perl Notes

Advanced Perl Notes

Like many of my blog entries, Advanced Perl Notes is my own list of notes on a subject.  It is one of the worst organized.

Using &subname defaults to call a subroutine in the current package.

Class methods are package methods in the form: PackageName->MethodName();

The my variables are not scoped to a particular package

$VERSION must be placed in a package that has the same name as the file (without the .pm)

File names conventionally match package names

Loading a Perl module like Module.pm with use Module happens at compile time, but loading a module with require Module happens at runtime.

Perl libraries like syslog.pl can be loaded with do syslog.pl  or require syslog.pl.  Require does error checking, and is preferred.  Libraries have difficulty using other libraries so modules are preferred.

Along with references and modules,  Perl release 5.000,  added objects.  

When you use the ref function on an object, it will return the name of the class it belongs to.

sub class_only_method {
    my $class = shift;
    die "class method called on object" if ref $class;
    # more code here

If you want to allow a particular method to be called as an instance method only, do something like this:
sub instance_only_method {
    my $self = shift;
    die "instance method called on class" unless ref $self;
    # more code here

To format dates and times:
use POSIX 'strftime';
print strftime 'Today is %x', localtime

Gnome 3 Desktop Tips and Tricks

Gnome 3 Desktop Tips and Tricks

In updating to RHEL 7 / CentOS 7, I found myself having to live with the Gnome 3 Desktop.  Fortunately, Red Hat has documentation available at DESKTOP MIGRATION AND ADMINISTRATION GUIDE.  As I've been reading through this documentation and other sources, I'll be sharing the helpful tricks and tips that I find.

First, as you might read this documentation, you should know that when they refer to the SUPER key, they mean the Windows key on your keyboard.  Here are some of the shortcuts:


 SUPER + m :  Display the message notification panel, and press ESC to return to normal view
                        This also happens when you point and click at the bottom of the screen, click again to return 
 SUPER + Tab:  Display window switcher

Desktop Customization

In the current desktop environment, you can customize the desktop by using the dconf-editor.
The dconf-editor package is not installed by default, and gives you access to be able to edit the settings of the desktop.  This tool replaces the gconf-editor that was used in Gnome 2 Desktop.  To install the tool you will need to have set yourself as an administrator during installation, or know the root password.

If you have been set up as an administrator, then you can execute and provide your own password:

sudo yum install dconf-editor

Otherwise, if you know the root password, then you can execute and provide the root password:

su -c 'yum install dconf-editor'

After executing as the user whose desktop you want to customize:


Then, you can navigate the tree on the left to org.gnome.desktop and then click on settings on the right to change your desktop settings.  For example you can click on the background and provide a simple file URI to change the desktop from the default xml file.  

For example, clicking on org, then gnome, desktop, and then background on the left, you could then click on picture-uri on the right.  The default setting is an xml file named file:///usr/share/backgrounds/default.xml, but you could set it to something like file:///home/kwright/Pictures/Wallpapers/_DSC1468.png. By the way, an easier way of accomplishing the above is to locate the picture you want to use as a wallpaper, and then right-click on it and choose 'Set as Wallpaper'.

If you liked icons on your desktop, like in the Gnome 2 Desktop environment, then in the same org.gnome.desktop.background part of the dconf-editor, you can select show-desktop-icons.

The org.gnome.desktop.interface selection of the dconf-editor has some nice customization options for the clock like being able to show the date and display a 12 hour clock.

One feature I went looking for and could not find within the standard interface was a way to control how long my session was idle before the screensaver came on.  You can adjust this time by going to org.gnome.desktop.session and selecting idle-delay and entering the number of seconds to delay.

Finally, if you want to lock down what a user can do, then you can go to the org.gnome.desktop.lockdown part of the dconf-editor and lock down the ability of the user to do things such as print, change the print setup, access the command line, and save to the disk among other options.


The gsettings command can be used to get, set and query different keys and schemas. It's main utility is that you can use it in scripts to automate the process of customizing settings. Otherwise, the dconf-editor provides a more user friendly interface, and is easier to explore.

Getting a Key

If I had set the custom background as shown above, then using the following gets what the key picture-uri is set to within the org.gnome.desktop.background schema:

gsettings get org.gnome.desktop.background picture-uri

Setting a Key

To change the value of the same key, again there will be a space between the schema and the key, but using the sub-command set instead of get:

gsettings set org.gnome.desktop.background picture-uri  'file:///home/kwright/Pictures/Exports/2greatblueherons.jpg'

For keys that have a checkbox in the dconf-editor, you can use the value true or false to mean the box is checked or not.  For example, to display the icons on the desktop, you could use true as the value for the show-desktop-icons key:

gsettings set org.gnome.desktop.background show-desktop-icons true

Listing the keys

To list the keys of the org.gnome.desktop.background schema, you can use the list-keys sub-command:

gsettings list-keys org.gnome.desktop.background


For more details about using gsettings, execute:

 man gsettings

Gnome Classic Desktop

Each user can choose whether they want to use classic desktop, which is more like Gnome 2 than Gnome 3, or the real Gnome 3.  By default users login with the classic desktop.  At the graphical login screen, you can click on the settings icon, which looks like a small gear, and choose which installed desktop they want to user.

To switch to the classic desktop for a session, from the command line you can execute:

gnome-shell --mode=classic -r &

If you are in a classic desktop, and want to use the current Gnome 3 desktop, then you can execute:

gnome-shell --mode=user -r &

For making a permanent change to which desktop a user will have, the file /var/lib/AccountsService/users/username can be modified.  The contents of this file on my CentOS 7 system looked like this:


Notice that the XSession is set to gnome-classic.  By default, users user the "classic" desktop.  In order to make the desktop use the true Gnome 3 desktop, then this file would look like the following with the XSession set to gnome.


After updating the file, the user will need to log out and back in again.

Locking Down Settings

If you want to lock down certain settings, and then you can create the following directory by executing as an administrator:

mkdir /etc/dconf/db/local.d/locks/

Next, create a file named something like 00-local-lockdown.  Its contents should be any keys that you want to lock down like the following:


After creating the file, execute as root or with sudo:

dconf update


Python Decorators

Python Decorators

What are Python decorators?

Python decorators are special syntax of the language that allows for functions to be applied to other functions or classes. The Python Enhancement Proposal (PEP) 318 describes the syntax used by these decorators as applied to functions. The Python Enhancement Proposal (PEP) 3129 describes the syntax used by these decorators as applied to classes.

The first use of decorator notation of @function_name appeared in Python 2.2.  The decorators for class methods and static functions were created so instead of using the following for a classmethod or a staticmethod: 

class Foo(object): 
    def bar(cls):
    bar = classmethod(bar)

class Biz(object):
    def baz():
    baz = staticmethod(baz)

The new decorator syntax allows you to call the __builtins__ functions, classmethod() and staticmethod() by using an @function_name syntax. This applied either the classmethod or staticmethod built-in functions to the function that followed the @function_name syntax.

class Foo(object): 
    def bar(cls):

class Biz(object):
    def baz():

PEP 318 also proposed and extended this syntax to be able to be used by user defined functions.  PEP 3129 also extended this syntax to be able to be used by user defined classes. 


Properties are a special case of the use of decorators. In the case of properties, the property function gets called on the function that is either a attribute setter, getter, deleter method of a class. The following two examples are equivalent

class C(object):
    def __init__(self):
        self._x = None

    def getx(self):
        return self._x
    def setx(self, value):
        self._x = value
    def delx(self):
        del self._x
    x = property(getx, setx, delx, "I'm the 'x' property.")

class C(object):
    def __init__(self):
        self._x = None

    def x(self):
        """I'm the 'x' property."""
        return self._x

    def x(self, value):
        self._x = value

    def x(self):
        del self._x

Examples of decorators

There is a repository containing numerous examples at https://wiki.python.org/moin/PythonDecoratorLibrary.


How to network between to VirtualBox virtual machines

How to network between to VirtualBox virtual machines

The problem is that the default NAT networking assigns every machine
NAT works well for Internet access, but not to connect to other virtual machines.

Change the Network adapter to Bridged and then select an active adapter from the host on both guests.
Configure each guest with a unique address that is on the bridged network.
Bridged will allow for virtual machines to connect to each other, but not necessarily to the Internet.

Configure two interfaces: one NAT and one bridged for the best of both worlds!

About Me - WrightRocket

My Photo

I've worked with computers for over 30 years, programming, administering, using and building them from scratch.

I'm an instructor for technical computer courses, an editor and developer of training manuals, and an Android developer.