Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Developer Toolbox

Developer Toolbox

Presented at PHP Dublin #2 - https://tito.io/engine-yard/php-dublin

Overview of six developer tools (Boris, HTTPie, jq, terminator, MailCatcher and boom) that will give you fabulous secret powers.

Eugene Kenny

May 21, 2013
Tweet

More Decks by Eugene Kenny

Other Decks in Programming

Transcript

  1. Technology on Adverts.ie • Graphite for stats and graphs •

    Varnish for load balancing, Pound for SSL • Composer for PHP dependencies
  2. What am I going to talk about? Overview of 6

    tools (Boris, HTTPie, jq, terminator, MailCatcher and boom) Assumption: you work on either Linux or OS X, use the command line
  3. php -a vs Boris > php -a php > $arr

    = ["Hello", "World"]; php > var_dump($arr); array(2) { [0]=> string(5) => "Hello" [1]=> string(5) => "World" } php > $arr[1] = "PHP" php > var_dump($arr); array(2) { [0]=> string(5) "Hello" [1]=> string(3) => "PHP" }
  4. php -a vs Boris > boris/bin/boris boris> $arr = ["Hello",

    "World"]; array(2) { [0]=> string(5) "Hello" [1]=> string(5) "World" } boris> $arr[1] = "Boris"; array(2) { [0]=> string(5) "Hello" [1]=> string(5) "Boris" }
  5. Loading your environment > boris -r bootstrap.php boris> $user =

    new User(); !object(User)#8 (1) { ["username"]=> NULL } boris> $user->username = "eugeneius" !string(9) "eugeneius" boris> $user !object(User)#8 (1) { ["username"]=> string(9) "eugeneius" }
  6. Other nice features: • Remembers your command history • Will

    load .borisrc file in your home directory, which can contain arbitrary PHP code to run at startup • You can implement a custom Inspector, to control how values are printed
  7. curl -X POST http://example.com \ -d arg=val -d foo=bar \

    -H X-Api-Key:a0b0c0 \ -H X-Custom-Header:whatever http POST http://example.com \ arg=val foo=bar \ X-Api-Key:a0b0c0 \ X-Custom-Header:whatever HTTPie vs cURL
  8. curl -X POST http://example.com -F arg=val -F [email protected] http POST

    http://example.com arg=val [email protected] Uploading files http PUT http://example.com < lolcat.jpg curl -X PUT http://example.com -T [email protected]
  9. > curl http://api.tumblr.com/v2/blog/wheningit.tumblr.com/posts? api_key=fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4 {"meta":{"status":200,"msg":"OK"},"response":{"blog": {"title":"When in git","name":"wheningit","posts": 49,"url":"http:\/\/wheningit.tumblr.com\/","updated": 1364229309,"description":"Remember

    that time using git when... Brought to you by @kylerush and @creighfishtaco.","ask":false,"ask_anon":false,"is_nsfw":false," share_likes":true,"likes":0},"posts": [{"blog_name":"wheningit","id":46258279610,"post_url":"http:\/\/ wheningit.tumblr.com\/post\/46258279610\/when-i-discovered-what- the-porcelain-flag-did-on-git","slug":"when-i-discovered-what- the-porcelain-flag-did-on-git","type":"text","date":"2013-03-25 16:35:09 GMT","timestamp": 1364229309,"state":"published","format":"html","reblog_key":"goC oFPdn","tags":[],"short_url":"http:\/\/tmblr.co\/ Zt8S7vh5DLIw","highlighted":[],"note_count":10,"title":"When I Fetching JSON with cURL
  10. Fetching JSON with HTTPie > http http://api.tumblr.com/v2/blog/wheningit.tumblr.com/posts? api_key=fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4 { "meta":

    { "status": 200, "msg": "OK" }, "response": { "blog": { "title": "When in git", "name": "wheningit", "posts": 49, "url": "http://wheningit.tumblr.com", "updated": 1364229309, "description": "Remember that time using git when... Brought to you by @kylerush and @creighfishtaco.", "ask": false,
  11. jq parses JSON > echo '{"key":"value"}' | jq '.key' "value"

    > echo '["one", "two", "three"]' | jq '.[]' "one" "two" "three" > echo '[1, 2, 3]' | jq 'add' 6 > echo '{"apples": 10, "pears": 13}' | jq '[.[]] | add' 23
  12. Pipe output from HTTPie > http https://api.github.com/users/eugeneius/repos [ { "id":

    3127875, "name": "boom", "full_name": "eugeneius/boom", "owner": { "login": "eugeneius", "id" 432189, "url": "https://api.github.com/users/eugeneius", "html_url": "https://github.com/users/eugeneius", ... }, private: false, html_url: "https://github.com/eugeneius/boom", url: "https://api.github.com/eugeneius/boom", ... } ... ]
  13. Pipe output from HTTPie > http https://api.github.com/users/eugeneius/repos \ | jq

    '.[].html_url' "https://github.com/eugeneius/boom" "https://github.com/eugeneius/jquery-onetime" "https://github.com/eugeneius/PHP-Xero" "https://github.com/eugeneius/URLShortener"
  14. Pipe output from HTTPie > http https://api.github.com/users/eugeneius/repos \ | jq

    '.[].html_url' "https://github.com/eugeneius/boom" "https://github.com/eugeneius/jquery-onetime" "https://github.com/eugeneius/PHP-Xero" "https://github.com/eugeneius/URLShortener" > http https://api.github.com/users/eugeneius/repos \ | jq '.[].html_url' | xargs -l xdg-open
  15. Pipe output from HTTPie > http https://api.github.com/users/eugeneius/repos \ | jq

    '.[].html_url' "https://github.com/eugeneius/boom" "https://github.com/eugeneius/jquery-onetime" "https://github.com/eugeneius/PHP-Xero" "https://github.com/eugeneius/URLShortener" > http https://api.github.com/users/eugeneius/repos \ | jq '.[].html_url' | xargs -l xdg-open
  16. Saved layouts [layouts] [[production]] [[[window1]]] type = Window size =

    1920, 1028 [[[split1]]] type = HPaned position = 960 parent = window1 [[[terminal1]]] type = Terminal parent = split1 command = ssh www1 [[[terminal2]]] type = Terminal parent = split1 command = ssh www2 ...
  17. Tool #5: MailCatcher sudo apt-get install ruby sudo apt-get install

    libsqlite3-dev sudo gem install mailcatcher mailcatcher Setup:
  18. > boris/bin/boris boris> $to = "[email protected]"; !string(15) "[email protected]" boris> $subject

    = "MailCatcher test"; !string(16) "MailCatcher test" boris> $message = "This message should go to MailCatcher"; !string(37) "This message should go to MailCatcher" boris> $headers = "From: [email protected]"; !string(23) "From: [email protected]" boris> mail($to, $subject, $message, $headers); !bool(true) Send a test mail with boris
  19. Tool #6: Boom sudo apt-get install ruby sudo gem install

    boom sudo apt-get install xclip Setup:
  20. > boom urls Boom! Created a new list called urls.

    > boom urls github https://github.com Boom! github in urls is https://github.com. Got it. > boom urls adverts http://www.adverts.ie Boom! adverts in urls is http://www.adverts.ie. Got it. > boom adverts Boom! We just copied http://www.adverts.ie to your clipboard. Boom is a key-value store
  21. { "lists": [ "urls": [ {"github": "https://github.com"}, {"adverts": "http://www.adverts.ie"}, ...

    ], "gifs": [ {"homerthink":"http://i.imgur.com/25J7e.gif"}, {"slothshades":"http://i.imgur.com/IHcRs.gif"}, ... ] } Data is stored in ~/.boom
  22. > boom temp clipboard "http://bit.ly/errhcw" Boom! clipboard in temp is

    http://bit.ly/errhcw. Got it. Dropbox for copy and paste On computer 1: > boom clipboard Boom! We just copied http://bit.ly/errhcw to your clipboard. On computer 2: Dropbox syncs ~/.boom
  23. > boom cmds gitlocalmerged Boom! We just copied git branch

    --merged master | grep -v 'master' | sed 's/ *//;' | tr '\n' ' ' | sed 's/^/git branch -d /' | sh to your clipboard. > git branch --merged [...] Deleted branch move_newsletter_scripts (was 81b0f8d) Deleted branch initialise_arrays (was 23945fe) ... Store common commands > boom echo gitlocalmerged | sh Deleted branch move_newsletter_scripts (was 81b0f8d) Deleted branch initialise_arrays (was 23945fe) ... Or:
  24. > boom cmds gitlocalmerged Boom! We just copied git branch

    --merged master | grep -v 'master' | sed 's/ *//;' | tr '\n' ' ' | sed 's/^/git branch -d /' | sh to your clipboard. > git branch --merged [...] Deleted branch move_newsletter_scripts (was 81b0f8d) Deleted branch initialise_arrays (was 23945fe) ... Store common commands > boom echo gitlocalmerged | sh Deleted branch move_newsletter_scripts (was 81b0f8d) Deleted branch initialise_arrays (was 23945fe) ... Or:
  25. Can we put them all together? No. I'm not MacGyver.

    But separately, these tools can each make you more productive.
  26. Can we put them all together? No. I'm not MacGyver.

    But separately, these tools can each make you more productive. Together, they can make you a LOT more productive.