Transform Matching Text with Gsub in Ruby and Regular Expression
Here is a gist that demonstrates how easy it is to transform text using #gsub and a block with Ruby.
"Scs Epc Score".gsub (/scs|epc/i) { |i| i.upcase }
# => SCS EPC Score
For more helpful string extensions in Ruby check out our Ruby Gem on GitHub...
Written by Sean Behan on 06/17/2012
Disk Usage Information on Mac OS X
Get disk usage information about the Desktop
$ du -h -d 0 Desktop
14G Desktop
Information about how much free space is available on computer
$ df -lh
Filesystem Size Used Avail Capacity Mounted on
/dev/disk0s2 111Gi 109Gi 2.3Gi 98% /
...
Written by Sean Behan on 06/17/2012
Using the PHP Mail Function with Additional Headers
Pass a fourth parameter to the mail() function with the header information.
<?php
$to = "jane@example.com";
$subject = "Hello World!";
$body = "This will be sent from email-addr@example.com";
$headers = "From: email-addr@example.com\r\nX-Mailer: php";...
Written by Sean Behan on 06/17/2012
How To Pipe To A Ruby Command Line Application
You need to read from STDIN rather than parse command line arguments.
while $stdin.gets
puts $_
end
Written by Sean Behan on 10/17/2013