Things I've Tagged ‘Development’

Page 1 of 1

Adventures in Dotfiles

I accidentally ran into a bit of laziness during my development process that turned into a productivity boon, and should prove to be absolutely essential during the setup of any new Mac I might purchase in the future.

Let me preface this by saying I am not a native of the command line–by any stretch. I find it to be cumbersome and annoying to remember commands and all of the possible flags that might apply to them. Even something as simple as showing hidden files on the Mac can be obnoxious:

# Show hidden files
--- ~ » defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder

# Hide hidden files
--- ~ » defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder

What if I could just type show or hide and be done with it? This is where aliases come in. This was a concept I was keenly aware of already–seeing that most of the helper plugins I used in my ZSH installation provide plenty of helpful aliases–but I figured, why not create some that I could use for operations I performed frequently? Or to find a way to easily navigate to directories I regularly used?

At first I created a simple .aliases file and started to add what I needed:

# Show/hide hidden files in Finder
alias show="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder"
alias hide="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder"

# Hide/show all desktop icons (useful when presenting)
alias hidedesktop="defaults write com.apple.finder CreateDesktop -bool false && killall Finder"
alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && killall Finder"

# Disable Spotlight
alias spotoff="sudo mdutil -a -i off"
# Enable Spotlight
alias spoton="sudo mdutil -a -i on"

#Git commands
alias gnb="git checkout -b"
alias gmsg="git commit -m"

I sourced it in my .zshrc file and called it good.

But then I wondered what would happen if I lost everything on this system? I started doing a little research and discovered that there were plenty of people working on ways to bootstrap their development environments for situations like this.1

I found one particular repo by Mathias that I was able to gather some items from, as well as an installation process that could get me started with everything I used. Now all I need to do is navigate to my cloned repo and type:

--- ~ » source boostrap.sh

I follow a few prompts and install what I need to get up and running. I can share my dev environment between machines fairly easily this way.

If you’re interested, feel free to browse my repo for reference, or fork it if you want to build on it. Keep in mind, there are more repos available with more sophisticated setups than my own if you’re looking for something more robust, but if you’re knew to this level of customization on this level, this is a good start.2

View Project on GitHub


  1. Getting Started with Dotfiles. Accessed May 23, 2018.
  2. GitHub does dotfiles. Accessed May 23, 2018.

Interacting With the Google Analytics Core Reporting API

I needed a way for my clients to access analytics data that for a variety of reasons didn’t need or have full access to Google Analytics data through the traditional web app. I found a simple, yet soon to be deprecated, solution to my problem–the Google Analytics Core Reporting API.

There are a couple of libraries that an individual can use, depending on the language you’re working in, and since my expertise is in php, I chose to use the Google Analytics PHP Interface. This happens to interact with the older v2.4 API; unfortunately, I didn’t realize this until I already built the thing…moving on.

Start Me Up

OK, so let’s just assume you already have a Google Analytics account, because frankly why else would you need something like this? So, let’s define a few things, include the gapi class and fill in our information to connect to the core reporting API.

define('ga_email','your@email.com');     // GA Email
define('ga_password','elkkdafasff');     // 2-part authorization password
define('profile_id','2345678');          // Analytics profile ID

require_once 'gapi/gapi.class.php';
$ga = new gapi(ga_email,ga_password);

So now we’ve got an object to work with and we can start grabbing some data for our report.

With the core reporting api, you have certain metrics that you can look at depending on the dimension you’re interested in. To find exactly what metrics go with what dimensions, browse the Dimensions and Metrics Reference.

I already know that I’m interested in seeing the visits, pageviews, pages/visit, and bounce rate of all traffic sources (referrals, search engines, etc.). So, using the object we’ve already created I can define the dimensions and metrics I’m interested in, sort it by greatest number of visits, and limit my results to 50. You’ll also see that you can choose a date range. For this example I’m not providing one, so by default it will show the last month’s worth of data.

$dimensions  = array('source');
$metrics     = array('visits','pageviews','bounces');
$sort_metric = '-visits';
                        			
$ga->requestReportData(profile_id,      
    $dimensions, 
    $metrics, 
    $sort_metric, 
    $filter=null, 
    $start_date=null, 
    $end_date=null, 
    $start_index=1, 
    $max_results=50);

It is also possible to filter your data, so that if you wanted to see only referrals as a source, then you could replace $filter=null with $filter='medium==referral'. For a quick reference of what you might be able to filter, take a look at a list of common queries. Really just explore the documentation there in depth.

So we’ve got our data, now let’s put it in a format that we can browse:

<table>
  <thead>
    <tr>
      <th>&nbsp;</th>
      <th>Source</th>
      <th>Visits</th>
      <th>Pageviews</th>
      <th>Pages/Visit</th>
      <th>Bounce Rate</th>
    </tr>
  </thead>
  <tbody>
  <?php
  $i = 1;
  foreach($ga->getResults() as $result):
  ?>
    <tr>
      <td><?php echo $i; ?>.</td>
      <td><?php echo $result; ?></td>
      <td><?php echo number_format($result->getVisits()); ?></td>
      <td><?php echo number_format($result->getPageviews()); ?></td>
      <td><?php echo number_format(($result->getPageviews()/$result->getVisits()),2); ?></td>
      <td><?php echo number_format(($result->getBounces()/$result->getVisits())*100,2); ?>%</td>
    </tr>
  <?php
  $i++;
  endforeach
  ?>
  </tbody>
</table>

How easy was that?

Utilizing that as a foundation, I was able to turn it into a tool for clients, or for myself, making it easy to get a quick look at stats. If you’re at all interested in using it yourself, let me know in the comments.


I’m going to make a bold prediction. Long after you and I are gone, HTML will still be around. Not just in billions of archived pages from our era, but as a living, breathing entity. Too much effort, energy, and investment has gone into developing the web’s tools, protocols, and platforms for it to be abandoned lightly, if indeed at all.

From Semantics in HTML 5 by John Allsopp