Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

What next?
1. Bookmark us with del.icio.us or Digg Us!
2. Subscribe to this site's RSS feed
3. Browse the site.
4. Post your own code snippets to the site!

Top Tags and Latest Posts

rails
  old deprecated legacy plugins repository for Rai..
  rails console - add module methods
  Capistrano task to load production data

ruby
  Capistrano task to load production data
  Сортировка массива с горо�..
  Calculate the number of working days between two..

php
  Get remote file size, following redirects (PHP)
  Facebook Status Updater using cURL
  Output all PHP variables

javascript
  UTF8 encode/decode helper library
  Never render the full layout in a Rails view whe..
  Javascript Numbers Only

osx
  Delete all Dreamweaver notes directories
  Install RdbiPgSQL package for R on OS X
  Clear DNS lookup / IP address cache on OS X Tige..

shell
  Latest file to download
  Convert Mac to Unix line endings in VI
  Interactive LAME-ifyer to convert WAV or AIFF fi..

css
  CSS image floats no text wrap
  Cross-browser solution for adding hover border t..
  Standard CSS helpers

mysql
  Limit equivelent for MSSQL
  add mysql symbolic link to OS X MacPorts install..
  mysql on OS X

linux
  grep - search for a string within files within a..
  Human Readable ls and df commands
  postfix - flush queues / logs

lighttpd
  Common Lighttpd rewrite requests
  Lighttpd redirect snippet
  one rails app, multiple domains (via alias domai..

ssh
  SSH dynamic forward (Linux)
  Access subversion repository on Textdrive via ss..
  linux ubuntu ssh login

html
  Standard CSS helpers
  PHP State-Array Generator
  US States Pop-up

Top Tags Alphabetically

actionscript (18)
administration (29)
ajax (23)
apache (27)
applescript (15)
backup (10)
bash (35)
cli (23)
css (44)
delphi (21)
dns (15)
dom (16)
effect (12)
email (16)
expressionengine (23)
fastcgi (14)
flash (16)
freebsd (11)
html (36)
image (21)
java (14)
javascript (96)
lighttpd (43)
linux (44)
mac (30)
mysql (44)
osx (77)
perl (13)
php (100)
prototype (15)
python (18)
rails (113)
recipe (16)
regex (19)
ruby (109)
rubyonrails (17)
shell (74)
sql (26)
ssh (42)
subversion (21)
svn (28)
sysadmin (10)
terminal (23)
textdrive (15)
textpattern (13)
tiger (11)
ubuntu (11)
unix (20)
utility (10)
xhtml (10)

« Newer Snippets
Older Snippets »
Showing 41-60 of 849 total

cmdparser - parse command line options

cmdparser - parse command line options

Author: jv
License: The MIT License, Copyright (c) 2007 jv
Description: a command line option parser for use in bash scripts (Mac OS X); an alternative to getopts
Usage: /path/to/script_with_cmdparser -a -b -c -f file -d dir (example)
Hints: add security features as needed (such as resetting the $PATH & $IFS variables, using full command paths, etc.; cf. Shell scripting 101: Part 6)



#!/bin/bash

# cmdparser

# define the names of flags as a regular expression
# flags are command line options that require arguments

flags="(flag1|flag2|flag3|flag4|flag5|flag6|flag7|flag8)"


# define the names of switches as a regular expression
# switches are command line options that do not take arguments
# make sure multi-char switches precede single-char switches in the regular expression
# note that the regular expression contains neither the special read-from-stdin switch "-" nor the special end-of-options switch "--"

switches="(cc|zz|a|b|c)"  


usage="usage: $(basename "$0") [-a] [-b] [-c] [-cc] [-zz] [-flag1 arg] [-flag2 'arg1 arg2 ...'] [-flag3=arg] [-flag4=\"arg1 arg2\"] ..."

declare flag1 flag2 flag3 flag4 flag5 flag6 flag7 flag8       # flags
declare cc zz a b c                                           # switches
#declare -i cc=0 zz=0 a=0 b=0 c=0                          

declare optstr flagvar argvar argvar_escaped pipedstr piped
declare -i optid pipedvar


# piped="piped" will be used for variable creation 
# example: piped="piped"; pipedstr="piped arg"; eval $piped='"$(echo "$pipedstr")"'; echo "$piped"

piped="piped"

# default value is set to "no pipe"
pipedvar=0

# if /dev/stdin has a size greater than zero ...
if [[ -s /dev/stdin ]]; then pipedstr="$("; else pipedstr=""; fi 

if [[ $# -eq 0 ]] && [[ -z "$(echo $pipedstr)" ]]; then
  echo "No arguments specified!"
  echo >&2 "$usage"
  exit 1
fi 

if [[ $# -eq 0 ]] && [[ -n "$(echo $pipedstr)" ]]; then
  eval $piped='"$(echo "$pipedstr")"'  
  pipedvar=1
fi 

# if there are command line arguments ...
if [[ $pipedvar -eq 0 ]]; then

   optstr=" "  
   optid=0

   while [[ -n "$optstr" ]]; do     

      # try to extract valid flags or switches from $1
      #echo "\$1:   $1"

      optstr="$(echo "$1"  |  grep -E "^\-\-?$flags$")"

      if [[ -n "$optstr" ]]; then optid=1; fi
      if [[ -z "$optstr" ]]; then optid=2; optstr="$(echo "$1" | grep -E "^\-\-?$switches$")"; fi
      if [[ -z "$optstr" ]]; then optid=3; optstr="$(echo "$1" | grep -E "^\-\-?$switches+$")"; fi
      if [[ -z "$optstr" ]]; then optid=4; optstr="$(echo "$1" | grep -E "^(\-\-?$flags\=.*|\-\-?$flags[^ ]+)$")"; fi
      if [[ -z "$optstr" ]]; then  
         if [[ "$1" = "-" ]] && [[ "$@" = "-" ]]; then  
            optid=5
            optstr="-" 
         fi
      fi

      if [[ -z "$optstr" ]] && ( [[ -n "$(echo "$@" |  grep -Eo "(^ *| )\-\-?$flags" )" ]] || [[ -n "$(echo "$@" |  grep -Eo "(^ *| )\-\-?$switches" )" ]] ); then
         optstr="$(echo $1)"
         echo "illegal option removed: $optstr"
         shift
         continue
         #optstr=" "
         #echo >&2 "$usage"
         #exit 1
      fi 

      #echo -e "optstr:\t$optstr"
      #echo -e "optid:\t$optid"
      #echo -e "piped:\t$piped"

      if [[ "$1" = "--" ]]; then shift; break; fi      # -- marks end of options

      if [[ -z "$optstr" ]]; then break; fi


      # flag followed by space (example: -f file)
      if [[ $optid -eq 1 ]]; then 

         if [[ -z "$2" ]]; then
            echo; echo "flag \"$1\" removed: no argument given!"
            shift
            if [[ -n "$(echo "$@")" ]]; then shift; continue; else shift; break; fi
            #echo >&2 "$usage"
            #exit 1
         fi 

         # make sure flag $1 is not directly followed by yet another flag or switch
         if [[ "$2" = "-" ]] || [[ "$2" = "--" ]] || [[ -n "$(echo "$2" |  grep -E "^\-\-?$flags.*$" )" ]] || [[ -n "$(echo "$2" |  grep -E "^\-\-?$switches+$" )" ]]; then
            echo; echo "flag \"$1\" removed because of illegal argument: \"$2\""
            shift
            continue
            #echo >&2 "$usage"
            #exit 1
         fi

         flagvar="$(expr "$1" : "^\-\{1,2\}\(.*\)$")"
         argvar="$2"
         eval $flagvar='"$(echo "$argvar")"'
         shift 2
         continue

      # single switch (example: -a)
      elif [[ $optid -eq 2 ]]; then
         flagvar="$(expr "$1" : "^\-\{1,2\}\(.*\)$")"
         eval $flagvar='"$(echo "1")"'
         shift
         continue
  
      # combined switch (example: -abcc)
      elif [[ $optid -eq 3 ]]; then
         flagvar="$(expr "$1" : "^\-\{1,2\}\(.*\)$")"
         while [[ -n "$flagvar" ]]; do
            char="$(echo "$flagvar" | sed -E "s/^$switches.*$/\1/")"
            eval $char='"$(echo "1")"'
            flagvar="$(echo "$flagvar" | sed -E "s/^$switches//")"
         done
         shift
         continue

      # flag without following space (example: -ffile)
      elif [[ $optid -eq 4 ]]; then 
         argvar="$(echo "$1" | sed -E "s/^\-\-?$flags\=?//")"
         argvar_escaped="$(echo "$argvar" | sed -E 's/([^[:alnum:]])/\\\1/g')"   # escape special regex metacharacters such as ., ?, *
         #argvar_escaped="$(echo "$argvar" | sed -E 's/([[:punct:]])/\\\1/g')"     
         #echo "argvar_escaped: $argvar_escaped"
         flagvar="$(echo "$1" | sed -E -e 's/^-\-?//' -e "s/\=?$argvar_escaped$//")"
         eval $flagvar='"$(echo "$argvar")"'
         shift
         continue

      # the special read-from-stdin switch "-"
      elif [[ $optid -eq 5 ]]; then 
         pipedvar=1
         eval $piped='"$(echo "$pipedstr")"'
         shift
         break

      fi

      # remove $1 from "$@"
      shift

   done

fi   # if [[$pipedvar -eq 0 ]]; then ...


echo 

echo -e "a:\t$a"
echo -e "b:\t$b"
echo -e "c:\t$c"
echo -e "cc:\t$cc"
echo -e "zz:\t$zz"
echo -e "flag1:\t$flag1"
echo -e "flag2:\t$flag2"
echo -e "flag3:\t$flag3"
echo -e "flag4:\t$flag4"
echo -e "flag5:\t$flag5"
echo -e "flag6:\t$flag6"
echo -e "flag7:\t$flag7"
echo -e "flag8:\t$flag8"

echo

if [[ $pipedvar -eq 1 ]] && [[ -z "$(echo $@)" ]]; then echo "remaining string-piped: $piped"; else echo "remaining string: $@"; fi

echo

exit 0




Test cases:

touch ~/Desktop/cmdparser; chmod +x ~/Desktop/cmdparser


1.

~/Desktop/cmdparser -abcc -c -zz -flag1="" -flag2=arg -flag3="arg" -flag4='arg1=*,arg2=?,arg3=!' -flag5 '(arg1|arg2|arg3)' -flag6 'arg1=ag,arg2=bg,arg3=cg' -flag7 An\ argument\ with\ spaces\! -flag8='Yet another argument with spaces!' filename1 filename2 filename3


Output:

a: 1
b: 1
c: 1
cc: 1
zz: 1
flag1:
flag2: arg
flag3: arg
flag4: arg1=*,arg2=?,arg3=!
flag5: (arg1|arg2|arg3)
flag6: arg1=ag,arg2=bg,arg3=cg
flag7: An argument with spaces!
flag8: Yet another argument with spaces!

remaining string: filename1 filename2 filename3


2.

echo filename | ~/Desktop/cmdparser -abcc -c -zz -flag1 arg -flag2=arg --flag3="arg" -flag4='arg1=*,arg2=?,arg3=!' -flag5 '(arg1|arg2|arg3)' -flag6 'arg1=ag,arg2=bg,arg3=cg' --flag7 An\ argument\ with\ spaces\! -flag8='Yet another argument with spaces!' -


Output:

a: 1
b: 1
c: 1
cc: 1
zz: 1
flag1: arg
flag2: arg
flag3: arg
flag4: arg1=*,arg2=?,arg3=!
flag5: (arg1|arg2|arg3)
flag6: arg1=ag,arg2=bg,arg3=cg
flag7: An argument with spaces!
flag8: Yet another argument with spaces!

remaining string-piped: filename

Javascript Numbers Only

Restrict entering anything but numbers in a form field with javascript

javascript:
<SCRIPT TYPE="text/javascript">

SCRIPT>


html
<FORM ACTION="../cgi-bin/mycgi.pl" METHOD=POST>
U.S. ZIP Code: 
  <INPUT NAME="dollar" SIZE=5 MAXLENGTH=5
   onKeyPress="return numbersonly(this, event)">
  <INPUT TYPE=SUBMIT VALUE="go">
FORM>

SSH dynamic forward (Linux)

This command will create a dynamic forward from an SSH client to an SSH server. Basically what this does is allow you to use any local port (8080 in this example) as a proxy for any TCP application.

Feedback, suggestions and comments are all welcome!

# In the following example, we create a dynamic
# forward from port 8080 (client) to port 22 (host.net).

ssh -D 8080 username@host.net

# Now, we'll check out netstat to see what we
# have done.

netstat

# Active Internet connections (w/o servers)
# ...
# tcp 0 0 host.net:ssh client.com:60565 ESTABLISHED
# ...
#
# Awesome! Now we've got the connection. I'll add
# another post telling how to use this port as a
# socks proxy for any TCP application :)

Scripting schema updates in MSSQL #1

This SQL statement will alter a table only if a column in the table to be altered does NOT contain a column named 'FavoriteColorId'.

From: http://haacked.com/

IF NOT EXISTS
(
    SELECT * FROM [information_schema].[columns]
    WHERE    table_name   = 'Customer'
    AND      table_schema = 'dbo'
    AND      column_name  = 'FavoriteColorId'
)
BEGIN
    ALTER TABLE [dbo].[Customer]
    ADD FavoriteColorId int

Retrieve MSSQL table information

Retrieve tons of information (length, data type, name, etc.) of columns for a table. Works in (T|MS)SQL (all I've tested it in).

SELECT * FROM information_schema.columns WHERE table_name = 'Customers'

Output all PHP variables

// This outputs PHP variables for debugging. I didn't create it, here is the original source. Thanks to the creator for writing it: kailashbadu at hotmail dot com

// http://us.php.net/get_defined_vars


<?php
  /**
   * @desc   works out the variables in the current scope(from where function was called).
   *         Returns an array with variable name as key and vaiable value as value
   * @param  $varList: variables returned by get_defined_vars() in desired scope.
   *         $excludeList: variables to be excluded from the list.
   * @return array
   */
  function getDefinedVars($varList, $excludeList)
  {
      $temp1 = array_values(array_diff(array_keys($varList), $excludeList));
      $temp2 = array();
      while (list($key, $value) = each($temp1)) {
          global $$value;
          $temp2[$value] = $$value;
      }
      return $temp2;
  }
 
  /**
   * @desc   holds the variable that are to be excluded from the list.
   *         Add or drop new elements as per your preference.
   * @var    array
   */
  $excludeList = array('GLOBALS', '_FILES', '_COOKIE', '_POST', '_GET', 'excludeList');
 
  //some dummy variables; add your own or include a file.
  $firstName = 'kailash';
  $lastName = 'Badu';
  $test = array('Pratistha', 'sanu', 'fuchhi');
 
  //get all variables defined in current scope
  $varList = get_defined_vars();
 
  //Time to call the function
  print "
";
  print_r(getDefinedVars($varList, $excludeList));
  print "
"; ?>

sample of dutch validation error messages

//Dutch validation error messages
//Put this at the end of environment.rb

module ActiveRecord
  class Errors
    begin
      @@default_error_messages = {
        :empty => "dient verplicht ingevuld te worden",
        :blank => "dient verplicht ingevuld te worden",
      }
    end
  end
end

director

i like this site

Ruby: Apple Aperture API

UPDATED WED Aug 15/07

PLEASE NOTE: requires the following modules "active_record", "rbosa" and "hpricot" and my own Imageshack API to work.

USAGE:

You can include/require this as a module in your own scripts, or as I do, use it directly from irb in the Terminal. Documentation is provided within the script itself, but essentially I use it to get these things done:

With Aperture launched, select the pictures of your choice (one or multiples makes no diff), then entering the following inside irb results in:

1. Aperture.reveal is essentially "Reveal in Finder"

2. Aperture.paths returns the Unix paths to the locations of the pics.

3. Aperture.open opens the pictures with an external default app (usually Preview).

4. If you provide the script with Photoshop's path, then:

Aperture.edit will open the original file directly in Photoshop without creating a separate version inside Aperture.

5. Aperture.ids will give you an array of the unique ID asssigned by Aperture to each pic within the ZRKVERSION table. What this is for is up to you to find out.

6. NEW: Imageshack.us upload/backup

Aperture.upload will upload the pic(s) to Imageshack.us and return the direct link/URL of the pic.

Upon first launch, a new metadata field is created inside Aperture's metadata panel called "Imageshack URL" (if you don't see it, inside Aperture, Ctrl-D --> Others). the uploaded pic's URL will be stored inside this field automatically.

The API directly interrogates Aperture's SQLite DB. Who knows, could be a nice place to start from to building other stuff.



require 'rubygems'
require 'active_record'
require 'rbosa'
require 'hpricot'
require 'open3'
require 'beckett/imageshack'

# --- GLOBALS --- #

HOME = ENV['HOME']
PATH_TO_PHOTOSHOP = "/Applications/Adobe\\ Photoshop\\ CS3/Adobe\\ Photoshop\\ CS3.app/Contents/MacOS/Adobe\\ Photoshop\\ CS3"

Aperture = OSA.app('Aperture')

# --- CONNECT TO CURRENT LIBRARY --- #

class LibraryConnect

  def initialize
    findLibrary
    connect unless $PATH_TO_DB.nil?
  end

  protected

  def findLibrary
  
  aperture_plist = HOME + '/Library/Preferences/com.apple.Aperture.plist'
  plistdump = HOME + '/Library/Caches/' + 'plistdump.tmp'
  plutil_error = Open3.popen3("plutil -convert xml1 -o #{plistdump} #{aperture_plist}") { |stdin,stdout,stderr| stderr.read }

  if plutil_error == ""
      doc = Hpricot(File.open(plistdump)) ; %x( rm #{plistdump} )
      relative_lib_path = (doc/:key).select { |key| key.inner_text == 'LibraryPath' }[0].next_sibling.inner_text
      $PATH_TO_LIB = relative_lib_path =~ /^~/ ? relative_lib_path.gsub(/^~/, HOME) : relative_lib_path
      $PATH_TO_DB = "#{$PATH_TO_LIB}/Aperture.aplib/Library.apdb"
      puts "Current library --> " + $PATH_TO_LIB
  else
      $PATH_TO_DB = nil
      puts "Cannot find library. Goodbye."
  end

  end

  def connect
    ActiveRecord::Base.establish_connection(
      :adapter => "sqlite3",
      :dbfile  => $PATH_TO_DB
    )
  end

end

# --- LIBRARY CLASSES-SQL TABLES MAPPINGS --- #

class Pictures < ActiveRecord::Base         # Contains the majority of non-metadata info on a picture
  set_table_name "ZRKVERSION"
  set_primary_key "ZUUID"
end

class Projects < ActiveRecord::Base         # Every pic only belongs to one project
  set_table_name "ZRKFOLDER"
  set_primary_key "ZUUID"
end

class Masters < ActiveRecord::Base          # Info on master images
  set_table_name "ZRKMASTER"
  set_primary_key "Z_PK"
end

class Files < ActiveRecord::Base            # Info on the actual image file 
  set_table_name "ZRKFILE"
  set_primary_key "Z_PK"
end

class Metadata < ActiveRecord::Base         # Metadata information tagged to every picture in library
  set_table_name "ZRKSEARCHABLEPROPERTY"
  set_primary_key "Z_PK"
end

class Albums < ActiveRecord::Base           # All albums within library
  set_table_name "ZRKPERSISTENTALBUM"
  set_primary_key "Z_PK"
end

class AlbumVersions < ActiveRecord::Base    # Foreign key that links a picture's Z_PK (from ZRKVERSION) to an
  set_table_name "Z_11VERSIONS"             # album's Z_PK in ZRKPERSISTENTALBUM
end

class Properties < ActiveRecord::Base       # Metadata categories
  set_table_name "ZRKPROPERTYIDENTIFIER"
  set_primary_key "Z_PK"
end

class Picture                               # Custom class that contains all relevant info on a picture

attr_reader :id, :project_id, :master_id, :file_id, :version_id, :width, :height, :filesize, :name, :moddate

def initialize(pic_id)

  # Query ZRKVERSION
  
  @id = pic_id
  pic = Pictures.find(pic_id)
  @project_id = pic.ZPROJECTUUID
  @master_id = pic.ZMASTER
  @file_id = pic.ZFILE
  @version_id = pic.Z_PK

  # Query ZRKFILE

  file = Files.find(@file_id)
  @width = pic.ZPIXELWIDTH
  @height = pic.ZPIXELHEIGHT
  @filesize = file.ZFILESIZE
  @name = file.ZNAME
  @moddate = realtime(file.ZFILEMODIFICATIONDATE_before_type_cast)

end

def filepath
    path = $PATH_TO_LIB + '/' + self.projectPath + '/' + self.importGroup + '/' + self.folderName + '/' + self.filename
end

def nixpath
    self.filepath.gsub(/ /,'\ ')
end

def open
  `open #{self.nixpath}`
end

def edit
  if PATH_TO_PHOTOSHOP != ""
    `open -a #{$PATH_TO_PHOTOSHOP} #{self.nixpath}`
  else
    `open #{self.nixpath}`
  end
end

def reveal
    puts nixpath
    `open #{File.dirname(self.nixpath)}`
end

def shack_uri
  pic_meta = Metadata.find( :first, :conditions => { :ZVERSION => @version_id, :ZPROPERTYIDENTIFIER => $SHACKURLPROP } )
  unless pic_meta == nil
    pic_meta.ZPROPERTYSPECIFICSTRING
  else
    return 'Does not exist.'
  end
end

def storeURI(url)
records = Metadata.find( :all, :conditions => { :ZVERSION => @version_id, :ZPROPERTYIDENTIFIER => $SHACKURLPROP } )
if  records.empty? == true
    new_uri = Metadata.create(
        :Z_ENT => 13,
        :Z_OPT => 1,
        :ZPROPERTYSPECIFICNUMBER =>  nil,
        :ZPROPERTYSPECIFICSTRING => url,
        :ZVALUETYPE => 3,
        :ZVERSION => @version_id,
        :ZPROPERTYIDENTIFIER => $SHACKURLPROP )
  new_uri.Z_PK
else
  records.each { |entry| Metadata.destroy(entry.Z_PK) }
  self.storeURI(url)
end

end

def realtime(sqtime)
  t = Time.at(sqtime.to_i + 978307200)      # => # Derives from: Time.utc(2001,"jan",1,0,0,0).to_i
  Time.utc(t.year,t.month,t.day,t.hour,t.min)
end

protected

def projectPath
    Projects.find(@project_id).ZLIBRARYRELATIVEPATH
end

def importGroup
   Masters.find(@master_id).ZIMPORTGROUP
end

def folderName
   Masters.find(@master_id).ZNAME
end

def filename
  Files.find(@file_id).ZNAME
end

end

class Album

def initialize(zpk)
  @album = Albums.find(zpk)
end

def add_count(n=0)
  @album.update_attributes(   :ZDATELASTSAVEDINDATABASE => (Time.now.to_f + 978307200.0),
                              :ZMETADATACHANGEDATE => (Time.now.to_f + 978307200.0),
                              :ZVERSIONCOUNT => @album.ZVERSIONCOUNT + n,
                              :ZCREATEDATE => @album.ZCREATEDATE_before_type_cast.to_f )
end

end

# --- INTERACTING WITH APERTURE FROM IRB --- #
# All operations are performed recursively on image(s) within the array returned by Aperture

class OSA::Aperture::Application

def new_prop(fieldName)

Properties.create(  :Z_ENT => 12,
                    :Z_OPT => 1,
                    :ZPROPERTYKEY => fieldName,
                    :ZPROPERTYTYPE => 7)
                    
return Properties.find_by_ZPROPERTYKEY(fieldName).Z_PK

end

def ids     # Returns the IDs used to query the ZRKVERSION table
  self.selection.collect { |pic| pic.id2 }
end

def paths   # Returns the filepaths of selected images
  self.ids.collect { |id| Picture.new(id).filepath }
end

def reveal  # 'Reveal in Finder' selected images
  self.ids.each { |id| Picture.new(id).reveal }
end

def open    # Opens selected images in Preview
  self.ids.each { |id| Picture.new(id).open }
end

def edit    # Opens the original file in Photoshop CS3 (if path provided or default)
  self.ids.each { |id| Picture.new(id).edit }
end

def upload(reveal=false)  # Uploads the image to Imageshack and returns the direct link to the pic, if called with true, then opens it in browser after upload

  self.ids.each do |id|
    pic = Picture.new(id)
    pic_mirror = ShackMirror.new(pic.filepath)
    pic.storeURI(pic_mirror.url)
    `open #{pic_mirror.url}` if reveal
    puts pic_mirror.url
  end

end

def print(name)
  self.ids.each { |id| puts Picture.new(id).send(name) }
end

end

# --- INITIALIZE --- #

LibraryConnect.new

$SHACKURLPROP = Properties.find_by_ZPROPERTYKEY("Imageshack URL") == nil ? Aperture.new_prop("Imageshack URL") : Properties.find_by_ZPROPERTYKEY("Imageshack URL").Z_PK

Ruby: Apple Shake - Report FileIn Nodes

Another quick and dirty script I wrote when I screwed up my media's filesystem and I had to put it back together and this script simply prints out (nicely) the location of the files of every FileIn node in the Shake script.


#! /usr/bin/env ruby

$SOURCE = "" # Where are the Shake scripts?

$FILE_LIST = %x| ls #{$SOURCE}*.shk |.split("\n")

$FILE_LIST.each do |f|
  
  filein_nodes = File.open(f).grep(/SFileIn/)

  puts " --------- #{f} ------------"

  filein_nodes.map! { |n| n.split(/SFileIn/).last }

  filein_nodes.each { |n| puts n }
  
  puts "\n\n"

end

« Newer Snippets
Older Snippets »
Showing 41-60 of 849 total