TSN: Top 10 Reasons Why You Can’t Possibly Like Vince Carter

December 1st, 2009

10. Tipping off the Sonics
9. Michelle Carter (his mother)
8. No More Dunking
7. All-Star Controversy
6. Injuries
5. Peterson Ejection
4. Graduation / Game 7
3. “Come on, MVP?”
2. The Trade
1. Didn’t Always Give 100% – “Do you think Vince Carter has pushed himself, as hard as he should have pushed himself?” VC: “In years past, no”.

XAMPP: Setting Up Virtual Hosts Using Apache Friends

October 29th, 2009

This is something I do often for development, but never actually knew if I was doing it correctly. I think I’ve finally gotten this right. What I want is: To be able to setup VirtualHosts in XAMPP and also define a PHP include path within that. I’m assuming you generally have an idea how to setup a VirtualHost in Apache.

The first step is to modify your Hosts file to point traffic to your local computer. My hosts file is here C:\WINDOWS\system32\drivers\etc\hosts, you’ll have to search for yours.

Code:
127.0.0.1		www.sun.com
127.0.0.1		sun.com

The next step is to define the VirtualHost within the httpd-vhosts.conf file in the conf directory of your XAMPP setup.

Code:
NameVirtualHost *
<VirtualHost *>
	DocumentRoot "C:\xampp\htdocs"
	ServerName localhost
</VirtualHost>
<VirtualHost *>
	DocumentRoot "C:\xampp\htdocs\sun"
	ServerName www.sun.com
	ServerAlias sun.com
        ErrorDocument 404 /error.php
	<Directory "C:\xampp\htdocs\sun">
		Order allow,deny
		Allow from all
	</Directory>
	<Directory "C:\xampp\htdocs\sun">
                 php_value include_path ".;C:\php\pear;C:\htdocs\sun\xx"
	</Directory>
</VirtualHost>

Using a php_value directive you can define the include path for that VirtualHost right from conf file – thank God.

Mr. Grover

October 5th, 2009

Mr. Grover

One of the better pictures I’ve taken with my iPhone. I took this in Vancouver this past April went I went to visit a friend of mine, Rishi.

MySQL: Backup Database and Upload to Amazon S3 via PHP

August 29th, 2009

Update (Dec 30/10) The following is how to load the dump into a db:

Code:
mysql -u #username# -p #database# < #dump_file#

I wrote a post a few years ago about a quick way to backup a MySQL database using email. Since then I’ve updated that script to upload the file to Amazon S3 instead of emailing it. I use an Amazon S3 PHP Class you can find here to make it happen. Your also going to need cURL enabled on your server. On Ubuntu/Debian that’s as easy as:

Code:
sudo apt-get install php5-curl 

Here is the script:

Code:
require_once 'S3.php';

if (!defined('awsAccessKey')) define('awsAccessKey', 'xxxxxxxxxxxxxxxxxxx');
if (!defined('awsSecretKey')) define('awsSecretKey', 'xxxxxxxxxxxxxxxxxxx');
//
// Check for CURL
if (!extension_loaded('curl') && !@dl(PHP_SHLIB_SUFFIX == 'so' ? 'curl.so' : 'php_curl.dll')) {
	exit("\nERROR: CURL extension not loaded\n\n");
}

$tmpDir = "/tmp/";
$user = "dbuser";
$password = "dbpassword";
$dbName = "dbname";
$prefix = "db_";

$sqlFile = $tmpDir.$prefix.date('Ymd_hisA').".sql";
$attachment = $tmpDir.$prefix.date('Ymd_hisA').".tgz";

$creatBackup = "mysqldump -u ".$user." --password=".$password." ".$dbName." > ".$sqlFile;
$createZip = "tar cvzf $attachment $sqlFile";
exec($creatBackup);
exec($createZip);

if (!file_exists($attachment) || !is_file($attachment)) {
	die("ERROR: No file");
}

$s3 = new S3(awsAccessKey, awsSecretKey);
$result = false;
if ($s3->putObjectFile($attachment, 'bucket-name', baseName($attachment), S3::ACL_PRIVATE)) {
	$result = true;
}

unlink($sqlFile);
unlink($attachment);

Taking Felix for a Checkup

August 26th, 2009

photo.jpg

Apache: Stripping/Remove the www from URLS

August 19th, 2009

For reasons I won’t go into, I wanted to force Apache to strip the www from the URLs. So if someone typed in http://www.abc.com, Apache would automatically send them to http://abc.com. First thing to do is make sure ModRewrite is enabled, once that’s done simply put the following in your VirtualHost configuration or in the associated .htaccess file:

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Setting Different PHP Include Paths per Apache Virtual Hosts

July 15th, 2009

I was always curious how to set different PHP include paths per Virtual Host in Apache. I didn’t want to use an .htaccess file hack or the PHP function set_include_path. After some digging, I came across a post on a mailing list showing how it’s done using a Directory directive:

Code:
# PHP OPTIONS ###########################
    <Directory /path/to/site>
        php_value include_path ".:/path/to/site:/another/path"
        php_admin_value session.entropy_file "/dev/urandom"
        php_admin_value session.entropy_length "512"
        php_admin_value session.auto_start 1
        php_admin_value session.use_cookies 1
        php_admin_value session.use_only_cookies 1
        php_admin_value session.cookie_lifetime 0
        php_admin_value session.cookie_secure 1
    </Directory>
# PHP OPTIONS ###########################

Las Vegas Blvd

May 6th, 2009

Las Vegas Blvd

Rogers iPhone 3G Roaming Charges – Canada to USA

