Blogs

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/watchdog.drush.inc, 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.)

But...

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 npmjs.com 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 example.com with your website and page you want to test.

Step 0: ping example.com

...

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

  • ...