Rake is great. It's a clean, high level API for running shell commands and defining / organizing task functions. I originally started using it for Rails projects but now I use it for AWS Lambda development, Continuous Development Projects (through Jenkins) and even Mac OSX. Here are a few of my favorite commands.


Internet speed test

This is a very simple example aimed to show how you can use Rakefile to substitute commands in Terminal. This collection of scripts will enable you to run Speedtest.net commands without having to open the browser or mistakingly click on an advertisement.

You will need homebrew to get started. Read this article.

namespace :speedtest do
  desc %Q{ Install Speedtest.net }
  task :install do
    sh %{ brew update && doctor }
    sh %{ brew install speedtest_cli }
  desc %Q{ Check Download & Upload Speed }
  task :all do
    sh %{ speedtest-cli --simple }
  desc %Q{ Check Upload Speed }
  task :upload do
    sh %{ speedtest-cli --no-download }
  desc %Q{ Check Download Speed }
  task :download do
    sh %{ speedtest-cli --no-upload }

Install Speedtest.net into your local computer.

rake speedtest:install

Check your upload speed. I use this all the time before uploading GB files to AWS S3.

rake speedtest:upload

IP Addresses

Create a Rakefile and paste this code.

namespace :ip do
  desc %Q{ Get Internal IP Address }
  task :internal do
    sh %{ ipconfig getifaddr en0 }
  desc %Q{ Get External IP Address }
  task :external do
    sh %{ curl -s http://checkip.dyndns.org/ | sed 's/[a-zA-Z<>/ :]//g' }

Retrieve your internal IP addresses.

rake ip:internal

Retrieve your external IP addresses.

rake ip:external


Modify your Proxy Settings

namespace :proxy do
  desc %Q{ Toggle Web Proxy (HTTP) OFF }
  task :off do
    sh %{ networksetup -setwebproxystate Ethernet off }
  desc %Q{ Toggle Web Proxy (HTTP) ON }
  task :on do
    sh %{ networksetup -setwebproxy Ethernet 3128 }
  desc %Q{ Add *.localhost to Mac OsX Network Proxy Settings }
  task :bypass do
    sh %{ networksetup -setproxybypassdomains Ethernet *.localhost, *.local, 169.254/16 }
rake proxy:on
rake proxy:off

Finding files

I prefer not to memorize find and grep commands and instead just use this cheat sheet to find stuff by name, text, or by type. Within your Rakefile paste:

namespace :find do
  desc %Q{ Find by file type. rake find:by_type[wav,~] }
  task :by_type, [:file_type, :dir] do |task, args|
    type = args.file_type
    dir  = args.dir
    sh %{ find #{dir} -iname "*.#{type}" }
  desc %Q{ Find by file type ignore error messages. }
  task :by_type_ignore, [:file_type, :dir] do |task, args|
    type = args.file_type
    dir  = args.dir
    sh %{ find #{dir} -type f -name "*.#{type}" 2>/dev/null  }
  desc %Q{ Finds [text] in any file in any subfolder of [dir]. }
  # rake find:by_text["chris mendez",~/Desktop/*.txt]
  task :by_text, [:text, :dir] do |task, args|
    text = args.text
    dir  = args.dir
    cmd  = %{ grep -r -l "#{text}" #{dir} }
    sh cmd
  desc %Q{ Find a phone number with this pattern 213400 }
  task :by_phone, [:digits, :dir] do |task, args|
    text = args.digits
    dir  = args.dir
    sh %{ grep -r -l [0-9][0-9][0-9][0-9][0-9][0-9] #{dir} }

Find .WAV files within my home directory.

rake find:by_type[wav,~] 

Find the save .WAV files within my home directory but ignore any errors.

rake find:by_type_ignore[wav,~] 

Find a Verizon cell phone number within a text file.

rake find:by_text_within[213400,~/Desktop/*.txt]


Ringtone Maker

You can even go further and include other OSX commands into your Rakefile and organize it with a namespace:

namespace :ringtone do
  desc %Q{ Convert an Mp3 into a Ringtone. }
  task :create, [:mp3, :name] do |task, args|
    mp3 = args.mp3
    name = args.name
    sh %{ afconvert #{mp3} #{name}.m4r -f m4af }
rake ringtone:create[/path/to/file.mp3,"My Ringtone"]

So Much More

There are many more OSX Commands you can create. Read More.