SlideShare uma empresa Scribd logo
1 de 82
Baixar para ler offline
Fifty Tips, Tricks & Tools
                                         …in one talk
               Sean Coates Fictive Kin
               gimmebar.com




Monday, March 7, 2011
“Hey, did
              you know that you
                   could use
                  {some tool}
              to do that better?”


Monday, March 7, 2011
Photo: http://flic.kr/p/82aL6y
Monday, March 7, 2011
Monday, March 7, 2011
                          I
                        Services
Paste Bins




Monday, March 7, 2011
one




                                         Paste Bins
                •Common
                •Useful for:
                  •large dumps
                  •source code sharing
                  •bugs
                  •diffs
                  •etc.
                •Lots of generic ones      http://pastebin.com/




Monday, March 7, 2011
two




                                                Mine
                •There are many like it, but
                this one is mine.
                •micro nano API:
                •“secret” URLs


                                               http://paste.roguecoders.com/




Monday, March 7, 2011
Mine
                •There are many like it, but
                this one is mine.
                •micro nano API:
                •“secret” URLs

                 $ cat /Users/sean/bin/pastebin | pastebin
                 URL: http://paste.roguecoders.com/p/d7df33ac561e8e46538a6f71e051f41d.html


                                                http://paste.roguecoders.com/




Monday, March 7, 2011
Mine
                •There are many like it, but
                this one is mine.
                •micro nano API:
                •“secret” URLs


                                               http://paste.roguecoders.com/




Monday, March 7, 2011
three




                                        Gist (GitHub)
                •Ties into GitHub
                •Forkable, iterative:
                •More collaborative



                                           http://gist.github.com/




Monday, March 7, 2011
Gist (GitHub)
                •Ties into GitHub
                •Forkable, iterative:
                •More collaborative



                                           http://gist.github.com/




Monday, March 7, 2011
Gist (GitHub)
                •Ties into GitHub
                •Forkable, iterative:
                •More collaborative



                                           http://gist.github.com/




Monday, March 7, 2011
Interactive Paste Bins




Monday, March 7, 2011
four




                                              JS Bin
                •Paste bin that understands
                HTML and JavaScript
                •Includes libraries
                •Code available on GitHub:
                   •github.com/remy/jsbin
                •Great for sharing browser-
                specific problems
                •Simple and straightforward   http://jsbin.com/




Monday, March 7, 2011
five




                                             JS Fiddle
                •HTML, CSS, JS
                •More complex, but nicer
                integration for non-simple
                •Easy pull-in for external
                URLs
                •Larger framework support
                •Versioning, easy sharing,
                forking                       http://jsfiddle.net/




Monday, March 7, 2011
six




                                               IDE One
                •Online code compiling and
                execution
                •Not just JavaScript: PHP,
                Python, Perl, Ruby, Java, C,
                and a whole bunch of others
                •Source, input, output
                •Great for posting questions
                on (e.g.) stackoverflow         http://ideone.com/




Monday, March 7, 2011
IDE One
                •Online code compiling and
                execution
                •Not just JavaScript: PHP,
                Python, Perl, Ruby, Java, C,
                and a whole bunch of others
                •Source, input, output
                •Great for posting questions
                on (e.g.) stackoverflow         http://ideone.com/




Monday, March 7, 2011
IDE One
                •Online code compiling and
                execution
                •Not just JavaScript: PHP,
                Python, Perl, Ruby, Java, C,
                and a whole bunch of others
                •Source, input, output
                •Great for posting questions
                on (e.g.) stackoverflow         http://ideone.com/




Monday, March 7, 2011
JavaScript Helpers




Monday, March 7, 2011
seven




                                         JS Beautifer
                •Pretty printer for JS
                •Useful for de-minification
                (will not rename variables)
                •Helps spot syntax problems
                •Formats JSON documents to
                make them readable
                •Python version coming
                •JS version uses Rhino        http://jsbeautifier.org/




Monday, March 7, 2011
JS Beautifer
                •Pretty printer for JS
                •Useful for de-minification
                (will not rename variables)
                •Helps spot syntax problems
                •Formats JSON documents to
                make them readable
                •Python version coming
                •JS version uses Rhino        http://jsbeautifier.org/




Monday, March 7, 2011
JS Beautifer
                •Pretty printer for JS
                •Useful for de-minification
                (will not rename variables)
                •Helps spot syntax problems
                •Formats JSON documents to
                make them readable
                •Python version coming
                •JS version uses Rhino        http://jsbeautifier.org/




