How to read a SPF record and allow Google Apps Gmail to send for your custom domain

An SPF record is a hack. It's a way of using the DNS protocol to say who is allowed to authoritatively send email as a domain name. It does this by using a DNS TXT record (as opposed to an A or MX record). TXT can contain any text. An SPF record is a specially encoded TXT record like this:

"v=spf1 ip4: -all"

The v=spf1 indicates that this is an SPF record, considered version 1 of the spf standard.

After the version, there are any number of 'directives'. In this example, there's only 1...

Import multi-line cells in CSV format into Google Sheets

In Google Sheets (and Excel or Mac Numbers should be similar for most of this), you normally enter a cell's value by hitting enter which moves to the next cell. But if you need multiple lines in a single cell, you need to know the trick of holding command/Apple-key when pressing enter.

If you want to import a CSV file into Google Sheets but get the same effect, then you need to escape the new-line markers.

First, a cell which contains more than one line (instead of each line being on a new row) needs to be "escaped" with double quotes at the start and end of the cell's...

JavaScript Namespaces and Closures instead of Global Variables

Have you heard? Global variables are bad, mmkay? So what should we do if we want to create a variable in our script and be able to refer to it elsewhere, globally?

What's in a Namespace?

A JavaScript namespace is just an idea or practice rather than an explicit feature of JavaScript. That is, you don't create a "namespace object" or declare a namespace. Instead, you would implement a namespace by creating and using an object which would contain sub-variables within it, so that those variables didn't pollute the namespace of the global scope (i.e. everything under the...

Cross-platform node scripts: better-npm-run to the rescue

We know that Node.js is awesome and JavaScript is the ultimate cross-platform language. Node has support for Windows despite the node command being a command line program. Windows users can use the command line shell for node. But the Windows shell environment isn't completely compatible with what Unix/Linux/Mac users are used to (i.e. Bash). The npm package Better-npm-run helps deal with running tasks with node across platforms including Windows.

Get it here:


Web viewports for mobile responsive websites

What is a viewport? You may have seen the meta-tag named "viewport" on newer mobile-friendly websites. The mobile (iOS) version of Safari introduced the "viewport meta tag" and "scale" on the viewport for mobile (scale optionally being one of the special values minimum-scale, maximum-scale, and user-scalable).

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

A viewport is like a logical window. You are on one side of the window looking through to the...

Embed a YouTube video player and control it via JavaScript

YouTube has long made it easy to share and embed videos into websites by giving you the HTML code to just copy and paste wherever you like. Over the years, different technologies have been used to play videos on the web, from Flash object elements to pure HTML5. YouTube's newest API for adding videos to web pages takes care of the technology, automatically choosing the best delivery method on a user by user basis.

YT did have something called the "YouTube JavaScript Player API" but this is out of date so don't use it. Instead use the new...

How to detect a swipe touch event on mobile browsers with JavaScript

Browsers have supported various mouse-based events like clicks, down to the detection of when the mouse button is down and when it's released. You can know the coordinates of the mouse cursor, all in JavaScript. Mobile interfaces have brought some new gestures beyond what desktops provided. One big set of such UI events is from the smartphone's screen allowing touch and even multi-touch. Multitouch allows more types of UI events.

Many mobile apps support swiping, not just as a way to move a visible object around thescreen but applied for the whole screen. Tinder uses left swipe and...

List of all Vim script events

To get an idea of what Vimscript is capable of, take a look at all the events it can react to because basically your script won't do much except when something happens (usually caused by the user) and your script reacts. For example, do something when opening a file, or highlighting a word, or hitting some trigger key. You don't want your script to just be running constantly in a loop in the background, and you also don't want it to stall Vim during its handling of events, including at startup. If you go through Vim's built-in documentation you can find the list of events but I've created...

How to run a cronjob every X seconds in cron

Running a Unix command every few seconds is not something Vixie cron can deal with natively because its smallest level of granularity is the minute. It can easily run a script every minute. But to run a cron job every second, or every 5 seconds, or even every 30 seconds, takes a few more shell commands.

As mentioned, a command can be run every minute with the crontab time signature of * * * * * (5 stars) followed by the command.

Had we wanted to run the command every 5 minutes, we can do that with /5 on the minute field: */5 * * * *....

Solving Error: Cannot use * as String because 'String' is a special class name

If you've ever seen an error message in your PHP 7 website about 'String' being a special class name, e.g. Error: Cannot use Drupal\Component\Utility\String as String because 'String' is a special class name in /Users/jesus/drush/commands/core/, line 4, the reason is that String is now a reserved class name as of PHP 7. So your code that worked fine on PHP 5.7 and earlier will now be broken. This affects Drupal but could affect any old PHP site with a class called String.

This is a problem with Drupal 8 which moved to an OOP-everywhere approach, so...

Move a div element to another div using jQuery

jQuery is good for many things related to the DOM - both querying and manipulating. Yes, we can move elements from one position to another with the help of jQuery, or add completely new elements (as in literal HTML text strings) anywhere in the DOM just by having a selector, and if a selector applies to multiple DOM nodes then adding into multiple places can be done with one call.

jQuery provides many functions for moving or adding elements/content: after, append, appendTo, before, insertAfter, insertBefore...

Drupal 8: Get the current Node's NID

Theming Drupal can be like working with layers of an onion. There are layers and layers and sometimes cutting through makes you cry. Besides not knowing what theme function or template file one must use (Drupal 8 helps with the knowing part with html comments) there is the big problem of global state and context, and the theme layer you're trying to use might be missing some context. The major example is that you want some block to be aware of the node on the page. (This is a problem which React.js helps deal with by passing state from parent to child component via props.)


Run a shell command on multiple servers over ssh simultaneously

If you have multiple Linux servers out there and have been managing them by hand, there's a better way. You have probably heard of Chef, Puppet, and Ansible, and might have heard that Chef and Puppet are a bit troublesome to get up and running. But there's a simpler way to just connect to a few of your Linux (or BSD) servers and run commands on them.

Example: Tell me what OS and version is running on all my servers

Step 1. Set up your ansible hosts file.

Quick version: Create the file named 'hosts' and put servername ansible_ssh_host=hostname in the...

What is Package.json

If you're looking at some JavaScript code you got from elsewhere, probably Node.js packages, you'll notice each has a file called 'package.json'. This will be in the module's base or root directory. This file is a sort of manifest file for the module, most likely an npm module/package. Any package listed at needs a package.json, and the absolute minimum the file should contain is the package's name and version. The name and version make up a unique key for the package within npmjs.

The file usually contains much more than name and version. You can guess by the...

Time your website speed with simple command line tools

When doing some initial, rough performance evaluation of a website's code, we can use some common tools which should be available on most desktops. Whether on Mac or Windows, you should have access to a command line (Terminal on Mac, git bash or Cygwin bash on Windows) with the regular "Unix" (POSIX) command line tools or GNU versions of them. You should also have 'curl' (and 'wget'), which is non-standard but very common and useful.

In the following examples, replace with your website and page you want to test.

Step 0: ping


What's my (external public) IP address (command line)?

The Internet is running out of IP addresses (ipv4, but years after ipv6 came out we still haven't switched over to it). This is realer than Peak Oil. And so most of us are connected to the Internet with an IP address shared with many other people, with many devices seen by the outside world as having one address.

But more locally, behind a router or gateway or firewall, we all have unique addresses and names to identify each other by. But only locally.

And so each of our devices have two or more possible IP addresses. Each computer should have a local IP address, its main...

Debugging and troubleshooting cron jobs

Usually when I have mysterious problems with a new crontab, it's that I'm not getting any results or output as expected, as if the command didn't run at all. Almost always, the newly added line to crontab was run. What did it do, what was the output, when did cron run? What should we check for?

  • Rarely, there is a problem in the time/data fields. The fields are:

    • minute
    • hour
    • day of month
    • month
    • day of week
    • then the command

    So make sure there are exactly 5 numbers or stars () before the command. Then

  • ...

Solve mysterious Drupal initial page load delay with cron

Sometimes you'll visit your Drupal site in the morning, or after logging in as admin for the first time in awhile, and the page will take forever to load, more than 30 seconds, even longer. (First, if you're using Cloudflare CDN, it could be a problem with their servers not sending the end of the page html when it's finished and thus causing the browser to hang for a long time.)

The main cause of this kind of page load lag is Drupal's cron task! There are two ways that Drupal will run cron. The first is when you trigger it externally (by pinging the cron.php url,...

More virtual memory in Mac OS X

Virtual memory is the RAM that processes see when they're running, the memory space which the operating system allocates to them. The memory is called virtual because the addresses don't necessarily conform to physical memory addresses of the RAM hardware but instead the same address could refer to any number of possible physical addresses. It's up to the OS and the memory hardware to resolve the virtual address to a physical address, and do so transparently to each process.

Virtual memory can also refer to the data which was stored in physical memory but "paged out" to disk. The...

The .htaccess file in Drupal 7 / Drupal 8

An "htaccess" file is a configuration file read and used by the Apache web server to configure settings local to your website or even just a subdirectory in the website. These are local settings as opposed to what you would configure in .conf files in Apache's conf directory.

There should be a dot in the filename: .htaccess - and so the file will often be hidden or invisible in directory listings unless you specify that hidden or system files should appear. But the file should exist in any Drupal installation in the top-most directory of Drupal (next to the README and...