<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: bash code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 29 Aug 2008 22:49:58 GMT</pubDate>
    <description>DZone Snippets: bash code</description>
    <item>
      <title>Dock 2D/3D</title>
      <link>http://snippets.dzone.com/posts/show/5998</link>
      <description>// Switch Dock 2D / 3D&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;CURRENT=`defaults read com.apple.dock no-glass`&lt;br /&gt;case $CURRENT in&lt;br /&gt;    0)&lt;br /&gt;        OPTION='YES'&lt;br /&gt;        ;;&lt;br /&gt;    1) &lt;br /&gt;        OPTION='NO'&lt;br /&gt;        ;;&lt;br /&gt;    *)&lt;br /&gt;        OPTION='YES'&lt;br /&gt;        ;;&lt;br /&gt;esac&lt;br /&gt;&lt;br /&gt;defaults write com.apple.dock no-glass -boolean $OPTION&lt;br /&gt;killall Dock&lt;br /&gt;echo "Restarting dock..."&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Fri, 29 Aug 2008 10:59:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5998</guid>
      <author>masssi (Massimiliano)</author>
    </item>
    <item>
      <title>List the 10 most recent files</title>
      <link>http://snippets.dzone.com/posts/show/5892</link>
      <description>&lt;code&gt;&lt;br /&gt; aimage_file = Dir.entries(".").select{|f| File.file? f }.sort_by { |f| File.mtime(f) }.reverse[0..9]&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;=&gt; ["14_12_10GMT_1.jpg", "14_12_09GMT_1.jpg", "14_12_09GMT.jpg", "14_12_10GMT.jpg", "14_12_08GMT.jpg", "14_11_38GMT_1.jpg", "14_11_38GMT.jpg", "14_11_37GMT_1.jpg", "14_11_37GMT_2.jpg", "14_11_37GMT.jpg"]&lt;br /&gt;&lt;br /&gt;References: &lt;br /&gt; - &lt;a href="http://www.ruby-doc.org/core/classes/Dir.html"&gt;Class: Dir&lt;/a&gt; [ruby-doc.org]&lt;br /&gt; - &lt;a href="http://www.ruby-doc.org/core/classes/File.html"&gt;Class: File&lt;/a&gt; [ruby-doc.org]&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Sun, 10 Aug 2008 14:13:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5892</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Bash prompt with git branch</title>
      <link>http://snippets.dzone.com/posts/show/5879</link>
      <description>&lt;code&gt;&lt;br /&gt;export PS1='\[\033[00;32m\]\u\[\033[01m\]@\[\033[00;36m\]\h\[\033[01m\]:\[\033[00;35m\]\w\[\033[00m\]\[\033[01;33m\]`git branch 2&gt;/dev/null|cut -f2 -d\* -s`\[\033[00m\]\$ '&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 06 Aug 2008 15:15:46 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5879</guid>
      <author>hmans (Hendrik Mans)</author>
    </item>
    <item>
      <title>Toggle hidden files in Mac OS X Finder</title>
      <link>http://snippets.dzone.com/posts/show/5855</link>
      <description>Works in Leopard, should work in all versions of OS X.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;if [ `defaults read com.apple.finder AppleShowAllFiles` == 1 ]&lt;br /&gt;then &lt;br /&gt;  echo "Hiding hidden files."&lt;br /&gt;  defaults write com.apple.finder AppleShowAllFiles -bool false&lt;br /&gt;else &lt;br /&gt;  echo "Showing hidden files."&lt;br /&gt;  defaults write com.apple.finder AppleShowAllFiles -bool true&lt;br /&gt;fi   &lt;br /&gt;     &lt;br /&gt;KillAll Finder&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 Jul 2008 02:00:25 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5855</guid>
      <author>Aupajo (Pete)</author>
    </item>
    <item>
      <title>Get input from terminal with prompt, history, line editor</title>
      <link>http://snippets.dzone.com/posts/show/5829</link>
      <description>Using this script you will be able to read user input using readline goodies but without need to manually program readline library. Just save it under e.g. /usr/local/bin/getline, and then call like:&lt;br /&gt;getline {prompt} {historydir}.&lt;br /&gt;&lt;br /&gt;for example:&lt;br /&gt;getline "input&gt; " "/tmp"&lt;br /&gt;&lt;br /&gt;You can for example call this script from php using popen(). This way php doesn't have to include readline module, and you can do shell stuff not inside php, but using shell code, which is more natural and comfortable way to do it.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash -f&lt;br /&gt;history -r "$2/.getline_history"&lt;br /&gt;LINE=""&lt;br /&gt;read -re -p "$1" LINE&lt;br /&gt;history -s "$LINE"&lt;br /&gt;history -w "$2/.getline_history"&lt;br /&gt;echo $LINE&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Sun, 27 Jul 2008 19:48:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5829</guid>
      <author>ptr128 (Mariusz)</author>
    </item>
    <item>
      <title>Decompress several filetypes with a single script</title>
      <link>http://snippets.dzone.com/posts/show/5785</link>
      <description>// Decompresses Z, gz, bz2, zip, rar, tar, and 7z with a single 'decompress' command&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;# decompress - will decompress a file, regardless of compression type.&lt;br /&gt;&lt;br /&gt;Z="compress -d"&lt;br /&gt;gz="gunzip"&lt;br /&gt;bz="bunzip2"&lt;br /&gt;zip="unzip -qo"&lt;br /&gt;rar="unrar x -id -y"&lt;br /&gt;tar="tar xf"&lt;br /&gt;7z="p7zip -d"&lt;br /&gt;&lt;br /&gt;if [ $# -eq 0 ]; then&lt;br /&gt;    echo "Usage: decompress file or files to decompress"&gt;&amp;2&lt;br /&gt;    exit 1&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;for name&lt;br /&gt;do&lt;br /&gt;	if [ ! -f "$name" ] ; then&lt;br /&gt;		echo "$0: file $name not found. Skipped." &gt;&amp;2&lt;br /&gt;		continue&lt;br /&gt;	fi&lt;br /&gt;&lt;br /&gt;	if [ "$(echo $name | egrep '(\.Z$|\.gz$|\.bz2$|\.zip$|\.rar$|\.tar$|\.tgz$|\.7z$)')" = "" ] ; then&lt;br /&gt;		echo "Skipped file ${name}: it's already decompressed." &lt;br /&gt;      		continue&lt;br /&gt;	fi&lt;br /&gt;&lt;br /&gt;	extension=${name##*.}&lt;br /&gt;&lt;br /&gt;	case "$extension" in&lt;br /&gt;		Z ) echo "Filetype is Z. Decompressing..."&lt;br /&gt;		    $Z "$name"&lt;br /&gt;		    ;;&lt;br /&gt;		gz ) echo "Filetype is gz. Decompressing..."&lt;br /&gt;		     $gz "$name"&lt;br /&gt;		     ;;&lt;br /&gt;		bz2 ) echo "Filetype is bz2. Decompressing..."&lt;br /&gt; 		     $bz "$name"&lt;br /&gt;		     ;;&lt;br /&gt;		zip ) echo "Filetype is zip. Decompressing..."&lt;br /&gt;		      $zip "$name"&lt;br /&gt;		      ;;&lt;br /&gt;		rar ) echo "Filetype is rar. Decompressing..."&lt;br /&gt;		      $rar "$name"&lt;br /&gt;		      ;;&lt;br /&gt;		tar ) echo "Filetype is tar. Decompressing..."&lt;br /&gt;              	      $tar "$name"&lt;br /&gt;              	      ;;&lt;br /&gt;		tgz ) echo "Filetype is tgz. Decompressing..."&lt;br /&gt;              	      $tar "$name"&lt;br /&gt;                     ;;&lt;br /&gt;               7z ) echo "Filetype is 7z. Decompressing..."&lt;br /&gt;                     $7z "$name"&lt;br /&gt;	esac&lt;br /&gt;&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;exit 0&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Fri, 18 Jul 2008 02:07:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5785</guid>
      <author>zdenton (Zach Denton)</author>
    </item>
    <item>
      <title>Inspect a website like a string in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/5745</link>
      <description>Put the following function into your ~/.bash_login (or alternatives).&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;unset -f inspect_url&lt;br /&gt;&lt;br /&gt;function inspect_url() { &lt;br /&gt;   /usr/bin/curl -L -s --max-time 10 "${@}" | ruby -n -e 'p $_.to_s'&lt;br /&gt;   return 0&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;inspect_url http://www.ruby-forum.com&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 09 Jul 2008 21:13:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5745</guid>
      <author>ntk ()</author>
    </item>
    <item>
      <title>Find ports used by applications on Mac OS X (i.e. netstat for os x)</title>
      <link>http://snippets.dzone.com/posts/show/5712</link>
      <description>&lt;code&gt;netstat&lt;/code&gt; on os x doesn't do what you hope it does - show port numbers for applications.&lt;br /&gt;&lt;br /&gt;Here's a snippet for your .bash_profile:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# replacement netstat cmd to find ports used by apps on OS X&lt;br /&gt;alias netstat_osx="sudo lsof -i -P"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;(thx Lachie Cox)</description>
      <pubDate>Mon, 30 Jun 2008 00:06:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5712</guid>
      <author>nicwilliams (Dr Nic Williams)</author>
    </item>
    <item>
      <title>Find girls</title>
      <link>http://snippets.dzone.com/posts/show/5704</link>
      <description>// having trouble finding attractive women??&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ls -a /girls | grep 'sexy'&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 27 Jun 2008 21:40:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5704</guid>
      <author>zscott (Zak Scott)</author>
    </item>
    <item>
      <title>Convert Canon RAW ( .CRW) to jpeg</title>
      <link>http://snippets.dzone.com/posts/show/5702</link>
      <description>This is adapted from http://www.howtofixcomputers.com/forums/digital-photo/my-humble-contribution-wrapper-script-dcraw-linux-4360.html to enable (I think) higher quality interpolation in dcraw and higher quality JPEGs.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;DCRAW="dcraw -w -c "&lt;br /&gt;while [ $# -ge 1 ]&lt;br /&gt;do&lt;br /&gt;OJPEG=$(echo $1| perl -pe 's/\.crw$//i' | tr 'A-Z' 'a-z')'.jpeg'&lt;br /&gt;echo "${DCRAW} $1 | cjpeg &gt; ${OJPEG}"&lt;br /&gt;${DCRAW} -q 3 $1 | cjpeg -quality 95 &gt; ${OJPEG} || echo " *PROBLEM*"&lt;br /&gt;# transfer EXIF data from the original raw file&lt;br /&gt;exiftool -overwrite_original -TagsFromFile "$1" "${OJPEG}" &gt;/dev/null&lt;br /&gt;# preserve timestamps as much as possible&lt;br /&gt;# touch -r "$1" "${OJPEG}"&lt;br /&gt;dcraw -z "${OJPEG}"&lt;br /&gt;shift&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 27 Jun 2008 07:01:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5702</guid>
      <author>sandos (John B&#228;ckstrand)</author>
    </item>
  </channel>
</rss>