Monday, March 7, 2011
eight




                                                  JSLint
                •Checks the syntax of your JS
                •Insults you when you do
                something stupid (you idiot)
                •Really helpful for debugging
                JS’s sometimes-hard-to-
                predict behaviour
                •Annoying when you are
                slightly smarter than it is (-:   http://jslint.com/

                •Also: Crockford

Monday, March 7, 2011
nine




                                      WonderProxy
                •Geolocation testing
                •37 Locations
                •25 Countries
                •5 Continents
                •Find Paul Reinheimer and
                ask him about it

                                            http://wonderproxy.com/




Monday, March 7, 2011
ten




                                            httpstat.us
                •Quick Reference for HTTP
                status codes
                •Build a RESTishfuly API!
                •Test pages for each code
                  •http://httpstat.us/200
                  •http://httpstat.us/404
                  •(etc.)
                                             http://httpstat.us/




Monday, March 7, 2011
Monday, March 7, 2011
                        II
                        Unix
eleven


                                        /etc/hosts
                           (or %SystemRoot%system32driversetchosts)
               • You probably already know about this:
                        $ cat /etc/hosts | grep habari.local
                        127.0.0.1! habari.local
                        $ ping habari.local
                        PING habari.local (127.0.0.1): 56 data bytes




Monday, March 7, 2011
/etc/hosts
                            (or %SystemRoot%system32driversetchosts)
               • But you can also name interfaces:
                        $ cat /etc/hosts | grep 'www.local'
                        64.15.79.182! eth0-0.local! www.local


               • Useful for daemon configuration:
                        <VirtualHost www.local:80>
                        !   ServerName www.seancoates.com
                        !   RedirectMatch ^/(.*)$ http://seancoates.com/$1
                        </VirtualHost>




Monday, March 7, 2011
twelve



                                        netstat
               • Find out which ports and IPs a process is bound to
               • On Linux (and elsewhere with different arguments):
                        # netstat -tlpn | grep mysqld
                        tcp        0      0 127.0.0.1:3306
                        0.0.0.0:*               LISTEN           31506/
                        mysqld


               • (Bound to 127.0.0.1 (localhost) on port 3306)

Monday, March 7, 2011
thirteen



                                   top & atop
               • High-level system overview




Monday, March 7, 2011
top & atop
               • High-level overview




Monday, March 7, 2011
top & atop
               • High-level overview




Monday, March 7, 2011
top & atop
               • High-level overview




Monday, March 7, 2011
fourteen



                                                          lsof
               • Ever wondered which process has a file open?
                        sean@iconoclast:~$ ls -l sekrit.log

                        -rw-rw-r-- 1 sean sean 32 2011-03-04 17:49 sekrit.log

                        sean@iconoclast:~$ ls -l sekrit.log

                        -rw-rw-r-- 1 sean sean 48 2011-03-04 17:49 sekrit.log

                        sean@iconoclast:~$ lsof sekrit.log

                        COMMAND      PID USER    FD    TYPE DEVICE SIZE      NODE NAME

                        php        17142 sean     3w    REG     8,1   80 755383 sekrit.log

                        sean@iconoclast:~$ ps auxwww | grep 17142

                        sean       17142   0.0   0.3   24008   6760 pts/10    S    17:49

                              0:00 php ./ninja.php




Monday, March 7, 2011
fifteen



                                                    strace
               • Ever wondered which syscalls a process makes?
                        sean@iconoclast:~$ strace php -r 'echo "FOO";' 2>&1 | grep FOO

                        execve("/usr/local/bin/php", ["php", "-r", "echo "FOO";"],

                        [/* 21 vars */]) = 0

                        write(1, "FOO"..., 3FOO)                  = 3

                        sean@iconoclast:~$ strace php -r 'error_log("FOO");' 2>&1 | grep FOO

                        execve("/usr/local/bin/php", ["php", "-r", "error_log("FOO");"],

                        [/* 21 vars */]) = 0

                        write(2, "FOOn"..., 4FOO




Monday, March 7, 2011
sixteen



                                                        ldd
               • Ever wondered which libraries an executable references?
                        sean@iconoclast:~$ ldd `which php` | grep mysql

                        !     libmysqlclient.so.15 => /usr/lib/libmysqlclient.so.15 (0xb77ed000)

                        sean@iconoclast:~$ ldd `which php`

                        !     linux-gate.so.1 =>   (0xb7ee2000)

                        !     libcrypt.so.1 => /lib/tls/i686/cmov/libcrypt.so.1 (0xb7ea2000)

                        !     libc-client.so.2007b => /usr/lib/libc-client.so.2007b (0xb7d8e000)

                        !     libreadline.so.5 => /lib/libreadline.so.5 (0xb7d5b000)

                        !     libncurses.so.5 => /lib/libncurses.so.5 (0xb7d29000)

                        !     librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb7d20000)

                        !     libpam.so.0 => /lib/libpam.so.0 (0xb7d14000)

                        ...




Monday, March 7, 2011
seventeen



                                                         nice
               • Ever wanted to run a job that needs a higher or lower priority
                        than other jobs?
                        sean@gimmebarvm-sean:~$ sudo nice -n -19 php -r

                          'for ($a=0; $a<=100000000; $a++) {}; echo "DONEn";' &

                        [1] 7025

                        sean@gimmebarvm-sean:~$ time ls

                        gimmebar-access_log   mime.php    prod_dump   src

                        real!0m0.129s




Monday, March 7, 2011
nice
               • The priority can range from -19 (highest) to +20 (lowest), and
                        the default is 10.
                        sean@gimmebarvm-sean:~$ sudo nice -n 19 php -r

                          'for ($a=0; $a<=100000000; $a++) {}; echo "DONEn";' &

                        [1] 7044

                        sean@gimmebarvm-sean:~$ time ls

                        gimmebar-access_log   mime.php    prod_dump   src

                        real!0m0.003s




Monday, March 7, 2011
eighteen



                                           cron
               • Users have individual cron spools on most Unix systems
               • Need a system-wide cron? Try /etc/crontab
                      • Note: it has a 6th field (not just the time fields): user
               • Much easier to maintain in version control and to provision
                 with sysdmin tools
               • Try also /etc/cron.daily, /etc/cron.hourly, etc.

Monday, March 7, 2011
nineteen



                                     GNU Screen
                    •Terminal multiplexer
                    •Keep shell apps running even after logout
                    •Handles scrollback, window splits, pane management
                    •See also: tmux




Monday, March 7, 2011
twenty



                              visudo, vipw, vigr
               • Imagine what kind of horrible things could happen if you
                 break a file like /etc/sudoers? or /etc/passwd?
                      • visudo: safely edit /etc/sudoers
                      • vipw: safely edit /etc/passwd
                      • vigr: safely edit /etc/group
               • Files are parsed for errors before they’re committed

Monday, March 7, 2011
Monday, March 7, 2011
                        III
                        Shell
twenty-one



                        reverse-i-search (ctrl-r)




Monday, March 7, 2011
twenty-one



                        reverse-i-search (ctrl-r)




Monday, March 7, 2011
twenty-two



                        reuse last argument (esc-.)




Monday, March 7, 2011
twenty-two



                        reuse last argument (esc-.)




Monday, March 7, 2011
twenty-three



                        edit+run last command (fc)




Monday, March 7, 2011
twenty-three



                        edit+run last command (fc)




Monday, March 7, 2011
twenty-four



                        bash completion (⌦(tab))




Monday, March 7, 2011
twenty-four



                        bash completion (⌦(tab))




Monday, March 7, 2011
twenty-five



                                                   pipes
               • One of the great beauties of Unix: text streams
               • Chain these together, easily
                        $ cat /www/logs/seancoates.com-access_log 

                             | grep 'gimme' 

                             | wc -l

                        12




               • Small, purposeful utilities, not monoliths

Monday, March 7, 2011
twenty-six



                                         grep, zgrep, ack
               • Filter text streams with grep (previous slide)
               • Uncompress and filter with zgrep
               • Use ack (non-standard) grouping, and to do the right thing:
                        sarcasm:~/src/gimmebar/api (master)$ ack 'Config::'

                        inc/content/Flickr.php

                        22:! !   !   !   'api_key' => Config::FLICKR_API_KEY,



                        inc/storage/S3Storage.php

                        24:! !   !   Config::S3_BUCKET,

                        34:! !   !   return 'http://' . Config::S3_BUCKET .




Monday, March 7, 2011
twenty-seven



                             download without the file
               • Pipe curl directly into tar:
                        $ curl http://files.seancoates.com/test.tar.gz | tar zxf




               • Alternative to wget + tar, but doesn’t leave a mess
               • (not always what you want, but still convenient)


Monday, March 7, 2011
twenty-eight



                                     bash: always there
               • Bash is on almost every system
               • Scriptable and powerful, even when alternatives aren’t
                        available
                        $ A='0'; 

                          for f in *.php; do A="$A + `cat $f | wc -c`"; done; 

                          echo $A | bc




               • Shows the sum of the file sizes of all PHP files in the current
                        directory (thanks to `bc`)

Monday, March 7, 2011
twenty-nine



                                       perl pie (see also: sed)
               • Perl pie runs an arbitrary expression against the passed files
                 and modifies them in place
               • My favourite (but least intelligent) refactoring tool
                        $ perl -p -i -e 's/Config::/Configuration::/g' *.php




               • Replaces “Config” with “Configuration” static calls:
                        -                       'database' => Config::DATABASE_URL

                        +                       'database' => Configuration::DATABASE_URL




Monday, March 7, 2011
thirty



                                       sticky shell start
               • Put this in ~/.bashrc or ~/.profile
                        cd () { builtin cd "$@" ; pwd > ~/.pwd; }

                        cd "`cat ~/.pwd`"




               • New shells launch where the last shell operated
                        sarcasm:~/src/gimmebar/api/www-api (master)$ login

                        login: sean

                        Password:

                        Last login: Sun Mar   6 18:09:15 on ttys000

                        sarcasm:~/src/gimmebar/api/www-api (master)$




Monday, March 7, 2011
thirty-something (bonus)



                                  misc. shell stuffs
               • The `find` command is your friend when working in a
                 directory tree
               • Use `tail -f filename` to continually watch a file
               • When scripting the shell, the `xargs` command is often
                 useful
               • Use `2>&1` to merge stderr into stdout, as in:
                        a_command_that_uses_stderr >/dev/null 2>&1




Monday, March 7, 2011
Monday, March 7, 2011
                        IV
                        SSH
thirty-one



                                              keypairs
               • Skip the password, use pre-shared keys to log in to your
                 shells
               • Use `ssh-keygen` to generate a pair
               • Keep the private key protected
               • Put the public key in ~/.ssh/authorized_keys on the server
               • Log in without a password
               • (If it doesn’t work, one common error is permissions;         
                        `ssh -v ...` will often tell you; if not: use more `v`)

Monday, March 7, 2011
thirty-two



                                        ssh-copy-id
               • Easily copy your new key to a remote server
               • Sets permissions properly, and uses the right file if it’s not
                        ~/.ssh/authorized_keys




Monday, March 7, 2011
thirty-three



                                         ssh config
               • Local configuration allows host-specific settings for:
                 • username
                 • private key
                 • forwarded ports
                 • many other settings (compression, X forwarding, etc.)
               • ~/.ssh/config:
                        Host *.php.net
                          User scoates




Monday, March 7, 2011
thirty-four



                         ssh tunnels (port forwarding)
               • Make the remote machine’s MongoDB port available as
                        localhost:27017
                        ssh -L27017:localhost:27017 local.gimmebar.com



               • Forward your local port 80 to a remote machine as port 8000
                        ssh -R80:localhost:8000 iconoclast.caedmon.net




               • (can now access with `curl localhost:8000/` on iconoclast)
Monday, March 7, 2011
thirty-five



                                       kill ssh
               • ssh sessions can hang
               • `killall ssh`sucks if you have more than one session
               • [enter] ~ .
               • (SSH over VPN == extremely robust)



Monday, March 7, 2011
Monday, March 7, 2011
                          V
                        Development
thirty-six



                           const == var (not var == const)
               • All else being equal, I prefer this:
                        if (3 == $tries) { … }



               • Over this:
                        if ($tries == 3) { … }



               • Because this causes a compiler error:
                        if (3 = $tries) { … }



Monday, March 7, 2011
thirty-seven



                          git: publish on post-receive
               • put this in your post-receive hook:
                        echo "Staging dev.seancoates.com ..." && 
                        cd /www/webroots/seancoates.com/seancoates-dev && 
                        env -i git pull && 
                        echo "Staged."



               • When you push, this path is pulled


Monday, March 7, 2011
thirty-eight



                    github: publish on post-receive
               • Put this script somewhere in your web root (beware of
                        security and stuff):
                        <?php
                        $gitpath = '/usr/local/bin/git';
                        header("Content-type: text/plain");
                        system("/usr/bin/env -i " .
                          "HOME=/www/webroots/phpcon.org " .
                          "{$gitpath} pull 2>&1");
                        echo "nDone.n";



               • …and set this up on GitHub:
Monday, March 7, 2011
github: publish on post-receive
               • Put this script somewhere in your web root (beware of
                        security and stuff):
                        <?php
                        $gitpath = '/usr/local/bin/git';
                        header("Content-type: text/plain");
                        system("/usr/bin/env -i " .
                          "HOME=/www/webroots/phpcon.org " .
                          "{$gitpath} pull 2>&1");
                        echo "nDone.n";



               • And set this up on GitHub:
Monday, March 7, 2011
thirty-nine



                                        Email override
               • If your code uses sendmail to… send… mail… and if you can
                        override the path, change the path to point to his on dev:
                        cat >> /tmp/logmail.log



               • PHP makes this easy with the sendmail_path INI setting


Monday, March 7, 2011
forty



                               Crockford on JS
               • http://developer.yahoo.com/yui/theater




Monday, March 7, 2011
Monday, March 7, 2011
                        VI
                        Utilities
forty-one




                                                rrdtool
                •round-robin
                •compare week-over-week,
                day-over-day
                •easy to feed
                •not terribly easy to set up
                •takes care of the hard parts



Monday, March 7, 2011
forty-two




                                           Elasticfox
                •add-on for FireFox
                •a little quirky
                •handles most (but not all) of
                EC2’s maintenance functions
                •WAY easier than the Java CLI
                tools




Monday, March 7, 2011
forty-three




                                               Firebug
                •add-on for FireFox
                •JavaScript debugger
                •DOM inspector
                •Network monitor
                •Other browsers have similar




Monday, March 7, 2011
forty-four




                                               Webshell
                •<plug type=self/>
                •scripted HTTP using JS
                •... lots of other stuff, but that
                was another talk (-:




Monday, March 7, 2011
forty-five




                                           Dropbox
                •Great for sharing among
                teams
                •Easy sync
                •Free (sort of)
                •Supports growl




Monday, March 7, 2011
forty-six




                                         VirtualBox
                •Free Virtual Machine
                •Ideal for developers, VPN
                •Runs our dev hosts very well
                •Easy to distribute images




Monday, March 7, 2011
forty-seven




                                           OpenVPN
                •Arbitrary virtual networking
                •Ties multiple locations
                together as one network
                •Private network for
                production servers
                •Good Mac client: Viscosity



Monday, March 7, 2011
forty-eight




                                    supervisord
                 •Dæmonize apps, easily
                 •(avoid writing dæmon code yourself)
                 •Handles launch, respawn, concurrency
                 •Handles logging
                 •See: http://phpadvent.org/200915



Monday, March 7, 2011
forty-nine




                                            netcat
                 •Turn anything into a server (sort of)
                 •Useful for testing (like telnet, but without the telnet stuff)
                 •pbcopy trick: http://seancoates.com/blogs/remote-pbcopy
                 •almost as much of a Swiss-Army knife as SSH




Monday, March 7, 2011
fifty!




                                               Visor
                •System-wide terminal
                •Accessible by hotkey
                •Great for resident CLI apps
                (Webshell, REPL, DB client)
                •Mac only
                •http://visor.binaryage.com/



Monday, March 7, 2011
Contact
                    • I’ve probably lost my voice by now, so here’s my contact
                      info:
                      • sean@seancoates.com
                      • seancoates.com
                      • Work: fictivekin.com, gimmebar.com
                      • The Twitter: @coates

Monday, March 7, 2011

Mais conteúdo relacionado

Destaque

Symfony2 en pièces détachées
Symfony2 en pièces détachéesSymfony2 en pièces détachées
Symfony2 en pièces détachéesHugo Hamon
 
Développeurs, cachez-moi ça ! (Paris Web 2011)
Développeurs, cachez-moi ça ! (Paris Web 2011)Développeurs, cachez-moi ça ! (Paris Web 2011)
Développeurs, cachez-moi ça ! (Paris Web 2011)Hugo Hamon
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
 
Prototyping in the cloud
Prototyping in the cloudPrototyping in the cloud
Prototyping in the cloudKirsten Hunter
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 
Symfony2 - Un Framework PHP 5 Performant
Symfony2 - Un Framework PHP 5 PerformantSymfony2 - Un Framework PHP 5 Performant
Symfony2 - Un Framework PHP 5 PerformantHugo Hamon
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2Hugo Hamon
 
API 101 Workshop from APIStrat Conference
API 101 Workshop from APIStrat ConferenceAPI 101 Workshop from APIStrat Conference
API 101 Workshop from APIStrat ConferenceKirsten Hunter
 
Monitor the quality of your Symfony projects
Monitor the quality of your Symfony projectsMonitor the quality of your Symfony projects
Monitor the quality of your Symfony projectsHugo Hamon
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console componentHugo Hamon
 
Api intensive - What they Are
Api intensive - What they AreApi intensive - What they Are
Api intensive - What they AreKirsten Hunter
 
Quantifying your-fitness
Quantifying your-fitnessQuantifying your-fitness
Quantifying your-fitnessKirsten Hunter
 

Destaque (20)

Symfony2 en pièces détachées
Symfony2 en pièces détachéesSymfony2 en pièces détachées
Symfony2 en pièces détachées
 
Développeurs, cachez-moi ça ! (Paris Web 2011)
Développeurs, cachez-moi ça ! (Paris Web 2011)Développeurs, cachez-moi ça ! (Paris Web 2011)
Développeurs, cachez-moi ça ! (Paris Web 2011)
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
Prototyping in the cloud
Prototyping in the cloudPrototyping in the cloud
Prototyping in the cloud
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Symfony2 - Un Framework PHP 5 Performant
Symfony2 - Un Framework PHP 5 PerformantSymfony2 - Un Framework PHP 5 Performant
Symfony2 - Un Framework PHP 5 Performant
 
Quantifying fitness
Quantifying fitnessQuantifying fitness
Quantifying fitness
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
Liberating your data
Liberating your dataLiberating your data
Liberating your data
 
API 101 Workshop from APIStrat Conference
API 101 Workshop from APIStrat ConferenceAPI 101 Workshop from APIStrat Conference
API 101 Workshop from APIStrat Conference
 
API First
API FirstAPI First
API First
 
Liberating your data
Liberating your dataLiberating your data
Liberating your data
 
Monitor the quality of your Symfony projects
Monitor the quality of your Symfony projectsMonitor the quality of your Symfony projects
Monitor the quality of your Symfony projects
 
Api 101
Api 101Api 101
Api 101
 
Facebook appsincloud
Facebook appsincloudFacebook appsincloud
Facebook appsincloud
 
Polyglot copy
Polyglot copyPolyglot copy
Polyglot copy
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
 
Api intensive - What they Are
Api intensive - What they AreApi intensive - What they Are
Api intensive - What they Are
 
Git store
Git storeGit store
Git store
 
Quantifying your-fitness
Quantifying your-fitnessQuantifying your-fitness
Quantifying your-fitness
 

Semelhante a Sean coates fifty things and tricks, confoo 2011

让开发也懂前端
让开发也懂前端让开发也懂前端
让开发也懂前端lifesinger
 
Javascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJSJavascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJSSylvain Zimmer
 
Node js techtalksto
Node js techtalkstoNode js techtalksto
Node js techtalkstoJason Diller
 
Web micro-framework BATTLE!
Web micro-framework BATTLE!Web micro-framework BATTLE!
Web micro-framework BATTLE!Richard Jones
 
Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)
Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)
Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)Ingo Renner
 
