May 23 2009

Iphone Lag Fixes

I’ve been spending way to much time on my iphone lately and It’s been becoming a little unresponsive. When I scroll I notice the refresh rate is delayed and loading programs like phone, sms and safari are delayed. At first I thought that my theme was the cause but even after turning off all winterboard effects I still have the same problem. I decided to research the issue and here are my results.

  • The iphone is said to never shut a program down so the memory of the device is getting saturated. To cure this you need to reset the device.You would think that powering down and back up again would do this but apparently you need to hold the power button and the home button at the same time until the iphone shuts down.
  • Remove unused programs. As soon as I got rid of a few of the apps that I never use the phone started responding a lot quicker but still not quick enough.
  • Turn off ssh. Running the ssh daemon in the background is using resources. If you’re not scp’d or ssh’d into the phone at the moment then why do you have it running?
  • Turn off the GPS services. If you need it then turn it back on. In Settings => General click “Location Services” to off. This will also help with battery life on the iphone.
  • If you’re suffering from SMS lag I’ve read that opening and closing the app store solves the problem on the iphone.

Mostly straight forward but still useful. I’ve found that Winterboard does not cause any lag whatsoever. I’ve tried multiple themes and played around with each and they don’t seem to lag the phone out at all.


Apr 25 2009

Power Outages Suck Balls. Mysql Database Problems.

I came home today to find that my computers were powered off. All my clocks were blinking. Power outages suck balls.
I don’t have a UPS but I am running a test web site on my local machine that has been getting some nice traffic lately so I should probably invest. After starting everything up I tried running one of my php scripts that access my mysql database. Error.

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/ctaylor/scripts/webcrawl.php on line 8

Why isn’t my database running? I have seen this before. Possible database corruption? I prayed that this wasn’t the case and executed:

codytaylor@desktop:~$ sudo /etc/init.d/mysql start
 * Starting MySQL database server mysqld                                                                 [fail] 
codytaylor@desktop:~$ sudo /etc/init.d/mysql restart
 * Stopping MySQL database server mysqld                                                                [ OK ] 
 * Starting MySQL database server mysqld                                                                 [fail] 

Awesome. So now what?
Hoping to get a handle on what exactly is causing it not to start I first checked /var/log/mysql.err and /var/log/mysql.log.
They were both empty. Useful right?
I then did decided to check syslog. I didn’t find anything at first but then I followed syslog while trying to restart mysql.

codytaylor@desktop:/var/log$ tail -f syslog
Apr 24 19:59:54 desktop mysqld_safe[8173]: started
Apr 24 19:59:54 desktop mysqld[8176]: 090424 19:59:54 [Warning] Can't create test file /var/lib/mysql/desktop.lower-test
Apr 24 19:59:54 desktop mysqld[8176]: 090424 19:59:54 [Warning] Can't create test file /var/lib/mysql/desktop.lower-test
Apr 24 19:59:54 desktop mysqld[8176]: 090424 19:59:54 [Warning] One can only use the --user switch if running as root
Apr 24 19:59:54 desktop mysqld[8176]: 
Apr 24 19:59:54 desktop mysqld[8176]: 090424 19:59:54  InnoDB: Operating system error number 13 in a file operation.
Apr 24 19:59:54 desktop mysqld[8176]: InnoDB: The error means mysqld does not have the access rights to
Apr 24 19:59:54 desktop mysqld[8176]: InnoDB: the directory.
Apr 24 19:59:54 desktop mysqld[8176]: InnoDB: File name ./ibdata1
Apr 24 19:59:54 desktop mysqld[8176]: InnoDB: File operation call: 'open'.
Apr 24 19:59:54 desktop mysqld[8176]: InnoDB: Cannot continue operation.
Apr 24 19:59:54 desktop mysqld_safe[8183]: ended
Apr 24 20:00:08 desktop /etc/init.d/mysql[8336]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
Apr 24 20:00:08 desktop /etc/init.d/mysql[8336]: Could not open required defaults file: /etc/mysql/debian.cnf
Apr 24 20:00:08 desktop /etc/init.d/mysql[8336]: Fatal error in defaults handling. Program aborted
Apr 24 20:00:08 desktop /etc/init.d/mysql[8336]: 

