TamWiki Main/Quick Action On Select

A new howto article in the wiki, this time some quick javascript to do an action based on the user selecting a value in a select block:

This is a quick and dirty way of getting your web page to respond to a change in value of a non-form-enclosed <select> tag. This is useful for causing changes to happen based on some specific set of values that you want to offer the user. First I will give the general form, then offer a specific example from some recent work I have done.

via TamWiki Main/Quick Action On Select.

TamWiki Main/Drop Caps With CSS

New article in the wiki on using CSS to implement drop caps:

Drop Caps are pretty much what the name implies: the first letter of a paragraph is enlarged and dropped to the left of the first paragraph on the page. This is seen in books, newspapers, and magazines all over. It is a classic design trick that can be successfully brought to a web page to give it a bit of elegance.

via TamWiki Main/Drop Caps With CSS complete with an example.

 

Update to wordpress plugin Sociable

You know those little links at the end of each post that let you share the post on various social network sites? They are powered by a wordpress plugin called Sociable. Sociable included a URL shortening service called awe.sm. However, awe.sm is in closed beta so they can’t be used. I decided to add a couple of other shortening services to the plugin, bit.ly and saf.li. I’ve posted the updated code to my public website:

http://public.tamaratemple.com/wordpress/plugins/mysociable.tar.gz

A diff of the old and new versions is here:

http://public.tamaratemple.com/wordpress/plugins/mysociable-diff.txt

Interesting to code a bit of plugin that has an admin screen.

YARS

Yet another ruby script

This time, taken from Rails Cookbook by O’Reilly. Checking in your spankin’-new Rails app to and SVN repository: svnizerails.rb. (It’s a little more complicated than it seems; hence the script.)

UPDATE: October 13, 2011: My advice: dump svn, go with git! With git, all you need to do is specify file patterns that you want to exclude (which is really the bulk of what svnizerails.rb was trying to do. So much simpler, so much cleaner!!

 

Writing ruby

Over the weekend, I wrote a small utility in ruby to backup my /Users directory to my external backup drive. Here it is: (script is downloadable here)

  1. #!/usr/bin/ruby
  2. #
  3. #  Created by Tamara Temple on 2007-03-16.
  4. #  Copyright (c) 2007. All rights reserved.
  5.  
  6. require 'FileUtils'
  7. include FileUtils::Verbose
  8.  
  9. LIBRARY_DIRS = 
  10.   ["./Library/Application Support",
  11.     "./Library/Keychains",
  12.     ",/Library/Mail",
  13.     "./Library/Mozilla",
  14.     "./Library/Preferences",
  15.     "./Library/Safari",
  16.     "./Library/StickiesDatabase",
  17.     "./Library/Workflows"]
  18.  
  19.  
  20. def getBackDir(timestamp)
  21.   prefix = "/Volumes/BootBackup/Users"
  22.   suffix = timestamp.strftime("%Y%m%d.%H%M%S")
  23.   backupdir = prefix + suffix
  24.   print "** backupdir: ", backupdir, "\n" if $DEBUG
  25.   backupdir
  26.  
  27. end
  28.  
  29. def getUserList(parentdir)
  30.  
  31.   userlist = Dir.entries(parentdir)
  32.  
  33.   if (!userlist.kind_of?(Array)) then raise "Internal Error: Dir.entries did not return an array." end
  34.  
  35.   userlist.delete(".") # remove the working directory from the list (this will not affect the directory on the disk)
  36.   userlist.delete("..") # remove the parent directory from the list
  37.   userlist.delete(".localized") # remove an extraneous file from the /Users directory
  38.   print "** userlist: ", userlist.join(", "),"\n" if $DEBUG 
  39.   userlist # return the userlist
  40.  
  41. end
  42.  
  43.  
  44. def getFileList()
  45.  
  46.   files = Dir.entries('.')
  47.  
  48.   if (!files.kind_of?(Array)) then raise "Internal Error: Dir.entries did not return an array." end
  49.  
  50.   files.delete(".") # remove the reference to the directory itself. (note this will not remove the directory -  files is an array not the directory)
  51.   files.delete("..") # remove the parent directory listing 
  52.   files.delete(".Trash") # don't backup the trash
  53.   files.delete("Library") # remove the Library directory as we don't want it all in the backup
  54.   print "** files: ", files.join(", "),"\n" if $DEBUG
  55.  
  56.   begin
  57.     libdirs = Dir.entries("./Library")
  58.   rescue Errno::ENOENT
  59.     libdirs = []
  60.   ensure
  61.     if (!libdirs.kind_of?(Array)) then raise "Internal Error: Dir.entries did not return an array." end
  62.   end
  63.  
  64.   # Remove extraneous entries
  65.   libdirs.delete(".")
  66.   libdirs.delete("..")
  67.   libdirs.delete(".localized")
  68.   libdirs.map! {|l| "./Library/" + l} # Need to add in the path to the Library subdirectories
  69.   print "** libdirs: ", libdirs.join(", "),"\n" if $DEBUG
  70.   libdirs = libdirs & LIBRARY_DIRS # get the intersection of library directories with the set we want to keep in backup
  71.  
  72.   files = files + libdirs
  73.   files.map! {|f| "'#{f}'"} # need to quote file names for find() command in backupUsers() procedure
  74.   print "** files: ", files.join(", "),"\n" if $DEBUG
  75.  
  76.   files # return the file list
  77. end
  78.  
  79. def backupUsers(userlist,backupdir)
  80.   for user in userlist
  81.     mkdir("#{backupdir}/#{user}") unless $DEBUG
  82.     print "** mkdir #{backupdir}/#{user}","\n" if $DEBUG
  83.     cd(user) do # change directories in a block, at the end of the block, direcotry will go back to previous working directory
  84.  
  85.       files = getFileList()
  86.  
  87.       begin
  88.         `find #{files.join(" ")} -print | cpio -pdv #{backupdir}/#{user}` unless $DEBUG
  89.         print "** find:", files.join(", ")," | cpio: ", "#{backupdir}/#{user}","\n" if $DEBUG
  90.       rescue
  91.         warn "Error with backing up #{user}: #{$!}\nContinuing with next user."
  92.       end
  93.  
  94.     end
  95.  
  96.   end
  97. end
  98.  
  99. backupdir = getBackDir(Time.now)
  100. mkdir(backupdir)
  101.  
  102. cd("/Users") do # change directories in a block, at the end of the block, directory will go back to the previous working directory
  103.   userlist = getUserList("/Users")
  104.   backupUsers(userlist,backupdir)
  105. end

Coding Practice

I am a software engineer by training and by temperament. I love working with computers, getting them to do all sorts of silly things. Having been without work for awhile, however, sort of stifles my creativity in terms of what to do about programming. In reading “My Job Went to India: 52 Ways to Save Your Job”, Chad Fowler recommends coding practice and points to the Pragmatic Programming weblog as a place where there are Kata, or exercises, available to help keep your programming skills honed.

I’ll be doing these and posting about them here, including links to the code. I’m currently learning Ruby, so that will be my primary language of development, at least for the time being.