Data Viz Barcamp, Amsterdam
Data Viz Barcamp, AmsterdamData Viz Barcamp, Amsterdam
Data Viz Barcamp, AmsterdamDan Brickley
 
The State of Front End Web Development 2011
The State of Front End Web Development 2011The State of Front End Web Development 2011
The State of Front End Web Development 2011Pascal Rettig
 
jQueryTO: State of jQuery March 2013
jQueryTO: State of jQuery March 2013jQueryTO: State of jQuery March 2013
jQueryTO: State of jQuery March 2013dmethvin
 
Create a Professional Blog with WordPress: Chapter 1 Introduction
Create a Professional Blog with WordPress: Chapter 1 IntroductionCreate a Professional Blog with WordPress: Chapter 1 Introduction
Create a Professional Blog with WordPress: Chapter 1 IntroductionAtit Patumvan
 
2011 JavaOne Apache TomEE Java EE 6 Web Profile
2011 JavaOne Apache TomEE Java EE 6 Web Profile2011 JavaOne Apache TomEE Java EE 6 Web Profile
2011 JavaOne Apache TomEE Java EE 6 Web ProfileDavid Blevins
 
Koss, How to make desktop caliber browser apps
Koss, How to make desktop caliber browser appsKoss, How to make desktop caliber browser apps
Koss, How to make desktop caliber browser appsEvil Martians
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011Charles Nutter
 
CollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPagesCollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPagesJesse Gallagher
 
Consuming the Twitter Streaming API with Ruby and MongoDB
Consuming the Twitter Streaming API with Ruby and MongoDBConsuming the Twitter Streaming API with Ruby and MongoDB
Consuming the Twitter Streaming API with Ruby and MongoDBJeff Linwood
 
PyData Texas 2015 Keynote
PyData Texas 2015 KeynotePyData Texas 2015 Keynote
PyData Texas 2015 KeynotePeter Wang
 
Apcug 2011 07-17-intro_to_drupal_jeff_schuler
Apcug 2011 07-17-intro_to_drupal_jeff_schulerApcug 2011 07-17-intro_to_drupal_jeff_schuler
Apcug 2011 07-17-intro_to_drupal_jeff_schulerhewie
 
PyCon 2011 Scaling Disqus
PyCon 2011 Scaling DisqusPyCon 2011 Scaling Disqus
PyCon 2011 Scaling Disquszeeg
 

Semelhante a Sean coates fifty things and tricks, confoo 2011 (20)

让开发也懂前端
让开发也懂前端让开发也懂前端
让开发也懂前端
 
Javascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJSJavascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJS
 
Node js techtalksto
Node js techtalkstoNode js techtalksto
Node js techtalksto
 
