<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>I’m a PHP developer from Melbourne. This blog is for a whollotta note-to-selfs, tricks I’ve learnt and cool random sh*t I found on the net. You can find me on LinkedIn, GitHub and Twitter</description><title>I didn't do it!</title><generator>Tumblr (3.0; @wickedwee)</generator><link>http://www.weekeat.com/</link><item><title>Symfony2, PHPUnit with Guard</title><description>&lt;p&gt;I came across an &lt;a href="http://erichogue.ca/2012/09/php/continuous-testing-in-php-with-guard/" target="_blank"&gt;article&lt;/a&gt; on continuous testing in PHP using &lt;a href="https://github.com/guard/guard" target="_blank"&gt;Guard&lt;/a&gt; and &lt;a href="https://github.com/Maher4Ever/guard-phpunit" target="_blank"&gt;guard-phpunit&lt;/a&gt;. I gave it a go and I absolutely love it!&lt;/p&gt;

&lt;p&gt;If you want to try it out, head over to the &lt;a href="http://erichogue.ca/2012/09/php/continuous-testing-in-php-with-guard/" target="_blank"&gt;article&lt;/a&gt; above for the setup and how to run it.&lt;/p&gt;

&lt;p&gt;You &lt;em&gt;may&lt;/em&gt; find following notes (on Debian) helpful:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt; Make sure &lt;code&gt;/var/lib/gems/1.8/bin&lt;/code&gt; is in your &lt;code&gt;$PATH&lt;/code&gt; (just substitute the right path)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; You may encounter the following error if you&amp;#8217;re using either PHPUnit 3.7.x or older version of guard-phpunit:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;Fatal error in PHPUnit 
Fatal error: Call to undefined method PHPUnit_Framework_TestResult::allCompletlyImplemented() in /var/lib/gems/1.8/gems/guard-phpunit-0.1.4/lib/guard/phpunit/formatters/PHPUnit-Progress/PHPUnit/Extensions/Progress/ResultPrinter.php on line 250
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The error is caused by a &lt;a href="https://github.com/sebastianbergmann/phpunit/issues/762" target="_blank"&gt;misspelled method&lt;/a&gt; in PHPUnit. Easiest way to fix this is to modify the offending file directly to correct the spelling:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;vim /var/lib/gems/1.8/gems/guard-phpunit-0.1.4/lib/guard/phpunit/formatters/PHPUnit-Progress/PHPUnit/Extensions/Progress/ResultPrinter.php&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Locate the misspelled method name &amp;#8216;&lt;code&gt;allCompletlyImplemented()&lt;/code&gt;&amp;#8217; - mine was in two lines: 1) line:250 and 2) line:256 and correct them to &amp;#8216;&lt;code&gt;allCompletelyImplemented()&lt;/code&gt;&amp;#8217; and you should be able to get your &lt;code&gt;phpunit&lt;/code&gt; to run successfully.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3)&lt;/strong&gt; A note on the Guardfile if you are using Symfony 2&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;set the &amp;#8216;&lt;code&gt;:cli&lt;/code&gt;&amp;#8217; variable to &amp;#8216;&lt;code&gt;-c app/&lt;/code&gt;&amp;#8217;&lt;/li&gt;
&lt;li&gt;set the :tests_path variable to &amp;#8216;&lt;code&gt;src/&lt;/code&gt;&amp;#8217;&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;4)&lt;/strong&gt; Here&amp;#8217;s an example &lt;code&gt;Guardfile&lt;/code&gt; that works for me (in the root of the Symfony project):&lt;/p&gt;

