code

You are currently browsing the archive for the code category.

Recently posted to the wiki, a jQuery example of how to do pop-ups:

TamWiki Main/Great Example Of A Pop Up Meta Link.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter

Tags: ,

Web site done.

I finished the web site I have been working on with a little help in figuring out the style sheet and putting some of those fancy-shmancy rounded corners on things. Oh so trendy!! Anyway, I’m glad I got it done, it was touch-and-go for awhile.

(more after the break…)

Read the rest of this entry »

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter

Tags: ,

wordpress

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.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter

Tags: , ,

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: http://tamaratemple.com/pub/ruby/svnizerails.rb. (It’s a little more complicated than it seems; hence the script.)

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter

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)
[code lang="ruby"]

  1. !/usr/bin/env ruby
  2. Created by Tamara Temple on 2007-03-16.
  3. Copyright (c) 2007. All rights reserved.

require 'FileUtils'
include FileUtils::Verbose

LIBRARY_DIRS =

["./Library/Application Support",
"./Library/Keychains",
",/Library/Mail",
"./Library/Mozilla",
"./Library/Preferences",
"./Library/Safari",
"./Library/StickiesDatabase",
"./Library/Workflows"]

def getBackDir(timestamp)

prefix = "/Volumes/BootBackup/Users"
suffix = timestamp.strftime("%Y%m%d.%H%M%S")
backupdir = prefix + suffix
print "** backupdir: ", backupdir, "\n" if $DEBUG
backupdir

end

def getUserList(parentdir)

userlist = Dir.entries(parentdir)

if (!userlist.kind_of?(Array)) then raise "Internal Error: Dir.entries did not return an array." end

userlist.delete(".") # remove the working directory from the list (this will not affect

  1. the directory on the disk)
userlist.delete("..") # remove the parent directory from the list
userlist.delete(".localized") # remove an extraneous file from the /Users directory
print "** userlist: ", userlist.join(", "),"\n" if $DEBUG
userlist # return the userlist

end

def getFileList()

files = Dir.entries('.')

if (!files.kind_of?(Array)) then raise "Internal Error: Dir.entries did not return an array." end

files.delete(".") # remove the reference to the directory itself. (note this will

  1. not remove the directory - files is an array not the directory)
files.delete("..") # remove the parent directory listing
files.delete(".Trash") # don't backup the trash
files.delete("Library") # remove the Library directory as we don't want it all in
  1. the backup
print "** files: ", files.join(", "),"\n" if $DEBUG

begin

libdirs = Dir.entries("./Library")

rescue Errno::ENOENT

libdirs = []

ensure

if (!libdirs.kind_of?(Array)) then raise "Internal Error: Dir.entries did not return an array." end

end

  1. Remove extraneous entries
libdirs.delete(".")
libdirs.delete("..")
libdirs.delete(".localized")
libdirs.map! {|l| "./Library/" + l} # Need to add in the path to the
  1. Library subdirectories
print "** libdirs: ", libdirs.join(", "),"\n" if $DEBUG
libdirs = libdirs & LIBRARY_DIRS # get the intersection of library
  1. directories with the set we want
  2. to keep in backup

files = files + libdirs
files.map! {|f| "'#{f}'"} # need to quote file names for find() command
  1. in backupUsers() procedure
print "** files: ", files.join(", "),"\n" if $DEBUG

files # return the file list

end

def backupUsers(userlist,backupdir)

for user in userlist

mkdir("#{backupdir}/#{user}") unless $DEBUG
print "** mkdir #{backupdir}/#{user}","\n" if $DEBUG

cd(user) do # change directories in a block, at the end of the block, direcotry will go back to previous working directoryfiles = getFileList()

begin

`find #{files.join(" ")} -print | cpio -pdv #{backupdir}/#{user}` unless $DEBUG
print "** find:", files.join(", ")," | cpio: ", "#{backupdir}/#{user}","\n" if $DEBUG

rescue

warn "Error with backing up #{user}: #{$!}\nContinuing with next user."

end

end

end

end

backupdir = getBackDir(Time.now)
mkdir(backupdir)

cd("/Users") do # change directories in a block, at the end of the block,

  1. directory will go back to the previous working directory

userlist = getUserList("/Users")
backupUsers(userlist,backupdir)

end

[/code]

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter