Chuck Grimmett

  • Automating Blog Posts with AppleScript v2

    Automating Blog Posts with AppleScript v2

    I decided that my earlier attempt at automating creation of these TIL posts was still too manual. This one is better!

    What it does:

    1. Creates a markdown file with today’s date and my specified string at the title.
    2. Launches Coda in the foreground and goes to my preset Jekyll blog site (cagrimmett.com)
    3. Opens the file it just created in the front window.
    4. Expands the previous TextExpander snippet I created as a template for these TIL posts.

    The Script

    %filltop%  on textexpander(abbreviation)	 do shell script "cd ~/Projects/cagrimmett-com/_posts/til; touch %snippet:fname%"  tell application "Coda 2" 	activate window 	get site 6 of application "Coda 2" 	tell window 1 		connect to site 6 of application "Coda 2" 			open "Macintosh HD:Users:CAG:Projects:cagrimmett-com:_posts:til:%snippet:fname%" 	end tell end tell tell application "TextExpander" 	expand abbreviation ";tem" end tell  end textexpander

    Here are what the other two snippets fill in:

    fname– I had to make this a snippet instead of putting it in directly because in the filename creation string TextExpander didn’t recognize the date string. If you nest it inside another snippet, it works just fine.

    %Y-%m-%d-%filltext:name=title%.md 

    ;tem

    --- layout: post title:  author: Chuck Grimmett date: %Y-%m-%d category: TIL feature-img: "/img/defaults/%snippet:;random-img%" tags:  -  excerpt: 

    --- ### Today I learned:
  • Cleaning up your Mac with Hazel

    Cleaning up your Mac with Hazel

    Today I learned how to clean up my Mac with Hazel

    Hazel

    Hazel is a preference pane-based application that helps you automate organization on your Mac.

    Within a few hours of using Hazel, I was able to clean out my 1000+ file Downloads folder, tame my unruly Desktop, get rid of all the trash that accumulated in my home folder, and organize my stashes of client files. I also set up rules for the future that will keep these places neat and orderly.

    The next step is to turn my gaze on my photo library to create one master repository.

    Tools and guides

    The best tools/guides on Hazel right now are:

  • Converting an Aperture Library to Lightroom

    Converting an Aperture Library to Lightroom

    I have multiple old Aperture photo libraries that I can’t really use anymore. Aperture doesn’t run on El Capitan and I don’t have any system that it can run on. I’ve been using Adobe Lightroom for the past four years anyway. So I did some research into options into how I can retrieve my photos.

    Opening the package

    The great thing about Aperture was that it always kept the master images and applied edits on the fly. So I knew that I could get the master images out of Aperture. The way you can get to them is right-clicking on the library file and selecting “Show Package Contents.” Then you can take the masters folder and copy it out of the library.

    Plugin from Adobe

    Adobe also has a plugin to copy over images and metadataArchived Link.

    Preserving your edits?

    Unfortunately I haven’t found a way to also preserve/move/translate edits made in Aperture to Lightroom. If you know a way, let me know!

  • Excel formulas to combine columns and convert time, More SQL functions

    Excel formulas to combine columns and convert time, More SQL functions

    Today I learned:

    Excel Formula to Combine Columns

    =[@Column1] & [@Column2]

    For example: here is how I’d combine columns of hours and minutes and put a colon in-between: =[@Hour] & ":" & [@Minute]


    Convert hours.minutes to hh:mm:ss in Excel

    Take 275.75 and convert it to 275:45 =CELL/24 converts the hours.minutes to days Then you format the column by Custom > Time > 37:30:55 (hh:mm:ss)


    SQL Dates, Concatenation, and Grouping

    I learned some useful things today in SQL: SUM(), CONCAT_WS() to get CSV output, DATE() to get the date part of a datetime stamp, and GROUP BY to get the sums grouped by another column

    SELECT SUM(calls), username  FROM scoreboard_calls GROUP BY username;  SELECT DATE(time), SUM(calls) FROM scoreboard_calls GROUP BY DATE(time);  SELECT CONCAT_WS(',',SUM(calls),username) "calls,user" FROM scoreboard_calls GROUP BY username ORDER BY username, SUM(calls);
  • Summing with Filters in Excel, Reminding Yourself “Why”

    Summing with Filters in Excel, Reminding Yourself “Why”

    Today I learned:

    Summing in Excel with Filters

    If you’ve ever tried to write a sum() function in Excel while you have filters on, you likely didn’t get the result you expected. The sum() function adds up what is in the raw cells. It does not take whether or not they’ve been hidden via a filter into account.

    subtotal() is the function you are looking for. Specifically, subtotal(9,range). The 9 refers to sum for hidden (not at a result of filtering, though) and non-hidden rows. See the documentation. subtotal() functions only on the results of filtered data.

    =SUBTOTAL(9,G1670:G640501) gave me the sum of the the filtered data from G1670 to G640501. (You can see why filtering would be important with such a large data set!)


    Remind yourself why

    Sometimes I spend too much time and effort trying to convince myself to do something I don’t want to do. This leads to general angst and despair.

    My wife reminded me yesterday that the best way of convincing myself is to reflect on why I’m doing it in the first place.

    Whatever your reason why is, as long as it outweighs the cost of not doing it, you’ll get over it and find a way. I keep an index card with some why bullet points on it nearby to keep things in perspective.

  • Easier Syntax Highlighting, Downloading WordPress.com Email Followers, and Jekyll Tools

    Easier Syntax Highlighting, Downloading WordPress.com Email Followers, and Jekyll Tools

    Today I learned:

    Easier syntax highlighting with Jekyll

    So it turns out that there is an even easier way to do syntax highlighting in Jekyll than I described last week. Jekyll 3 has Rouge highlighting built right in.

    To use it:

     {% highlight liquid %} Put your foo here 	bar end foo {% endhighlight %}  

    I need to go back though my previous posts and remove the Pygments highlighting then uninstall the plugin. Rouge supports fewer languages than Pygments, but Rouge supports all of the languages I use, plus Liquid and Markdown, which Pygments doesn’t.


    Downloading WordPress.com Email Subscribers

    I learned today that it is possible to download a CSV of the email subscribers to your WordPress.com blog (or WordPress.org blog powered by WordPress.com’s JetpackArchived Link). They don’t make it obvious, but the option is there:

    1. Go to https://wordpress.com/stats/follows/email and log in.
    2. Select the site you want to download your email subscribers for.
    3. At the bottom of the list, you should see an icon and download button:

    Download all email followers as CSV


    Jekyll Tools

    Last night I cleaned up some of my Jekyll templates and put them on Github with instructions for how to use them. Check them out:

  • How to keep track of files and requests in Slack

    How to keep track of files and requests in Slack

    Today I learned:

    How to keep track of files and requests in Slack

    Slack is wonderful for collaborating with remote teams, but if there is a lot of activity at once, it can be easy to lose files and requests.

    • If I’ve seen the request or file, I acknowledge by marking it with , then I put it on my to-do list of choice, WunderlistArchived Link. (They have a great Slack commandArchived Link to make this easy: /wunderlist add)
    • If I’ve fulfilled the request or processed the file, I mark it with
    • If the request/file is no longer needed or I’ve tried to process it, encountered an error, and notified the appropriate parties, I mark it with so that I know in the future that there was an issue with it instead of assuming it was done and I moved on.
    • Using Slack’s great search functionality, I can easily visually figure out what I’ve processed and what is still outstanding.
    • If I get a request when I’m in the middle of something else, I copy the link and use Slack’s /remind command to remind me about it later in the day.
  • Readable Code Snippets, VPN Clients, and Privacy

    Readable Code Snippets, VPN Clients, and Privacy

    Today I learned:

    Making code snippets prettier

    • I did some research for Sean Nelson about making code snippets prettier without using Github’s Gist.
    • This problem is already solved. Google’s Code Prettify is javascript that works parses your code pretty well and colors it.
    • Put the prettyprint class on your
      
      

      tags and put this script in your document:

    "https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js">
    • I might start using this for my code snippets in the future. Right now I have some CSS styles that conflict with it, so I need to sort those out first.

    VPN Connection issues


    Privacy Policies

    I’ve been having a lot of discussions about privacy and data collection recently, both at work and with friends. This episode of What’s the Point on privacy with Kashmir Hill cleared up some common misconceptions. The main points:

    • If a company’s fundamental business model is collecting data and figuring out things about you (i.e. Google and Facebook), they aren’t selling your data, but rather selling access to your attention to advertisers. They don’t want to give up your data to other people because it is such a valuable resource to them.
    • Some companies who sell you physical products have a side-business selling data on what you bought and when to others.
    • Privacy has become a genuine concern for companies recently, as evidenced by the rise in end-to-end encryption in consumer products like iMessage. This is worrying to some government agencies.
    • If you read privacy policies, they actually tell you all the ways a company is going to violate your privacy. As long as a company doesn’t do anything they didn’t say they were going to do, they are protected.
  • Photoshop Patterns, Homestead Provisioning, Composer Basics

    Photoshop Patterns, Homestead Provisioning, Composer Basics

    Today I learned:

    Tiling Photoshop Patterns

    I’ve been making some patterns for the header images on these TIL posts in my down time the past few days. There are two ways to tile patterns in Photoshop. One is manual and time consuming, the other is fast, easy, and less prone to error.

    • The manual, time consuming way is to open a pattern in one layer, duplicate the layer multiple times, and move the layers so that they line up in a tiling pattern. While PS is pretty great at snapping items to a grid, sometimes they don’t always line up and you only find out after you export the image.
    • The fast and easy way is to open the pattern in PS, go to Edit > Define Pattern…, then use the Pattern Stamp Tool to paint the pattern you just created across a large canvas.

    This would have saved me a lot of time on the first nine headers, but c’est la vie. This will definitely save me time going forward.


    Homestead Provisioning

    I use Laravel Homestead for my local PHP environment. Provisioning a new site is something I’ve done multiple times, but I do it so infrequently that I have to look it up each time. So here are my quick notes:

    • Create the site folder in ~/Projects/
    • Map the folder and domain in ~/.homestead/Homestead.yaml
    • Map the domain to 192.168.10.10 in /etc/hosts/ (reminder: $ sudo nano /etc/hosts/)
    • Run $ cd ~/Homestead
    • Run $ vagrant up --provision or $ vagrant reload --provision if vagrant is already running.
    • Site should now be accessible locally.

    If you need a new database for this site and load it from a SQL dump:

    $ vagrant ssh $ mysql -u homestead -p -e 'create database DBNAME;' $ mysql -u homestead -p  DBNAME < path/to/file.sql

    Composer Basics

    Composer is a dependency manager for PHP. I’ve used Composer, but like Homestead provisioning above, I’m a little rusty. Writing it down helps me remember.

    After you’ve installed it (I have it installed globally), the basic usage is:

    • Set up composer.json in the directory you are working on. A basic structure looks something like this:
    {     "require": {         "ajt/guzzle-toggl": "^0.10.0",         "corneltek/getoptionkit": "~2"     } }
    • In that directory, run $ composer install to install the dependencies listed in composer.json. They will be in a file called vendor.
  • Automating Drudgery, Project Planning, Parent Selectors, and Find and Replace

    Automating Drudgery, Project Planning, Parent Selectors, and Find and Replace

    Today I learned:

    Automating the tedious parts of these TIL posts

    When writing these TIL posts, I want to eliminate as much resistance as possible so I can get straight to writing. The more steps I have to take, the less likely I am to follow through. So I took some time today to automate the one of the tedious parts: Setting up the markdown file I write these posts in with most of the specs already filled out.

    I created 3 TextExpander snippets to help with this process:

    • One with today’s date string and extension separated by dashes for the file name: %Y-%m-%d-.md (I tried a fill-in for the title, but the filename doesn’t stay selected in Coda when another window launches)
    • One with Javascript randomly picking one of the 7 default header images I use (this is used in the next snippet):
    var random = Math.floor(Math.random() * 7) + 1; TextExpander.appendOutput(random + ".jpg");
    --- layout: post title:  author: Chuck Grimmett date: %Y-%m-%d category: TIL feature-img: "/img/defaults/%snippet:;random-img%" tags:  -  excerpt: 

    ---

    Better Project Planning

    Besides for the normal scope, budget, platform, dependencies, timeline, and underlying technologies, here are a few things you need to consider when architecting and planning out a software development project:

    • After delivery, what resources will we have available to maintain the system and handle emergencies?
    • What impact will maintenance and support have on our ability to sell and develop new projects in the future?
    • What is the opportunity cost of using one developer over another?

    Parent Selectors in CSS

    There are no parent selectors in CSS.

    There are two ways around this:

    1. Use the jQuery parents() selector to return the appropriate parent element, then use the css() method to set the style you want. For example, ("a i").parents("li").css({"margin-right": "5px"}); finds list items who are the ancestors of icons wrapped in links and makes their right margin 5px.
    2. Change the structure of your code and add specific classes that you can apply your desired styles to. For example, instead of applying a right margin to all list items and then a different right margin (via parent selector) for all list items that contain icons, make two classes with the proper margins and apply one to the plain list items and the other to list items that contain icons.

    I opted for #2. It makes your CSS cleaner, keeps you from having to load new dependencies like jQuery, and keeps the styles in one place so you don’t have to search 6 months from now for where that extra margin is coming from. I’d only use the first option in cases where you have complex rules that can’t be accomplished by restructuring your code and/or adding classes to make your desired change possible.


    Project-wide Find and Replace in Coda

    I do the vast majority of my code-writing in Coda. I used to have to open up TextWrangler to do find and replace across multiple files, but apparently Panic added this feature into Coda sometime between v1 and v2.5. I got used to having to switch and didn’t look for it again until today.

    It is buried in the sidebar under “Find In” instead of in the regular find and replace bar, so I never saw it. You can search across open files, the entire site, or in a specific directory on your local machine.

    Find In is buried under the sidebar in Coda