Web micro-framework BATTLE!
Web micro-framework BATTLE!Web micro-framework BATTLE!
Web micro-framework BATTLE!
 
Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)
Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)
Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)
 
Data Viz Barcamp, Amsterdam
Data Viz Barcamp, AmsterdamData Viz Barcamp, Amsterdam
Data Viz Barcamp, Amsterdam
 
The State of Front End Web Development 2011
The State of Front End Web Development 2011The State of Front End Web Development 2011
The State of Front End Web Development 2011
 
jQueryTO: State of jQuery March 2013
jQueryTO: State of jQuery March 2013jQueryTO: State of jQuery March 2013
jQueryTO: State of jQuery March 2013
 
Create a Professional Blog with WordPress: Chapter 1 Introduction
Create a Professional Blog with WordPress: Chapter 1 IntroductionCreate a Professional Blog with WordPress: Chapter 1 Introduction
Create a Professional Blog with WordPress: Chapter 1 Introduction
 
Joomla 2.5 Feature
Joomla 2.5 Feature Joomla 2.5 Feature
Joomla 2.5 Feature
 
2011 JavaOne Apache TomEE Java EE 6 Web Profile
2011 JavaOne Apache TomEE Java EE 6 Web Profile2011 JavaOne Apache TomEE Java EE 6 Web Profile
2011 JavaOne Apache TomEE Java EE 6 Web Profile
 
Koss, How to make desktop caliber browser apps
Koss, How to make desktop caliber browser appsKoss, How to make desktop caliber browser apps
Koss, How to make desktop caliber browser apps
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
 
Extending rails
Extending railsExtending rails
Extending rails
 
CollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPagesCollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPages
 
Consuming the Twitter Streaming API with Ruby and MongoDB
Consuming the Twitter Streaming API with Ruby and MongoDBConsuming the Twitter Streaming API with Ruby and MongoDB
Consuming the Twitter Streaming API with Ruby and MongoDB
 
PyData Texas 2015 Keynote
PyData Texas 2015 KeynotePyData Texas 2015 Keynote
PyData Texas 2015 Keynote
 
Apcug 2011 07-17-intro_to_drupal_jeff_schuler
Apcug 2011 07-17-intro_to_drupal_jeff_schulerApcug 2011 07-17-intro_to_drupal_jeff_schuler
Apcug 2011 07-17-intro_to_drupal_jeff_schuler
 
TermGenie and Shoge
TermGenie and ShogeTermGenie and Shoge
TermGenie and Shoge
 
PyCon 2011 Scaling Disqus
PyCon 2011 Scaling DisqusPyCon 2011 Scaling Disqus
PyCon 2011 Scaling Disqus
 

Mais de Bachkoutou Toutou

hacking your website with vega, confoo2011
hacking your website with vega, confoo2011hacking your website with vega, confoo2011
hacking your website with vega, confoo2011Bachkoutou Toutou
 
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011Bachkoutou Toutou
 
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011Bachkoutou Toutou
 
Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011Bachkoutou Toutou
 
Connecting web Applications with Desktop, confoo 2011
Connecting web Applications with Desktop, confoo 2011Connecting web Applications with Desktop, confoo 2011
Connecting web Applications with Desktop, confoo 2011Bachkoutou Toutou
 
Connecting Web Application and Desktop, confoo 2011, qafoo
Connecting Web Application and Desktop, confoo 2011, qafooConnecting Web Application and Desktop, confoo 2011, qafoo
Connecting Web Application and Desktop, confoo 2011, qafooBachkoutou Toutou
 
99 problems but the search aint one, confoo 2011, andrei zmievski
99 problems but the search aint one, confoo 2011, andrei zmievski99 problems but the search aint one, confoo 2011, andrei zmievski
99 problems but the search aint one, confoo 2011, andrei zmievskiBachkoutou Toutou
 
Php Inside - confoo 2011 - Derick Rethans
Php Inside -  confoo 2011 - Derick RethansPhp Inside -  confoo 2011 - Derick Rethans
Php Inside - confoo 2011 - Derick RethansBachkoutou Toutou
 
WebShell - confoo 2011 - sean coates
WebShell - confoo 2011 - sean coatesWebShell - confoo 2011 - sean coates
WebShell - confoo 2011 - sean coatesBachkoutou Toutou
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011Bachkoutou Toutou
 
Confoo 2011 - Advanced OO Patterns
Confoo 2011 - Advanced OO PatternsConfoo 2011 - Advanced OO Patterns
Confoo 2011 - Advanced OO PatternsBachkoutou Toutou
 

Mais de Bachkoutou Toutou (13)

hacking your website with vega, confoo2011
hacking your website with vega, confoo2011hacking your website with vega, confoo2011
hacking your website with vega, confoo2011
 
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
 
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
 
Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011
 
Connecting web Applications with Desktop, confoo 2011
Connecting web Applications with Desktop, confoo 2011Connecting web Applications with Desktop, confoo 2011
Connecting web Applications with Desktop, confoo 2011
 
