A Developer's Arsenal of Productivity Hacks

Ben Buckman

New Leaf Digital

DrupalCampNYC8 July 2010

View the blog post & comments about this session

Welcome

Drupal runs on *nix servers, it helps to know how to use them
Non-developer with dev skills = Productivity Boost

some macro some micro
some basic some advanced
some sophisticated some ghetto

I hope everyone will learn something & then we can share our own tricks

We're mostly self-taught or learn through human osmosis ∴ we can all learn from each other.

Going thru everything fast, but will all be
@ http://benbuckman.net/hacks

What We'll Cover

Terminal fu

Basics

Basics (cont.)

Output

Handling Output

Editing:

find

Loops

Loops cont.

grep

Shell Stew

Shell Stew

find . -name "*.tpl.php" | wc -l
if [[ `find . -name "*.tpl.php" | wc -l` -gt 100 ]];
then echo "Jeez you have a lot of templates!"; fi

Symlinks

More shell goodness

More shell goodness

SVN

Drush

  DB_NAME=`drush sql-conf | grep "database" | awk '{print $3}'`
  drush sql-query "SELECT table_name, 
  (data_length+index_length)/1024/1024 'Size_MB', 
  data_free/1024/1024 'Free_MB' FROM information_schema.TABLES 
  WHERE table_schema='${DB_NAME}' ORDER BY table_name;"
  <!-- `drush sql-query "SELECT table_schema 'DB', sum(data_length+index_length)/1024/1024 'Size_MB', sum(data_free)/1024/1024 'Free_MB' FROM information_schema.TABLES WHERE table_schema='${DB_NAME}' GROUP BY table_schema;" ` -->

Scripting

Some of my scripts

Apache: Environment detection with mod_rewrite

  RewriteEngine On
  <!--## set env vars for domains
    ## dash indicates no subst
    ## '.*' is critical!! thanks http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html
    ## no commas between flags!-->
  #  siteenv = local, live, dev
  RewriteCond %{SERVER_NAME} localhost
  RewriteRule .* - [E=siteenv:local]
 
  RewriteCond %{SERVER_NAME} ^site.com$ [OR]
  RewriteCond %{SERVER_NAME} ^www.site.com$
  RewriteRule .* - [E=siteenv:live]
 
  RewriteCond %{SERVER_NAME} ^dev.site.com$
  RewriteRule .* - [E=siteenv:dev]

Mac

Textmate

Capistrano/Webistrano + Drush

    namespace :drush do
 
    set :webroot, "#{deploy_to}/current"
    set :drush_cmd, "drush --root=#{webroot} --uri=#{drush_uri} "
 
    def drush_intro
      logger.info "Running drush with root=#{webroot} and uri=#{drush_uri}"
    end
 
    # status/info
    task :drush_status do
      drush_intro
      # hide the DB password
      logger.info capture "#{drush_cmd} status  | grep -v \"Password\" "
    end

Misc

Resources

Thanks to

Contact Me

http://benbuck.net/hacks

Thank You