April 29th, 2009

Update (May 6/09): I used 12 megs of data while in the States. Without the US Roaming package at the rate of $30/meg my total would have been $360!! With US Roaming plan $10/month + $1/meg = $22.

I’m heading to the States this weekend (I live in Toronto) and got a bit paranoid about what my roaming data (3G) charges would amount to. A quick look on the Rogers website confirmed my fears: $0.03/kb or $30/mb! That’s madness! I heard from a few people that Rogers had a US Roaming Package of some sort. I tried looking for it on the Rogers website, but couldn’t find it anywhere. I then somehow thought to search (on the Rogers website) for ‘Roaming’ and this appeared:

US Data Roaming Add-On – $10.00
Buy the $10/month U.S Data Roaming Add-On and then pay only $1/MB ($0.001 per KB) while roaming in the U.S

I called Rogers and had them add the package to my plan. You can remove it at anytime and only be charged for the month you used. Keep in mind this plan only covers data. Regardless if you have a text-messaging plan in Canada, in the States it’s $0.60 per text message. I don’t even want to know what voice + roaming would hit.

Friday Troubles

April 17th, 2009

What a way to spend Good Friday. I just sent this email to a few people at Big Blue explaining what happened…

_______________

Hey guys,

You may have noticed I was offline for most of the afternoon. My timing belt broke on the highway (401) while I was driving. I heard a (really) strange noise — the car lost all power and I quickly moved to the shoulder. I called some people and eventually got it towed off the highway. What a way to spend Good Friday (I’m Greek Orthodox). All that said, is it too early to ask for a raise? Ha, just joking. Have a good weekend guys.

Friday Troubles

Excerpts from Obama’s Speech at Prague, 2009 [Economist cover also]

April 15th, 2009

"Today, the Cold War has disappeared but thousands of those weapons have not. In a strange turn of history, the threat of global nuclear war has gone down, but the risk of a nuclear attack has gone up. More nations have acquired these weapons. Testing has continued. Black market trade in nuclear secrets and nuclear materials abound. The technology to build a bomb has spread. Terrorists are determined to buy, build or steal one…. Some argue that the spread of these weapons cannot be stopped, cannot be checked — that we are destined to live in a world where more nations and more people possess the ultimate tools of destruction. Such fatalism is a deadly adversary, for if we believe that the spread of nuclear weapons is inevitable, then in some way we are admitting to ourselves that the use of nuclear weapons is inevitable…. So today, I state clearly and with conviction America's commitment to seek the peace and security of a world without nuclear weapons. I'm not naive. This goal will not be reached quickly — perhaps not in my lifetime. It will take patience and persistence. But now we, too, must ignore the voices who tell us that the world cannot change." – Obama, Prague, 2009 [April 11-17 Economist]

On the IBM 1130

April 15th, 2009

“I built my first computer when I was twelve in Amarillo, Texas. At the time I was into hardware because you couldn’t really program things. No courses or books existed, and, as a twelve-year-old boy, I couldn’t ask my peers for help. So, I pounded the doors at the local IBM sales office until a salesman took pity on me. After we chatted for a while, he handed me a Fortran [manual]. I’m sure he gave it to me thinking, “I’ll never hear from this kid again.” I returned the following week saying, “This is really cool. I’ve read the whole thing and have written a small program. Where can I find a computer?” The fellow, to my delight, found me programming time on an IBM 1130 on weekends and late-evening hours. That was my first programming experience, and I must thank that anonymous IBM salesman for launching my career.” – Grady Booch (link)

Setting Up Memcached on Ubuntu/Debian and Windows XAMPP

March 9th, 2009

I have a big problem with writing things down. This inevitably leads me to spending excessive amount of time looking all over the internet for how to solve a problem. Most recently I was trying to remember the steps to get Memcached going on my Debian server and on my laptop.

Luckily I came across this comment on php.net, which explains nicely how to get this going on Debian/Linux. The only thing I needed to do was make sure g++ was installed (i.e. apt-get install g++). Here are the steps:

Code:
-------------------------
# Prerequisite Install
-------------------------
# Download & install libevent (memcached dependency)
wget http://www.monkey.org/~provos/libevent-1.4.8-stable.tar.gz
tar xfz libevent-1.4.8-stable.tar.gz
cd libevent-1.4.8-stable
./configure && make && sudo make install

# Create a symlink to libevent
sudo ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib

# Download & install memcached
wget http://danga.com/memcached/dist/memcached-1.2.6.tar.gz
tar xfz memcached-1.2.6.tar.gz
cd memcached-1.2.6
./configure && make && sudo make install

# Run memcached as a daemon (d = daemon, m = memory, u = user, l = IP to listen to, p = port)
memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211

-------------------------
# PHP5-Memcache Install
-------------------------
# Download the extension module
apt-get install php5-memcache

# Edit /etc/php5/conf.d/memcache.ini and uncomment the following line by removing the semi-colon
extension=memcache.so

# Restart apache
/etc/init.d/apache2 restart

-------------------------
# Test Install
-------------------------
# Create a file 'memcache_test.php' in your webroot and paste the following:
<?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";

$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";

var_dump($get_result);
?>

In Windows (assuming you have XAMPP installed) go into your php.ini (check phpinfo for location) file and un-comment the following:

Code:
...
extension=php_memcache.dll
...
[Memcache]
memcache.allow_failover = 1
memcache.max_failover_attempts=20
memcache.chunk_size =8192
memcache.default_port = 11211
...

Then head to Jellycan Code and download the Windows memcached port (binary). At this point you should be able to launch the .exe and run the sample code above.