• Development,  Tech Tips

    Handling Daylight Saving Time in Cron Jobs

    • Our business is located in Maine (same timezone as New York; we set clocks back one hour in the Fall and ahead one hour in the Spring)
    • Server A uses ET (automatically adjusts to UTC-4 in the summer, and UTC-5 in the winter)
    • Server B uses UTC (not affected by Daylight Saving Time) – we cannot control the timezone of this server

    We want to ensure both servers are always referencing, figuratively, the same clock on the wall in Maine.

    Here’s what we can do to make sure the timing of cron jobs on Server B (UTC) match the changing times of Server A (ET).

    Only one of the php artisan scrub-db  commands will execute, depending on the time of year.

  • Development,  Tech Tips

    Automatically Put Files Into a YYYY/MM Directory Structure

     

  • Development,  Tech Tips

    Find and Open (in vim) Multiple Files

    This is a quick set of examples for finding and opening multiple files in Vim.

     

  • Development

    Monitoring a Drupal 8 Migration Executed with Drush

    Update 2 is proving to be the most useful method.

    Update 1

    Somehow I missed the documentation regarding the --feedback  argument for the drush mi  command. It’s similar to the methods below in that it helps you see that the migration is working, though you don’t see the totals. You can ask for feedback in seconds or items.

    Update 2:

    Another method that is a bit dirty but very useful is to add a single line to core/modules/migrate/src/MigrateExecutable.php.

    Adding the highlighted line to \Drupal\migrate\MigrateExecutable::import will let you see exactly where the migration is (which row is being processed).

    If this is something you want permanently, consider posting an issue on d.o to request more verbose logging. This is my hackey solution for my immediate needs.

    The output (in your logs, and in the drush output) will be something like this (institution_node is my migration, inst_guid is the only id):

    As of Thursday, August 16, 2018 the counter() method is removed. So, you have to drop a counter variable in place like this:

    This method of monitoring execution is surprisingly effective as it’s fast and you don’t have to lift a finger for it to happen each time you run a migration.


    Original Post

    This isn’t exactly an ideal solution, but it will do in a pinch. I’m working on a migration of more than 46,000 nodes (in a single migration among many). I needed a way to monitor the progress but I wanted to do it as quickly as possible (no coding). Here’s what I came up with, which I run in a new iTerm window.

    All we’re doing is asking how many records are in the “member_node” migration map every 5 seconds. If we started at 6350 items we know that by the end of 20 seconds we have created 35 records.

    We could also query the target content type itself:

    Here we can analyze the data the same way to see how many records the migration is creating.

    I recognize that this is pretty crude, but it’s effective; you are able to see that it’s working, instead of just staring at an unchanging prompt and watching your CPU jump.

  • 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:

     

  • Tech Tips

    Delete Last Command from Bash History

    If you’re like me, on occasion you accidentally (or sometimes purposefully) include a password in a command. Until recently I would execute history , find the offending command’s number, then do a history -d NUMBER . It is kind of a pain.

    The following deletes the last item in your bash history:

    You can create an alias for this, type it manually (umm, no thanks), or, as is the case for me, create a Keyboard Maestro macro for it. Here’s what my macro looks like:

    img20141208190438

  • Tech Tips

    Customizable Date variables in Keyboard Maestro

    UPDATE: Though the solution below works well, I do recommend following the first commenter’s advice and using the ICUDateTime text tokens instead, which allow you to use any ICU date format, without having to invoke a shell script.

    Sometimes you need a date and/or time variable in your Keyboard Maestro macros. The easiest One way I’ve found to do this is via an “Execute Shell Script” action. You’ll just use the date command and format as desired.

    Keyboard Maestro "Date" Variable

  • Tech Tips

    Determining Your Most Used Commands in Terminal

    I’m always looking to automate things using Alfred, Keyboard Maestro, Text Expander, and Python. I was curious which terminal commands I use most often, so I did some experimenting. Basically I wanted to know how many times I’ve executed each unique command ( ssh myserverx or ssh myservery, not just ssh). I started by piping the output of history to  sort (to group), then to  uniq (to count), then back to sort (to sort by the number of occurrences).

    Unfortunately, the result contained the same number of lines as the original history output. I figured this was because each line had a unique integer prefix (the line number in the history output). As it turns out, ~/.bash_history (where history gets its records) doesn’t contain line numbers. I simply changed the source and it worked like a charm:
  • Tech Tips

    “755”-style permissions with ‘ls’

    After a quick Google search for “ls permissions octal” I found a very handy alias to put in my .bashrc. Not only is it handy to see the OCTAL value of the permissions for each file/dir, it will undoubtedly help you more quickly recognize/interpret the normal ls -al output.

     Example usage:
    You can also type (or paste) this slightly different version into terminal:
  • Development

    Automatically Stage All Deleted Files (Git)

    Tab-completion is a really nice thing that we often take for granted. While working with Git I’ve found that it becomes inconvenient to stage (add for inclusion in the next commit) removed files using git rm path/to/my/file.php. Tab completion doesn’t work on paths that no longer exist, so you have to manually type the path to the deleted item. The following snippet automatically stages ALL removed files.

    git ls-files -d -z | xargs -0 git rm --cached --quiet