nix, shell, perl, php, mysql and mac os x tips and tricks

Wednesday, July 16, 2008

Regex to match a price with or without the decimal

\d+\.?\d{0,2}?

command to kill a process by name

kill `ps -axwwwww | grep MyAPP | grep -v grep | awk '{print $1}'`

Friday, July 11, 2008

Applescript to close all open applications

tell application "System Events" to set the visible of every process to true

tell application "System Events" to set theApps to (name of every process whose visible is true and name is not "Finder" and name is not (my name as text))

repeat with theApp in theApps
    tell application theApp to quit
end repeat



Applescript to unmount disk image


tell application "Finder"
    if exists "MyDisk" then
        do shell script "hdiutil detach \"/Volumes/MyDisk\""
    end if
end tell



Another way:


tell application "Finder"
    if (exists the disk "local_home_backup") then
        eject "local_home_backup"
        delay 2
    end if
end tell

Wednesday, July 9, 2008

MySQL use CONCAT and UPDATE together in mysql to add to an existing string

UPDATE products SET SHIPPING = CONCAT('+', SHIPPING) WHERE SHIPPING != "" AND SHIPPING REGEXP '^[^\+]'

Wednesday, July 2, 2008

install perl module at the command line with CPAN

perl -MCPAN -e 'install Bundle::CPAN'