David Janes' Code Weblog

February 26, 2012

iTunes & Missing Files

macintosh,tips · admin · 2:45 pm ·

If you’re like me and keep your iTunes files on external disks, you’ll occasionally end up in a situation where the external disk is not available and iTunes ends up marking all your files with an “exclamation mark”, indicating they’re not available.

To have to do to fix this is hold CTRL+ALT when starting iTunes and it’ll re-figure everything out.

Hat tip.

December 22, 2010

Installing Drupal on a Macbook Air

drupal,macintosh · David Janes · 1:58 pm ·

This documents how I installed Drupal on a brand new Macbook Air running Snow Leopard 10.6.5.

Web/Desktop/Shell: Install MySQL

  • Go here (“Mysql Community Server”) and download the 64 bit version
  • Double click on the DMG and Install
  • Drag the .PREF file in the DMG to the System Preferences

Note – I’m still having trouble starting MySQL from the command line. Right now I’m doing:

  • cd /usr/local/mysql/bin
  • nohup ./mysqld_safe &
  • disown %1

If you have advice, I’d appreciate it.

Web/Shell: Install Drupal

  • Download Drupal
  • Untar Drupal in ~/Sites/
  • In Apple > System Preferences > Sharing, select Web Sharing
  • In your browser go to http://localhost/~USERNAME/drupal-6.20/

In case it’s not clear what happened here:

  • Snow Leopard has an Apache Server built in
  • each user account gets it’s HTTP files in ~/Sites/
  • you turn on Apache by turning on Web Sharing
  • you browse by going to ~USERNAME/

You’ll notice at this stage we’re just seeing a directory listing, or if you’re a little more ambitious and click on “index.php”, PHP code. If you’re actually seeing a Drupal setup page, skip the next section.

Shell: Setup PHP

This is just following the excellent instructions from here.

  • sudo vim /etc/apache2/httpd.conf
  • uncomment LoadModule php5_module
  • bash (to start a subshell)
  • cd /etc
  • sudo cp php.ini.default php.ini
  • sudo chmod 666 php.ini
  • sudo vi /etc/php.ini
  • search for ;date.timezone
  • uncomment and change to:
    date.timezone=America/Toronto
  • restart apache: sudo apachectl restart
  • end the subshell: exit

Note – if you see the error “/usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument“, follow the instructions here:

  • sudo vim /usr/sbin/apachectl
  • comment out ULIMIT_MAX_FILES at line 64

Local Web/Shell: Set up Drupal

  • go to the webpage install.php (on the URL figured out way above)
  • click on Install Drupal in English
  • if you get an error message about default.settings.php
    • cd ~/Sites/drupal-6.20/sites/default
    • cp default.settings.php settings.php
    • chmod a+w settings.php
  • if you get an error message about sites/defaults/files
    • cd ~/Sites/drupal-6.20/sites/default
    • mkdir files
    • chmod 777 files

At this point you should be brought to a “Database Configuration Page” and we have to leave the browser and go back to the command line.

Shell: MySQL Database Configuration

These instructions create a MySQL database called “drupal_db” with access by “drupal_user” using the password “drupal_password“.

  • /usr/local/mysql/bin/mysql -u root
    • create database drupal_db;
    • grant all privileges ON drupal_db.* TO "drupal_user"@"localhost" identified by "drupal_password";
    • grant all privileges ON drupal_db.* TO "drupal_user"@"127.0.0.1" identified by "drupal_password";
    • flush privileges;
    • exit;

Local Web: Enter MySQL information into Drupal

Back in the browser you should be on the Drupal Database Configuration page. Enter drupal_db, drupal_user and drupal_password (the values you created in the previous step)

Submit the form. If you get the following error message:

Failed to connect to your MySQL database server. MySQL reports the following message: No such file or directory.

Make sure you typed everything correctly. If necessary, click on Advanced Options and change the hostname from localhost to 127.0.0.1.

Local Web: Configure Site page for Drupal

  • Site Information:
    • Site Name: localhost (why not)
    • Site e-mail address: your@email.com
  • Administrator account:
    • Username: admin (why not)
    • E-mail address: your@email.com
    • Password:/Confirm password: your-favorite-password

Local Web: Drupal installation complete

After you hit submit, you should be finished installing Drupal, except for the next little cleanup step.

Shell: Clean up files

Drupal doesn’t like you leaving settings.php alterable by the web server around:

  • cd ~/Sites/drupal-6.20/sites/default
  • chmod go-w settings.php

The directory files must be left writable.

November 20, 2009

How to use XCode for Android Projects

android,code fragments,ideas,macintosh · David Janes · 6:07 pm ·

Let’s assume you already have an Android project on your Mac.

Create the XCode Project

  • start XCode
  • select File > New Project…
  • select External Build System
  • go to the parent directory of your Android Project
  • in the Save As: field, enter the directory name of your Android Project
  • select the scarily-misnamed Replace option [not in XCode 4 -- thanks Jusin]

Add Files

In your new XCode project:

  • select first item in the left hand column, which is the name of your project
  • right-click, select Add > Existing Files…
  • select add files (don’t select the Copy option)
  • organize as desired (I like to do a lot of grouping). You should be probably adding at least your Java files and your Layout resources.

Configure your Build Target

In your new XCode project:

  • look for Targets
  • inside will be a target for your project’s name
  • double click on it
    • change Build Tool to ant
    • change Arguments to install

Clicking ⌘B should now compile your project.

Note: if you figure out how to have a Build vs. Build & Install (e.g. ⌘ENTER) please let me know!.

Getting XCode to Recognize Java errors

  • Reconfigure the Build Target, changing ant to ./xant
  • Make a file xant in the project’s home directory, using the code below
  • do (from a Terminal) chmod a+x xant
#!/usr/bin/env python

import sys
import re
import subprocess

av = list(sys.argv)
av[0] = "ant"

p = subprocess.Popen(av, stdout = subprocess.PIPE)

javac_rex = re.compile(" +[[]javac[]] +")
line_rex = re.compile("[.]java:[\d]+:")

pending = ""
while True:
    d = p.stdout.read(128)
    if not d:
        break

    d = pending + d

    nx = d.rfind('\n')
    if nx == -1:
        pending = d
        continue
    else:
        d, pending = d[:nx + 1], d[nx + 1:]

        d = javac_rex.sub("", d)
        d = line_rex.sub(r"\g error: ", d)
        sys.stdout.write(d)
        sys.stdout.flush()

sys.stdout.write(pending)
p.wait()
sys.exit(p.returncode)

Note: this code has been updated from the original post. It now reads little chunks and outputs them immediately rather than post-processing the ant output.

November 16, 2009

PIL, libjpeg, jpeg and Mac OS/X Snow Leopard

macintosh,python,tips · David Janes · 7:47 am ·

If you want to the use the Python Imaging Library on Mac OS/X Snow Leopard, these instructions appear to be the best way to to get libjpeg installed:

1. Download the source from http://libjpeg.sourceforge.net/

2. Extract, configure, make:

tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
cp /usr/share/libtool/config/config.sub .
cp /usr/share/libtool/config/config.guess .
./configure --enable-shared --enable-static
make

3. You may need to create the following directories:

sudo mkdir -p /usr/local/include
sudo mkdir -p /usr/local/lib
sudo mkdir -p /usr/local/man/man1

4. Now you can install it as usual.

sudo make install

I used to use Fink on Leopard, but it didn’t seem to work to well this time. If you’ve previously made an attempt at installing PIL, make sure to rm -rf build.

December 23, 2008

Interact with applications from the command line on the Mac

macintosh,tips · David Janes · 6:50 am ·

I’m a command line guy – I spend 90% of my non-blog reading day in Terminal, working on Python apps on my Mac or SSHed into work and working on Java and Javascript applications. I do realize the benefit of “real” applications, for image editing, for advanced text processing and so forth. On the Mac you can send files to the default application easily:

open "Madeline Doll House.jpg"

(Don’t ask). If the Mac doesn’t know how to deal with the file type, or you want to specify a particular app, that’s cool too:

open -a smultron index.jd

Note that it doesn’t matter that I’m SSHed into a work computer – we got around that issue last week using MacFUSE.

December 11, 2008

Mount NTFS and remote filesystems using MacFUSE

macintosh,tips · David Janes · 11:56 am ·

MacFUSEEarlier this week I bought a LaCie 500Gb USB drive so I could bring VMWare images between work and home. When I went to copy the image, the copy failed with no meaningful error message (Error 0, I believe). Trying the copy on the command line was a little more informative: as it turns out, the LaCie drive ships with a FAT-32 file system which can only handle files up to 4Gb in size. As the image I was trying to copy had a 8Gb file in it, this was a no go.

My initial thought was to use the UNIX commands tar and split to break the files into individual smaller chunks, but this is hardly a satisfactory answer. If I formatted the drive to the Mac filesystem, the Windows machines would not be able to read it at all. If I formatted the drive the “new” NTFS filesystem, Windows can read and write just fine but the Macintosh wouldn’t be able to write to it.

Fortunately, there’s an excellent install for the Mac called MacFUSE that allows access to all sorts of filesystem types not natively supported by the Macintosh, include NTFS. Here’s how I set up MacFUSE.

MacFUSE Installation

Installation by itself does nothing except set you up for the next stage: installing drivers for particular file systems.

NTFS

You have to search through the documentation for a bit to figure out where to get NTFS to with Windows filesystems. It actually turns out to be rather easy:

You can now write to NTFS drives. It’s a little slow – it’s taking me about 2 hours to copy 8Gb to the La Cie drive, but that’s better than not being able to do it at all. You wouldn’t want to work live off the drive however, and it may be worth investigating commercial NTFS compatibility applications if you need to do this.

To reformat your La Cie drive plotline, use Applications > Disk Utility to erase and install an empty NTFS file system.

SSHFS

SSHFS lets you see remote filesystems through SSH.

  • go to http://code.google.com/p/macfuse/wiki/MACFUSE_FS_SSHFS
  • download the version appropriate to your Mac; you can store this in your home directory or if you’re a little more organized about your path, a directory link ~/bin
  • make a mount point – this is just a directory on your Mac that is needed by MacFUSE; it can be hidden as Mac OS will show you the mounted drive on your desktop and in /Volumes. For example, on the command line run mkdir -p ~/.Volumes/Remote.
  • run the mount command; you’ll be prompted for your remote system password

You’ll see the drive appearing on your desktop. I’ve actually created a shell alias to do the mounting for me called “mount-xxx”. If you don’t know how to do this, it’s probably too much to go into right now.

The nice thing about SSHFS is that I could see being able to run an entire Mac desktop development shop with all the backend computing running Linux, all being accessed nicely through SSHFS.

Powered by WordPress

Switch to our mobile site