An Internet Scrapbook

Automated Updates with Drush

Check for available updates: drush ups

Put site into maintenance mode before updating using:

drush sset system.maintenance_mode 1
drush cr

Then execute the updates:

Update Drupal core: drush up drupal
Update a single module: drush up module_name
Only apply security updates: drush up –security-only

This is a more selective/cautious approach to updating everything with drush up

Next, apply any required database and entity updates:
drush updb
drush entu
p

Now check your site is OK – look at the status report page, test the site, and finally turn maintenance mode off if applicable:

drush sset system.maintenance_mode 0
drush cr

Finished. Go to admin/reports/status to check for errors.

Explanation of Trump Victory

Many folks have spent many hours recently contemplating the recent Presidential election. I have been among them, and so far I have come up with what follows. I may change my mind later.

The results indicate a geographical divide exists in the United States. With the exception of the Rust Belt, we have blue states on the two coasts and red states in between. We can also see that heavily urban areas belong to the Dems while the Reps dominate in the rural areas. That division is not new. It has been around for at least three decades, if not longer. Trump won all the states he was expected to win, which includes most of the states between the coasts, but he also won what we must call The Big Three in this election: Michigan, Ohio, and Pennsylvania. The Reps do not always win those three, and a reason may be that those three states are pretty heavily urban, or at least they all have several cities (well, Michigan only has one, but it is really big). So much for the urban-rural divide. Apparently, the GOP got the rural vote and enough of the urban vote to win the electoral vote. The rural folks certainly voted for Trump — not just in these three states but all over the country — but the urban vote didn’t fall completely in line for the Dems. But is this the real reason for Trump’s win?

I was starting to buy this explanation of the result until I started listening to people who analyze this stuff for a living. Granted, most of them were dead wrong in their predictions, but with the benefit of hindsight many have recovered and are assessing their own screw-up to the good of others who are still sort of in the clouds on this election. Their expert comments provided me with the aha moment I needed to develop my own theory of what happened. My realization, of course, had little to do with their actual blathering. After all, the media’s credibility is now nonexistent in any analysis of this election.

About 35% of America is comprised of people who would be attracted to Trump no matter what. These include the racists, sexists, xenophobes, homophobes, and any other group found distasteful to the liberals. As Trump himself pointed out, he could shoot someone in downtown New York in broad daylight and not lose one of those supporters. They are rock solid. But outside of that 35% he would be hard pressed to find anyone who would want him to be President. The problem for the Dems is that they were fighting the same image problem with Hillary. Most people didn’t want either one of them as President, but it was the media and not the people that provided the killer fodder that sunk the Clinton ship. The majority of the print and broadcast media told the country that the Dems would win. Get ready for another Clinton in the White House.

A short diversion before I deliver the definitive reason for Trump’s victory. In 1984, Mitch McConnell was running for his first term in the Senate against two-term incumbent, Dee Huddleston. Pretty much everyone, including the local media outlets, predicted a Huddleston win. I didn’t want to vote for Huddleston because I detested his support of a movement advocating that English be declared the official language of the United States. Why would a senator from Kentucky care about such an issue? We could count the number of Kentucky residents speaking a foreign language on our fingers (ok, maybe we needed our toes as well), so Huddleston was obviously playing politics and doing a favor for a colleague from a border state. [By the way, after Huddleston was defeated he became the chair of the English Language Political Action Committee (ELPAC), which not only advocated for English but also wished to limit immigration.] Anyway, all fingers were pointing toward a Huddleston victory. I didn’t particularly like McConnell — in fact, I didn’t like him as Country Judge Executive, the position he held in Louisville, Kentucky, before he ran for senator — but I was confident he would lose. Thus, I voted for him, but really I was voting against Huddleston. Shock! McConnell won by only about 5,000 votes. How many of my fellow Kentuckians made the same blunder I did! Here we are over 30 years later and Mitch is still in the Senate!

Thus, my explanation for the Trump victory. People didn’t like Hillary and they didn’t like Trump. The press convinced them that Hillary was going to win, so they felt that they could do their civic duty — that is, vote — and not have to sell out their integrity. They didn’t want to vote for Hillary so they cast sort of an anti-vote for Trump, being assured by the media that there was no way Trump would win. And across The Big Three only about 100,000 votes gave us The Donald. I hope it does not take as long to get rid of him as it has to get rid of Mitch.

