Category: Code

Stop macOS from asking for the ssh passcode every time

Upon the most recent update for macOS ( version 10.12.2), I was being prompted for my SSH passcode every time I would ssh into a server.  As someone who moves between servers often, this got annoying.

Thankfully, a new config option can fix this:

UseKeychain yes

Just add that to your .ssh/config and you don’t need to enter your private key passcode every time you ssh.  The old behavior will be back.  This can be enabled only for specific servers using the cascade inside.ssh/config or for all servers.

WordPress in a next generation PHP world

HHVM has now released it’s second long term support release and PHP 7 is in the final stages of implementing changes. It’s an exciting time for PHP and to be a PHP developer which means it is also an exciting time to be a WordPress developer since it creates an opportunity for WordPress to once again embrace forwards compatibility.

While I was at PHPUK, one of the most common conversations I had was people being critical of WordPress for supporting PHP 5.2 as a minimum.  Many of those same people became less critical once they find out WordPress runs great on PHP 5.6 and that many people run it on HHVM.

For the last several weeks, WordPress has been running it’s unit tests on PHP7 nightly builds. They’ve been running on HHVM for months. Right now, the unit tests are not passing for either one and as far as I know, have never passed for either one.  This is a problem.

I’m planning on spending some time during the 4.3 development cycle focused on these next generation platforms. Rasmus has put together a php7 vagrant box and JJJ created an addon to Varying Vagrant Vagrants to enable HHVM there. WP engine also has it’s own WordPress HHVM vagrant box. I intend to use all three of these to help.

Davey Shafik has put together a great two part series on the changes coming in PHP 7.  The two changes that are most likely to cause issues for WordPress sites are the removal of all deprecated features and the deprecation of PHP4 style constructors. This is going to affect many widgets along with all sorts of other code.

It’s exciting to see PHP moving forward.  The competition between HHVM and PHP runtimes is making PHP faster and is only going to push the language forward. It’s a great time to be writing PHP.

Aggregate Multiple Log Files From Multiple Servers

The majority of the time I need to analyze logs across multiple servers, I use logstash.  Sometimes though I want to aggregate the actual files on the server and go through them myself with awk and grep.  For doing that, I use two tools.

  1. In my bash config, I have a function called access_concat that reads out regular and gzipped access logs.
    access_concat(){
        find $1 -name "acc*" -not -name "*.gz" -exec cat '{}' \;
        find $1 -name "acc*" -name "*.gz" -exec zcat '{}' \;
    }

    I can pass a path that log files are stored in and it will search them to find the files I actually want.

  2. Dancer’s Shell (or DSH) makes it easy for me to run a command across multiple servers.

Combining these two, I can run:  dsh -M -c -g prd-wp 'access_concat /logs >> ~/oct22.logs' to concatenate all of the log files that exist on the server today. I then just need to scp down oct22.logs and I can easily run my analysis locally.

Note that to do this, you need to configure dsh so that the servers you want to access are in the prd-wp group (or better yet, the logical name for whatever you are working on).

Introducing Punchcard.py

If you haven’t noticed, I like punchcard graphs.  I like them so much, I have a script that to generate them.  I’ve now released this script for everyone to use.

Punchcard.py is simple to use and I hope you find it useful.  It accepts a stream of unix timestamps and creates a punchcard graph. It can very useful if you’re trying to figure out days and times of activity.

How Do I Install punchcard.py?

The easiest way to install punchcard.py is with pip.  Just run

pip install punchcard.py

If you install it manually (by cloning the punchcard.py git repository and running python setup.py install), you’ll also need to install the dependency pygooglechart.

What options are available

The only option that is currently available is to change the filename. To do that, use the -f option like

punchcard.py -f tweets.png

How do I generate a stream of timestamps

For WordPress Posts, I Butchered the WordPress importer plugin. To use this, clone that repo and run

php punchcard.php export_file_name.xml | punchcard.py

For Twitter, I created a similar simple script. I have the script setup for retweets, original tweets and all tweets. I just change the echo line at the end depending on which I want to output. To use this script, I run

php twitter.php archive.csv | punchcard.py

What should I do if I find bugs

Please create a github issue with any bugs you might find. Please make sure to include steps to reproduce including a relevant data source file.

Inspiration

This script is largely just an abstraction of Bash History Punchcard by Matt Behrens. Without his work, this wouldn’t exist.

Final Notes

If you use punchcard.py to create any interesting graphs, tweet @aaronjorbin, I’d love to see that it’s being used.

The new AddThis.com homepage

Yesterday my team relaunched AddThis.com, consolidated our brand, and launched a bunch of cool new features. One of my favorite parts is the map on the homepage which shows real-time shares as they are happening.

The map was interesting to build. We wanted it to be fast, look good on all browsers (including mobile and tablets) and communicate the reach we have being on 14 million websites and reaching 1.3 billion (yes, with a B) users every month. To do this, I looked at options using Canvas and SVG, but ultimately decided that good old-fashioned HTML and JavaScript would do the job best. We do use SVG and Canvas for it though, just not in the traditional in browser way.

The map itself is built using Protovis which while no longer actively developed, includes multiple map projections out of the box. We then use PhantomJS to create a png from the SVG that Protovis spits out. The share icons are built in a similar manner. They are canvas circles that we build into a sprite and then use PhantomJS for the actual sprite construction. By scripting the generating of these two key images, we were able to tweak and play with colors simply and with real data. No need for our design team to fire up photoshop and send over an image. Change some CSS or JS, run the build script and everything is ready to go.

Take a look at the rest of the site. Our entire team did a killer job with these new features and styling. Will, Foo, Jeff, and Jim all wrote up other pieces of this launch. Greg also highlighted how to user the new Trending Content Tool in WordPress. Exciting times here at AddThis.

IRC Notifications from a remote machine to my mac

For IRC, I like to use Irssi on a server that I can always keep running and log into no matter what machine I am on. One of the initial challenges with doing this was getting notifications on mentions. I solved this by following the tutorial on Irssi, screen, fnotify and Growl on OSX. The only difference between his setup and mine is that my bash script to do the notifying is simpler. I’ve pasted it below for you to use.

[bash]
#!/bin/sh

ssh harpua "tail -f .irssi/fnotify " | while read heading message; do growlnotify -t "${heading}" -m "${message}"; done
[/bash]

How do you solve the problem of IRC notifications from a remote machine?

In case you are wondering, all of my machines are aliased to Phish songs, hence Harpua.

EDIT: I’ve added the -s flag to growlnotify so that the updates are sticky and thus I see them when I get back to my machine if I’ve stepped away and I don’t leave people hanging.

Facebook shares some secrets on making MySQL scale — Cloud Computing News

When you’re storing every transaction for 800 million users and handling more than 60 million queries per second, your database environment had better be something special.

via Facebook shares some secrets on making MySQL scale — Cloud Computing News.

Facebook uses and pushes MySQL like no other. This article gives a great insight into how it uses MySQL to a level and degree like no other. Hattip Rich

Barcamp News Innovation Philly Hackathon Project

Part of Barcamp News Innovation Philly is an open data hackathon.  I wanted to do a live visualization of something and I wanted to use canvas.  What I did is create a “Paint thrown against the wall” visualization of tweets tagged #bcniphilly.  The color of the tweet is specific for the user, the size of the circle is based on the length of the tweet and the location is based on the id (so it’s pretty random).  It will take a moment to load the most recent tweets and auto updates every five seconds.  I’ve only tested it in Chrome (so no promises that it will work in anything else)  Check it out!

Flot – sexy graphs created in JavaScript

I recently had the opportunity to speak at the DC jQuery User Group during an entire meetup dedicated to charts and graphs. Russel Heimlich presented on Google Charts and Chris Bannon presented on Wijmo while I had the honor to present on Flot.

When AddThis switched to Flot, I had a chance to build some really cool charts. This was my opportunity to get some more developers interested in Flot. You can check out my slides and my Sample Code. If you’re looking for more information, check out Flot on Github or the old Google Code site.