Libby Hemphill research and posts on social media, collaboration, and related technologies

18Oct/090

Ruby on Rails on Snow Leopard

I finally tackled the (hopefully) last bit of my Snow Leopard upgrade today: getting Ruby (and Rails) ready to go. I'm working on an information visualization project and am using Ruby to write the app. Mike Gunderloy at A Fresh Cup has a great step by step guide (I started at step 19 since I was happy to upgrade in place):

Migrating to Snow Leopard for Rails Development

As always happens when upgrading or installing, it seems, I did run into a few problems.

Errors and Workarounds

Problem: Git doesn't want to install.

Error:

ld: warning: in /opt/local/lib/libiconv.dylib, file is not of required architecture

Workaround:

MacPorts is to blame. To uninstall MacPorts, use

sudo rm -rf \
/opt/local \
/etc/manpaths.d/macports \
/etc/paths.d/macports \
/Applications/DarwinPorts \
/Applications/MacPorts \
/Library/LaunchDaemons/org.macports.* \
/Library/Receipts/DarwinPorts*.pkg \
/Library/Receipts/MacPorts*.pkg \
/Library/StartupItems/DarwinPortsStartup \
/Library/Tcl/darwinports1.0 \
/Library/Tcl/macports1.0

(Thanks, Simon Engledew)

Problem: MySQL gem doesn't install.

Error:

ERROR: Failed to build gem native extension mysql

Workaround:

Make sure you installed the latest version of MySQL, the MySQL Preference Pane, and that you started the MySQL server before trying to install the gem. iCoreTech has directions for installing MySQL and MySQL gem on Snow Leopard.

Other Options

HiveLogic has another method for installing Git on Snow Leopoard. I was having trouble with the package installers, and doing it "by hand" via HiveLogic's instructions worked well.

My project uses RMagick. RMagick's DMG installer wouldn't work for me either. I was able to install RMagick from source using a script from OnRails.org.

Filed under: Code, OS X No Comments
26Jun/090

Get Upgraded SVN Working on a Mac OS X Server

Jeremy Whitlock has a great blog post about how to set up your OS X-based Subversion server. His post includes instructions for Apache configs, but not for svn+ssh. When you type

svn+ssh://user@host/repos

you'll likely get an error such as

svn: Expected FS format '2'; found format '4'

which means that you're repository was created in a newer version of SVN than the version you run when you call svn+ssh. Using Jeremy's instructions results in two versions of Subversion being available on your server - one in /usr/local and one in /opt/subversion. In order to use the one in /opt/subversion (the newest one) through an SSH tunnel, you need to make some SSH configuration changes on your server.

Getting svn+ssh to work requires:
1. Set (or uncomment) PermitUserEnvironment Yes in /etc/sshd_config (on server)
2. Add PATH=/opt/subversion/bin:$PATH to ~/.ssh/environment (on server; may have to create the environment file)
3. restart SSH (on server) with sudo /sbin/service ssh stop and sudo /sbin/service ssh start
Ta da!

Thanks for the jumpstart, Jeremy!

Filed under: Code, OS X, Technology No Comments
14Mar/096

JavaScript date checking

Sometimes we ask users to enter a date range. I wrote some code today to check whether the date a user entered was (1) after today and (2) before some other date she entered. In my situation, I was building a flight search form and wanted to check that the user-entered departure date was before the user-entered return date and that the user wasn't trying to depart in the past. To do this, I needed to turn the user's input into a JavaScript Date and then compare that Date to Today's date. I found a lot of similar code online, but none of it work quite right.

I have a form with text box inputs for dateDepart and dateReturn. This code takes those inputs, turns them in JavaScript dates, compares them to each other and to today, and returns alerts or submits the form, depending on how the comparisons shake out.

Here's my code:

// check to make sure Return date is after Departure date, and both are after today
if ( (the_form.dateDepart.value !="") && (the_form.dateReturn.value !="") )
{
	var strFromDate = the_form.dateDepart.value;
	var dayPartFromDate = parseInt(strFromDate.substring(3,5),10);
	var monPartFromDate = parseInt(strFromDate.substring(0,2),10);
	var yearPartFromDate = parseInt(strFromDate.substring(6,10),10);
	var dtDepart = new Date(yearPartFromDate, monPartFromDate-1, dayPartFromDate);

	var strToDate = the_form.dateReturn.value;
	var dayPartToDate = parseInt(strToDate.substring(3,5),10);
	var monPartToDate = parseInt(strToDate.substring(0,2),10);
	var yearPartToDate = parseInt(strToDate.substring(6,10),10);
	var dtReturn = new Date(yearPartToDate, monPartToDate-1, dayPartToDate);
	var now = new Date();
	var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());	

	if(dtDepart > dtReturn)
	{
		alert('Departure date must be before return date. Please fix and resubmit.');
		return false;
	}
	else if (dtDepart < today)
	{
		alert('Departure date must be after today. Please fix and resubmit.');
		return false;
	}
	else
	{
		the_form.submit();
	}
}