Spanish Verbs with Spelling Changes

When I first attempted to lean Spanish I was a bit overwhelmed by how many “irregular” verbs there are in the language. However, I ran across a little snippet in an old Spanish grammar book that helped sort this out for me. Not only did it help with some of these so-called irregular verbs, but it renewed my faith in my belief that knowing how a word is spelled facilitates language learning. Many Spanish learning systems essentially ignore any formal lessons in spelling or grammar in favor of having the students focus on phonology. Of course, listening to native speakers is crucial for learning a language, but sometimes a newbie to a language will hear the speaker incorrectly and thus think he or she has learned a certain work or sound only to learn later that such was not the case. If the sound of a word is coupled with its spelling those types of errors can be reduced.

So what I originally thought of as irregular verbs turned out to be pretty regular once I learned a few basic spelling rules in Spanish. Of course, there are always exceptions to rules, but spelling in Spanish is much more consistent than I had originally realized.

Consider the verb “modificar” (modify, change, moderate). Because it is an -ar verb we know that the present the conjugation is ‘modifico, modificas, modifica, modificamos, modificais, modifican,’ but in the preterit we get ‘modifique, modificaste, modifico, modificamos, modificasteis, modificaron’. Why isn’t the first person singular in the preterit ‘modifice’? After all, that is how other -ar verbs are conjugated. Well, not all -ar verbs, I guess. ‘Buscar’ in the preterit yo form is busque, pagar is pague, and just to make life more confusing comenzar is comence.

But they are not all that bizarre. They are following rules.

The sound /k/ is written as c before a, o, and u. But it becomes qu before e and i. Thus, what we would expect to be “modifice” should be modifique and “busce” should be “busque.” So the preterit yo form of indicar is indique, of pescar it is pesque, of secar it is seque, and so on. Very regular once you know the spelling rule.

Here are a couple more rules:
The /g/ sound is written as a g before a, o, u, but becomees gu before e and i. So the preterit of pagar is pague.
The /s/ is written as a z before a, o, u but become c before e and i. Thus, comenzar is comence in the yo preterit form.

Dates In Unix/Linux

