What We Learned Last Month #1

As part of being a distributed company, we've found that using Know Your Team on a regular basis helps us communicate outside of projects and tasks and deadlines. It periodically sends us questions and on Fridays at noon it asks, “What’s something you figured out this week?” This gently reminds us to think about the week that just happened, and to reflect on what we’ve learned.

People share everything from a life hack anyone can use to a deep concept in Drupal that only a handful of people will appreciate. We're planning on sharing the best of what we've learned with you.

Number 1—September, 2019

Charlene

I was going to rent a Uhaul cargo van to pick up the boxes I shipped cross country. Unfortunately the boxes were 50 miles away, and Uhaul charges $19.95 + .59 cents a miles = $78.90. I discovered you can rent cargo vans from Enterprise, and it’s cheaper: $19.95/day and 100 miles FREE! I saved myself $58.95!

Chris

A cool thing I learned this week is the power of using usort to sort a given array by a non-intrinsic arbitrary order: Let's say you have a data source that provides a list of items by date shorthand M, T, W, Th, F but the list is not always in that order. Sometimes it's alphabetical. What you do is create template representing your arbitrary order $template = ['M','T','W','Th','F']; And the order provided by your data source is $source_array = ['T','Th','W','F','M'];

Enter the usort method. Usort uses a binary stepping method where it compares each item to the next one one by one until everything is evaluated and properly positioned. Any item in the $source that isn't in the $template will end up being at the beginning.

asort($source_array, function($a, $b) use ($template)
   {
      //get the position of the first comparison item in the template array
      $pos_a = array_search($a, $template);
      //get the position of the second comparison item 
      $pos_b = array_earch($b, $template);
      //are we positive or negative and order accordingly.      
      return $pos_a - $pos_b; 
});
return $source_array;

Jason

  • I learned that you probably want array_shift instead of array_pop. I mean, when are you ever taking the last thing and not the first? (Obviously, sometimes. But not very often.)
  • I really miss D8 when forced to work on a D7 site.
  • I built a custom configuration page so client could add custom text to a thing. Then you just get that custom text by using \Drupal::config('thing')->get('fieldname'). Super easy.
  • When you create a new service you use the Drupal service registry to access your class, you don't instantiate a new instance of the class. Which, I'm pretty sure, is the whole point of registering a service.
  • Creating a custom block plugin is super easy. And you can even get started using Drupal console. drupal generate:plugin:block

Jill

FOUC, Flash of Unstyled Content, is when a web page loads without styles for less than a second. One possible method of correcting this is by placing scripts at the bottom of the page.

Les

  • You can change the default local IP address blocks that Docker Compose assigns to your projects, which is useful to avoid conflicts with other services that might want to use those same IPs. https://serverfault.com/questions/916941/configuring-docker-to-not-use-the-172-17-0-0-range
  • Confluence has an undocumented bulk-issue creation mechanism, if you are right-click-creating from a basic table.

Tess

Ansible does not treat localhost as special, but rather like any other fully qualified domain. Furthermore, when a host is in multiple groups in an inventory, they groups are not applied separately, but together as a merged item. To combine inventories while keeping localhostspan> separate, the trick is to create a fake mysite.localhost inventory item, with ansible_connection=local to skip any domain lookups.

Ivan Stegic

Founder and President
 
Image
Ivan Stegic

Words that describe Ivan: Relentlessly optimistic. Kind. Equally concerned with client and employee happiness. Bowtie lover. Physicist. Ethical. Lighthearted and cheerful. Finds joy in the technical stuff. Inspiring. Loyal. Hires smart, curious and kind employees who want to create more good in the world. His favorite things right now: the TEN7 podcast and becoming the next Björn Borg.