Generating XML and passing it to jQuery

I am generating some XML and then POSTing it to a jQuery based plugin. Looking at the POSTed XML in Firebug, everything appears normal. However, something is not getting passed to the plugin so it is using a amount (which results in no data being properly displayed). The solution turned out to be quite simple… set the Mime-Type on the posted XML! Doh!

So by adding

header('Content-Type: text/xml');

everything passed smoothly.

          

, ,

No Comments

Accessing Your Local MAMP Dev Environment From VirtualBox

You already have a local development environment set up using MAMP (MAMP uses port 8888 so your localhost is accessed at http://localhost:8888 and custom sites, assuming you have set any up, are available at http://whatever:8888).

Naturally you need to test your sites in Internet *barf* Explorer so you have set up a virtual environment to do this. I am using Sun’s fantastic, open source application VirtualBox. The question is, how do you access your local sites from within VirtualBox? Launching IE and going to http://localhost:8888 does not work… hmmm.

Turns out, the address you need to point at is http://10.0.0.2:8888. That will get you to MAMP’s htdocs directory, i.e. your http://localhost:8888!

Now that is useful but it doesn’t get give you access to your custom sites. Here is how you access those!

  1. Open your Windows host file. It is found here: C:\windows\system32\drivers\etc\hosts
  2. Under the bit that says: 127.0.0.1 localhost add the following (using whatever your actual project is called): 10.0.2.2 whatever

That’s it! Now you can visit http://whatever:8888 using IE from within your virtual Windows environment.

          

, ,

No Comments

Improve Netbeans IDE Memory Usage

Netbeans is my IDE of choice but the resources it commands sometimes cause my machine to choke like the Cleveland Browns on any given Sunday.

Here is what I’ve done to improve the situation a bit:

Nutshell: edit the netbeans conf file to increase the amount of memory allocated and permitted

You’ll be editing the netbeans conf file which, on my Mac and under version 6.7, is located in /Applications/NetBeans/NetBeans\ 6.7.app/Contents/Resources/NetBeans/etc/netbeans.conf The way I handled this was to open the file, copy the chunk that handles configuration (so I have a backup of the original settings), comment the old settings out and then make my changes.

The original settings (notice the pound sign at the start indicating this is commented out):#netbeans_default_options="-J-Dcom.sun.mysql.startcommand=/usr/local/mysql/support-files/mysql-admin.server -J-Dcom.sun.mysql.stopcommand=/usr/local/mysql/support-files/mysql-admin.server -J-Dcom.sun.mysql.startargs=start -J-Dcom.sun.mysql.stopargs=stop -J-Dcom.sun.mysql.port=3306 -J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true"

My new settings:netbeans_default_options="-J-Dcom.sun.mysql.startcommand=/usr/local/mysql/support-files/mysql-admin.server -J-Dcom.sun.mysql.stopcommand=/usr/local/mysql/support-files/mysql-admin.server -J-Dcom.sun.mysql.startargs=start -J-Dcom.sun.mysql.stopargs=stop -J-Dcom.sun.mysql.port=3306 -J-client -J-Xss2m -J-Xms256m -J-Xmx512m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true"

Changes include:

Old New
not set -J-Xmx512m
-J-Xms32m -J-Xms256m

Some definitions… the -J-Xms setting defines the initial memory size, -J-Xmx defines the maximum.

You could set these numbers higher if you have more RAM but going too high can cause instability. One way to determine how much memory Netbeans is using is to turn on View->Toolbars->Memory. This will give you some feeback on how much you are actually using.

          

No Comments

Magento and jQuery, Sitting in a Tree…

… k-i-s-s-i-n-g. First comes love, then comes… oh who am I kidding! They don’t really like each other that much. That said, here is how to make them at least tolerate each other:

Integrating jQuery with Magento is not complicated but there are a number of gotchas.

In a nutshell you…

  1. Create a directory named “jquery” (really you could name it “gorgonzola” but why not be consistent, eh?) in Magento’s js folder and stick the current version of jQuery inside itwherever-you-installed-it/js/jquery/jquery.js
  2. Implement jQuery’s noconflict mode by putting the following at the very end (very, very end… not inside a function or something) of the jQuery code
    jQuery.noConflict();
  3. Add a call to jquery in the page.xml file (located somewhere like wherever-you-installed-it/app/design/frontend/default/blank/layout/page.xml Note that this assumes you are using the “blank” theme in the “default” frontend)

    This bit goes with all of the other addJs bits but, and this is what took up an hour of my incredibly valuable time (an hour I could have spent playing Wii Sports, anyway), make sure you put it after all of the other javascript files. Not just after some of them… after all of them.

  4. To now make use of all of this go into wherever-you-installed-it/app/design/frontend/default/blank/template/page/html/head.phtml and put your jquery code right there at the end of the code
          

,

No Comments

Magento, MAMP and {{base_url}} Issues

A local install of Magento may give you a warning to change {{base_url}} for security purposes. I believe this only applies to production environments but it is annoying nonetheless. To solve this, within your Magento admin section, go to System-> Configurations and select the ‘Web’ tab (it’s over on the left under the configuration sidebar). Open the “Unsecure” and “Secure” sections and where you see {{base_url}} (this will be in the Base URL fields of each section… ignore any that say {{unsecure_base_url}} and the like, they don’t matter here) put in your actual base url.

In MAMP you may have something like: http://localhost:8888/magento/ (don’t forget that last slash). This will solve the issue.

          

1 Comment

Interesting Article about Caching Models in Zend Framework

Interesting article over at http://www.contentwithstyle.co.uk/content/a-caching-pattern-for-models about implementing caching with Zend Framework models. In the comments there is a good point about how to refresh such a cache with the author suggesting using something like a $this->cache->clear() to clear the cache upon adding or updating content.

          

, , ,

1 Comment

Zend_Tool Set-up

Download Zend Framework (1.8.0 is the current version at present… change as needed):

wget http://framework.zend.com/releases/ZendFramework-1.8.0/ZendFramework-1.8.0-minimal.tar.gz

Unpack the downloaded file:

tar zxvf ~/Downloads/ZendFramework-1.8.0-minimal.tar.gz

Move into that unpacked directory:

cd ~/Downloads/ZendFramework-1.8.0-minimal

Find out where your PHP binary is:

which php

Put zf.sh and zf.php into the same dir as the PHP binary:

cp bin/zf.sh bin/zf.php /Applications/MAMP/bin/php5/bin/

Find out your include path:

php -i | grep "include_path"

Put the contents of the library folder into that location:

cp -r library/* /Applications/MAMP/bin/php5/lib/php/

Test Zend_Tool:

zf.sh show version

For ease of use, let’s alias zf.sh to just zf. First open your bash login file:

vim ~/.bash_login

Add this line:

alias zf=zf.sh

You are now set up. Next stop, actually creating a project with Zend_Tool!

          

, , ,

No Comments

Using UNIX’s find to locate modified files

This will find anything that was accessed in the past 30 minutes:
sudo find / -amin 30

Finds anything larger than 10k that was modified today:
find / -size +10k -mtime 0

Finds any file larger than 1MB that was not modified in the past year:
find / -type f -size +1M -mtime +365

Finds any php file larger than 1k that was accessed in the past 30 minutes:
find / -size +1k -name "*.php" -amin -30

          

,

No Comments

Using Vault from the command line on OS X

These are directions for using SourceGear’s Vault version control from the command line on a Mac (OS X 10.5). You will need the Vault client installed (the client, not the server… you’ll be connecting to the server) as well as mono. I recommend using a package manager like MacPorts to handle mono (and any other unixy linuxy command line stuff you need to install). Oh, here is a useful link to the SourceGear support forums (well, kind of useful, Mac users are not exactly a priority as this app is really meant to be used with a Windows GUI client… oh, and don’t bother asking for a Mac GUI client. It ain’t happening).

The basic set of commands to use Vault from terminal on a Mac involve enough typing to wear your fingers out quick (note that I am using a very old version of the client software. This is because the server I am connecting to is old and won’t work with the latest versions of the client). Thus we will create aliases for everything. So the basic command to get into Vault is:
mono /usr/local/bin/VaultClientAPI_3_1_9/vault.exe -repository "My Repository"
Let’s alias that in .bash_login:
alias vault='mono /usr/local/bin/VaultClientAPI_3_1_9/vault.exe -repository "My Repository"'

Now we only have to type “vault”! In these following commands note the need to type backslash, dollar sign, forward slash ( \$/ ) before your repository project path. Weird but you gotta do it (I think that Vault expects $/ and that initial backslash is simply there to escape the dollar sign).

Get a project’s files:
vault get \$/projectname/
Checkout:
vault checkout \$/projectname/assets/css/main.css
Checkin:
vault checkin \$/projectname/assets/css/main.css
Checkin but no changes:
vault checkin -unchanged undocheckout \$/projectname/assets/css/main.css
Add a file and commit the add (all in one):
vault add -commit \$/projectname/assets/images/speakers/ /local/path/to/files/projectname/assets/images/speakers/schmitt.jpg
Rename and commit a file (all in one):
vault rename -commit \$/projectname/about/index.php index_2.php

Help! Vault is all $#^@%& up!

Sometimes errors will crop up. You may have commits that didn’t take or adds or other changes that did not go through for some reason. This will clutter your changeset (give it a look if you’ve been using Vault for a while… you may be surprised). You can view the changeset with:
vault listchangeset

To delete the changeset or to reset things when something goes wrong you can delete certain files. For example:
CacheMember_ChangeSetItems
CacheMember_CheckOutList

These are located on a path named something like:
/Users/yourusername/.config/SourceGear/Vault_1/Client/F8FB077F-8F3B-44B1-80B3-8BDC93CBC0F1/admin/

Great but it’s still too much typing, homes.

For further ease you can alias some of these commands. For example:
alias vci='vault checkin'
or
alias vciun='vault checkin -unchanged undocheckout'

So that the entire series of commands to checkin an file goes from:
mono /usr/local/bin/VaultClientAPI_3_1_9/vault.exe -repository "My Repository" checkin \$/projectname/index.php
to
vci \$/projectname/index.php
and for an unchanged checkin:
mono /usr/local/bin/VaultClientAPI_3_1_9/vault.exe -repository "My Repository" checkin -unchanged undocheckout \$/projectname/index.php
to
vciun \$/projectname/index.php

          

, ,

No Comments

Sample Configuration for mod_deflate

These conf settings will avoid compressing images (generally a bad thing) but will compress various text, xml, css and javascript files. This is better than minifying javascript because minified js must be decompressed by the client js and this is not as efficient as doing it with Apache’s mod_deflate. This goes in httpd.conf.
#
# Deflate conf
#
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no=gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

          

, ,

No Comments