I executed the restart of mysql as root didn’t I? All the folders and files are owned by the mysql user. WTF?
So it’s saying that first it can’t create a test file /var/lib/mysql/dektop.lower-test and then that it can’t open ./ibdata.
My first instinct was to set everything to 777 and just go get a beer. But probably not a good idea.
So obviously this is a permissions error. But seeing as the mysql user owns everything in this folder it’s a little confusing.
I then executed:

codytaylor@desktop:/var/lib/mysql$ sudo chmod -R 755 ./*

I tried starting mysql again. Same error.
I got frustrated and said screw it for the night. This morning while I was trying to get rid of the hangover I tried again to start mysql again and I got a totally different error in my syslog.

Apr 25 20:49:48 desktop mysqld_safe[31095]: started
Apr 25 20:49:48 desktop mysqld[31098]: 090425 20:49:48  InnoDB: Started; log sequence number 0 60274
Apr 25 20:49:48 desktop mysqld[31098]: 090425 20:49:48 [ERROR] Can't start server: Bind on TCP/IP port: Cannot assign requested address
Apr 25 20:49:48 desktop mysqld[31098]: 090425 20:49:48 [ERROR] Do you already have another mysqld server running on port: 3306 ?
Apr 25 20:49:48 desktop mysqld[31098]: 090425 20:49:48 [ERROR] Aborting
Apr 25 20:49:48 desktop mysqld[31098]: 
Apr 25 20:49:48 desktop mysqld[31098]: 090425 20:49:48  InnoDB: Starting shutdown...
Apr 25 20:49:50 desktop mysqld[31098]: 090425 20:49:50  InnoDB: Shutdown completed; log sequence number 0 60274
Apr 25 20:49:50 desktop mysqld[31098]: 090425 20:49:50 [Note] /usr/sbin/mysqld: Shutdown complete
Apr 25 20:49:50 desktop mysqld[31098]: 
Apr 25 20:49:50 desktop mysqld_safe[31119]: ended
Apr 25 20:50:02 desktop /etc/init.d/mysql[31263]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
Apr 25 20:50:02 desktop /etc/init.d/mysql[31263]: ^G/usr/bin/mysqladmin: connect to server at 'localhost' failed
Apr 25 20:50:02 desktop /etc/init.d/mysql[31263]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Apr 25 20:50:02 desktop /etc/init.d/mysql[31263]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
Apr 25 20:50:02 desktop /etc/init.d/mysql[31263]: 

All of a sudden it’s only a problem with the bind address? What happened to the permissions error? I didn’t reboot or anything.
Easy enough to fix though.
I open up the my.cnf file which resides in /etc/mysql/.
I look for the bind-address and noticed it was set to instead of my new ip
DHCP assigned it a new ip address which sucks.
So I change the line to reflect the change and restart again. All is now well.
-Cody Taylor


Apr 25 2009

mount_point cannot contain the following characters: newline, G_DIR_SEPARATOR (usually /)

Can’t Mount Drive in Ubuntu Linux 8.10. Cannot mount volume. Unable to mount the volume.

mount_point cannot contain the following characters: newline, G_DIR_SEPARATOR (usually /)

After a power outage it seems something got screwed up with my drive mounting.
I got this error when I decided to access my 500gig drive on my ubuntu linux desktop. A quick google and I found the solution.

Type this into the terminal:

codytaylor@desktop:~$ gconf-editor

Looks like a linux regedit a little eh? Scary.

Go to System -> Storage -> drives.

This will show you the value of the mount point. Change it to only one word without any slashes.
Thats it. For me it put it in as /media/disk-4 but it showed up properly in all the menus. I wish it would just auto mount so I don’t have to reconfigure sharing every time this happens.

-Cody Taylor


Apr 23 2009

Unable to load dynamic library php_pgsql.dll

I was installing a postgres database to work with apache from uniform server. It was very slow due to running both mysql and postgres on a laptop. Since it was only for a tradeshow I didn’t really care. But I did get this error:

Unable to load dynamic library php_pgsql.dll The application has failed to start because its side-by-side configuration is incorrect. 

After some reading about similar errors which were mostly about mysql because no one likes postgres. I managed to fix it by replacing the dll’s in the apache folder with the dll’s from the postgres folder.
Nice and Easy.


Apr 22 2009

Fix “Shared Key is Invalid” Error on a Bell 6520 Modem/Router.

WPA-PSK Wireless Network Error on Speedstrem 6520 Modem/Router.

I went to set up a wifi network today on my Speedsream 6520 Router/Modem. I chose the WPA-PSK encryption option because WEP is stupidly easy to crack. It seemed that whatever I entered for the shared key gave me this “Shared Key is invalid” error. This was a problem. I immediately started cursing the developers of the web interface for not making it clear what the length or format should be.

After trying a few times I was getting ready for a night of frustration.
I looked a little closer at the page that prompts for the shared key for the WPA-PSK Shared Key.
The page has a fair amount of text on it describing the different encryption schemes and right under that there is a bullet labeled Shared Key.

The third sentence tells us that the password be a minimum of 10 characters.
This got me thinking because every key I used for the TKIP network was as many characters as the text box would allow, so I tried a Key that was 8 characters in length. This got rid of the error but left the WPA-PSK hackable due the the lack of strength of the Key. I put another 4 characters onto the WPA-PSK Shared Key and tried again.This also works. Not really sure why they would make the text box hold more characters than the firmware would allow but it happens. Anyway with a WPA-PSK wireless network encrypted with a Shared Key of 12 characters my network should be secure enough for now.


Apr 20 2009

Solved: The iPhone cannot be synced. The required disk cannot be found.

I got an error tonight that read “The iphone cannot be synced. The required disk cannot be found.”
Of course, having had almost all my gadgets die on me many times before I jumped to the though of just reinstalling the original firmware for my iphone 3G. But I did some research first on the sync error and why it can’t find the required disk.

My initial assumption was that the “required disk” was the iphone drive itself and I’m very glad that I was wrong.
This sync error was happening on my iphone due to trying to sync the iphone with a ringtone that was on a network drive that I recently reformatted and reorganized. Disabling the files that were on the network drive in itunes completely solved my problem. So if you ever read “The iphone cannot be synced. The required disk cannot be found.” Make sure that all the files that you are trying to sync are actually accessible.


Apr 12 2009

INCREASE SEO with this mod_rewrite tutorial. Only the useful.

Since I didn’t really delve into how to actually use mod_rewrite to do something useful in my last post I will now.
The main reason I got mod_rewrite going is to improve my search ranking for a few sites so I’ll show how to do this with a dynamic php site.
What I primarily aimed at was to get $_GET variables to look like directories.

The .htaccess file from the previous post was

1. RewriteEngine on
2. RewriteRule ^/?test\.html$ test.php [L]

First line obviously turns on the .htaccess Rewrite Engine. .htaccess files can be used for other stuff. Check here for an example of a different use of a .htaccess file.

The second line is rewriting test.html to test.php. The text before the space represents the string to search and replace using regular expressions. The text after the space specifies what to replace the aforementioned string with.

This rule is really simple. The special characters that denote the regular expression are:

‘^’ This symbol, the caret, signifies the start of the URL.
This is under the current directory. Think of it like the ‘~’ character on the command line.
If your site is then
the ‘^’ in these regular expressions are the equivalent of the that URL
(as long as the htaccess file is in the root directory for that site).

‘$’ This symbol, the dollar sign, signifies the end of the URL.

“\.’ This is just a period. There is nothing special about this because it is ‘escaped’ by the slash.
For the search this will look just tell apache to treat it like a normal period.
This is necessary because the period has a special meaning and in this case we just
want to look for a period and not any character (which is the ‘.’s normal meaning).

It’s great and all to redirect from one file to another using mod_rewrite and apache but it’s not that helpful for SEO.
Here is another search and replace rewrite rule:

RewriteRule ^posts/([^/\.]+)\.html$ single_post.php?post_name=$1 [L]

This rule isn’t that simple.
First we want to match all urls that start with ‘posts/’.
Then we want to capture the characters that come after ‘post/’ but before ‘.html’ and use them as the get variable for the single_post php script.

This will rewrite pages like :

The ‘()’ brackets tell apache to take whatever is inside of them and put it in a temporary location that can be acessed by the replacement string.
In this case the string ‘somepost’ is stored as $1. If you had multiple parenthesis then the $2,$3,.. would be used also.

The square brackets signify an expression of a sort. [0-9] will match any digit between 0 and 9. [^0-9] will match any character that is not between 0 and 9.
So [^/\.]+ matches one or more characters that are not a slash or a dot.

After that the ‘\.html$’ searches for the .html file extension so that url will look like a basic old html file.

A general overview of the structure of a mod_rewrite RewriteRule:

RewriteRule Pattern Substitution [OptionalFlags]

Fairly simple right? RewriteRules are dissected as follows:

This is just the name of the command for apache.

This is a regular expression which will be applied to the current URL.

Substitution occurs in the same way as it does in Perl or PHP.

You can include backreferences and server variable names in the substitution. Backreferences to this RewriteRule should be written as $N, whereas backreferences to the previous RewriteCond should be written as %N.

A special substitution is -. This substitution tells Apache to not perform any substitution.


Any flags should be surrounded in square brackets and comma separated. The most useful are:

F – Forbidden. The user will receive a 403 error.
L – Last Rule. No more rules will be proccessed if this one was successful.
R[=code] – Redirect. The user’s web browser will be visibly redirected to the substituted URL.
If you use this flag, you must prefix the substitution with

There are more flags but I haven’t had a use for them yet.

I did up a few other more complex rewrites for one of my dynamic sites.

RewriteRule ^([0-9]+)/([0-9]+)/?$ /index.php?num_posts=$1&start=$2  [L]

This one is pretty straight-forward if you understood the previous example.
It is looking for two numerical strings separated by slashes. It then takes those two values and places them as the
$_GET[‘num_posts’] and $_GET[‘start’] variables. The ‘/?’ at the end allows for a possible slash.
[0-9]+ means: match one or more characters that are between 0 and 9.

The main problem that I ran into was that after a rewrite all of the images and includes would not work because I’m lazy and use relative paths.
So when I type a url like I don’t get any images or style sheets because the browser is trying to find images
at I had to write two rules to make this work properly:

RewriteRule ^.*/?.+/images/(.+)$ /images/$1 [L]
RewriteRule ^.*/?.+/includes/(.+)$ /includes/$1 [L]

These rules check for one or more directories before the image or includes directory and if they exist then it rewrites the url to either /images or /includes.
The ‘.*/?’ means 0 or more characters before an optional slash (the ‘?’ following the slash means that it is optional).
‘.+/images/’ and ‘.+/includes/ tries to match one or more characters before the image or includes directory.
The ‘.’ means any character. So ‘.*’ means 0 or more any characters which is essentially any string.

Hopefully that wasn’t too confusing. There are a lot of great resources out there for learning regular expressions if you still don’t get it.
-Cody Taylor


Apr 12 2009

Setting up mod_rewrite on ubuntu example. Only the useful.

mod_rewrite is a way to change one url to another. It is very useful for making dynamic php sites better for search engine optimization (SEO).

Obviously you’re going to need apache installed. I’m using Apache 2.0 with php5. This is how I did it.

I had hoped that it was already installed and I could just start writing regular expressions in an htaccess file and have everything work. So I went to check if it was installed by calling the phpinfo function. I created a file called asdf.php which contained:

I then did a search for rewrite in my browser. No go. So it’s either not installed or not enabled.
I checked the /etc/apache2 directory for any files that look like mod_rewrite.
I found rewrite.load in the mods-available directory. There is also a mods-enabled directory so I copied rewrite.load to mods-enabled with this command.

cody@taylor:/etc/apache2$: sudo cp rewrite.load ../mods-enabled/rewrite.load

I thought this may do it so I restarted apache2 with this command:

cody@taylor:/etc/apache2$: /etc/init.d/apache2 restart

I created two text files to test whether it was working:

filename: test.html
This is a HTML File

filename: test.php
This is a PHP File

I then created a .htaccess file in my web root directory which contained this text:

RewriteEngine on
RewriteRule ^/?test\.html$ test.php

I went to http://localhost/test.html hoping to see that it’s a php file. Didn’t work obviously.
I checked the sites-enabled directory and opened 000-default in vim.

It contained :

ServerAdmin webmaster@localhost
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ “/usr/share/doc/”
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from ::1/128

AllowOverride is what I was looking for so I change AllowOverride to all and restart apache again.
This time when i check http://localhost/test.html I get that it is a php file which is good.

I noticed I was getting this error when I restarted apache:

cody@taylor:/etc/apache2$: sudo /etc/init.d/apache2 restart
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName

I fixed this by adding this line to the apache2.conf file:

ServerName ""

A restart fixed it all up.

-Cody Taylor


Apr 5 2009

SSH and SCP into your Iphone with USB instead of WIFI. Only the Useful.

I had to go through four or five iphone SCP/SSH howto tutorials before I got it to work. So I figured I’d put only the useful steps here without all the garbage that the other sites spew. Here are the useful steps that allowed me total root access through SSH and SCP to my iphone harddrive. This guide requires that you have already jailbroken your iphone. Jailbreaking is stupidly easy and there is plenty of tutorials out there on how to do it.

First download this file. You will need to unzip it.
Run that file and a black DOS window should be displayed.

Next download this file. You will also need to unzip this one.

Before we log into the iphone with SCP we need to disable Auto-Lock because when the phone goes to sleep it drops the connection. On your iphone go to Settings -> General -> Auto-Lock. Set it to Never.

Make sure you have the OpenSSH package installed on the Iphone. If you don’t then go to Cydia on your iphone and select categories. I think it is in the networking category but I could be wrong. It’s in there somewhere. Install it.

Make sure you still have that black DOS window running. Without it you will be unable to connect to your iphone.

Now run WinScp. Enter as the Host name. Leave the port number on 22. User ‘root’ for the username and ‘alpine’ as the password. Hit the Login Button.

SCP to Iphone

SCP to Iphone

You will be prompted about adding a RSA host key. Click Yes.

Now you have complete access to the Iphone’s filesystem.
If you want to SSH in then download Putty and use the same settings to SSH in. Always make sure that the itunnel black console (DOS) window is running.

-Cody Taylor

I did this again today and it wouldn’t work right away. I was getting this error on the iphone tunnel black screen when I tried to use SCP to log in.

new connection !
AMDeviceNotificationSubscribe = 0
iPhone attached !
AMDeviceConnect = 0
AMDeviceIsPaired = 1
AMDeviceValidatePairing = 0
AMDeviceStartSession = 0
MobileDevice: AMDeviceStartService: AMDeviceStartService: Could not connect to USB mux (error 10061)
AMDeviceStartService = -402653131
AFCConnectionOpen = 0

I was puzzled at first but then I realized why I couldn’t SCP into my iphone. I had turned SSH off from within the SBSettings menu. How would SCP work without SSH? It won’t.


Apr 1 2009

Bridge Virtual Windows XP Installation to Linux so VirtualBox Can Access Your Network Shares. Only the useful instructions.

This quick tutorial or example displays how to quickly bridge your windows xp install in virtual box running on Linux to your local area network so you can stream video or just acces your network shares.

I set up a windows xp virtual box on my ubuntu 8.04 desktop so I could stream H.264 high def content to my xbox 360 using tversity.
Because Virtual Box is by default set up on a different subnet this would not work as easily as I would like. Here is only the useful information on how to set up a network bridge between Linux and Virtualbox.

Install virtualbox on ubuntu and set up windows xp. For anyone trying to follow these instructions then this should be simple. Google it and use apt-get.

These packages are required for the bridge.

sudo apt-get install uml-utilities bridge-utils

Now create TAP interface. The tap interface is a software loopback mechanism.

sudo tunctl -t tap1 -u username

where username is obviously your username.

Create a bridge named br0

sudo brctl addbr br0

Put your physical network interface into promiscuous mode

sudo ifconfig eth0 promisc

Link your physical interface to the bridge br0 that we created
sudo brctl addif br0 eth0

Give the bridge br0 a static IP address or use DHCP

sudo ifconfig br0


sudo dhclient br0

Link the tap interface to your bridge br0

sudo brctl addif br0 tap1

You will now need to activate the tap interface using the ifconfig command

sudo ifconfig tap1 up

Alter the permissions of the tunnel device

sudo chmod 0666 /dev/net/tun

Now, assuming that you got virtual box installed and working, (If you can’t then you need to play with linux more, It’s really not that hard)
Start VirtualBox but don’t start your windows installation. Click on Settings, select Network and then set ‘Attached to’ to “Host Interface” and add tap1 to Interface Name.

Boot up your virtual windows xp installation and change the IP address of the local area connection in network connections to an ip on the same subnet.
You will have to set the proper gateway and possibly the dns servers. Although typically these can just be set to the same as the gateway.

when you reboot Linux and want to use the windows install on the same network then you will have to repeat most of that stuff. I use a shell script that runs it on boot.
Here is an example of one that you could use. Fill in your own info of course.

#must run as root
tunctl -t tap1 -u codytaylor
brctl addbr br0
ifconfig eth0 promisc
brctl addif br0 eth0
sleep 10
dhclient br0
brctl addif br0 tap1
ifconfig tap1 up
chmod 0666 /dev/net/tun

-Cody Taylor