&lt;pre class="ruby"&gt;&lt;code&gt;guard 'phpunit', :tests_path =&amp;gt; 'src/Company', :cli =&amp;gt; '--colors -c app/' do
  watch(%r{^.+Test\.php$})
  watch(%r{^src/Company/SomeAppBundle/Entity/(.+)\.php$}) { |m| "src/Company/SomeAppBundle/Tests/Entity/#{m[1]}Test.php" }
  watch(%r{^src/Company/SomeAppBundle/Helper/(.+)\.php$}) { |m| "src/Company/SomeAppBundle/Tests/Helper/#{m[1]}Test.php" }
  watch(%r{^src/Company/SomeAppBundle/Command/(.+)\.php$}) { |m| "src/Company/SomeAppBundle/Tests/Command/#{m[1]}Test.php" }
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The above will cause all unit test trigger when any &lt;code&gt;*Test.php&lt;/code&gt; files changes and any modified &lt;code&gt;*.php&lt;/code&gt; files from &lt;code&gt;Entity&lt;/code&gt;, &lt;code&gt;Helper&lt;/code&gt; and &lt;code&gt;Command&lt;/code&gt; folder to trigger its own corresponding test files.&lt;/p&gt;

&lt;p&gt;Have fun!&lt;/p&gt;</description><link>http://www.weekeat.com/post/46061346286</link><guid>http://www.weekeat.com/post/46061346286</guid><pubDate>Sat, 23 Mar 2013 20:53:00 +1100</pubDate><category>linux</category><category>php</category><category>tdd</category><category>symfony</category></item><item><title>Ad-hoc keymapping in Vim II</title><description>&lt;p&gt;This is a follow up on my earlier post &lt;a href="http://www.weekeat.com/post/24469611708/ad-hoc-keymapping-in-vim" target="_blank"&gt;Ad-hoc keymapping in Vim&lt;/a&gt; where I map &amp;#8216;&lt;code&gt;,s&lt;/code&gt;&amp;#8217; to first save the file that I am editing and then executes the specified file.&lt;/p&gt;

&lt;p&gt;Wouldn&amp;#8217;t it be better if it saves and execute &lt;em&gt;any&lt;/em&gt; file that is currently in the active window? You can do it with &lt;code&gt;%&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In Vim, the &lt;code&gt;%&lt;/code&gt; sign is a variable containing the full path to the file currently active your window.&lt;/p&gt;

&lt;p&gt;So intead of:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:map ,s :w\|!php filename.php&amp;lt;cr&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can do:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:map ,s :w\|!php %&amp;lt;cr&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, doesn&amp;#8217;t matter which file you&amp;#8217;re editing at any given time, hitting &amp;#8216;&lt;code&gt;,s&lt;/code&gt;&amp;#8217; will save and then execute it.&lt;/p&gt;</description><link>http://www.weekeat.com/post/45989539189</link><guid>http://www.weekeat.com/post/45989539189</guid><pubDate>Sat, 23 Mar 2013 00:45:50 +1100</pubDate><category>vim</category></item><item><title>Out of sync</title><description>&lt;p&gt;If your Linux, for some unknown reason ran out of sync by days, and you need a quick solution, use &lt;code&gt;ntpdate&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;First stop &lt;code&gt;ntp&lt;/code&gt;:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;[me@localhost ~] /etc/init.d/ntp stop&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then update time with a server using &lt;code&gt;ntpdate&lt;/code&gt;:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;[me@localhost ~] ntpdate ntp.ubuntu.com
18 Mar 17:23:16 ntpdate[20660]: step time server 91.189.94.4 offset
269404.459039 sec&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then start &lt;code&gt;ntp&lt;/code&gt; again:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;[me@localhost ~] /etc/init.d/ntp start&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Done.&lt;/p&gt;</description><link>http://www.weekeat.com/post/45692768860</link><guid>http://www.weekeat.com/post/45692768860</guid><pubDate>Tue, 19 Mar 2013 07:08:00 +1100</pubDate><category>linux</category><category>date</category><category>time</category><category>ntp</category></item><item><title>CentOS 6.x Minimal Network Issue</title><description>&lt;p&gt;Just realised that CentOS 6.x minimal setup is so minimal that you have no networking to boot? The fix is very easy (assuming you&amp;#8217;re just wanting to DHCP it).&lt;/p&gt;

