Tuesday, April 30, 2013

Flash TextField.textHeight only returns Zero.

I was doing some Flash development this afternoon and ran into an issue with TextFields...

I was creating a dynamic textfield and needed to retreive the field's height after the text was set. No matter what I did, the textHeight property was always Zero.

Finally, I discovered the problem: I had set the textfield.embedFonts=true BUT I HAD FORGOTTEN TO ACTUALLY EMBED THE FONT. (actually I did on the dev version, but not on my test file which is where I was noticing this issue.)

I don't know whether Flash was able to fall back to a default font or if it was because my test file didn't actually display my text field (only builds it and checks its size), but I never received any errors to help point me to the source of this issue.

Once I added the correct font to the Fla's library, I began getting correct values for TextField.textHeight.

It was a silly error, but none of the other formus I read mentioned it.

Friday, February 22, 2013

A shell script to set up a GIT development workflow for a Drupal site

Since I need someplace to "backup" this script, I thought I may as well share it here as a way to preserve it.

This script resides on my development server. It sets up a GIT-based workflow based on this one.

When run, this script creates a project-specific "central" repository, pulls in the drupal source (from a master Drupal repo I use to stay synched to the Drupal codebase), and creates the necessary branches. The script then creates a few "web" directories to use as GIT working trees and modifies the post-update hook to keep the working trees synched to the repo.

All I have to do it push my changes from my local repo to the "central" repo and all three of the "sites" are automatically updated.

The script so far:
#!/bin/sh

set -e
set -o nounset
installpath=/opt/scripts
. ${installpath}/wfvars.sh
#wfvars.sh is a small script that creates the variables used below - based on the supplied project name

DRUP_VER=$2
DRUPALGIT=${GITHOME}/drupal

echo "Setting up workflow for: "$PROJECTNAME"..."

# set up "central" repo
echo "Making repo dir ("$PROJECTREPO")..."
mkdir $PROJECTREPO

if [ -d $PROJECTREPO ]; then
cd $PROJECTREPO
echo "Initializing bare repo ("$PROJECTREPO")..."
git init --bare
# now add as remote to drupal source repo ($DRUPALGIT)
cd $DRUPALGIT

git remote add $PROJECTNAME $PROJECTREPO
git checkout $DRUP_VER
git checkout -b $PROJECTNAME

git push $PROJECTNAME $PROJECTNAME
git clone --branch $PROJECTNAME $DRUPALGIT $DEVTREE
git clone --branch $PROJECTNAME $DRUPALGIT $STAGTREE
git clone --branch $PROJECTNAME $DRUPALGIT $PRODTREE

# create databases for each branch
createDEVDBquery="create database "$PROJECTNAME"_dev;"
createSTAGDBquery="create database "$PROJECTNAME"_staging;"
createPRODDBquery="create database "$PROJECTNAME"_production;"

#grant privileges
grantDEVQuery="grant all privileges on "$PROJECTNAME"_dev.* to MYSQLUSERNAME@localhost;"
grantSTAGQuery="grant all privileges on "$PROJECTNAME"_staging.* to MYSQLUSERNAME@localhost;"
grantPRODQuery="grant all privileges on "$PROJECTNAME"_production.* to MYSQLUSERNAME@localhost;"

echo "...creating databses for dev streams. Please enter your MYSQL password to continue..."

mysql -u MYSQLUSERNAME-p << eof
$createDEVDBquery
$createSTAGDBquery
$createPRODDBquery
$grantDEVQuery
$grantSTAGQuery
$grantPRODQuery
eof


# change permissions on /sites/default to 0777
sudo chmod 0777 $DEVTREE/sites/default
sudo chmod 0777 $STAGTREE/sites/default
sudo chmod 0777 $PRODTREE/sites/default
# copy default.settings.php to settings.php
cp $DEVTREE/sites/default/default.settings.php $DEVTREE/sites/default/settings.php
cp $STAGTREE/sites/default/default.settings.php $STAGTREE/sites/default/settings.php
cp $PRODTREE/sites/default/default.settings.php $PRODTREE/sites/default/settings.php
#set permissions on settings.php
sudo chmod 0777 $DEVTREE/sites/default/settings.php
sudo chmod 0777 $STAGTREE/sites/default/settings.php
sudo chmod 0777 $PRODTREE/sites/default/settings.php
fi


There is a bit more to the script. It adds an entry to a project directory that I mantain on my server homepage, but this is the guts of the functionality.

I'm kinda new to writing shell scripts so I am open to suggested improvements...

