Reckless Abandon within the World Wide Web (Part 1)

Many coders will end up on all sorts of Stack Exchange sites–whether through need or curiosity. I’ve registered on a couple of stacks. And I still come across questions on stacks I want to favorite, but I’ve yet to register on.


It stirred me slightly. I mean, who hasn’t pent up some aggression towards Stack before ;)?

My issues:

  1. This ‘favorite’ may be the only star I have at stats.StackExchange for some time.
  2. I didn’t remember if it was a quick process to add another stack.
  3. There’s a slight psychological burden. Namely “Ughhhhh I have to register yet another account on the interwebs. Another account to have dangling in the furthest recess of my mind.”

With fairness, it turned out to be an easy 15 seconds to add this stack to my account. Yet, I’m here writing for something bigger. I want to document and formalize my thoughts of web inefficiencies we all deal with, and maybe build up a grander case over time. The world may never be perfect–yet there is nothing damning us from a more perfect world other than our obstinateness of the idea that we shouldn’t strive for it.

For that Stack issue:

a) Just star the question when I click on it, flashing that the Stats Stack has been added to my accounts with an undo button.
b) Or better yet, decouple favorites from specific Stacks and just add them to a list in my main Stack account.

You may argue these things are often not trivial to change. That the complexity of changing it isn’t worth the benefits of the change. Maybe. But what I’ve noticed in my advent into the coding world is that changing or adding things is too frequently overly stressful and difficult. I think this is because we often don’t code in modular blocks. What we’re tossed into doesn’t help us code in modular blocks. We just want to get the job done. This leads to the really big picture I’ve been troubled about.

We spend too much time using our tools instead of developing our tools. Heck, even the best coding tools we possess either have a learning curve || significant setup cost || cost money. Even our terminals and IDEs–everything we build becomes so specialized that it’s hard to contribute any component without knowing the whole thing well, or requiring an infeasible amount of time of the core developers. Our tools should encourage us to plan and organize. To track what effects there will be. To warn us. And we shouldn’t have to do/master all of those things on an individual basis. We shouldn’t have to be experts in a development environments. Our environments should guide more intuitively. I don’t know what that solution looks like, but we’re smart people who spend a lot of time doing the same things–debugging and tiptoeing.

There is certainly no solution without garnering a bandwagon. No bandwagon here. Just a spoke for now.

Footnote: aye my site is quite neglected by expectation of few visitors. If you are here, please pardon this. When the time is good, the site will be redone.

Docker linked container problems

I need a postgres container linked to a rails container. The rails container needs to install SpreeCommerce, but not before pointing to the postgres container for the database connection.

Using docker-compose to orchestrate these things leads to a common problem. All of the containers launch concurrently, and the rails container attempts the Spree Commerce installation before the postgres server is actually listening for connections.

Let it be known I am holding back from venting about the dichotomy between Docker’s amazing ability to simplify the development/deployment process, and Docker’s grand reluctance to implement even a basic ready-state for containers (instead insisting on multi-step implementation of ready-state scripts). Docker has their reasons, but google the issue and you’ll see this is a sorely needed functionality. Whoops, I just vented.

This post aims to create more of a ‘lay tutorial’ for linking containers. I explore the method of using a shell script (on container1) that waits and listens for a postgres server (on container2) to become ready, after which container1 can install Spree Commerce (as spree initially populates its database).

Docker recommends using a docker-compose entrypoint, and a CMD (in the dockerfile) to be completed after says the database is ready.

Using the example from Docker’s recommendation. The docker-compose file looks like this:


version: “2”
build: .
– “80:8000”
– “db”
entrypoint: ./ db:5432
image: postgres

docker-compose.yml has two services (actions), and thus builds two images. Whenever you want to use those images, they create separate entities called containers.

build: .
#builds the web image using the dockerfile located in the directory you run the “docker-compose build .” command from. This directory is alternatively called the ‘current context’. Note that those dockerfile instructions are not shown in this post.

– “8000:80”
#expose ports to the host as HOST:CONTAINER. That is, container port 8000 is routed to host port 80. For example, if you are running a webserver in your container that is expecting traffic from port 8000, you can communicate with it from the computer running docker via your-docker-host-ip:80. Note that if you try to expose ports via your dockerfile (not covered here), those ports are only available to other containers within your virtual docker network. For example, using EXPOSE 8000 in your dockerfile would allow outgoing traffic from other containers (whatever port they choose) to be sent to port 80 on the container you EXPOSED.

– “db”
#some newcomers may be tempted to think that the web image is somehow being built from db. That is not true here. The depends_on key instead means the Web container will not run without the companionship of the DB container (example: if you were to use docker-compose to build these two images, create their respective containers, manually delete the db container, you would not be able to launch the web container).

entrypoint: ./ db:5432
#First off, is a github project by vishnubob–big thanks to him (and his employer Ginkgo Bioworks). In a nutshell, this instruction looks for Work-dir-set-by-dockerfile/ located in the Web image. That is, in the dockerfile you can set a work directory (such as /usr/home/scripts/) and that will become the relative path used whenever you don’t explicitly specify an absolute path. The arguments passed to the script (db:5432) tell the script to repeatedly check the linked container db for a port 5432 response.