&lt;p&gt;Step 1&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;dhclient eth0&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Step 2&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Change the line&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;ONBOOT="no"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;to&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;ONBOOT="yes"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Hang on.. what? Still not getting an address after rebooting? Try editing the same file as above:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Add the following:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;BOOTPROTO="dhcp"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will make it automatically ping DHCP server for an IP.&lt;/p&gt;</description><link>http://www.weekeat.com/post/27690416242</link><guid>http://www.weekeat.com/post/27690416242</guid><pubDate>Sat, 21 Jul 2012 20:15:35 +1000</pubDate><category>centos</category><category>linux</category><category>networking</category><category>dhcp</category></item><item><title>Jot it down</title><description>&lt;p&gt;For testing purposes, I usually create a series of files to run my bash scripts against and I love using the &lt;code&gt;jot&lt;/code&gt; command.&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;jot 3&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Generates:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;1
2
3&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Awesome! This allows me to:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;jot 8 | xargs touch&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I also use it to generate random series of numbers:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;jot -r 10&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What if you want to specify a range of numbers to which the randomisation occur?&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;jot -r 10 580 900&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The above gives you 10 random numbers between 580 to 900. Awesome, right? Then there&amp;#8217;s more - you can prepend a word to it!&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;jot -w file_%d -r 10 580 900&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Like I said, I &lt;em&gt;love&lt;/em&gt; the &lt;code&gt;jot&lt;/code&gt; command. There&amp;#8217;s a lot more use of this nifty little command. I only cover those I use often.&lt;/p&gt;

&lt;p&gt;For the rest of it, you can go through the &lt;a href="http://docstore.mik.ua/orelly/unix/upt/ch45_11.htm" target="_blank"&gt;tutorial here&lt;/a&gt;.&lt;/p&gt;</description><link>http://www.weekeat.com/post/25334559332</link><guid>http://www.weekeat.com/post/25334559332</guid><pubDate>Mon, 18 Jun 2012 12:01:41 +1000</pubDate><category>mac</category><category>linux</category><category>cli</category><category>commandline</category><category>bash</category></item><item><title>Oh yes!</title><description>&lt;p&gt;Ever come across a situation where you need to do this (very quickly):&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;rm -rf *&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And you get this (with the &lt;code&gt;-i&lt;/code&gt; flag):&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;rm: remove regular file 'PRON_0001.jpg'?&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Sh*t! I have to hit &lt;code&gt;'y'&lt;/code&gt; to &lt;em&gt;every&lt;/em&gt; single file? Well, you can use the &lt;code&gt;yes&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;The yes command generates an &lt;strong&gt;infinite loop&lt;/strong&gt; of &lt;code&gt;'y'&lt;/code&gt;. So, your problem solved:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;yes | rm -rf *&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Of course the above example uses the &lt;code&gt;rm&lt;/code&gt; command, which can be solved with the &lt;code&gt;-f&lt;/code&gt; flag but you can use it for any other commands that doesn&amp;#8217;t offer such an option.&lt;/p&gt;</description><link>http://www.weekeat.com/post/25263453918</link><guid>http://www.weekeat.com/post/25263453918</guid><pubDate>Sun, 17 Jun 2012 11:57:00 +1000</pubDate><category>bash</category><category>linux</category><category>unix</category><category>cli</category><category>commandline</category><category>mac</category></item><item><title>Mac OS command line goodies</title><description>&lt;p&gt;I always love doing things without my fingers leaving the keyboard. So, the more I can do from my terminal, the better. Over the years, I&amp;#8217;ve come to like quite a few really handy commands.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Open files&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open most files as if you double clicked on it in &lt;code&gt;Finder&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;open usage_report.pdf&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Wanna open &lt;code&gt;Finder&lt;/code&gt; where you are in terminal?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;open .&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Emailing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Emailing output to yourself (you need to &lt;a href="http://www.riverturn.com/blog/?p=239" target="_blank"&gt;enable &lt;code&gt;postfix&lt;code&gt; first&lt;/code&gt;&lt;/code&gt;&lt;/a&gt;):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ps aux | mail -s "Subject line" me@example.com&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You should be able to check if the email has been placed in queue:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mailq&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You should see something like this if you&amp;#8217;re quick (before it gets sent):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
6762CA18F19*   20039 Sat Jun  9 20:12:03  root@macbookpro.local
                                         me@example.com

