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...

Start a separate Chrome app on OSX with flags from Terminal

Chrome can be opened from the command line. And by running it from the command line you can configure Chrome with a number of options, there are several hundred possible flags which you can start Chrome with.

First of all, just to start/open Chrome from the command line instead of the Dock (or Spotlight) all you need is the path to the Chrome app binary. This is the absolute location of Chrome on Mac OS X: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome. You can copy and paste that to Terminal and it should open Chrome without any special options, or...

Installing Drupal 8 (with differences between Drupal 7) on your web host

Drupal 8 is out and many of the necessary modules have been ported to version 8. Drupal 8 is quite different under the hood from Drupal 7. But it's also fun to play with straight out of the box so let's spin up a new Drupal 8 demo installation. All of this assumes you have shell access, even if you don't normally use the command line, but should be applicable whether ssh'ed to a remote Linux server or testing locally on your Mac OS X laptop. To install Drupal 8 then:

  1. Download Drupal 8 (.tar.gz) and untar it in your web root. (As of publication, the most recent version is

  2. ...

Manage clearing / refreshing cache in Chrome when reloading page

Web developers are constantly clicking the refresh button in their browser to see their latest changes. It almost becomes like a nervous tick, clicking that refresh to get that fix. And it's frustrating when changes on the backend don't result in the reward-inducing changes in the page loaded by the browser.

Web page caching explained

There's two levels of caching, and we deal with them in different places. First, there's flushing any cached resources in the browser, whether in the browser's memory or in files. And then there's requesting non-cached resources from the web...

Clean up Mac ._ files on external/USB disk

Have you ever looked at an external drive with folders created on a Mac but then loaded on Windows or Linux? If you look carefully (turn on viewing of hidden and system files) you'll see a file beginning with ._ for some or many of your files, varying by file type. What are these mysterious '._xxx' files?

Mac OSX Resource Forks

Those ._ files are called resource forks. Resource forks are specific to Mac filesystems. They don't take up too much space and can contain useful data about your files. But deleting them also won't delete your files (the data...

How to watch for file changes and trigger a shell command on any modification in OS X and Linux

These days our files are everywhere, you need an advanced IDE just to track where all the code for a small software project is, and you have many background processes running as dependencies on your main application. It's not always possible to know when a particular file will be updated since it's done via a chain of automatic processes. Have you ever been waiting for a process to run and not notice that it had finished? As developers, we need ways to hook into these chains and be aware of files which change when they change in order to trigger new actions off of those "filesystem events...

Managing OS X Terminal Windows Groups

I prefer OS X's stock Terminal app to iTerm 2 because it automatically reopens and restores previous terminal windows and tabs and keeps the scrollback for each tab (although bash history is lost per tab, reasonable since bash is a separate program from Terminal). iTerm2 used to be a much better Terminal but Terminal has gotten better and is more than usable now. iTerm2 does have some cool features like instant replay/rewind, better support for the mouse for vim. [Note: xterm is also available on stock Mac OS X.]

Besides restoring, you can save your windows and tabs as a 'Windows...

Escaping special characters in markdown

These characters need to be escaped in Markdown in order to appear as literal characters instead of performing some markdown functions:

\ ` * _ { } [ ] ( ) # + - . !

Special escaping for hash (#)

You can usually escape a # with the \ character like others in the above list, but if your hash appears on the same line as an h1/h2/h3 which themselves start with #, ##, or ### then you need extra escaping for the inline #. In this case, add another # at the end...

Vim is grep, and more vim search tips

Something I learned the other day blew my mind even after years of using VI/vim. Because I'd also been using grep for years.

The name 'grep' comes from the vi command g/re/p

g in ex-mode of vi means 'global', so any :g command will apply to all the text in the current buffer.

p after 're' means print.

're' in g/re/p actually just means a regular expression should go there (a vim regular expression, which is different fromregex in PHP or even a re string in grep - this is where vim magic modes...

How to save battery life on MacBooks

Here are some tips I use to optimize battery life on my MacBook Pro. Being aware of energy hogging apps (all browsers) and pausing them can extend your battery life to what Apple advertises.

  1. Open Activity Monitor and switch to the Energy pane. This will tell you who the big offenders are. Chrome is a notorious energy hog, but Safari would be #1 too if you're using it to do a lot of browsing. If there's anything else in there which isn't obvious (like video players, bitcoin miners ;) then you may want to shut them down while you're on battery power. You can also get a summary
  2. ...

Stack traces, backtraces, call stacks explained in JavaScript, Python, PHP

People are rarely happy to see a stack trace. A stack trace often appears when software encounters an exception, an unexpected error which can't be handled gracefully and therefore most stop execution of the program. What the stack trace shows is what was happening in the moments leading up to the bug. The stack is called a stack because each item (each function call) is stacked on top of the previous one in a special part of computer memory called the stack. Most computers and programming languages work with a stack. In programs written in programming languages without side effects, a...

FTP vs SFTP vs FTPS vs SCP/SSH

FTP is the historically standard protocol for copying files from one computer to another over a network connection (TCP/IP, so any host on today's Internet, but it wasn't always the case). Many people including many developers learned how to use an FTP client on Windows in order to connect to a server and upload and download files.

Stop using FTP!

FTP is not secure for the same reason that HTTP is not secure and why there's a movement (Let's Encrypt) to move every website to use TLS, i.e. HTTPS instead of HTTP. The reason HTTP and FTP are not safe is that they are not...

Tricks to get the full path and filename of a file in Finder

Since I do a lot of work in Terminal and find it quicker to process files on the command line for some things so I need to get the path to a file for passing as an argument to Unix commands. It's not obvious at all how to do this from Finder. You can have Finder show the path but there's no way to copy it! Right-clicking only shows the parent directories in order to quickly navigate but not to copy (unlike Windows Explorer where you can access the path like a browser URL).

If you right click a file and select 'Get Info' you will see in the 'Where' section the parent folders are...

Using ExFAT on Mac OSX

ExFAT is an updated version of FAT (Microsoft DOS's original File Allocation Table) meant for use across platforms (not only PCs) and on external drives. Don't confuse exFAT with EXtFS. ExFAT is still a Microsoft product, meaning companies (hardware companies, like memory card manufacturers, who want to use exFAT on their disks/drives) need to pay a licensing fee to Microsoft. It is not open source. ExFAT is the file system I recommend for external USB disks.

Fortunately...

Free mailing list service: MailChimp + MPZmail + MailerLite (Freshmail + Campayn) and an unlimited bonus

How can your organization get free email list management service totaling 6000 managed addresses?

MailChimp is the leader in the full-featured managed mailing list services, helping customers get users signed up to a mailing list, then letting owners manage lists and campaigns, including editing email campgaign templates in the browser. They also let you subscribe up to 2000 members for free, This is a great way for non-profit organizations to get started. But they aren't the only company around for sending emails and their pricing when you pass 2000 subscribers, even if you are...

Drupal SEO in 2016: URLs

SEO is a moving target. For blackhat SEOs, it's a constant back and forth cat-and-mouse game between them and Google. And the potential penalties by Google against sites employing blackhat tactics should be enough to encourage you as a site owner to focus your efforts on whitehat SEO. Drupal has a lot of tools which can help site builders format their content to be easily understood and categorized by search engines. And one of those factors which Google uses is the page's URL.

So it's important to pay attention to a few things related to URLs in your Drupal config.

  1. ...

How to Use Drupal 7 Views to Count Content

Here's how to quickly use Views UI to count content in your Drupal database. You can then display the counts as Blocks or even pages or just use them internally as site admin. The only prerequisite is to have Views and VIews UI enabled.

  1. Create a new view of content (aka nodes). Leave out sorting! (Sorting/ordering won't be visible in the count anyways but can prevent counting from working.)
  2. Under Advanced settings, enable Use aggregation to Yes.
  3. Under FIELDS, only use one main field, such as a title or nid. There should
  4. ...

Scala vs Javascript (ES6, TypeScript, Node.js)

Now with Scala.js allowing isomorphic Scala code to run on both browser and server. Scala contends with JavaScript in the web domain. But assuming we are talking about web, how do the two languages compare?

First, JavaScript comes in a few flavors. There's ES5 which is currently running in all browsers. There's Node.js, which is the same Google V8 JavaScript engine but running outside the browser and thus without browser/web apis included, but which can run ES6 (EcmaScript 6). And then there are the many languages that compile or transpile down to plain old ES5 JavaScript,...

TECH.SAIGONIST.COM | Tips, tricks, hacks, howtos, & research on web development, servers, and software

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /home/tomo/web/tech.saigonist.com/drupal7/php/includes/common.inc:2776) in drupal_send_headers() (line 1486 of /home/tomo/web/tech.saigonist.com/drupal7/php/includes/bootstrap.inc).
  • Error: Class 'CToolsCssCache' not found in _cache_get_object() (line 32 of /home/tomo/web/tech.saigonist.com/drupal7/php/includes/cache.inc).
The website encountered an unexpected error. Please try again later.