Archive for the ‘programming’ Category

excluding files from tar

Wednesday, June 2nd, 2010

For the website I work on for my company I have a very large number of files in a single folder that is strictly data for the clients and not data I have to regularly modify.  So when I’m doing a tarball/gzip of my files on the server I need to exclude that folder and all it’s subfolders from the process, here it is:

~# tar -czf /home/test/download.tgz ./ --exclude="*/events/auto/*" --exclude="*/images/waveforms/*"

Till Next Time

WordPress theme hacked?

Friday, February 5th, 2010

I’ve been using a WordPress theme created by Jorge Gomez at switchroyale.com and have been very happy with it.  I logged on today to get a bit of info from one of my earlier posts and noticed that after ~5 seconds after the page loaded my site was redirecting to a seemingly random website.

I started some debugging and first deactivated my AdSense plugin thinking that was the culprit.  It turns out that the theme was loading some javascript from an external site and was executing the redirect.

I was using Azul 1.4 and noticed there was an upgrade available and I updated my site to Azul 1.51.  This did not solve my problem.  I’ve reverted back to an old WordPress default theme and the problem went away.  I’ve sent an email to Mr. Gomez to let him know about the issue.  I hope that it’s either a simple error or that his site was hacked (I’m not being mean).  I’d much rather believe that his site got hacked than if he decided to start screwing with people themes out of malicious intent.

I’m happy to give him the benefit of the doubt until I learn otherwise.  I’ve included the email that I sent him below:

Hey I just wanted to let you know that I’ve been using your theme for awhile and have enjoyed it, but today I noticed that there is some javascript coming through on your theme that is causing my site to redirect to a seemingly random website after the site is loaded for ~5 seconds.

I had been using Azul 1.4, but after noticing this issue I upgraded to Azul 1.51 and am still getting this issue.  I’ve reverted back to an old default WP theme and the issue went away and when I reactivated your theme the issue came back.

I don’t know if you are aware of this issue or whether your site might have gotten hacked.

Just wanted to let you know.

Hope this gets resolved.

I’ll update this post as needed.

Till Next Time

quickie: creating symfony delete button

Friday, January 15th, 2010

Many months ago I had asked for help on the symfony forums on how to create a delete button using either the link_to() or button_to() method. I had tried but was always getting validation errors. Today a person asked whether anyone had figured out a solution. It prompted me to do more research into symfony’s core code and found a solution (though the solution wasn’t in the core code).

Original delete text link code:

echo link_to(
	'Delete',
	'state/delete?id='.$form->getObject()->getId(),
	array('method' => 'delete', 'confirm' => 'Are you sure?')
);

New delete BUTTON link code:

echo link_to(
	'<button>Delete</button>',
	'state/delete?id='.$form->getObject()->getId(),
	array('method' => 'delete', 'confirm' => 'Are you sure?')
);

Till Next Time

quickie: setting symfony datetime default

Wednesday, January 6th, 2010

Setting the default value for a symfony form field is one of those tasks so simple that it’s impossible to find out how to do it without a good bit of trial and error.  So without further ado, here is how to set a DateTime field’s default value:

$this->widgetSchema['start_time']->setDefault(date("m/d/Y", now()));

Till Next Time

updating symfony form values after submitting

Friday, January 1st, 2010

One thing that’s made programming on symfony very aggravating has been dealing with the forms.  Some sections of the forms are not well documented.  The main issue that I have with this at work is that we deal with GPS coordinates and the users enter their coordinates in degree-minute-seconds format but the database saves them in degree-decimal format.

I had googled for a solution to this problem before, but had not found anything to guide me to the answer.  The couple answers I had found were not very clear on getting it to work.  Till I found this.  Following these guidelines I got it to work on a test deployment of symfony.  Code below:

class Blog extends BaseBlog {
 
	/**
	 * Initializes internal state of Blog object.
	 * @see        parent::__construct()
	 */
	public function __construct()
	{
		// Make sure that parent constructor is always invoked, since that
		// is where any default values for this object are set.
		parent::__construct();
	}
	/*
	 * this function overrides the BaseBlog::save function to allow
	 * changes to be made to the object before saving to the database
	 */
	public function save(PropelPDO $con = null)
	{
		$this->setCommentCount('11');
		return parent::save($con);
	}
 
}

Till Next Time

updating centOS 5 PHP install with mbstring & APC

Tuesday, December 22nd, 2009

The default install on A2hosting’s VPS does not have mbstring or APC installed by default.  I became aware of this as I was setting up symfony on the new server.  I googled around looking for a quick guide to install them.

mbstring is a straight-forward install:

yum install php-mbstring

Easy.

Installing APC is a pretty simple affair with one big caveat at the end.  The guide that I found for installing APC is on HowToForge. The last two steps are particular to CentOS on A2hosting’s platform.

1.  Install PEAR.

yum install php-pear

2.  Install php-dev & httpd-dev.

yum install php-devel httpd-devel

3.  Install group Development Tools

yum groupinstall 'Development Tools'

4.  Install group Development Libraries

yum groupinstall 'Development Libraries'

5.  Install APC

pecl install apc

6.  Reboot Apache

httpd -k restart

7.  Error alerts you to SSLRandomSeed error.

SSLRandomSeed Error

SSLRandomSeed Error

8.  Fix Centos Dev

Fix CentOS Dev on A2hosting

It took me an hour last night to figure out the last step.  Without the last step there is no authentication so there is no SSH access.

Till Next Time

setting up a domain-nameless domain

Monday, December 21st, 2009