(copied from http://www.mustbebuilt.co.uk/php/handling-dates/)

There are a series of functions built into both PHP and MySQL which will help you when working with dates.

UNIX Timestamps

The UNIX timestamp represents the number of seconds that have passed since the 1 January 1970 and for PHP it is the only way it really understands time and dates. However, PHP has lots of ways to manipulate and represent this number in all the many ways we do with dates and time.

Creating Timestamps with time(), mktime() and gmmktime();

The function time() returns an integer which is a UNIX date/time stamp.

<?php
echo time();
//outputs something like 1139328834
?>

The function mktime() can be feed integers for the hour, minute, second, month, day and year for the required timestamp. The output would still be an unfriendly integer representing the seconds since 1 January 1970.

<?php
$mydate1 = mktime(1,30,50,12,13,1971);
echo $mydate1;
//outputs 61435850 the number of seconds since 1 January 1970
?>

The function gmmktime() works the same as mktime() but whereas mktime() uses local time gmmktime() uses Greenwich Mean Time (GMT).

Using strtotime()

The function strtotime() can be used to create timestamps between December 13 1901 and January 19 2038. The function accepts dates in the format “05 DEC 2004” and “12/05/2004”.

Warning: Note the use of the American style of shorthand date ie 12/05//2011 for 5 December 2011.

<?php
$mydate = strtotime("5 MAY 2006");
echo $mydate;
?>

This is useful when you are allowing the user to enter dates and need to compare it with another timestamp.

Getting the Current Date/Time with getdate()

The getdate() function will output the current date/time. The function takes a timestamp value as a parameter. If not is provided the current date is returned.

<?php
$today = getdate();
print_r($today);
?>

Notice that the timestamp can be output as an array.

Array ( [seconds] => 8 [minutes] => 4 [hours] => 14 [mday] => 8 [wday] => 3 [mon] => 2 [year] => 2006 [yday] => 38 [weekday] => Wednesday [month] => February [0] => 1139407448 )

A timestamp is an associate array.

The strtotime() function can also be used to get the current time

<?php
$currentdate = strtotime("now");
echo $currentdate;
?>

The date is still in integer format.

Formatting a Date with date() and strftime()

The integer format of the timestamp is not particularly user friendly. Therefore there are various techniques to format date output.

The date() function takes a timestamp and formats it according to user defined format characters.

<?php
$mydate = strtotime("1/31/80");
echo date("D d M Y", $mydate);  //  outputs Thu 31 Jan 1980
?>

Headline format characters are:

d
Day of the month, 2 digits with leading zeros 01 to 31
D
A textual representation of a day, three letters Mon through Sun
j
Day of the month without leading zeros 1 to 31
l
(lowercase ‘L’) A full textual representation of the day of the week Sunday through Saturday
F
A full textual representation of a month, such as January or March January through December
m
Numeric representation of a month, with leading zeros 01 through 12
M
A short textual representation of a month, three letters Jan through Dec
n
Numeric representation of a month, without leading zeros 1 through 12
t
Number of days in the given month 28 through 31
Y
A full numeric representation of a year, 4 digits Examples: 1999 or 2003
y
A two digit representation of a year Examples: 99 or 03

Taking our earlier example

<?php
$mydatetest = strtotime("1/31/80");
echo date("l j F Y", $mydatetest);  // outputs Thursday 31 January 1980
?>

In addition the strftime() function can be used for date formatting. Like date() this takes formatting rules (known as conversion specifiers) and a timestamp.

Headline conversion specifiers are:

%a
abbreviated weekday name according to the current locale
%A
full weekday name according to the current locale
%b
abbreviated month name according to the current locale
%B
ull month name according to the current locale
%d
day of the month as a decimal number (range 01 to 31)
%D
same as %m/%d/%y
%e
day of the month as a decimal number, a single digit is preceded by a space (range ‘ 1′ to ’31’)
%m
month as a decimal number (range 01 to 12)
%y
year as a decimal number without a century (range 00 to 99)
%Y
year as a decimal number including the century

Therefore:

<?php
$mydatetest2 = mktime(1,30,50,12,25,1986);
echo strftime("%d %B %Y", $mydatetest2);
//outputs 25 December 1986
?>

Validating Dates with checkdate()

Use checkdate() to check if date is a valid Gregorian date. Returns a boolean true/false. The date is passed to checkdate() in the format

checkdate( int month, int day, int year )

This is useful when allowing users to enter dates as it will catch incorrect dates such as 31 Feb 2012 and leap year adjustments.

<?php
echo checkdate('2', '31', '2001');
//no output as false date – no date 31 Feb
echo checkdate('1', '31', '2001');
//outputs 1 to indicate true – yes 31 Jan valid
?>

Date Picker

A popular way to ensure date accuracy is to use a date picker. With many of the Javascript date pickers available you can choose to have the date formatted in a MySQL friendly YYYY-MM-DD format.

Tip: The jQuery UI project offer an excellent javascript based date picker that can be customized for almost any purpose.

HTML5 Form Fields

Although browser support is not yet consistent HTML5 offers a new form field type of date. In some browsers this will automatically produce a date picker with no need to use PHP or indeed Javascript.

<input type="date" name="startDate">

This is what your browser makes of it:

Outputting Dates From MySQL

In MySQL dates are stored in the date format YYYY-MM-DD ie 2012-11-30. This is not a particularly user friendly output format.

There are two ways to approach this. Either format the date via PHP or via the SQL statement.

Using PHP to Format MySQL Dates

To format a date from a database query we could use two of the date functions in combination.

The strtotime() function can be used to convert the YYYY-MM-DD format from MySQL into a timestamp.

<?php
$timestamp_date = strtotime($database_date);
?>

Then the timestamp could be formatted with the date() or the strftime() function.

<?php
$display_date = date("D d M Y", $timestamp_date);
?>

This could be combined in one line.

<?php
$display_date = date("D d M Y", strtotime($database_date));
?>

Using SQL to Format MySQL Dates

In SQL the DATE_FORMAT() function can be used. The function is wrapped around a valid date field name from the database and feed formatting rules. In the SQL this formatted date should be allocated with an ‘AS’ to a new field name for outputting.

$query = "SELECT DATE_FORMAT(release_date, '%d/%m/%Y') AS df_release_date, product_name FROM products";

Like the PHP functions strftime() and date() the DATE_FORMAT function accepts specifers. Headline specifiers are:

%a
Abbreviated weekday name (Sun..Sat)
%b
Abbreviated month name (Jan..Dec)
%c
Month, numeric (0..12)
%D
Day of the month with English suffix (0th, 1st, 2nd, 3rd, …)
%d
Day of the month, numeric (00..31)
%e
Day of the month, numeric (0..31)
%M
Month name (January..December)
%m
Month, numeric (00..12)
%Y
Year, numeric, four digits
%y
Year, numeric (two digits)

As such the following:

SELECT DATE_FORMAT(release_date, '%D %b %Y') AS df_release_date, title FROM videos;

Would format the date as:

30th Nov 2011

Querying by Dates in MySQL

When querying a date in a MySQL database we need to place the date in the format:

YYYY-MM-DD ie 1999-05-30
or
YY/MM/DD ie 99/5/30

Warning: The date must be treated as a string in the SQL statement

Inputting Dates into MySQL

As with querying by date, the date chosen by the user needs to be in the correct format for MySQL. Notice how in the mysqli example below how the prepare statement treats the date as a string.

$filmDate = "2013-01-31" //YYYY-MM-DD
$stmt = $mysqli->prepare("INSERT INTO movies(filmRelease) VALUES (?)");
$stmt->bind_param('s', $filmDate);
$stmt->execute();
$stmt->close();

To generate a MySQL friendly timestamp using PHP we can use the date() method ie:

$thisDate = date('Y-m-d');
echo $thisDate; // output as YYYY-MM-DD

If you want the time as well then use:

$thisDate = date('Y-m-d h:i:s');
echo $thisDate; // output as YYYY-MM-DD H:M:S

Tip: If you want to use GMT then use the gmdate() variant of the date() method. It works exactly the same but returns the date/time according to Greenwich Mean Time (GMT)

Date Stamps in MySQL

Often with a database it is useful to have a field that represents the last time (and date) when a particular field was updated. This can be done via phpMyAdmin. When creating your field in the database create it as a datatype of ‘timestamp’.

phpmyAdmin-autodates

Then edit this field in phpMyAdmin and you will see the option to set a default value to ‘CURRENT_TIMESTAMP’. This will mean that when a new record is created the current date/time is entered automatically to that field. In addition, under the attribute option for that field, you can choose ‘ON UPDATE CURRENT_TIMESTAMP’. This will ensure that when the record is updated with a SQL UPDATE statement, the field is automatically updated – so you don’t need to send a new date value through to the database – neat.

Installations of phpMyAdmin vary so if you don’t see the option above you can run the following SQL to add a current timestamp when a field is updated:

ALTER TABLE `yourtable`
CHANGE COLUMN `yourlastUpdatedField`
TIMESTAMP NOT NULL 
DEFAULT CURRENT_TIMESTAMP 
ON UPDATE CURRENT_TIMESTAMP;

Foreign Character Shortcuts for Microsoft Word 2010

Ctrl+’ Adds an acute accent to the character typed next
Ctrl+’ When followed by d or D, creates the old English character “eth”
Ctrl+` Adds a grave accent to the character typed next
Ctrl+^ Adds a circumflex to the character typed next
Ctrl+~ Adds a tilde to the character typed next
Ctrl+: Adds a dieresis or umlaut to the character typed next
Ctrl+@ Adds a degree symbol above the letters a and A; used primarily in Danish, Norwegian, and Swedish
Ctrl+& Creates combination or Germanic characters based on the character typed next
Ctrl+, Adds a cedilla to the character typed next
Ctrl+/ Adds a slash through the letters o and O; used primarily in Danish and Norwegian
Alt+Ctrl+? Creates an upside-down question mark
Alt+Ctrl+! Creates an upside-down exclamation mark

Upload a zipped Presenter Presentation to Blackboard.

HOW TO: Upload an Adobe Presenter Zip File to Blackboard

To upload an Adobe Presenter zip file to Blackboard, please follow the steps below:

  1. Login to Blackboard and navigate to the course.
  2. Under Course Management/Control Panel, click on Content Collection.
  3. From the choices available, click on the Course ID to access the Course Content page.
  4. Create a Folder for the Lectures and then click on the Folder's name to open it.
  5. Hover your mouse on the Upload button in the gray bar and choose Upload Zip Package from the drop-down menu.
  6. Click Browse to find and upload the zip file you wish to use, and then click Submit.
  7. Next, go to the Content area in the course menu where the lectures will be available for the students.
  8. Click on the Lecture folder or where you want the lecture to appear.
  9. Hover your mouse on Build Content and select Item from the drop-down menu.
  10. When the Create Item page opens, type in a Name for the Item.
  11. Under Attachments, Browse Content Collection to attach the file. Select index.htm under the Lectures folder.
  12. Once the file is attached, click on Link Title to give the index.htm a lecture name.
  13. Set the Standard Options or accept the default.
  14. Click Submit.

Alert! System battery voltage is low.

Alert! System battery voltage is low.
Strike F1 key to continue F2 to run the setup utility
Press F5 to run onboard diagnostics

When you see this alert you need to follow a sequence of steps to get your system to boot again. The steps listed here work for a Dell Optiplex 755, and I have used very similar steps for other Dell models. Just try to get the gist.

  1. Unplug the power cord from the computer.
  2. Remove the cover.
  3. Take out the hard drive (make sure to unplug the cables connected to the hard drive — should be two of them)
  4. Locate the battery. On the small form 755 it will be under the fan. There is a screw that holds the fan cradle in place, so remove that screw and slide the tabs out of their places on the sides of the blue cradle that holds the fan (be careful because there are many things plugged into the motherboard that you do not want to have to figure out). Then you can raise the fan up and see the battery.
  5. Remove the battery and inspect it to see what type battery it is.
  6. Ascertain a replacement battery. Make sure the replacement battery is the same type as the one you remove. The 755 uses a 2032.
  7. Place the new battery in the battery slot (if there is tape on the bottom of the battery remove it). The flat part that has the brand, model, etc., etched on it should be facing up.
  8. Replace the cradle and secure it with the screw you took out previously
  9. Replace the hard drive and plug in the cables
  10. Replace the cover
  11. Plug in the computer’s power cable. That may start the computer. If so, you can let the computer power up. You will get two or three messages, including the alert about the system battery voltage being low. Don’t worry about it. You need to change some settings to reset the system
  12. Press F2 and go into the BIOS setup.
  13. On the Dell System 755 there is a menu on the left. Use the DOWN arrow to go to Maintenance.
  14. With the Maintenance item highlighted press ENTER. On the drop down menu go to Load Defaults and press ENTER.
  15. On the right side of screen press the RIGHT arrow and go to Continue and press ENTER.
  16. Under the title “Faculty Default Acknowledgement the OK should be highlighted. Press ENTER and you will be taken back to the previous menu. The Load Defaults item on the Maintenance submenu should be highlighted.
  17. Press the UP arrow until you get to the Drives menu item and then press ENTER.
  18. On the Drives submenu go DOWN to SATA Operation and press ENTER. You will probably see on the right side of screen the AHCI item highlighted. You want to highlight the ATA item so use the RIGHT arrow to highlight ATA and press Enter.
  19. You will see a popup menu that tells you the SATA Operation is being changed. Press the RIGHT arrow to ACCEPT the change. And press ENTER.
  20. SATA Operation on the left menu should now be highlighted. Press the UP arrow to get to Module Bay menu item and press ENTER
  21. Under Module Bay title, you will see On highlighted. Press the LEFT arrow to highlight IDE and Press ENTER
  22. The Module Bay menu item should be highlighted now. Press the UP arrow until to get to the System menu item. Press ENTER and use the DOWN arrow to get to the Date/Time submenu and press ENTER. (Actually, on my 755s the System submenu is available when I go into Setup. Your may or may not be, but whichever it is just find the Date/Time menu item).
  23. With the Date/Time menu item highlighted press ENTER.
  24. Set the proper date and time and press ENTER.
  25. You are now finished with Setup so press ESC.
  26. Use RIGHT arrow to highlight Save/Exit on the right side of screen. Press ENTER.
  27. The system will reboot. When you see the Dell Logo window press CTRL-P. This is the Management Engine BIOS Extension.
  28. When you get the blue and black screen notice that you are asked for a password. The factory default is ‘admin’ so type that into the space asking for the password and press ENTER.
  29. Now an item at the top of the page will be highlighted. Use the proper arrow to select the Change Intel(R) Password and then press ENTER.
  30. Type in a new password. The system requires a strong password, so you must include at least one upper case letter, one lower case letter, a number, and a special character (I always use an exclamation point !). Also, the password must be at least 8 characters long. After you type it you will be asked to type it again to verify it.
  31. Once verified you will be taken back to the menu at the top of the page. Select EXIT and press ENTER.
  32. You will be asked whether you are sure you want to exit. Press Y.
  33. Your system should now reboot. If you were repairing a disk or doing some other maintenance you may have to shut the system down and do a hard boot.

Simple Use of Cloud Computing in Education

If you do a Google search for cloud computing in an attempt to find out how it is being used, you often get hits that really don’t tell you much. You are told how wonderful cloud computing is and how it saves money, time, hardware, energy, etc. You are told that you can use applications without having to download them, how you can have access to your data anytime, anywhere. It is all quite wonderful.

But what if you want to actually use it and you are not part of some company that is using SAAS or PAAS or some other iteration of cloud computing? What if you just want to get your feet wet?

I found that a good way to ease into this morass is to start simple. Start with securing some “cloud” storage space. If you have an Apple IPhone, IPod, or IPad you have at least five gigabytes of storage space “in the cloud” at your disposal. You probably don’t realize it, but you use that space whenever you back-up your device. You may not even realize that you back up your device. But you probably do. It is probably done for you. So you may be using the cloud without realizing it.

Yes, it is that easy.

dropboxBut let’s turn to a simple example of how a teacher/professor might use this storage space to help improve the efficiency of his or her class. Assume the prof gets an account with one of the many providers of free storage space (besides Apple). I like to use Dropbox.com. So I go to Dropbox.com and create an account by following the instructions on the page — takes about a minute or two. Then I create a folder on my new account, and I call the folder “CommClass” (I call it that because I teach courses in communication). Then I get a list of my students’ email addresses and I “invite” each one of them to “join” my CommClass folder. It may take a day or two for all of them to join but they all do. Of course, each student has to create an account on Dropbox.com as well in order to join my folder. They all do.

Now, I have a “shared” folder (CommClass) that is being shared with all my students. Anything I put into that folder will also show up on their accounts because my shared folder acts like any folder the student might have created. I can put up assignments, handouts, exercises, notes, and so on — anything I want them to access — and they can get to them anytime, anywhere they have an internet connection. Pretty cool.

But that is not all. I have the students create another folder on their accounts, say CommClassStuff, and have then send me — and me only — an invitation to join. I join everyone’s CommClassStuff folder. Anything the student puts into that folder I can access. So a student completes an assignment and puts it into the folder so I can retrieve it, read it, mark it up, and save it in the same folder so that the student can see my comments. That is also pretty cool, but it gets even better.

If I download a small piece of code from Dropbox.com onto my computer (platform does not matter) when the student saves something into the CommClassStuff folder I get a notifiation that a new item has been placed into the folder, so I can retrieve it on my computer and look at it. I can load the file into whatever application I would like on my computer, mark it up, makes comments, and so on, and then save it back to the student’s folder simply by saving it on my computer. The downloaded code then uploads the file to the student’s CommClassStuff folder.

So I have a complete record of what each student has done and what I said about what each has done, and I have an automatic backup of it as well — one copy on my computer and one copy on the Dropbox.com server. I never have to collect or return papers during class. I never have to hand out handouts during class. I have a permanent record of each student’s work. I can easily share whatever I need to with whichever student needs it. It makes class time much more efficient, especially now that most students bring some sort of device to class with them anyway. Dropbox will work on cellphones, tables, laptops, and desktops. The technology is simple but very productive and anyone can start using it immediately. Each student gets a couple of gigs of storage space free and so far that has been enough for my classes — but if you need more there are ways you can get even more free space.

And Dropbox is not the only service. Like I said, Apple provides free space, as does Amazon, Google, Microsoft, and many others. Just do a Google search for the latest players in the online storage game.