Testing HTTP redirects with Curl

We’ve got a really complex redirection setup for the current project at work, a mix of some general rules (http://blog.example.com/ to http://www.example.com/blog/), some oddball domain redirects (http://blog.example.jp/ to http://www.example.co.jp/blog/), and some more esoteric ones thrown in there for luck. I started off briefing my colleague with a description of what I needed, but this very quickly became too complex and I realised I really needed to give him a set of initial URLs and expected results. Why not express these rules in a quick test script? My colleague could run the script against the redirects as he wrote them, and see the successful ones and the failures, along with detail about why they failed. Continue reading Testing HTTP redirects with Curl

Using the OSX clipboard from the command line

The OSX pbcopy terminal command, which adds “stuff” to the clipboard to be pasted later, is really useful. For example, to download some webpage and put the HTML source in the clipboard:

curl -s http://example.com/ | pbcopy

Here’s a WordPress example; want to get some fresh API salts and keys for a wp-config.php? Try this:

curl -s https://api.wordpress.org/secret-key/1.1/salt/ | pbcopy

Want to be notified when the download and copy are complete? Add the say command, like this:

curl -s https://api.wordpress.org/secret-key/1.1/salt/ | pbcopy; say 'Ready to paste';

I use DTerm, which is an excellent little “popup terminal” which inherits the current context, and these commands are super handy here.

Alfred extension: Convert clipboard to plain text

Update: Well, what do you I know? It turns out that Andrew, developer of Alfred, has already got this covered and my weak Google-Fu didn’t turn it up: plain text paste in Alfred. So don’t use my version, use his.

I got tired of copying formatted text from a web page, pasting into a text editor, copying again, then pasting into a formatted email to get the clean, default, styling. The Alfred App extension linked below allows you to launch Alfred, type “pt”, hit return and boom anything in your clipboard is plain text.

Download: Convert clipboard to plain text.alfredextension (zip file) (Don’t download, use the method on Andrew’s blog post.)

For those interested, this is was the (very simple) command inside the extension:

pbpaste | textutil -stdin -stdout -convert txt | pbcopy;
echo "Converted to plain text: ";