My company’s website is being completely rewritten from scratch and I chose to move to A2hosting.com.  We are going with a Virtual Private Server (VPS) from them and have found a little difficulty setting up web access to it.

The main issue is that since the website is already up and running, I can’t just transfer the domain name to the new server and be done with it.  I need to be able to access the new website by just the IP address for a while, until we move the production site over to it.  This is not documented anywhere on A2hosting’s site that I could find.

The issue resides in the setup of IP address of the server through Kloxo.  I am unable to configure the domain to default to the domain of my choice.  The error checking of this function disallows the assigning of that domain name since the domain name does not currently resolve to the server’s IP address.The solution resides in the /etc/hosts file.  I had to set the IP to equate to the domain name that WILL be the correct name once the production site is moved over.

A quick little walkthrough:

Set the /etc/hosts file

IP Addresses link in Kloxo admin

IP Address table

IP Address info

Select the proper domain name for the IP Address

Hope this helps.

Till Next Time

Adding javascript to symfony form field

Tuesday, November 17th, 2009

In the users table at my company’s website there are fields for company, division, region, and location. Since each level of the company organization affects all the lower categories I have to filter out the invalid choices when a higher level choice is selected.

I’ve implemented this on some forms that I’ve created manually on the site but not in any forms that I haven’t heavily modified from the stock symfony creation.  I started googling around to find a solution but could not find a simple explanation of how to do it.  I expected to find at least some information in one of symfony’s otherwise excellent tutorials, but alas, no.

I had a minor epiphany and went digging through the forms API that symfony provides and realized that I should easily be able to do this through the sfWidgetFormPropelChoice method.  The second parameter passed is the html attributes for the form field.  I thought I had seen a form post here that said that I could add javascript code to the html attributes and not have it get converted into html entities.

I tried throwing a simple alert() inside the onchange attribute for my company box and wham! it worked!  So simple.  Code below:

new sfWidgetFormPropelChoice(
	array(
		'model' => 'Company',
		'add_empty' => true
	),
	array(
		'onchange' => "filterBy('company', 'division', this.value, 'sf_guard_user_user_division_id');" .
			"filterBy('company', 'region', this.value, 'sf_guard_user_user_region_id');" .
			"filterBy('company', 'location', this.value, 'sf_guard_user_user_location_id');"
	)
)

Till Next Time

IE 7 javascript bug

Friday, November 6th, 2009

In a form that I administer at work I have a javascript filtering function for a few select boxes.  It is called whenever the first select box changes and removes the ineligible options from the second select box.  Simple.  Straight-forward.

It doesn’t work in IE 7, works fine in IE 8, Firefox, Chrome.  But we have many clients that are stuck in IE 7 or even IE 6.  I sat down to figure this out and realized that my IE debugging tools aren’t nearing as good as my Firefox debugging.  In Firefox I use Firebug, but in IE I use the built in Developer Tools (DT).

The one big difference between these two plug-ins for this particular problem is that DT doesn’t live update the code of the page when it is changed with javascript.  You must manually refresh the code inside of DT.  Once I discovered this I was much more productive.

But onto the problem.  I discovered that when I was creating the ‘filtered’ select box, I was actually just wiping the original box out and creating a new one from scratch.  In this new select box all the attributes were correct except for the name.  Instead of the attribute being called ‘name’ it was being called ‘submitName’.

I googled that and the only relevant thing that I could get was an experts-exchange link that I refuse to use.  I have a problem with a website charging people for solutions to simple code problems.  Whenever I get google results for that site I remove it from my results.

I ended up reworking my code to actually filter out the unwanted options when the first select box is changed.  But in case someone else has had the problem that I’m having and knows the solution, I will post the code that I was using to create the select box.

function createSelect(parent_cell, name, id, options, option_values, classs, onchange, removeChildren)
{
	// classs is misspelled cause otherwise IE thinks it is a Class
	try
	{
		var par_cell = document.getElementById(parent_cell);
		var sel_box = document.createElement('select');
		sel_box.setAttribute('name', name);
		sel_box.setAttribute('id', id);
		sel_box.setAttribute('onchange', onchange);
		sel_box.setAttribute('class', classs);
 
		var first_opt = document.createElement('option');
		first_opt.value = '';
		first_opt.text = 'Select an Option';
		sel_box.options.add(first_opt);
 
		for(var i=0;i<options.length;i++)
		{
			var opt = document.createElement('option');
			opt.value = option_values[i];
			opt.text = options[i];
			sel_box.options.add(opt);
		}
		if(removeChildren)
			removeAllChildren(parent_cell);
 
		par_cell.appendChild(sel_box);
	}
	catch(err)
	{
		alert("There was an error creating the options menu: " + err);
		return false;
	}
	return true;
}

Till Next Time

ahhh, cronjobs!

Tuesday, May 26th, 2009

One of the features of the new platform that I am working on is the ability to automatically retrieve all new seismic activities before the end-user posts that there has been an activity.  This will make the data transfer appear instantaneous to our clients and make us look all-around awesome.

So I have a script designed to run whenever I need it to automatically get any new activities and save them to the local database waiting for the end-user.  I set it up to run every 15 minutes until I got the multitudes of old data into the new platform.  I’m talking ~170,000 activities, and each activity takes about 45-90 seconds to process.

So below is my simple cronjob command to have it run every 15 minutes 24/7/365.

*/15 * * * * php /var/lib/symfony/cron/runcron.php >> /var/lib/symfony/cron/test_cron_log.log

Till Next Time