Connecting Web Application and Desktop, confoo 2011, qafoo
Connecting Web Application and Desktop, confoo 2011, qafooConnecting Web Application and Desktop, confoo 2011, qafoo
Connecting Web Application and Desktop, confoo 2011, qafoo
 
99 problems but the search aint one, confoo 2011, andrei zmievski
99 problems but the search aint one, confoo 2011, andrei zmievski99 problems but the search aint one, confoo 2011, andrei zmievski
99 problems but the search aint one, confoo 2011, andrei zmievski
 
Php Inside - confoo 2011 - Derick Rethans
Php Inside -  confoo 2011 - Derick RethansPhp Inside -  confoo 2011 - Derick Rethans
Php Inside - confoo 2011 - Derick Rethans
 
WebShell - confoo 2011 - sean coates
WebShell - confoo 2011 - sean coatesWebShell - confoo 2011 - sean coates
WebShell - confoo 2011 - sean coates
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011
 
Apc Memcached Confoo 2011
Apc Memcached Confoo 2011Apc Memcached Confoo 2011
Apc Memcached Confoo 2011
 
Xdebug confoo11
Xdebug confoo11Xdebug confoo11
Xdebug confoo11
 
Confoo 2011 - Advanced OO Patterns
Confoo 2011 - Advanced OO PatternsConfoo 2011 - Advanced OO Patterns
Confoo 2011 - Advanced OO Patterns
 