-------------------------------

Here are the associated helper scripts:
deletewf (to completely remove a project from the environment)

#!/bin/bash
installpath=/opt/scripts/
. ${installpath}wfvars.sh

DRUPALGIT=$GITHOME/drupal

read -p " THIS WILL COMPLETELY DESTROY THIS PROJECT!! ARE YOU ABSOLUTELY SURE?? ...y/n ?" -n 1 -r

if [[ $REPLY =~ ^[Yy]$ ]]
then

cd $DRUPALGIT
echo "Changing to latest branch ("$DRUPALGIT")"
git checkout 8.x
echo "deleting branch: "$PROJECTNAME
git branch -D $PROJECTNAME
echo "deleting remote: "$PROJECTNAME
git remote rm $PROJECTNAME

if [ -d $PROJECTREPO ]; then
echo "deleting project repo: "$PROJECTREPO
rm $PROJECTREPO -r
fi

if [ -d $PROJECTWEB ];then
echo "deleting project web: "$PROJECTWEB
rm $PROJECTWEB -r
fi

#delete the databases
deleteDEVDBquery="DROP database "$PROJECTNAME"_dev;"
deleteSTAGDBquery="DROP database "$PROJECTNAME"_staging;"
deletePRODDBquery="DROP database "$PROJECTNAME"_production;"

mysql -u chris << eof
$deleteDEVDBquery
$deleteSTAGDBquery
$deletePRODDBquery
eof
echo "Done."
else
cancel
fi


-----------------------------------------
wfvars.sh (creates the variables)  
#!/bin/sh
PROJECTNAME=$1

# Set up workflow
GITHOME=/home/git/
WEBHOME=/var/www/

PROJECTREPO=${GITHOME}${PROJECTNAME}
PROJECTWEB=${WEBHOME}${PROJECTNAME}
DEVTREE=${PROJECTWEB}/dev
STAGTREE=${PROJECTWEB}/staging
PRODTREE=${PROJECTWEB}/production

Re-enabling --skip-grants-table

Ok...

So, I had forgotten what my MYSQL root password was from when I originally set up my Ubuntu server.  I followed one of the tutorials I found online that uggested the following:

sudo /etc/init.d/mysql stop
sudo mysqld --skip-grant-tables & mysql
mysql> use mysql;
mysql> INSERT INTO user VALUES ('localhost','root',password('newpassword'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);



...and that was about where I stopped reading ('cause I'm an impatient knob)...
(*note: the query above is as it appeared in the tutorial.  ...but it seems out of date as it is missing some field values.  I had to cross-reference the table structure and add the missing fields to the query.)

...which was a mistake because I missed some important steps... 

When I then tried to run a shell script I was working on (to automate the setting up of a development workflow) - that involved setting up some databases - I would get a message telling me that the command could not be executed because MYSQL was running with --skip-grants-table enabled.

A number of forum posts suggested that simply restarting the MYSQL service would remedy this.  Unfortunately, this was not the case.  I repeatedly tried stopping and starting MYSQL but I always got the same message.

Fortunately, I was able to find the original post.  ...which gave the steps I was missing:

mysql>flush privileges;
mysql>quit
sudo killall mysqld
sudo /etc/init.d/mysql start


...see, I never managed to kill the mysqld process.

Once I did, everything started working as desired.

Wednesday, February 20, 2013

Reconfiguring SSH access after a router change

So, we ran into an issue the other day, when we were suddenly unable to access a few of our client's domains.  This was only an issue from inside our office network.  External resources and other users outside our network had no trouble connecting to these sites.

We never did get to the bottom of it.  Instead, we removed our router and the problem went away.

But...  this meant reconfiguring our modem from bridge mode to routing mode.  To be clear, we did not have to do this.  Shaw (our ISP) did this reconfiguration remotely.

Unfortunately, this meant that I had to add all of our previously forwarded ports to the "new" machine.  I ran into a problem when I got to configuring the SSH forwarding.  We are using the SMCD3GN modem/router we got from Shaw and when I tried to add the pre-configured SSH forward, I received an erro message telling me that my setting "Conflicts with Remote Management Ports!".

After cursing Shaw for making my life more difficult, I decided that there was more than one way to skin this cat.  On my server, i reconfigured SSH to use a different port (I went with 222 rather than 22).  ...then on the "router" (#scarequotes), I added a user-defined service which I called MySSH and set up the forwarding on port 222.

This solved the problem and I can now SSH into my server.