Josh Betz
Made with 🧀 in Madison
Made with 🧀 in Madison
Occasionally I need to send sensitive files to someone on the internet. I took a tip I once heard from Merlin Mann and built a script to automate this as much as possible. It requires Hazel and a cloud sharing service that syncs to your Mac. I’m using Dropbox.
The basic idea is to use Dropbox as a place to share files safely and automate the process with Hazel. We’re going to rely on long, obscure filenames along with randomly generated passwords and short availability windows to protoct our files. We can automate all of this through a couple Hazel commands and an Applescript.
The Hazel commands are set up as follows. The first one looks for any file or folder older than 7 days that is a zip archive and deletes it. This enforces our short availability window. You could make the window anything you like. The second command looks for anything that’s not a zip archive and runs the following Applescript on it.
https://gist.github.com/4686756
We generate a random password with openssl rand -base64 32
— this means we’ll get 32 random base64 characters. We also create a SHA1 hash of the file to append to the filename. After that, just zip the file with the random password and put the password on the clipboard. You can do more, like generating a notification when the script is done. I have a TextExander snippet that lets you fill in the filename and grabs the password off the clipboard.
Ideally, you wouldn’t send the password along with the link to document. Try to use two different methods to notify someone where the file is located and what the password is — even if it’s just two different email accounts on a separate server.
For now this won’t work with directories because the SHA1 hash of a directory is blank. An easy way to fix that would be to zip the directory first and then get the hash and rename the zip file.
Chris Coyier recently posted an article about using lists in navgiation on CSS Tricks. I tend to agree that they’re unnecessary. The first time I built a menu with a nav
wrapping a ul
wrapping a bunch of li
‘s wrapping a bunch of a
‘s it felt gross, but I did it because I thought that was easier for screen readers to understand.
I just redesigned my site and decided that I wanted a simpler structure for my menu this time. Since WordPress builds menus in lists, I created a custom walker class for wp_nav_menu
that formats the menu the way I want.
https://gist.github.com/4688292
That looks like a lot. It’s mostly just a copy of the Walker_Nav_Menu
class with a few things changed:
nav
instead of ul
div
instead of ul
li
wrapping each linkid
and class
‘s that would normally go on the li
on the a
instead.Of course, you have to tell your nav menu to use this walker. Since this disables the fallback if you don’t have a menu set, you’ll have to specify a menu.
wp_nav_menu
↩
Paul Irish explains when translate()
is better than top/right/bottom/left. I think the most interesting part of this is how he uses the tools in Chrome to diagnose the problem.
In the past1, I’ve been a big fan of running a virtualized web server locally instead of intalling PHP and Apache (or Nginx) directly on my development machine. I think I just changed my mind.
A little over a month ago, I read Elliot Jay Stocks’ article abou the stuff he missed on vacation. One of those things was the release of Anvil. Anvil is really just a nice looking front-end for Pow. Pow is a local rack web server built on node.js. It adds some cool stuff to /etc/resolvr
to handle DNS for development domains and then you just symlink a directory into ~/.pow
to get a server at a domain like .dev
.
For some reason I’ve never really been a fan of MAMP. I think the “zero-config” thing stuck with me when I saw Pow though. So I started looking around2 to see if I could use Pow with PHP apps.
It turns out to be possible. There’s a gem called rack-legacy which is exactly for this purpose. Unfortunately rack-legacy uses the CGI version of PHP which doesn’t come in Mountain Lion. So you have to install PHP from source, which requires you to install mcrypt from source as well.
cd
into the PHP source directory and configure it ./configure --with-cgi --enable-mbstring --with-curl --with-xmlrpc --with-mcrypt=/usr
make
and make install
PHP.So, now that we have PHP set up, install Pow, Rack, and all the other dependancies.
brew install node sqlite
gem install rack rack-legacy rack-rewrite
curl get.pow.cx | sh
I think the only dependancy for pow is node, which I used homebrew to install. I also installed sqlite because it’s easier to use locoally than MySQL. And Laravel makes it simple to switch over to a SQLite database.
It’s finally time to set up our Laravel app. Rack apps need a config.ru
file in the root which is just a Ruby script that configures the server for this particular app. Put the following config.ru
in Laravel’s public
folder and point Pow at the same folder.
require 'rack'
require 'rack-legacy'
require 'rack-rewrite'
use Rack::Rewrite do
send_file %r{([^?]+)}, Dir.getwd + '$1', :if => Proc.new { |env|
path = File.expand_path(Dir.getwd + env['PATH_INFO'])
File.file?(path)
}
rewrite %r{(.*)?}, 'index.php$1'
end
use Rack::Legacy::Php, Dir.getwd
run Rack::File.new Dir.getwd
That’s it.
There were kind of two main resources that I used to fully understand what was going on here and how to set this up. If you’re going to be a PHP developer and use Ruby tools, get used to seeing PHP as “Legacy Development” I guess.
I’ve written a few articles about setting up a VM in VirtualBox for PHP development locally. Including the original, part 2, the one about nginx, and the video. ↩
I even considered writing my own “zero-configuration” web server that would work with PHP for a minute. ↩