Tag: Tips
Control Flow Keywords in PHP Loops
Too frequently I see PHP code that treats looping constructs (e.g. for, foreach, while) like runaway trains. Terminal conditions are set before entering the loop, but once the loop is started, it’s all hands off until it finishes. Unless there is an express need to iterate over every value, control flow keywords should be used [...]
Edit Remote Files in Vim via SCP
One of the many neat features of VIM is support for remote editing. The Vim command is simply: :edit scp://username@hostname/directory/path/starting/in/home If the scp:// protocol wasn’t already a give away, VIM uses secure copy (scp) to edit remote files. This means many of the same tricks used with scp on the command-line can be used inside [...]
Using Help to Supplement Man Pages
Man pages are an invaluable tool in the Unix eco-system. Providing both a starting overview and a deep-dive future reference, what you need to know about a command is only a $ man <command> away. But there are times when the man command doesn’t provide all the information needed. Many of the most common Unix [...]
Referencing Last Argument in Bash using Special Parameters
Bash contains a number of powerful special parameters that can be used on both the command line and inside scripts. My most used of the bunch is $_, which references the last argument of the preceding command. To illustrate the power of this, take the example of creating a new directory and cd’ing into it. [...]
Bending PHP, Control Flow Flexibility With call_user_func()
In comparison to other dynamic languages like Python and Ruby, control flow mechanisms in PHP are rigid. But in the absence of first-class functions and limited OOP paradigms, there’s still some flexibility in the language thanks to built in functions like call_user_func(). While lacking the same syntactic sugar, call_user_func() is the equivalent of variable variables($$v) [...]