image: postgres
#This is analogous to the “build: .” key used above in Web. Instead of looking to the dockerfile for image build instructions, this points docker to use an image that already exists (docker looks locally for the existence of a “postgres” image, and if not found, looks on the official docker repository).

What is my docker host ip (Windows)?

On Docker for Windows, it wasn’t immediately obvious how to find out the host IP of docker. I tried docker-machine ip default to list the ip address of my docker host, most likely called ‘default’, but it doesn’t exist. In fact for whatever reason, when I run “docker-machine ls”, there are no host machines listed.

I checked ipconfig and see a DockerNAT virtual ethernet adapter at (which is indeed my docker host ip). I can also see the docker host IP by right clicking on the Docker icon in the system tray, choosing settings, and network.

On Mac and Linux systems, “boot2docker ip” will suffice.

Create a launcher for Sublime Text which always opens a new window (in Windows)

The default behavior of the Sublime Text 3 launcher in Windows is to show any currently open Sublime Text windows. This really shouldn’t be the default behavior, but what-evs.

My quickfix: create a new batch file named sublime-launcher.bat with the following contents:
start “C:/Program Files/Sublime Text 3/sublime_text.exe” “–new-window”

For whatever reason, I’m not able to pin this to my start bar in Windows 10. Tired of these things–so as soon as I get the time I’ll be swapping my primary installation over to some flavor of linux.

Using get_template_part() in wordpress theme development.

get_template_part() calls some other functions and essentially has the action of doing a require(‘something.php’). Generally: get_template_part() -> locate_templates() -> load_template() -> require(‘theFoundTemplateFile.php’).

It takes two arguments. get_template_part(‘generic template file’, ‘specialized template file’). The first argument is commonly called the ‘slug’ and the second the ‘name’. No worries though.

Let’s contextualize this a little. Assume we have a file structure like this:




Example 1 (EX1):
And you use get_template_part(‘themecore’). This is the simplest situation. WordPress will search for the template in the child theme directory, then parent theme directory in that order, using the first template file it comes to with the right name.

It looks through these directories for ‘themecore.php’:

WordPress finds wp-content/themes/mythemechild/themecore.php first and loads it, ignoring the other file in the parent theme.

Example 2 (EX2):
Let’s use two arguments: get_template_part(‘themecore’,’nosidebar’). WordPress searches for ‘themecore-nosidebar.php’ in the same order as in EX1.

It looks through these directories for ‘themecore-nosidebar.php’:

WordPress finds wp-content/themes/mythemechild/themecore-nosidebar.php first and loads it, ignoring the other file in the parent theme.

Example 3 (EX3):
Still two arguments: get_template_part(‘themecore’,’fullwidth’). WordPress searches for ‘themecore-fullwidth.php’ in the child, then parent theme folders.

It looks through these directories for ‘themecore-fullwidth.php’:

WordPress has no luck in the child theme folder, and finds wp-content/themes/mytheme/themecore-fullwidth.php and loads it.

Example 4 (EX4):
Still two arguments: get_template_part(‘themecore’,’idontexist’). WordPress searches for ‘themecore-idontexist.php’ in the child, then parent theme folders. But if it doesn’t find this appended file name, it is supposed to repeat the search without it.

It looks through these directories for ‘themecore-idontexist.php’:

WordPress doesn’t find themecore-idontexist.php, so it searches in the same order for the base template ‘themecore.php’. It ends up using wp-content/themes/mythemechild/themecore.php.

Adding a google font to a wordpress theme (via child theme)

Anatomy: Background // What you came here for // Conclusion

Since I’ve gone freelance, a number of jobs I’ve done are WordPress updates, repairs, and migrations.

It’s been a challenge and forced me to rework my general approach to technical troubleshooting to save time. I have a locust of problems experienced locusting through my poor head right now from the site I’m currently working on, and situations worth mentioning from past sites. Do I fix these problems the right way, or blindly toss a patch in for the next poor soul 3 years later? I try to do it the right way–I’ll slowly get fast at all the right ways.

The site I’m currently working on is for a big-time music video producer–its theme hasn’t been updated in 3 years, and lives somewhat inharmoniously with an almost-up-to-date WordPress core. It’s slow, and barely responsive (to screens/mobile).

What you came here for:

The client wants this Google Font:

  1. I tried the quick and wrong way first so I could instead work on more important problems. Keyword: tried.

    In /wp-content/themes/aware/header.php towards the top of <head></head> section, insert the code <link href=”” rel=”stylesheet”>

    It is safer to do it towards the top of the head section, ensuring you don’t accidentally place the font-import after the CSS import which calls for the font. That is it say, you want this order of events: (1) Import font, (2) Import CSS file that says, “use this font.”

    Calling for google font above any other style sheets.
    Notice the stylesheet is called immediately after, and definitely outside of any php tags (though you could have it inside of php tags if you echo the <script> statement).

    I then modified /wp-content/themes/aware/styles.css. I searched for font-family in that file and added ‘Poiret One’ and an !important tag. That is: font-family: ‘Poiret One’, Arial, Helvetica, sans-serif !important;

    add the new google font as the first font to use
    Unashamed use of !important.

    But it didn’t work and I didn’t delve into why.

  2. With some quick google-fu, I found some tips on adding the font to this theme the correct way. Update with that in progress.