• Development

    Bulk Add URL Redirects in Drupal 7

    Here’s a quick example showing how to add URL redirects (for the redirect module) in bulk.

    Instead of a separate page for each list of “fellows”, we built a single view with exposed filters to choose a semester.

    The original paths looked like “/fall-2000-fellows” and the new path looks like “/fellows/list?semester=5493”.

     

  • Tech Tips

    Random Mouse Distance in Keyboard Maestro

    Here’s one way to choose a random item in a select list using just mouse movements and a random number. If you’re trying to do this in a browser there are cleaner ways to do it (javascript, chrome/safari actions, etc.), but for general usage across many applications this is a pretty universal solution.

    2016-03-03_20-04-27

    I was surprised to find that you can type variables into the tiny coordinate text fields. They get bigger when you do.

    When executed, this will select a random item (excluding “- None -“) from the select list.

  • Development

    Adding a “Filter by year” Facet for a Date Field in Apachesolr for Drupal 7

    A Drupal 7 site I’m working on makes use of the Apache Solr Search module and FacetAPI. Some of the content has a date field named field_s_date. I was tasked with providing a sidebar “Filter by year” facet block to filter the content by the year value of this date field. I’m pretty sure I could have done this a few different ways, but I settled on adding the year value as a separate field to the solr index and adding an associated facet using hook_facetapi_facet_info() .

    First, to add the field, I used hook_apachesolr_index_document_build() in a custom module as follows:

  • Development

    Rendering an Image in Apache SOLR Search results (Drupal 7)

    Introduction

    There are a few ways to get extra information into the output of your Apache Solr Search results. The most efficient ways involve getting the information into the solr index and pulling it directly from the solr index. We do not want to introduce extra node_load()  calls to render our search results. We do not want to have to use Views either.

    So, using just apachesolr and some functions, I’m going to show how to get an image field into the search index and pull it back out in our result output. I know I’m not handling alt and title attributes in this example. I’ll let you figure that one out.

    This is a step-by-step breakdown of my experience getting this to work. In this example I’m attempting to render an image field called field_forum_image for the forum (content type) nodes in my search results. You can use the same procedure for adding other fields, but please make sure you understand the solr prefixes (e.g., ss, ts, tm, etc.) before doing so. You can find these in the schema.xml file with in the apachesolr module.

  • Tech Tips

    Use Keyboard Maestro to Hide Instead of Close an Application

    I use SnagIt to capture screenshots. The editor window that appears after you capture takes a few seconds to open if the application isn’t running. I realized that, while the capture tools remain open, the editor goes away when I hit ⌘W to close the window. Instead of using ⌘W to close the editor window, I sometimes remember to use ⌘H to hide the window, which hides the window but leaves the application open. The editor window pops open much quicker if the application is still open.

    Using Keyboard Maestro I’m able to intercept the ⌘W that I do all the time (muscle memory), and turn that into a ⌘H.

  • Tech Tips

    Launch Center Pro actions for Day One

    Here are my Launch Center Pro actions for the Day One app on iOS. I’m not here to teach you how to use Launch Center Pro (a huge topic), so if you need to learn that I suggest a lot of Googling and perhaps a visit to their official documentation and FAQs. Basically LCP will step you through prompts as it builds the output to move into a new Day One journal entry. Day One supports markdown, so you can make entries that look nice, like this:

    2016-02-15_06-15-13

    Use this LCPEncoder to convert the templates you see below into URLs. After you generate the URL, get it into the “url” field of the LCP action.

  • Development

    Recursively Finding and Operating on the Largest n Number of Files of a Particular Type

    If you want to reverse-engineer this, you can work from left to right, adding one command at a time to see what each step does to the output.

    2016-02-03_15-52-47

    This example just lists the files we found, which is pointless given that’s what we already had before introducing the cut command.

    How about a practical example?

    Here’s how you can resize the 25 largest jpg files using mogrify (part of ImageMagick) to reduce the quality to 80:

    What if you wanted to only grab files that are larger than a specific size? One way to do it is with the find command. For example, find all files greater than 8M:

     

  • Development

    Extracting Image “src” Attributes from an HTML String using PHP

    Here are a few ways to build an array of image sources extracted from an HTML string. I’m sure there are other ways, but these seem to be reliable.