I’m glad that Stir Trek has released videos of its 2016 talks, since I didn’t luck out in getting a ticket this year like I had last year. At least I will (hopefully) be much less tired watching them than when I drove down to Columbus early morning last year. Of course, the videos are good to have even for people who went: These multitrack conferences always seem to have multiple good talks at the same time, including at least one slot with multiple “must see” ones.
WWW posts page 27
Dreamhost must’ve had an outage of some sort this (last) morning. I noticed a little after 11 that I couldn’t upload anything to or log into my (shared) server. My sites were inaccessible. I tried the sites of a couple other people I know using Dreamhost (also shared), and they were also inaccessible, so it must’ve been something somewhat significant. Strangely, nothing relevant was on Dreamhost status. I tweeted about it at 11:20 and got a response from DreamhostCare that they were looking into it. They didn’t say anything more, but I noticed things were up and running again around 11:42. I found later that it must’ve been a DDoS on their nameservers. Outages have been rare, but certainly annoying when they happen.
Duplicate selectors: Increase specificity without being more specific
CSS has a concept of specificity wherein more “specific” selectors take precedence over less specific. Sometimes specificity rules cause a set of property values to be applied while another is desired. This can result in the developer increasing specificity on the desired set to outweigh the other set. When I’ve needed extra specificity, I’ve often use an ‘html’ class on the <html>
element or a ‘body’ class on the <body>
element. The downsides of are it:
- is more specific, as in precise, meaning the selector won’t match in a document without those helper classes.
- has a performance penalty for needing to check a(nother) parent element of the target element.
- only allows one more unit of specificity at the class level for each parent used.
Today (yesterday), I found a better way that can add any amount of class level specificity (weight) without being more specific (precise), thanks to CSS Wizardry. I’ve been doing this CSS thing for a while, but I hadn’t realized .foo.foo
would match <div class="foo">
. In essence, you can duplicate a selector and chain it onto itself to create an equivalent selector, but with double the specificity. You can duplicate it as many times as needed to get the desired specificity, e.g. .foo.foo.foo.foo
to override .foo.foo.foo
, without requiring any parent selectors. Besides the benefits already mentioned, it could be seen as more explicit in its purpose than using parent elements, because there is no other reason to do it. I will have to start using this.
WordPress.com redirects don’t support HTTPS
Gah. Apparently wordpress.com is discouraging ‘https’ for self-hosted blogs: Their redirection service does not allow any protocol but ‘http’. I could swear it did when I first set it up, as I remember typing in my URL with ‘https’ and I thought I tested it with curl -I
to make sure it works, but the docs have an explicit note saying:
Note: Site redirects will only point to a non-ssl ( http:// ) url.
I don’t remember seeing it before, but the wayback machine suggests it was there since 2013, well before I switched to self-hosted.
Continue reading post "WordPress.com redirects don’t support HTTPS"Jetpack’s sitemap plugin has gotten an update or two since I found it listing the wrong protocol for my URL’s, so I decided to give it another try. Now the protocol seems to be correct, so I am leaving it enabled and hoping it helps Google to get my URL’s indexed as ‘https’ instead of ‘http’.
Sending email attachments with PHP `mail`
I recently had to set up a PHP script to send an email with an attachment. With the current version of our CMS, we have swiftmailer available, which would make this easy, but for this site, I didn’t have it easily available. I considered bringing it in, but since this was just a simple script, I decided to give a go at doing it directly with PHP’s built in mail()
function. I found an answer on StackOverflow to guide me. Many respondents to that question recommended just using a library, but the answers that didn’t seemed reasonable.
It took me a number of failed attempts to get the headers and line-breaks just right so that both the email message and attachment sent properly, but I got it working. The code of my solution was fairly specific to the application, so I’ve modified it to make it more generically applicable for this post. The (untested but generic) variant of the solution looks like:
Continue reading post "Sending email attachments with PHP `mail`"SCSS rgba color fallback mixin
Browser support for rgba
colors is very wide, basically working in everything but IE8- and really old browsers. In the name of progressive enhancement, it’s still good to give those browsers a fallback, the simplest being the solid version of the same color. This can be done by putting the property twice, once with a solid value and once with an rgba
value. The non-supporting browsers will take the solid color and ignore the rgba
, while the supporting browsers will take both, with the rgba
overriding. As an example: color: #fff; color: rgba(1, 1, 1, 0.6);
.
To that end, I created a mixin to do this automatically, similar to my remFallback
mixin:
There must’ve been a flexbox bug in Firefox 45. Today, it was brought to my attention that nav was getting cut off on a site. I added a flex-shrink: 0
to ensure the logo shrank to accommodate, fixing the problem in Safari, but not Firefox. Thinking it odd that Firefox was behaving so differently from other browsers, I decided to check for an update, and 46 happened to be available. After updating, the problem disappeared. I’ve ran into browser bugs with flexbox before.
Globbing files including dot-files
Normally globbing for the wildcard *
will find all files in a directory except for ones beginning with a .
. Sometimes I need to get all files including the dot-files. The pattern .*
will find these hidden files, but will also include .
and ..
, referring to the directory and its parent. As I’ve learned in the past, this can be dangerous with commands like rm
, (i.e. you running rm -rf .*
to remove dot-files will remove more than expected). Today, needing to get all files in a particular path in PHP, I sought a solution. A post on a Perl forum gave me a solution using curly braces: {.??*,.[!.],*}
. Braces basically allow multiple comma-separated patterns to be evaluated. The three patterns are:
.??*
matches a dot followed by two characters followed by any number of characters..[!.]
matches a dot followed by a single character that isn’t a dot. This is needed since the previous pattern doesn’t match this case.*
is the normal wildcard glob, matching all non-dot-files.
In PHP, the glob()
function requires the GLOB_BRACE
flag to use braces. An example might look like: $files = glob($path . '/{.??*,.[!.],*}', GLOB_BRACE);
. This did exactly what I wanted.
WordPress plugin: changing rel-canonical
I serve my site over both HTTP and HTTPS to support older browser that can’t support modern or any HTTPS protocols. I prefer HTTPS for search engines and general use though, as it is more secure, increases user privacy, and is factored into SEO rankings. Due to an issue with my sitemap, Google ended up indexing all of my blog pages as HTTP. The first thing I’m going to try to get Google to show my blog pages as HTTPS is to set the rel-canonical
link to the HTTPS version regardless of which protocol the visitor uses. WordPress doesn’t have a built in way to change the canonical URL, and I didn’t want to install a heavy SEO plugin just for this, so I wrote my own.
This simple plugin removes WordPress’s rel_canonical
action, then replaces it with its own. I basically re-implemented WordPress’s own functionality, replacing the http
with https
before outputting the link. It looks like: