Skip to content


Import mySQL dump – os x terminal

To import a dumped mySQL database (.sql file), first create a new database to import into:

mysql -u[username] -p -e "create database [databasename];"

You will be asked for you password (alternatively, you can include it in the command – just change -p to -p[password]).

Now that you have a database to import into, navigate to the directory that your .sql file is in and then:

mysql -u[username] -p [databasename] < [.sql filename]

Again, you'll be asked for your password, and then the .sql file will be executed, pointing at your database. In a few moments/minutes, depending on how large the .sql file is, you will have a populated database.

Posted in Almost Random.


Set up Drupal on OS X, natively

The OS X installation instructions at Drupal.org will have you install MAMP, which is maybe a little weird, since Apache and PHP are pre-installed with OS X.

Also a little weird is that there are not a lot of resources available for setting up a Drupal installation without going the recommended MAMP route. However, Vesa Palmu put up a very thorough walkthrough at http://mearra.com/blogs/vesa-palmu/how-setup-mac-os-x-106-drupal-environment.

I had a few small problems with Vesa’s instructions, almost entirely due to me not knowing enough about what I was doing. All in all, I think it’s a great resource. If you are already fairly experienced with configuring Apache and MySQL on your machine, you may not need any of the information below.

Note that this information is just a set of notes and may have some holes in it… Please drop me a line in the comments if you have any corrections or additions.

Vesa’s post is organized into a couple of headers, and my notes follow those headers. I recommend reading my post and Vesa’s all the way through before doing anything, by the way (hindsight).

System setup

In the System setup section, I discovered while trying to install Drupal that I had to export the mysql path to ~/.bash_profile, as well as to ~/.profile.

Also, during Drupal installation I found I had to manually change references to /var/mysql/mysql.sock (change them to /tmp/mysql.sock) – so the instructions for linking these files may not be relevant – but it doesn’t hurt anything, as far as I can tell.

Configuring Apache

The only part of the instructions that gave me any trouble was the section on setting up virtual hosts. Virtual hosts (in this context) are a convenience and not at all necessary. The idea is that you will be able to type http://drupal to hit your Drupal installation, rather than something like http://localhost/~rosshenderson/drupal. However, this section of the instructions actually derailed me a bit, as it turns off normal usage of the Sites directory (http://localhost/~rosshenderson/site root).

For now, do not comment out the User home directories include in httpd.conf (Include /private/etc/apache2/extra/httpd-userdir.conf)

I’m not sure why this is part of the given instructions, but I think it has to do with the next set of steps, which involve setting up a series of virtual hosts. The virtual hosts are a convenience and not at all necessary. Since getting my installation running, I haven’t gone back and experimented further with virtual hosts, but I will try to do so in the near future. For now, just ignore all instructions that have to do with setting up virtual hosts, and put your Drupal installation in your Sites directory (i.e. unpackage the Drupal download in the Sites directory). I named my root Drupal folder ‘drupal’, and access it at http://localhost/~rosshenderson/drupal. Would be nice to be able to hit it at http://drupal, but we’ll see.

Ignoring the virtual hosts instructions includes:

1. Commenting in the Include /private/etc/apache2/extra/httpd-vhosts.conf
line in httpd.conf (leave it commented out).
2. All modifications to httpd-vhosts.conf.

Installing Drupal

Note that the terminal command provided for creating databases assumes that you have not set up a password for your root user via phpMyAdmin, or some other way. If you already have a password set up for your root user, change:

mysql -uroot -e “create database drupal6;create database drupal7;”

to:

mysql -uroot -p[your password] -e “create database drupal6;create database drupal7;”

Incidentally, you can actually just skip this step, since you have to do some work in phpMyAdmin as part of the Drupal installation instructions, anyway.

These minor modifications to the post got me to the point where I was ready to install Drupal.

Lastly, I unpackaged phpMyAdmin in my /Library/WebServer/Documents directory (so it is available at http://localhost/phpMyAdmin).

If you don’t have the mySQL panel installed in your Preferences Pane, you can start/stop/restart mySQL via the terminal like so:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart

(thanks to mloughran’s response to this question on StackOverflow)

Setting up Drupal

The Drupal installation guide is available at http://drupal.org/documentation/install.

Since you have already downloaded Drupal, go to Step 2: Create the database – even if you created a database while following the mearra instructions.

Next, move on to Step 3: The settings.php file. Not having worked with PHP for quite awhile, I got stuck here for a bit because the initial setup of phpMyAdmin allows a username of ‘root’ with no password, which is what I was using. I had to go into phpMyAdmin and change the password before I could get a working connection going.

Around line 93 of settings.php there is a line that should look something like this:

$db_url = ‘mysql://root:drupa1@localhost/umdrupaldb’;

Or, if you created a user called ‘myUser’ with a password of ‘myPassword, and a database called ‘myDrupalDb’:

$db_url = ‘mysql://myUser:myPassword@localhost/myDrupalDb’;

The format, given a few lines above, is: $db_url = ‘mysql://username:password@localhost/databasename’;

Finally, move on to Step 4: Run the installation script. Here’s where this document really pays off, if you are working with Drupal 6. First, you have to scroll down quite a ways to get to the Drupal 6 instructions.

Secondly, the instructions are wrong. DO NOT point your browser to the base URL of your Drupal site – point it at baseURL/install.php.

Posted in Almost Random.


Sencha/PhoneGap CSS import trickiness

One of my coworkers set up a Sencha/PhoneGap project, recently. Once the project was close to completion, he got it running on an iPad – except that it didn’t run on an iPad. Ran fine as a web app, and fine in the simulator.

The issue turned out to be that two of the css import links in index.html didn’t have closing slashes…

This will work fine when the project is run as a web app or in the simulator, but will kill the project when run on a device.
<link rel="stylesheet" href="resources/css/main.css" type="text/css">

This (correct syntax) prevents the bug.
<link rel="stylesheet" href="resources/css/main.css" type="text/css" />

Posted in Almost Random.


OS X: Add spacer to dock

Add a spacer to the apps side of the dock with:
defaults write com.apple.dock persistent-apps -array-add '{ "tile-type"="spacer-tile"; }’

Or, add a spacer to the right-hand side of the dock with:
defaults write com.apple.dock persistent-others -array-add '{tile-type=“spacer-tile”;}’

Then bounce the dock to affect changes with:
killall Dock

Here’s an example:

Posted in Almost Random.


Sneaky but great way to create multicolumn lists in Flash/Flex (and maybe HTML, too)

I’ve been working on and off on a website built in Flash, and recently received a client request to display a section of content in two bulleted lists, side by side, rather than in one long bulleted list.

The text content for this site is being rendered entirely via Flash’s basic HTML support, and a two-column list is definitely not an available option. It seemed like there were two possible approaches:

  1. Write a non-trivial amount of code to handle this (in which case the effort and cost would really be disproportionate to the end value)
  2. Realize that there is a way to generate the outcome of a two-column list without without writing any code

Luckily, I had a realization – which I normally don’t do…

Since Flash supports a reasonable range of HTML entity characters, I used the entities for tab stops, single spaces and bullets to create a multi-column list.

  • The HTML entity for a tab stop is &#09;
  • The HTML entity for a bullet is &#8226;
  • The HTML entity for a single space is &#32;

So, the if the xml driving a given unordered list looks like this:


<li>Oranges</li>
<li>Grapes</li>
<li>Apples</li>
<li>Plums</li>
<li>Lillies</li>
<li>Chrysanthemums</li>
<li>Daffodils</li>

You’ll get a list that looks like:

  • Oranges
  • Grapes
  • Apples
  • Plums
  • Lillies
  • Chrysanthemums
  • Daffodils

Add a couple of tab stops, a bullet, a few single spaces, and then another item, to each entry. The following example creates a two column list with the four fruits in a bulleted list on the left, and the three flowers in a bulleted list on the right.

Note that this is a VERY manual approach and requires you to set the necessary number of tabs – if you have a very long word in the first list, you’ll probably need to add an extra tab stop two.


<li>Oranges&#09;&#09;&#09;&#09;&#8226;&#32;&#32; Lillies</li>
<li>Grapes&#09;&#09;&#09;&#09;&#8226;&#32;&#32; Daffodils</li>
<li>Apples&#09;&#09;&#09;&#09;&#8226;&#32;&#32; Chrysanthemums</li>
<li>Plums</li>

You get a list that looks something like the following. However, at least in the context of this blog’s theme, the HTML doesn’t render so great. The tab stop entities are ignored, and the character used for the ‘bullet’ for unordered lists is different than the bullet defined by &#8226;. It works great with Flash – I’m not much of an HTML/CSS/JS developer, but it seems that if you can get tab stops to render (or just put in four single spaces for each tab stop…), you’d just need to make sure the character you use for the second (or third, fourth, …) bullet matched the bullet used for unordered list items.

  • Oranges • Lillies
  • Grapes • Daffodils
  • Apples • Chrysanthemums
  • Plums

Obviously, there are preferable ways of handling this in both HTML and Flash/Flex. But if you have just an incidental need for a multi-column list, this gets the job done pretty well. It’s a string mess, and has no layout smarts, but for certain situations, it’s really handy.

Posted in Almost Random.


Where is my JAVA_HOME (OS X)

Was setting up a project this morning and needed to copy some files into my JAVA_HOME directory. Didn’t know where that was. I found a quick terminal command to find it at ha.ki, but when I ran the command I got:

$ /usr/libexec/java_home
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

instead of:

$ /usr/libexec/java_home
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home

No big deal – the location of JAVA_HOME on my machine shouldn’t necessarily be the same as on someone else’s. But, when I tried to browse to my location in Finder, I couldn’t get there – because 1.6.0.jdk isn’t a directory…

So, I browsed to the the location indicated by the Ha.ki post and found that …/Versions/1.6.0 was a symlink to …/1.6.0.jdk, or something inside of the 1.6.0.jdk package. Since …/Versions/1.6.0 contains a directory called ‘Home’, I am thinking that it is my JAVA_HOME directory. However, the ‘Home’ directory is actually the ‘jre’ directory.

That is if I need to put, say a security policy file in JAVA_HOME/jre/lib/security, I’ll put it in …/Versions/1.6.0/Home/lib/security.

I also noticed a directory next to …/Versions/1.6.0 called CurrentJDK, which was also a symlink to …/1.6.0.jdk. There is a …/Versions/1.6 directory, which symlinks to …/1.6.0.jdk as well.

Posted in Almost Random.


ListCollectionView/ArrayCollection tip for using GraniteDS

I’ve been kind of baffled by the use of the ListCollectionView object in GraniteDS. I just learned something that helps a lot.

In our app we have an object called Organization, which has a list of OrganizationLicense objects. The list is called ‘licenses’, and is typed as ListCollectionView.

Initially, Organization objects have been created on the server. However, we recently built functionality for creating new Organization objects via the UI. I ran into a problem when populating the ‘licenses’ list – though. If I just left it as null, there were no problems, but if I added an item (or more than one item), I would get a channel failure error from Granite when I tried to submit the new Organization.

The Tomcat log said that Granite was unable to convert the ListCollectionView to a Set.

Running through posts on similar problems, I saw a comment that said to type the collection as an ArrayCollection.

So, instead of this:

var organization:Organization = new Organization();
organization.licenses = new ListCollectionView(); // or new ListCollectionView(new ArrayCollection());
organization.licenses.addItem(new OrgLicense()); // or organization.licenses.list.addItem(new OrgLicense())

do this:

var organization:Organization = new Organization();
organization.licenses = new ArrayCollection();
organization.licenses(new OrgLicense());

That works. I’m not really sure what the deal is, and haven’t spent much time working it out – but it works to instantiate a new ArrayCollection where a ListViewCollection is expected.

Posted in Almost Random.


GraniteDS – deserialize ActionScript object to a Java Map object

Yesterday I ran into an issue with how GraniteDS converts ActionScript to a Map object. The Map in question was to be a single-entry object with a key of type String and a value of type List.

Granite claims to implement the same serialization/deserialization matrix as BlazeDS (with two small exceptions).

The BlazeDS documentation is a little loose on this particular topic, in my opinion. Loose and kind of confusing.

There are two ActionScript data structures that will be deserialized to a Map object:

  1. A generic Object
  2. A ‘sparse’ Array

* Note that a ‘dense’ Array is supposed to deserialize to a List object – this is important in a minute.

Based on the given documentation (which is probably completely correct for BlazeDS), I expected to structure my ActionScript in one of two ways, in order for it to be deserialized into a Map object on the Java side.

  1. var mapObject:Object = {key:value};
  2. var mapArray:Array = new Array(); mapArray[key] = value;

Right?

Nope. Neither of those approaches worked. But one of them was very close.

Correct answer is either of the following:

  1. var mapDictionary:Dictionary = new Dictionary(); mapDictionary[key] = value;
  2. var mapArray:Array = new Array(); mapArray[key] = value;

HOWEVER, the value has to be an ArrayCollection, not an Array.

* Remember a minute ago when we saw that the Array type is supposed to deserialize to List?

The Dictionary object is very similar to Java’s Map object. I don’t know why BlazeDS isn’t taking advantage of that fact – possibly because Dictionary is not available in AS 2? Whatever the reason, the Dictionary object is not mentioned in the BlazeDS documentation. Again, this may be perfectly valid for BlazeDS.

Likewise, the ArrayCollection object is not mentioned in the BlazeDS documentation, but is apparently required in this case for deserialization to Java’s List object for GraniteDS. ArrayCollection, not Array.

Posted in Almost Random.


Include non-defined classes

If a remote service returns an object that includes a list of objects of a type that is not ever used in the client, you will probably get an exception of some sort.

There are a couple of ways to force-include non-defined classes, but the one I like the most is with the following (undocumented) metadata.

[Frame(extraClass="class.path.ClassName")]

Posted in Almost Random.


OS X script to remove svn directories

$ find . -name “*.svn” -exec rm -rf {} \;

After installing Lion (and maybe XCode 4… ?) other commands no longer worked. This works great, though.

Thanks to Seb Lee Delisle for this.

Posted in terminal.

Tagged with .