Sean coates fifty things and tricks, confoo 2011

  • 1. Fifty Tips, Tricks & Tools …in one talk Sean Coates Fictive Kin gimmebar.com Monday, March 7, 2011
  • 2. “Hey, did you know that you could use {some tool} to do that better?” Monday, March 7, 2011
  • 4. Monday, March 7, 2011 I Services
  • 6. one Paste Bins •Common •Useful for: •large dumps •source code sharing •bugs •diffs •etc. •Lots of generic ones http://pastebin.com/ Monday, March 7, 2011
  • 7. two Mine •There are many like it, but this one is mine. •micro nano API: •“secret” URLs http://paste.roguecoders.com/ Monday, March 7, 2011
  • 8. Mine •There are many like it, but this one is mine. •micro nano API: •“secret” URLs $ cat /Users/sean/bin/pastebin | pastebin URL: http://paste.roguecoders.com/p/d7df33ac561e8e46538a6f71e051f41d.html http://paste.roguecoders.com/ Monday, March 7, 2011
  • 9. Mine •There are many like it, but this one is mine. •micro nano API: •“secret” URLs http://paste.roguecoders.com/ Monday, March 7, 2011
  • 10. three Gist (GitHub) •Ties into GitHub •Forkable, iterative: •More collaborative http://gist.github.com/ Monday, March 7, 2011
  • 11. Gist (GitHub) •Ties into GitHub •Forkable, iterative: •More collaborative http://gist.github.com/ Monday, March 7, 2011
  • 12. Gist (GitHub) •Ties into GitHub •Forkable, iterative: •More collaborative http://gist.github.com/ Monday, March 7, 2011
  • 14. four JS Bin •Paste bin that understands HTML and JavaScript •Includes libraries •Code available on GitHub: •github.com/remy/jsbin •Great for sharing browser- specific problems •Simple and straightforward http://jsbin.com/ Monday, March 7, 2011
  • 15. five JS Fiddle •HTML, CSS, JS •More complex, but nicer integration for non-simple •Easy pull-in for external URLs •Larger framework support •Versioning, easy sharing, forking http://jsfiddle.net/ Monday, March 7, 2011
  • 16. six IDE One •Online code compiling and execution •Not just JavaScript: PHP, Python, Perl, Ruby, Java, C, and a whole bunch of others •Source, input, output •Great for posting questions on (e.g.) stackoverflow http://ideone.com/ Monday, March 7, 2011
  • 17. IDE One •Online code compiling and execution •Not just JavaScript: PHP, Python, Perl, Ruby, Java, C, and a whole bunch of others •Source, input, output •Great for posting questions on (e.g.) stackoverflow http://ideone.com/ Monday, March 7, 2011
  • 18. IDE One •Online code compiling and execution •Not just JavaScript: PHP, Python, Perl, Ruby, Java, C, and a whole bunch of others •Source, input, output •Great for posting questions on (e.g.) stackoverflow http://ideone.com/ Monday, March 7, 2011
  • 20. seven JS Beautifer •Pretty printer for JS •Useful for de-minification (will not rename variables) •Helps spot syntax problems •Formats JSON documents to make them readable •Python version coming •JS version uses Rhino http://jsbeautifier.org/ Monday, March 7, 2011
  • 21. JS Beautifer •Pretty printer for JS •Useful for de-minification (will not rename variables) •Helps spot syntax problems •Formats JSON documents to make them readable •Python version coming •JS version uses Rhino http://jsbeautifier.org/ Monday, March 7, 2011
  • 22. JS Beautifer •Pretty printer for JS •Useful for de-minification (will not rename variables) •Helps spot syntax problems •Formats JSON documents to make them readable •Python version coming •JS version uses Rhino http://jsbeautifier.org/ Monday, March 7, 2011
  • 23. eight JSLint •Checks the syntax of your JS •Insults you when you do something stupid (you idiot) •Really helpful for debugging JS’s sometimes-hard-to- predict behaviour •Annoying when you are slightly smarter than it is (-: http://jslint.com/ •Also: Crockford Monday, March 7, 2011
  • 24. nine WonderProxy •Geolocation testing •37 Locations •25 Countries •5 Continents •Find Paul Reinheimer and ask him about it http://wonderproxy.com/ Monday, March 7, 2011
  • 25. ten httpstat.us •Quick Reference for HTTP status codes •Build a RESTishfuly API! •Test pages for each code •http://httpstat.us/200 •http://httpstat.us/404 •(etc.) http://httpstat.us/ Monday, March 7, 2011
  • 26. Monday, March 7, 2011 II Unix
  • 27. eleven /etc/hosts (or %SystemRoot%system32driversetchosts) • You probably already know about this: $ cat /etc/hosts | grep habari.local 127.0.0.1! habari.local $ ping habari.local PING habari.local (127.0.0.1): 56 data bytes Monday, March 7, 2011
  • 28. /etc/hosts (or %SystemRoot%system32driversetchosts) • But you can also name interfaces: $ cat /etc/hosts | grep 'www.local' 64.15.79.182! eth0-0.local! www.local • Useful for daemon configuration: <VirtualHost www.local:80> ! ServerName www.seancoates.com ! RedirectMatch ^/(.*)$ http://seancoates.com/$1 </VirtualHost> Monday, March 7, 2011
  • 29. twelve netstat • Find out which ports and IPs a process is bound to • On Linux (and elsewhere with different arguments): # netstat -tlpn | grep mysqld tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 31506/ mysqld • (Bound to 127.0.0.1 (localhost) on port 3306) Monday, March 7, 2011
  • 30. thirteen top & atop • High-level system overview Monday, March 7, 2011
  • 31. top & atop • High-level overview Monday, March 7, 2011
  • 32. top & atop • High-level overview Monday, March 7, 2011
  • 33. top & atop • High-level overview Monday, March 7, 2011
  • 34. fourteen lsof • Ever wondered which process has a file open? sean@iconoclast:~$ ls -l sekrit.log -rw-rw-r-- 1 sean sean 32 2011-03-04 17:49 sekrit.log sean@iconoclast:~$ ls -l sekrit.log -rw-rw-r-- 1 sean sean 48 2011-03-04 17:49 sekrit.log sean@iconoclast:~$ lsof sekrit.log COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME php 17142 sean 3w REG 8,1 80 755383 sekrit.log sean@iconoclast:~$ ps auxwww | grep 17142 sean 17142 0.0 0.3 24008 6760 pts/10 S 17:49 0:00 php ./ninja.php Monday, March 7, 2011
  • 35. fifteen strace • Ever wondered which syscalls a process makes? sean@iconoclast:~$ strace php -r 'echo "FOO";' 2>&1 | grep FOO execve("/usr/local/bin/php", ["php", "-r", "echo "FOO";"], [/* 21 vars */]) = 0 write(1, "FOO"..., 3FOO) = 3 sean@iconoclast:~$ strace php -r 'error_log("FOO");' 2>&1 | grep FOO execve("/usr/local/bin/php", ["php", "-r", "error_log("FOO");"], [/* 21 vars */]) = 0 write(2, "FOOn"..., 4FOO Monday, March 7, 2011
  • 36. sixteen ldd • Ever wondered which libraries an executable references? sean@iconoclast:~$ ldd `which php` | grep mysql ! libmysqlclient.so.15 => /usr/lib/libmysqlclient.so.15 (0xb77ed000) sean@iconoclast:~$ ldd `which php` ! linux-gate.so.1 => (0xb7ee2000) ! libcrypt.so.1 => /lib/tls/i686/cmov/libcrypt.so.1 (0xb7ea2000) ! libc-client.so.2007b => /usr/lib/libc-client.so.2007b (0xb7d8e000) ! libreadline.so.5 => /lib/libreadline.so.5 (0xb7d5b000) ! libncurses.so.5 => /lib/libncurses.so.5 (0xb7d29000) ! librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb7d20000) ! libpam.so.0 => /lib/libpam.so.0 (0xb7d14000) ... Monday, March 7, 2011
  • 37. seventeen nice • Ever wanted to run a job that needs a higher or lower priority than other jobs? sean@gimmebarvm-sean:~$ sudo nice -n -19 php -r 'for ($a=0; $a<=100000000; $a++) {}; echo "DONEn";' & [1] 7025 sean@gimmebarvm-sean:~$ time ls gimmebar-access_log mime.php prod_dump src real!0m0.129s Monday, March 7, 2011
  • 38. nice • The priority can range from -19 (highest) to +20 (lowest), and the default is 10. sean@gimmebarvm-sean:~$ sudo nice -n 19 php -r 'for ($a=0; $a<=100000000; $a++) {}; echo "DONEn";' & [1] 7044 sean@gimmebarvm-sean:~$ time ls gimmebar-access_log mime.php prod_dump src real!0m0.003s Monday, March 7, 2011
  • 39. eighteen cron • Users have individual cron spools on most Unix systems • Need a system-wide cron? Try /etc/crontab • Note: it has a 6th field (not just the time fields): user • Much easier to maintain in version control and to provision with sysdmin tools • Try also /etc/cron.daily, /etc/cron.hourly, etc. Monday, March 7, 2011
  • 40. nineteen GNU Screen •Terminal multiplexer •Keep shell apps running even after logout •Handles scrollback, window splits, pane management •See also: tmux Monday, March 7, 2011
  • 41. twenty visudo, vipw, vigr • Imagine what kind of horrible things could happen if you break a file like /etc/sudoers? or /etc/passwd? • visudo: safely edit /etc/sudoers • vipw: safely edit /etc/passwd • vigr: safely edit /etc/group • Files are parsed for errors before they’re committed Monday, March 7, 2011
  • 42. Monday, March 7, 2011 III Shell
  • 43. twenty-one reverse-i-search (ctrl-r) Monday, March 7, 2011
  • 44. twenty-one reverse-i-search (ctrl-r) Monday, March 7, 2011
  • 45. twenty-two reuse last argument (esc-.) Monday, March 7, 2011
  • 46. twenty-two reuse last argument (esc-.) Monday, March 7, 2011
  • 47. twenty-three edit+run last command (fc) Monday, March 7, 2011
  • 48. twenty-three edit+run last command (fc) Monday, March 7, 2011
  • 49. twenty-four bash completion (⌦(tab)) Monday, March 7, 2011
  • 50. twenty-four bash completion (⌦(tab)) Monday, March 7, 2011
  • 51. twenty-five pipes • One of the great beauties of Unix: text streams • Chain these together, easily $ cat /www/logs/seancoates.com-access_log | grep 'gimme' | wc -l 12 • Small, purposeful utilities, not monoliths Monday, March 7, 2011
  • 52. twenty-six grep, zgrep, ack • Filter text streams with grep (previous slide) • Uncompress and filter with zgrep • Use ack (non-standard) grouping, and to do the right thing: sarcasm:~/src/gimmebar/api (master)$ ack 'Config::' inc/content/Flickr.php 22:! ! ! ! 'api_key' => Config::FLICKR_API_KEY, inc/storage/S3Storage.php 24:! ! ! Config::S3_BUCKET, 34:! ! ! return 'http://' . Config::S3_BUCKET . Monday, March 7, 2011
  • 53. twenty-seven download without the file • Pipe curl directly into tar: $ curl http://files.seancoates.com/test.tar.gz | tar zxf • Alternative to wget + tar, but doesn’t leave a mess • (not always what you want, but still convenient) Monday, March 7, 2011
  • 54. twenty-eight bash: always there • Bash is on almost every system • Scriptable and powerful, even when alternatives aren’t available $ A='0'; for f in *.php; do A="$A + `cat $f | wc -c`"; done; echo $A | bc • Shows the sum of the file sizes of all PHP files in the current directory (thanks to `bc`) Monday, March 7, 2011
  • 55. twenty-nine perl pie (see also: sed) • Perl pie runs an arbitrary expression against the passed files and modifies them in place • My favourite (but least intelligent) refactoring tool $ perl -p -i -e 's/Config::/Configuration::/g' *.php • Replaces “Config” with “Configuration” static calls: - 'database' => Config::DATABASE_URL + 'database' => Configuration::DATABASE_URL Monday, March 7, 2011
  • 56. thirty sticky shell start • Put this in ~/.bashrc or ~/.profile cd () { builtin cd "$@" ; pwd > ~/.pwd; } cd "`cat ~/.pwd`" • New shells launch where the last shell operated sarcasm:~/src/gimmebar/api/www-api (master)$ login login: sean Password: Last login: Sun Mar 6 18:09:15 on ttys000 sarcasm:~/src/gimmebar/api/www-api (master)$ Monday, March 7, 2011
  • 57. thirty-something (bonus) misc. shell stuffs • The `find` command is your friend when working in a directory tree • Use `tail -f filename` to continually watch a file • When scripting the shell, the `xargs` command is often useful • Use `2>&1` to merge stderr into stdout, as in: a_command_that_uses_stderr >/dev/null 2>&1 Monday, March 7, 2011
  • 58. Monday, March 7, 2011 IV SSH
  • 59. thirty-one keypairs • Skip the password, use pre-shared keys to log in to your shells • Use `ssh-keygen` to generate a pair • Keep the private key protected • Put the public key in ~/.ssh/authorized_keys on the server • Log in without a password • (If it doesn’t work, one common error is permissions;          `ssh -v ...` will often tell you; if not: use more `v`) Monday, March 7, 2011
  • 60. thirty-two ssh-copy-id • Easily copy your new key to a remote server • Sets permissions properly, and uses the right file if it’s not ~/.ssh/authorized_keys Monday, March 7, 2011
  • 61. thirty-three ssh config • Local configuration allows host-specific settings for: • username • private key • forwarded ports • many other settings (compression, X forwarding, etc.) • ~/.ssh/config: Host *.php.net User scoates Monday, March 7, 2011
  • 62. thirty-four ssh tunnels (port forwarding) • Make the remote machine’s MongoDB port available as localhost:27017 ssh -L27017:localhost:27017 local.gimmebar.com • Forward your local port 80 to a remote machine as port 8000 ssh -R80:localhost:8000 iconoclast.caedmon.net • (can now access with `curl localhost:8000/` on iconoclast) Monday, March 7, 2011
  • 63. thirty-five kill ssh • ssh sessions can hang • `killall ssh`sucks if you have more than one session • [enter] ~ . • (SSH over VPN == extremely robust) Monday, March 7, 2011
  • 64. Monday, March 7, 2011 V Development
  • 65. thirty-six const == var (not var == const) • All else being equal, I prefer this: if (3 == $tries) { … } • Over this: if ($tries == 3) { … } • Because this causes a compiler error: if (3 = $tries) { … } Monday, March 7, 2011
  • 66. thirty-seven git: publish on post-receive • put this in your post-receive hook: echo "Staging dev.seancoates.com ..." && cd /www/webroots/seancoates.com/seancoates-dev && env -i git pull && echo "Staged." • When you push, this path is pulled Monday, March 7, 2011
  • 67. thirty-eight github: publish on post-receive • Put this script somewhere in your web root (beware of security and stuff): <?php $gitpath = '/usr/local/bin/git'; header("Content-type: text/plain"); system("/usr/bin/env -i " . "HOME=/www/webroots/phpcon.org " . "{$gitpath} pull 2>&1"); echo "nDone.n"; • …and set this up on GitHub: Monday, March 7, 2011
  • 68. github: publish on post-receive • Put this script somewhere in your web root (beware of security and stuff): <?php $gitpath = '/usr/local/bin/git'; header("Content-type: text/plain"); system("/usr/bin/env -i " . "HOME=/www/webroots/phpcon.org " . "{$gitpath} pull 2>&1"); echo "nDone.n"; • And set this up on GitHub: Monday, March 7, 2011
  • 69. thirty-nine Email override • If your code uses sendmail to… send… mail… and if you can override the path, change the path to point to his on dev: cat >> /tmp/logmail.log • PHP makes this easy with the sendmail_path INI setting Monday, March 7, 2011
  • 70. forty Crockford on JS • http://developer.yahoo.com/yui/theater Monday, March 7, 2011
  • 71. Monday, March 7, 2011 VI Utilities
  • 72. forty-one rrdtool •round-robin •compare week-over-week, day-over-day •easy to feed •not terribly easy to set up •takes care of the hard parts Monday, March 7, 2011
  • 73. forty-two Elasticfox •add-on for FireFox •a little quirky •handles most (but not all) of EC2’s maintenance functions •WAY easier than the Java CLI tools Monday, March 7, 2011
  • 74. forty-three Firebug •add-on for FireFox •JavaScript debugger •DOM inspector •Network monitor •Other browsers have similar Monday, March 7, 2011
  • 75. forty-four Webshell •<plug type=self/> •scripted HTTP using JS •... lots of other stuff, but that was another talk (-: Monday, March 7, 2011
  • 76. forty-five Dropbox •Great for sharing among teams •Easy sync •Free (sort of) •Supports growl Monday, March 7, 2011
  • 77. forty-six VirtualBox •Free Virtual Machine •Ideal for developers, VPN •Runs our dev hosts very well •Easy to distribute images Monday, March 7, 2011
  • 78. forty-seven OpenVPN •Arbitrary virtual networking •Ties multiple locations together as one network •Private network for production servers •Good Mac client: Viscosity Monday, March 7, 2011
  • 79. forty-eight supervisord •Dæmonize apps, easily •(avoid writing dæmon code yourself) •Handles launch, respawn, concurrency •Handles logging •See: http://phpadvent.org/200915 Monday, March 7, 2011
  • 80. forty-nine netcat •Turn anything into a server (sort of) •Useful for testing (like telnet, but without the telnet stuff) •pbcopy trick: http://seancoates.com/blogs/remote-pbcopy •almost as much of a Swiss-Army knife as SSH Monday, March 7, 2011
  • 81. fifty! Visor •System-wide terminal •Accessible by hotkey •Great for resident CLI apps (Webshell, REPL, DB client) •Mac only •http://visor.binaryage.com/ Monday, March 7, 2011
  • 82. Contact • I’ve probably lost my voice by now, so here’s my contact info: • sean@seancoates.com • seancoates.com • Work: fictivekin.com, gimmebar.com • The Twitter: @coates Monday, March 7, 2011