Turn User Input into a JavaScript Date
To turn the user's input into a Date, I needed to parse the input and then pass the pieces to the Date() function.

The JavaScript substr function syntax I used corresponds to dateToChange.substring(start,finish). My users are mostly in the U.S., and they enter dates in the form MM/DD/YYYY, e.g., 03/14/2009. JavaScript starts counting at 0, so the substr functions above grab "14" for the day, "03" for the month, and "2009" for the year and then pass those substrings to the Date()function to be converted in a Date JavaScript understands.

getFullYear(); returns a four-digit year such as "2009" that makes it easy to compare to the default version of today's date that
var now = new Date();
var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());

gives.

Why monPartToDate-1? Remember, JavaScript starts counting at 0, so January is month 0, and December is month 11. That means I need to subtract 1 from what my user entered to get the right month for JavaScript.

Compare Dates
I needed to compare the two dates the user entered to make sure she had departure first, then return. Once I have converted both her inputs to JavaScript dates, the comparison uses a simple "greater than" operator: dtDepart &gt; dtReturn

Calling the Date-checking Function
You'll notice my code doesn't include a function declaration; that's because this date-checking procedure is part of a larger function to validate my form. You could wrap this code in a function declaration such as
function checkDates(the_form){}

In order to call the code when the user submits the form, I like to use something like

<input id="search" onclick="checkDates(this.form);" type="button" value="Submit Form" />

in the HTML.

6Aug/084

Technology I could use

Here are two things I want that I don't have the time (or probably the skills) the code:

1. A flight search engine that searches flights from multiple destinations to one.  I want to use this when planning trips with my family and friends.  We don't all live in the same place.  We'd like to get together.  This seems like a pretty common task (e.g. national holidays, girls' weekend, bachelor parties, etc.).  I shouldn't have to search each person's flight independently and then hope that the one around the time of everyone else's doesn't sell out or go up in price before I find flights for everyone.  I'm pretty sure Kayak's API could do this, but I don't have time to figure it out.

2. Movies starting near me in the next couple of hours with the added bonus of web ticket sales.  This seems like an iPhone app that should already exist.  I can't even find this on the web though.  Does movietickets.com or some other site let me search by zip code and time?

Anybody know where I can find these or want to build them for me for free?  Sweet.

Filed under: Code, Technology 4 Comments
27Jul/080

Moving Data

A couple months ago someone hacked into a perfectly innocent server some friends and I use for things like storing backups of our dissertations and running Perl scripts. I was in Seattle when this happened so couldn't be much help in the recovery process. The helpful people at SI Computing recovered all the data from the server and put in on another server ("SIC") for me to access. My job was to move all the data from SIC to a third place so that SI Computing could have their Projects space back. I haven't ever had to remotely administer such a data transfer task. So, I had to learn a few new UNIX commands. Here's how I was able to move 57GB of data from the "SIC" server to the "Hosted" server. I used "screen" and "scp" commands to securely copy my data without requiring a Terminal window to stay open for the 36 hours it took the data transfer to complete. The most helpful websites I could find for those are

screen: http://jmcpherson.org/screen.html
scp: http://kb.iu.edu/data/agye.html

1. ssh libbyh@sic.edu
2. screen
3. scp MyData libbyh@hosted.com:MyData
4. Ctrl+A, d
5. exit

That should do it. You can check in on the data transfer by typing this at the prompt:
screen -r
Hopefully your next big data migration will go as smoothly as mine did.

Filed under: Code, Links, Technology No Comments
26Mar/080

TeX tip: Storing files in multiple folders

See, here's a TeX tip already. I have a somewhat strange filing system on my computer. It's marked by a number of behaviors that don't work smoothly with TeX - storing images in their own folder, keeping one giant references file instead of different ones for each paper, putting the main tex file in a folder by project rather than file type. So, this means that for any given TeX file, the .cls file that formats it, the references file where it's bibliography is stored, and the .tex file itself will be in 3 different folders. TeX doesn't like that. It's not easy to reference or include files in other folders within one's TeX document. So, I make symlinks for the files that live elsewhere. Symlinks are possible only on Mac (not Windows), and you can create them in Terminal. So, fire it up and navigate to the folder where your .tex file lives. Then use

ln -s [directory_with_file_you_want_to_include]/filename .

Note that space and period at the end. Those are important; they create the symlink instead of an alias. LaTeX actually doesn't care if you use an Alias instead of a symlink, but Subversion does. If you're using Subversion for version control (say you're writing a paper in LaTeX with your colleagues), Subversion will follow symlinks and update your project accordingly.

For example, I'm writing a CSCW paper with Sean and Jude that uses my "references.bib" file. That file is stored in "/Documents/endnote files/references.bib". I have a symlink in "/Documents/ResearchProjects/KNOWSI/CSCW 2008" for the references.bib file, and when I add citations, Subversion knows to grab the real file and commit that to our Subversion project. Cool, huh?

More about Subversion. Note: I recommend TortoiseSVN on PC for managing Subversion projects. I'm still hunting for a good Mac GUI (good = one that works!) I've tried Finder scripts, svnX, and RapidSVN with no success.

26Mar/080

Saving money, writing in TeX

I've switched many of my writing tasks to TeX, and it's time I talked about that decision. I wrote a paper for a class last term in TeX, and I think that was the official beginning. Well, I guess I'd tried and failed to write a paper in TeX before, so my paper for Curtis LeBaron's class was my first success. EndNote and Office 2008 for the Mac don't get along yet, so TeX has a couple months to cement itself as my paper-writing environment of choice.

Some of you may have no idea what I'm talking about. For you, I recommend Wikipedia and CTAN: WHat are TeX, LaTeX, and Friends? Basically, TeX lets me write papers without having to format them at the same time. It uses tags to give formatting directions, then I run some command business, and wala, a PDF appears! I'm using it instead of Word because Word makes me angry when I'm trying to write papers for ACM conferences (e.g. GROUP, CSCW) with figures and/or tables. I'm also afraid of using Word for my dissertation because the rules about formatting are super-strict, and I bet Word could screw it up. TeX and the software I need to do my writing are also FREE. 100% FREE. The latest and greatest reason for me to use TeX, though, is that TeX + BibTeX works and Word 2008 + EndNote doesn't. Putting references into a paper by hand is not an option. My dissertation proposal is only 19 pages long, and 2 of those pages are a single-spaced citation list. Sean, Jude, and I are working on a paper for CSCW that has 9 references, and each reference appears in the text a couple of times. You can see that I'm not going to be able to keep track of all those citations myself, let alone switch between citation styles (e.g. between APA 5th and ACM proceedings).

So, TeX + BibTeX beat out Word 2008 + EndNote. How do I do it? I'm also using Windows occasionally now, and because TeX documents are plain text, they couldn't care less which OS I'm using. If you're somewhat comfortable with markup (e.g. HTML, XML), TeX may be a good option for you. Even with the student discount, Office 2008 is $50, and EndNote will probably be $90 again when they have a version that works with Office 2008 - likely summer 2008. Save yourself the $140 and give TeX a shot.

I use TeXShop and BibDesk on the Mac (available in the MacTeX package), and I wouldn't recommend other software. I tried iMacTeX or some such thing, and it was awful. TeXShop has a bunch of built-in AppleScripts that are helpful including Bibliography which automatically does the latex-bibtex-latex-latex order that you need to run in order to get a PDF with a properly formatted reference section. If you miss Bibliography in the dropdown list, you'll change the color scheme of your TeXShop windows, and there's no menu for resetting them. Instead, to change the background color of your source window, get the RGB values of the color you'd like, open up Terminal and use these commands (where XX = the appropriate R, G, or B value):

defaults write TeXShop background_R 0.XX
defaults write TeXShop background_G 0.XX
defaults write TeXShop background_B 0.XX

Similarly, you can change the colors of the text and the insertion point using foreground_R, insertionpoint_R and the like.

Now that I'm humming along on my dissertation and a couple of papers for CSCW, I'll probably be posting TeX tips. I get stuck a lot, and you probably will too when you get started.

28Jan/0811

Swapping MacBook hard drives, including Boot Camp partition

Sigh. I use Parallels and Boot Camp because I like having options. Unfortunately, wanting options means that my life is quite complicated. Today's problem: swap out the failing hard drive in my MacBook for a new one without losing any of my Mac OS or Windows XP data. Well, it's actually this month's problem, but whatever. Judging by the amount of search results I get when looking for help online, lots of people want to move their Boot Camp partition to a new drive or to back it up. This should solve both those problems. Here's my setup:

  • MacBook 2.0 GHz Core Duo
  • 160GB internal drive (brand new; Leopard cloned my Mac OS disk partition from the old drive to the new one)
    • 145GB Mac OS X partition (running fine)
    • 15GB Boot Camp partition (formatted FAT32 by Boot Camp Assistant; empty)
  • 160GB external drive (used to be internal, now in a case and attached via USB)
    • 130GB Mac OS X partition
    • 30GB Boot Camp partition (formatted FAT32 by BCA; runs fine)
  • Parallels 3.0
  • Winclone
  • Windows XP SP2

And here's what I did:

Convert the external drive's Windows partition from FAT32 to NTFS:

  1. On the external Windows drive, go to Start - Run - and type cmd to get the command line
  2. At the prompt type convert c: /fs:ntfs where "c:" is the drive you want to convert to NTFS
  3. Answer "No" to the first question - forcefully unmount the drive
  4. Answer "Yes" to the second question - convert on restart
  5. Restart your drive

I did all of that using Parallels so I could work on other stuff at the same time. When you restart, diskcheck will run a few times to convert the drive, and then it will restart in NTFS.

Once you've successfully converted your Windows drive to NTFS, you can clone it using Winclone. Winclone's site has good instructions, but here they are just in case:

  1. Make an image of the Windows partition you want to clone
  2. Store that image on your internal Mac OS partition (where you have Winclone installed)
  3. Restore the Winclone image to the empty Boot Camp partition

Questions
1. Why convert from FAT32 to NTFS?
I tried a number of ways of migrating my FAT32 drive (dd, Acronis True Image), and they all failed. Winclone works for NTFS drives and is a snap.

2. Won't converting from FAT32 to NTFS mean I can't write from my Mac to my Boot Camp drive or cause other problems?
Nope. The conversion happens without harming your data, so that's not a problem. As far as writing from Mac OS to NTFS, you can do so through Parallels. That's good enough for me, and NTFS adds protections and features that FAT32 can't offer. See Microsoft's site for more information about FAT32 vs. NTFS

3. How long does this take?
About two and a half hours from start to finish (18GB partition)

4. Winclone warned me about something happening to my partition; what should I do?
Winclone's just making sure you know that if you disconnect any of the partitions it's using while it's working, bad things will happen. As long as you leave everything connected while Winclone runs, you'll be fine.

5. Winclone thinks my Windows drive is FAT32, but I converted it to NTFS. What do I do?
Restart Winclone or click "Refresh" next to the Source drop down in the Backup tab. It should recognize your drive as NTFS then.

6. Will this work with Vista?
I have no idea. I bet, but I don't use Vista so can't be sure.

7. Where can I get a good deal on an external hard drive?
Try Amazon!

17Jan/081

Cloning my Boot Camp partition to a new hard drive

UPDATE: See my other cloning post for alternative instructions that don't require UNIX commands; it's easier, faster, and less likely to fail.

My MacBook needed a new hard drive. Leopard was quite helpful in moving all my old Mac OS information from the old drive to the new one, but it won't move my Boot Camp partition. I backed up my data, swapped my hard drives, and stuck my old hard drive in an external USB case. The instructions that follow assume that you have both your old and new drives connected, but they should work whether you've already physically swapped your drives or not. If you formatted your BootCamp partition NTFS, you can try using WinClone instead. Mine's FAT32, so that didn't work for me.

MAKE SURE YOU HAVE ALL YOUR DATA BACKED UP. THESE DIRECTIONS ARE OFFERED WITHOUT GUARANTEE OR WARRANTY OR ANY OTHER KIND OF "TY". THIS MAY NOT WORK FOR YOU. YOU CAN'T BLAME ME IF IT DOESN'T.  THIS ALTERNATIVE METHOD WORKS BETTER

So, here's what I did to clone my Boot Camp partition to a new drive, partition, whatever.

  1. Create a new partition on my new drive (I used Boot Camp Assistant)
  2. Open Disk Utility and get the Disk Identifier for my old Boot Camp partition and my new one
  3. Use Disk Utility to Unmount both the old Boot Camp partition and the new one
  4. Open Terminal and get ready for some UNIX fanciness
  5. Use "dd" to clone my old Boot Camp partition to my new one with the following command

    sudo dd if=/dev/disk1s3 of=/dev/disk0s3 bs=1mwhere

    disk1s3 = the Disk Identifier for my old drive
    disk0s3 = the Disk Identifier for my new drive
    bs=1m = tells dd to use bigger chunks so it clones faster

Common errors
"dd: /dev/disk1s3: Resource busy" - you didn't Unmount that partition properly
"dd: /dev/disk0s3: Permission denied" - you're not using sudo and don't have permissions to write the new partition
"dd: bs: illegal numeric value" - you may have typed "bs=1M" when you meant "bs=1m"; just doublecheck it

dd used 12-14% of my CPU while it was working, so I barely noticed.

UPDATE: You may find that using these instructions gets all your data moved but that your partition still isn't bootable. I'm working on a fix and will post when I have it. Use this method instead