-- 19 Kbytes in 1 Request.&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Oh this works on any Linux with &lt;code&gt;mailx&lt;/code&gt; and local mta installed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Clipboard manipulation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How about copying something in terminal to clipboard?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cat some_text.txt | pbcopy&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can then use &lt;code&gt;Ctrl+V&lt;/code&gt; anywhere. And if you want to past from clipboard:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;pbpaste &amp;gt; from_clipboard.txt&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Other misc tools&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Current Mac version:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sw_vers&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Profiler information:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;systerm_profiler&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Use the &lt;code&gt;Spotlight&lt;/code&gt; engine:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mdfind textedit&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Screencapture (full tutorial &lt;a href="http://osxdaily.com/2010/07/11/take-a-screen-capture-from-the-command-line/" target="_blank"&gt;here&lt;/a&gt;):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;screencapture ~/Desktop/mycapture.jpg&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&amp;#8217;s it! Now go have fun!&lt;/p&gt;</description><link>http://www.weekeat.com/post/24994951085</link><guid>http://www.weekeat.com/post/24994951085</guid><pubDate>Wed, 13 Jun 2012 11:53:57 +1000</pubDate><category>unix</category><category>mac</category><category>bash</category><category>commandline</category><category>cli</category></item><item><title>What are your names?</title><description>&lt;p&gt;Wanna quickly rename files right there and then? I &lt;a href="http://stackoverflow.com/a/68424" target="_blank"&gt;discovered&lt;/a&gt; this awesome tool &lt;code&gt;rename&lt;/code&gt;. You have the following:&lt;/p&gt;

&lt;pre class="content"&gt;
&lt;code&gt;IMG_001.jpg
IMG_002.jpg
...
IMG_113.jpg
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;You want to rename the following to &lt;code&gt;paris_2012_XXX.jpg&lt;/code&gt;:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;rename 's/IMG/paris_2012/g' *.jpg&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Boom! Done!&lt;/p&gt;</description><link>http://www.weekeat.com/post/24926900672</link><guid>http://www.weekeat.com/post/24926900672</guid><pubDate>Tue, 12 Jun 2012 12:03:28 +1000</pubDate></item><item><title>Mass revert in SVN</title><description>&lt;p&gt;Ever experience merging something in SVN just to realise that merged the wrong
branch or things don&amp;#8217;t work? In few cases, you may want to revert all the changes.&lt;/p&gt;

&lt;p&gt;So let&amp;#8217;s start with this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;svn st&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You get a list of files. But you only want those that has &amp;#8216;M&amp;#8217; status. So, let&amp;#8217;s to
filter that using grep:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;svn st | grep '^M'&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Good. Now that I have only the ones that are modified, all I need is get the 
filename.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;svn st | grep '^M' | awk '{print $2}'&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will actually list only the filename part. The &amp;#8216;$2&amp;#8217; means print only column 2.
And finally, we run &lt;code&gt;svn revert&lt;/code&gt; on each of the filenames returned:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;svn st | grep '^M' | awk '{print $2}' | xargs svn revert&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Of course, this means you can now do specific things like removing newly added
files, conflicted files, etc.&lt;/p&gt;</description><link>http://www.weekeat.com/post/24856852434</link><guid>http://www.weekeat.com/post/24856852434</guid><pubDate>Mon, 11 Jun 2012 11:59:00 +1000</pubDate></item><item><title>Bash be nimble...</title><description>&lt;p&gt;If you use terminal a lot you should know a few really useful keybindings (generally
works with bash and zshell). Here&amp;#8217;s what I use often:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;&lt;code&gt;Ctrl+L&lt;/code&gt;: Clear your terminal&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Ctrl+K&lt;/code&gt;: Delete from cursor to end&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Ctrl+K&lt;/code&gt;: Delete from start to cursor&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Ctrl+E&lt;/code&gt;: Move to the end of line&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Ctrl+A&lt;/code&gt;: Move to the end of line&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Alt+F&lt;/code&gt;:  Move a word forward&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Alt+B&lt;/code&gt;:  Move a word backward&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Ctrl+R&lt;/code&gt;: Reverse history search&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Ctrl+W&lt;/code&gt;: Delete backward a word&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;There&amp;#8217;s quite a few more. So, you may wanna hunt around for more but these are just a few that I personally remember and use on a daily basis.&lt;/p&gt;</description><link>http://www.weekeat.com/post/24784820155</link><guid>http://www.weekeat.com/post/24784820155</guid><pubDate>Sun, 10 Jun 2012 11:57:59 +1000</pubDate><category>cli</category><category>commandline</category><category>bash</category><category>linux</category></item><item><title>Reload!</title><description>&lt;p&gt;I notice quite often terminal users don&amp;#8217;t know how to reload their rc files - &lt;code&gt;bashrc&lt;/code&gt;, &lt;code&gt;zshrc&lt;/code&gt;, etc. There are two ways:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;. ~/.bashrc&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;source ~/.bashrc&lt;/code&gt;&lt;/pre&gt;</description><link>http://www.weekeat.com/post/24718437576</link><guid>http://www.weekeat.com/post/24718437576</guid><pubDate>Sat, 09 Jun 2012 11:51:47 +1000</pubDate><category>cli</category><category>commandline</category><category>linux</category></item><item><title>Grep basics in 25 seconds</title><description>&lt;p&gt;Well, not exactly 25 seconds, but I thought that would make a great title. I find I always have to introduce new junior devs to the world of &lt;code&gt;grep&lt;/code&gt; and I think the following will get anyone started very quickly.&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re searching for a specific term or keywords within a million files, use this:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;grep -ir pattern /path/to/search/&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;-i&lt;/code&gt; switch stands for case insensitive and r is for recursive.&lt;/p&gt;

&lt;p&gt;Another good search, especially within source code is:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;grep -rn 'pattern' /path/to/search&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This adds the line number to output so you can easily see where a variable or function is used.&lt;/p&gt;

&lt;p&gt;If you ever need to search amongst a million files, with thousands of different extensions, but you&amp;#8217;re only interested in specific file type, then you can try something like this:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;find . -type f -name "*.php" | xargs grep -i pattern&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&amp;#8217;ll give you very specific searches. The above, as an example, search only actual files that ends with &amp;#8216;&lt;code&gt;.php&lt;/code&gt;&amp;#8217;.&lt;/p&gt;

&lt;p&gt;If the tree you&amp;#8217;re searching contains whitespace in the paths names you can use &lt;code&gt;find … -print0 and xargs -0&lt;/code&gt;:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;find . -type f -name "*.php" -print0 | xargs -0 grep -i pattern&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To search multiple keywords use this:&lt;/p&gt;

&lt;pre class="bash"&gt;&lt;code&gt;find . -xdev -type f -name "*.php" | xargs grep -iHE "keyword1|keyword2"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Have fun!&lt;/p&gt;</description><link>http://www.weekeat.com/post/24651647092</link><guid>http://www.weekeat.com/post/24651647092</guid><pubDate>Fri, 08 Jun 2012 11:57:25 +1000</pubDate><category>linux</category><category>grep</category><category>cli</category><category>commandline</category></item><item><title>Finding &amp; bashing stuff</title><description>&lt;p&gt;We often use the &lt;code&gt;find&lt;/code&gt; command to look for specific files like so:&lt;/p&gt;

&lt;pre&gt;&lt;code class="bash"&gt; find . -type f -name '*.rb'&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What if you want to do something with the result? With the &lt;code&gt;find&lt;/code&gt; command, you can&amp;#8217;t pipe the result because it is not a shell and it can&amp;#8217;t spawn one.&lt;/p&gt;

&lt;p&gt;Luckily &lt;code&gt;find&lt;/code&gt; has a &lt;code&gt;-exec&lt;/code&gt; function, so that you can do the following:&lt;/p&gt;

&lt;pre&gt;&lt;code class="bash"&gt;find . -type f -name '*.txt' -exec bash -c 'cat {}' \;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note the &lt;code&gt;\;&lt;/code&gt; at the end - that&amp;#8217;s important if you&amp;#8217;re executing the bash shell as it indicates the end of the line.&lt;/p&gt;</description><link>http://www.weekeat.com/post/24581213090</link><guid>http://www.weekeat.com/post/24581213090</guid><pubDate>Thu, 07 Jun 2012 11:53:42 +1000</pubDate><category>linux</category><category>commandline</category><category>cli</category></item><item><title>ifconfig.me</title><description>&lt;p&gt;Awesome little site. Allows you to do this from any servers at command line:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;curl ifconfig.me&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It returns your external IP address!&lt;/p&gt;</description><link>http://www.weekeat.com/post/24532232923</link><guid>http://www.weekeat.com/post/24532232923</guid><pubDate>Wed, 06 Jun 2012 20:16:00 +1000</pubDate></item><item><title>Cheap SSH key tricks</title><description>&lt;p&gt;Of course, most will know how to generate new SSH keys for passwordless entry like so:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ssh-keygen -t rsa&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But I always want to add the key to the remote server first and then ssh in. So, I do this:&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;cat ~/.ssh/id_rsa.pub | ssh root@server.me "cat &amp;gt;&amp;gt; ~/.ssh/authorized_keys"&lt;/code&gt;
&lt;/pre&gt;</description><link>http://www.weekeat.com/post/24512768683</link><guid>http://www.weekeat.com/post/24512768683</guid><pubDate>Wed, 06 Jun 2012 11:57:00 +1000</pubDate><category>linux</category><category>ssh</category><category>commandline</category><category>cli</category></item><item><title>Ad-hoc keymapping in Vim</title><description>&lt;p&gt;Ever since I saw a screencast by Gary Bernhardt from &lt;a href="https://www.destroyallsoftware.com" target="_blank"&gt;Destroy All Software&lt;/a&gt;, I&amp;#8217;ve been using his awesomely handy key mapping trick in vim while writing scripts.&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re like me, you&amp;#8217;ll spend most of your time writing small shell/bash scripts. I typically would write/edit my script, save my work, switch to another pane in &lt;a href="http://www.iterm2.com/" target="_blank"&gt;iTerm2&lt;/a&gt;, test the script, back to my editing pane, edit, save, switch pane, test&amp;#8230; repeat.&lt;/p&gt;

&lt;p&gt;How about just create an ad-hoc mapping to do both saving and execution of the script all in one go?&lt;/p&gt;

&lt;p&gt;In vim&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:map ,s :w\|!./script_name.sh&amp;lt;cr&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&amp;#8217;s it.&lt;/p&gt;

&lt;p&gt;Now, every time you&amp;#8217;re done editing, hit &amp;#8216;&lt;code&gt;,s&lt;/code&gt;&amp;#8217; and you&amp;#8217;ll save &lt;em&gt;and&lt;/em&gt; execute the script, all in one go.&lt;/p&gt;</description><link>http://www.weekeat.com/post/24469611708</link><guid>http://www.weekeat.com/post/24469611708</guid><pubDate>Tue, 05 Jun 2012 23:38:00 +1000</pubDate><category>linux</category><category>vim</category><category>vi</category></item><item><title>Perl Search &amp; Replace One-Liner</title><description>&lt;p&gt;Yes, it’s been used for a long long time and I have been using them for quite a while too. But the problem is, I always forget which one to leave out for a dry run.&lt;/p&gt;

&lt;p&gt;For search and replace applied to files specified:&lt;/p&gt;

&lt;pre class="perl"&gt;&lt;code&gt;me@mycomp:~$ perl -pi -e ‘s/search/replace/g’ *.html&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For non-applied search and replace (without the i argument):&lt;/p&gt;

&lt;pre class="perl"&gt;&lt;code&gt;me@mycomp:~$ perl -p -e ‘s/search/replace/g’ something.html&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The way I try to use now to remember which one to exclude is this:
&lt;code&gt;-pi&lt;/code&gt; means print into as in print into the file(s) searched and &lt;code&gt;p&lt;/code&gt; means print only [to screen].&lt;/p&gt;

&lt;p&gt;Have fun!&lt;/p&gt;</description><link>http://www.weekeat.com/post/24468170247</link><guid>http://www.weekeat.com/post/24468170247</guid><pubDate>Tue, 05 Jun 2012 22:50:00 +1000</pubDate><category>perl</category><category>linux</category><category>commandline</category><category>cli</category></item></channel></rss>
