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’.
WWW posts page 27
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:
Tax worries again
This past night I worked on my taxes, a stressful endeavor. I am an independent contractor, which has made things way more complicated than they used to be. I’ve been using the Free File program to use online applications for filling out taxes for years now, usually using TurboTax or H & R Block. They abstract from the forms and walk me through everything, and often provide help when I’m confused, but they can sometimes be worded confusingly. I just do the best I can. The biggest problem with the abstraction is that everything is trapped in this interface, so it’s hard to review it yourself and make sure everything is right.
Every year I worry that I’ve done something wrong, and this year is no exception. Since becoming an independent contractor, having to pay estimated taxes, I don’t really get a “return”, either applying my over-payments to next year or often having to pay additional. This year, though, I have a rather large over-payment, more than enough to pay my first quarterly estimates for 2016. That worries me. I’ve made a fair amount less than last year, so it may be right, but I’m still unsure. I’m going to sit on it and come back to it another night, see what I can do to review it.
Another thing I do every year is say that next year I’m going to work with an accountant. Every next year I wait until it’s too near tax time to comfortably figure out how to do that. I don’t really know how that works or what it would cost. It’s more of a consultation and review of how I’m doing the taxes myself that I need. Maybe next year. We’ll see.
Got moved to a new server in a new datacenter by Dreamhost this weekend. Seems to be significantly faster than the old one for first page load, like an order of magnitude. It’s more in line with what I get when testing locally. I assume the server I was on was just overloaded. It had often had a load average in the 6’s or 7’s. I had been wondering what was wrong and if I should swtich to VPS. This one’s been at less than one. Hopefully it stays snappy and doesn’t get too loaded up over time.
I was using Jetpack’s sitemap plugin and even submitted it to Google until I noticed that it had the wrong protocol for all of the post URL’s. Now Google has a bunch of ‘http’ URL’s for my posts in its listings, even though they are available over ‘https’. I couldn’t figure out how to change the protocol (there is no config or documentation about where that is coming from) so I just disabled the sitemap for now.
WordPress code plugin, a quick solution
I’m slowly copying the markdown versions of my posts after my recent move of this blog. It really is tedious, and I don’t think I’ll finish anytime soon, so in the meantime I created a plugin to output the [ code]
shortcode that wordpress.com put in my post export in the same way that markdown does. This is the first plugin and shortcode I’ve created in a long while, but it was relatively quick to do working off of my posts on plugins and shortcodes. The biggest time consumer was figuring out how to deal with whitespace issues. Apparently, WordPress sometimes will add <p>
and <br />
to shortcode content. Also, there were leading and trailing line breaks adding unnecessary space. My quick solution: