Blaine Freelance

Removing content set with :after using :last-child

April 16, 2018

When you use :after to set content, you might then want to remove the content from the last element using :last-child.

I was attempting to do this the other day, and ultimately what I had to do was use two pseudo-elements together.

ul li:last-child:after {
    content: none;
}

That was the selector I ultimately ended up with.

I’ve just discovered Google Apps Script, and it is awesome

December 13, 2017

I’ve recently stumbled upon Google Apps Script, the Tools > Script Editor option available to certain Google web apps like Sheets. The name “Google Apps Script” is kinda weird and clunky in my opinion, so in this article I’ll refer to it as simply “the script editor”.

One particular way in which I’ve been using the script editor, is to create JavaScript functions that will fetch the current price of cryptocurrencies like Bitcoin, Litecoin, and Ethereum, and then update a spreadsheet with these values. This is tremendously cool. With the script editor you can essentially add much more capability to your spreadsheets. In my case, I’m using it to fetch data from a 3rd party API and keep my spreadsheets up to date with the current price of Bitcoin. Pretty neat.

Once I have the current price of Bitcoin set as a cell in my spreadsheet, I can then proceed to use it in novel ways. For example, multiply it by the amount of Bitcoin that I personally hold, and so on. I can then go on to deduce the exact amount of profit I’ve made, and so on. This basically opens up a lot of possibilities, and I can essentially use this spreadsheet to get more information out of my current crytpo holdings than a service such as Coinbase is able to provide. A service such as Coinbase only provides so much information, it won’t show you your exact profit, your principle, and so on… it’s essentially lacking in terms of information that it will provide to you. However, with Google sheets, and a few lines of JavaScript, I’m able to generate the data that is missing from Coinbase, and get a better idea of how my crypto holdings are doing.

 

In case you’re curious, here’s the code I’m using:

 

How to load libraries that depend on the jQuery dollar sign when using WordPress

December 12, 2017

WordPress has its own version of jQuery that you should use. It is generally advised to use the built-in WordPress version of jQuery instead of a different version.

The WordPress version of jQuery removes all definitions of $ from the global scope, meaning, you have to type ‘jQuery’ instead of ‘$’ to use the jQuery library. This is basically so that libraries don’t conflict with each other by all trying to define the $ sign as a variable.

Because of this, you might run into issues where Bootstrap is unable to add functions to jQuery. I ran into this particular problem just today.

I was getting the error message:

TypeError: $(...).scrollspy is not a function

You may get other errors as well, saying `$` is undefined.

What this means is, Bootstrap was expecting the dollar sign to be defined, but it wasn’t, because WordPress undefines it.

The solution? Temporarily define $ and then undefine it.

Essentially, you set $ to jQuery, load the library you need, then unset $ by calling jQuery.noConflict(true), and there you have it.

My thoughts on AWS since switching from my previous hosting provider

November 22, 2017

I’ve recently started using AWS for my website hosting. This website is hosted on AWS in fact. What is AWS? It stands for Amazon Web Services, which is essentially a collection of services provided by Amazon for building and hosting web applications.

My website needs have been pretty small so far, but I’ve switched to AWS anyway to check it out. My bill is actually quite lower since I’ve switched. Funnily enough, my monthly bill comes out to around $1.00. I was previously using another hosting provider, renting a VPS for $10 per month. Quite a reduction in hosting costs.

AWS has a huge variety of services, and seems to work well for websites of just about any size. Even massive web applications that use a lot of bandwidth. The scalability of AWS is another aspect I find appealing about it. In the event that I ever do need tons of servers, I should be able to scale upward pretty quickly.

I’m definitely liking AWS so far. It can feel a little overwhelming with all of the services and options available, but once you get a feel for it it’s quite nice and affordable.

Part of the reason I like AWS is by how you’re billed. You’re only billed for what you use, and so far I’ve ended up saving money, so I’m pretty happy with it.

Should you use WordPress?

November 22, 2017

If you’re looking to start a website, WordPress may be a decent option. WordPress can usually fulfill just about any basic website need you might have, and it’s quite popular and well supported.

You might be turned off by the fact that WordPress is written in PHP. I’ll admit, I was at first. I typically build websites in Ruby or Python, but I’m learning to like WordPress. It’s simple, it’s easy to set up, and it gives me a decent starting point for making a basic website.

If your website is primarily content-driven, then WordPress is not a bad option. If you want a lot of customization, you may want to develop something from the ground up with Ruby or Python.

I use WordPress for blogging mostly. If I wanted something that was more flexible, and I had an idea for a web app, I’d probably go with Ruby on Rails. But for most things, WordPress works great.

Even if you do want to customize some things, WordPress makes it pretty easy to build plugins.

I’d say in most cases, if your website is going to be mainly content (articles, pictures, pages, etc) then WordPress is the way to go.

Free and easy SSL with Certbot

November 4, 2017

There’s this cool website I discovered for getting totally free SSL certificates. It’s called letsencrypt.org. It’s a free service where you can get set up with SSL certificates on your site.

Of particular interest to me was the Certbot command-line tool which you can use to set up SSL relatively painlessly. You select your platform for which you’re running your site, and it provides you with instructions on how to install the software. The tool can update your Apache virtual host entries automatically and set it up so that all traffic is redirected to the HTTPS endpoint of your website. Pretty awesome.

Problems using sendmail on AWS (among other things)

October 24, 2017

Recently I wanted to get e-mail sending capability set up on this website, which is hosted on an AWS instance. All I really need it for is the simple contact form I have on this site. My initial idea was to simply use sendmail as the e-mail sending program to give my website the ability to send e-mails written via contact form.

After doing some research I learned that AWS instances have a tendency to get abused by spammers. A spammer can cheaply and quickly buy AWS instances to send their spam e-mails from, and as a result of this, major e-mail service providers are likely to block e-mails coming from AWS instances.

Instead, it’s generally recommended to use SES instead, a service provided by Amazon for sending e-mails, which doesn’t seem to have been blacklisted by major e-mail providers.

For my purposes, I only need contact form submissions e-mailed to me, and so the simplest solution seemed to be to use sendmail. Although it appears that gmail, my e-mail provider, is probably blocking all e-mail coming from AWS instances, so I’ll probably have to use SES.

Something to keep in mind is the fact that AWS is an easily abused platform. Today, I was trying to download wordpress via wget, and it just hung, and then I remembered… “oh yeah, they probably disabled downloads from AWS instances because of DDoS attacks… that makes sense…” So that’s something to keep in mind when working with AWS instances.

Using wget to grep through a website

October 14, 2017

Recently I needed to sift through a client’s website to figure out which media of theirs was used or unused. They had a lot of unused media which they wanted to get rid of, but they didn’t want to mistakenly delete something that was unknowingly being used somewhere.

So, I had the idea to use wget for this. With wget you can crawl an entire website and save the output HTML into a neat little folder, which can then be used for grepping. Sounded like a good solution to me.

Specifically, I used wget -m -e robots=off http://site.com

The -m option stands for ‘mirror’ which will use settings intended to crawl and copy an entire website. I also thought it would be useful to ignore robots.txt, for a more complete download of the site. I believe wget adheres to robots.txt by default, but for my purposes I needed to turn it off, because I needed an as-complete-as-possible download of the entire site.

From that point I wrote some bash scripts to accomplish the aforementioned task I was tasked with, and that was that.

A problem I had with wp_enqueue_style not appearing to load any stylesheets

October 14, 2017

So I had a problem with wp_enqueue_style seemingly not loading any stylesheets! Arg! I spent 3 hours trying to figure this one out.

When I would look at the page source of the site I was working on, I couldn’t find the stylesheet I had enqueued with wp_enqueue_style… anywhere. After three hours of taking shots in the dark trying to fix this, I put body { background-color: black; } in my stylesheet. To my astonishment, the page turned black. My styles were being recognized by the browser. Yet I saw no reference to the CSS file in the page source anywhere. Despite this being a major WTF, it told me something. My styles were making it to the page. I was able to turn the page black with CSS. I looked through the page source… again… and found my styles in an inline script tag. Not where I was expecting them to be.

How did my styles go from being in their own file to being in an inline script tag? A plugin called autoptimize.

*womp womp trombone*