Voice From Beyond

My friend Danny passed away way too young at the age of 24.  He drove off an embankment and that was the sad end for him.  A while after I was in my trailer where I lived in Arcata, CA when the phone rang. “Hey man it’s Dan,” the voice on the line said. I don’t know any other Dan and clearly from the tone he not only expected me to know him, but expected me to be surprised too. I can’t describe the feeling of getting a phone from the “other side.” It felt like the blood rushed out of my body.  I’m sure I turned as “white as a ghost” as the expression goes … as white as the ghost that apparently was speaking to me.

We often talk about ghosts and the after life, do we believe or not, but for the most part we do not know.  Here I was facing the prospect of moving from the whelm not knowing to having an actual experience.  What will become of me now?  I’d be that crazy guy swearing he knows and has talked to the dead, perhaps delivering messages to his family.  My world was about to change for sure … one I replied. There was a chilling cold accompanying the vacant feeling of blood.

“What? Danny?” I managed to say rather meekly. “No, Ken, man.  It’s Ken,” came a reply of relief.  My consciousness came back to reality.  It was my old buddy Ken from when I lived in Maine. He was still alive and kicking … and perfectly capable of making a phone call.  It felt good to get the blood circulating through my body again.  However,it would have been good to talk to Danny one more time.

How the Niagara Falls Formed

I left Niagara Falls without knowing much of how it was formed, so I did my own research and learned some very interesting things:

Niagara Falls was formed around 11,000 years ago when the receding glaciers carved out the great lakes.

The melt water began to flow over the Niagara Escarpment which is a wonder in itself. It is a long cliff that extends 1,000 miles from east-central Wisconsin to Upstate New York. It forms the northern boundary of Lake Michigan and Huron and Southern boundary to Lake Ontario. It has existed for 400 million years and is believed to be the edge of an ancient basin, the Michigan Basin.

When the glaciers retreated the escarpment was exposed and the melting water water began to flow over its edge. The water eroded the softer rock at the base of the escarpment wearing it away until the harder rock at the top of the cliff caves away. This keeps the flowing water flowing in a vertical fashion (a falls) rather than eroding into a cascade as the falls carved its way southward along the Niagara River. Over the 11,000 years that falls existed it carved the basin, moving it 6.8 miles southward from its original location at Lewiston, New York.

If you do the math that comes to and average of about 3 feet 4 inches per year, however while the water was flowing the erosion was probably greater. You see, after the falls was formed, for a few thousand years there was a time that it ceased to exist.

There is evidence that 8,000 years ago the water levels of the Great Lakes were lower by about 40 to 50 meters. During that time Niagara Falls would have dried up until the water levels rose again.

At the bottom of Lake Huron in the Bruce Peninsula there are the remnants of many waterfalls, many of these falls were greater than Niagara Falls, that used to exist during the time when the water levels were low.

Today the erosion caused by the Falls is greatly reduced by human intervention, mainly channeling about 75% of the water for hydroelectric power production.

Information for this article was gather from the following sources:
https://en.wikipedia.org/wiki/Niagara_Escarpment
http://onmilwaukee.com/visitors/articles/niagaraescarpment.html
https://en.wikipedia.org/wiki/Bruce_Peninsula
https://en.wikipedia.org/wiki/Michigan_Basin
http://historyoftheearthcalendar.blogspot.com/2014/03/march-12-michigan-basin.html

CORS POST to AWS S3 using PHP and AJAX

I’m going to post this here in case it helps someone down the line.  I spent days trying to get this to work including countless hours with AWS (Amazon Web Services) support, who go above and beyond to try to help.  Note: I modified the code a bit from my working, live example, so the code below is untested.  There may be a few minor bugs that I will let you work out :-)  And, sorry for the lack of formatting on the code below.

The problem is to upload a file from an HTML form on a website and have it go directly to an AWS S3 Bucket.  Sounds easy, right?  Here are the issues:

  1. The POST upload will work directly, however when we put the request in AJAX we run into issues with the denial of Cross Origin Requests Sharing (CORS).  This means a request from one domain is not accepted by a different domain … unless it is approved on the receiving domain’s server configuration.
  2. The request requires a policy and a signature that need to be generated on the requesting server.  The signature includes information (filename) of the file being uploaded, so it needs to be generated AFTER the file is selected.  Unless the filename is set in advance.
  3. The secret access key needs to be secure so the public may not see it.
  4. The AJAX upload POST request needs to be in a particular format.

The solutions:

  1. A few years ago AWS began to allow CORS on the S3 Buckets.  THis needs to be configured.  I’ll show you how to do in in a bit.
  2. I found many examples how to do this with Rails, but not with PHP.  The policy and signature may be done with AJAX requests to PHP scripts.  I’ll show you how i did this in a bit.
  3. The secret access key may be hidden in the PHP scripts as mentioned above.
  4. I’ll show you this.  I found it in this StackOverflow question here: http://stackoverflow.com/questions/11240127/uploading-image-to-amazon-s3-with-html-javascript-jquery-with-ajax-request-n.  I modified it a bit to work with PHP.

Here is the code below:

Enabling CORS on your S3 Bucket

Log into your AWS account and browse over to S3.  Select the bucket that you wish you upload to and click on “Properties.”  Open the “Permissions” area.  Click on “Edit CORS Configuration.”  There you will see the CORS Configuration.  Change it to the code below substututing [YOUR_FULL_DOMAIN] for your full domain name.  This si the domain from where the POST request will originate.  You may use one wildcard (ex: http://*.yourdomain.com).  You may also just use a straight wildcard here * to open it up to all origins.  This is helpful for testing and debugging.

<?xml version=”1.0″ encoding=”UTF-8″?>
<CORSConfiguration xmlns=”http://s3.amazonaws.com/doc/2006-03-01/”>
<CORSRule>
<AllowedOrigin>[YOUR_FULL_DOMAIN]</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

PHP Scripts to Generate Policy and Signature

I use two different scripts.  Each will be called with an AJAX request.  These will be separate PHP files on your server:

PHP to generate the policy.  (I saved this as filename:  php/s3_upload_create_policy.php):

<?php

$key = $_GET[‘key’]; // This is the filename as it will be uploaded to S3
$type = $_GET[‘type’]; // TThis is the file type

date_default_timezone_set(‘America/Los_Angeles’); // Update to your time zone
$now = strtotime(date(“Y-m-d\TG:i:s”));
$expire = date(‘Y-m-d\TG:i:s\Z’, strtotime(‘+ 10 hours’, $now)); // This sets the policy expiration time. I select 10 hours from now, but it can be much less. Keep in mind time zone differences from your instance time to the time of the AWS region that your bucket is located.

$aws_access_key_id = ‘[YOUR_ACCESS_KEY_ID]’; // Substitute for your access key ID
$bucket = ‘[YOUR_S3_BUCKET]’; // Substiture for your S3 Bucket name (ex: my_aws_bucket)

$acl = ‘public-read’; // if you prefer you can use ‘private’
$url = ‘http://’.$bucket.’.s3.amazonaws.com’;

$policy_document=’
{“expiration”: “‘.$expire.'”,
“conditions”: [
{“bucket”: “‘.$bucket.'”},
[“starts-with”, “$key”, “‘.$key.'”],
{“acl”: “‘.$acl.'”},
[“starts-with”, “$Content-Type”, “”]
]
}’;

// create policy
$policy = base64_encode($policy_document);

echo $policy;

?>

PHP to generate the signature.  (I saved this as filename:  php/s3_upload_create_signature.php):

<?php
$policy = $_GET[‘policy’];
$aws_secret_key = ‘[AWS_SECRET_ACCESS_KEY]’; // Substitute for your secret access key

function hmacsha1($key,$data)
{
$blocksize=64;
$hashfunc=’sha1′;
if (strlen($key)>$blocksize)
$key=pack(‘H*’, $hashfunc($key));
$key=str_pad($key,$blocksize,chr(0x00));
$ipad=str_repeat(chr(0x36),$blocksize);
$opad=str_repeat(chr(0x5c),$blocksize);
$hmac = pack(
‘H*’,$hashfunc(
($key^$opad).pack(
‘H*’,$hashfunc(
($key^$ipad).$data
))));
return bin2hex($hmac);
}

function hex2b64($str)
{
$raw = ”;
for ($i=0; $i < strlen($str); $i+=2)
{
$raw .= chr(hexdec(substr($str, $i, 2)));
}
return base64_encode($raw);
}

$signature = hex2b64(hmacsha1($aws_secret_key, $policy));
echo $signature;

?>

Page Script

And finally we need the HTML page script.  This includes the javascript and the form.

Here is the javascript.  This is mainly copied from the StackOverflow question mentioned above, with a few minor tweaks including nested AJAX requests to the PHP documents above to generate policy and signature.  You will need JQuery as well.  I’m using 2.1.3:

<script type=”text/javascript” src=”/js/jquery-2.1.3.min.js”></script>
<script type=”text/javascript”>

function uploadFile() {

bucket_name = [YOUR_AWS_BUCKET_NAME]; // Substitue with your bucket name
access_key_id = [ACCESS_KEY_ID]; // Substitue with your Acess Key ID

var file = document.getElementById(‘file’).files[0];
var fd = new FormData();

var key = ‘uploaded/’+file.name;
var type = file.type;

theSource = ‘/php/s3_upload_create_policy.php?key=’+key+’&type=’+type;

var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
policy = xmlhttp.responseText;

theSource2 = ‘/php/s3_upload_create_signature.php?policy=’+policy;

var xmlhttp2;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp2=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp2=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp2.onreadystatechange=function() {
if (xmlhttp2.readyState==4 && xmlhttp2.status==200) {
signature = xmlhttp2.responseText;

fd.append(‘key’, key);
fd.append(‘acl’, ‘public-read’);
fd.append(‘Content-Type’, file.type);
fd.append(‘AWSAccessKeyId’, access_key_id);
fd.append(‘policy’, policy);
fd.append(‘signature’,signature);

fd.append(“file”,file);

var xhr = new XMLHttpRequest();

xhr.upload.addEventListener(“progress”, uploadProgress, false);
xhr.addEventListener(“load”, uploadComplete, false);
xhr.addEventListener(“error”, uploadFailed, false);
xhr.addEventListener(“abort”, uploadCanceled, false);

xhr.open(‘POST’, ‘https://’+bucket_name+’.s3.amazonaws.com/’, true); //MUST BE LAST LINE BEFORE YOU SEND

xhr.send(fd);

}
}
xmlhttp2.open(“GET”,theSource2,true);
xmlhttp2.send();

}
}
xmlhttp.open(“GET”,theSource,true);
xmlhttp.send();

}

function uploadProgress(evt) {
if (evt.lengthComputable) {
var percentComplete = Math.round(evt.loaded * 100 / evt.total);
document.getElementById(‘progressNumber’).innerHTML = percentComplete.toString() + ‘%’;
}
else {
document.getElementById(‘progressNumber’).innerHTML = ‘unable to compute’;
}
}

function uploadComplete(evt) {
/* This event is raised when the server send back a response */
alert(“Done – ” + evt.target.responseText );
}

function uploadFailed(evt) {
alert(“There was an error attempting to upload the file.” + evt);
}

function uploadCanceled(evt) {
alert(“The upload has been canceled by the user or the browser dropped the connection.”);
}

</script>

And finally here is the HTML.  This is mainly copied from the StackOverflow question mentioned above:

<form id=”form1″ enctype=”multipart/form-data” method=”post”>
<div class=”row”>
<label for=”file”>Select a File to Upload</label><br />
<input type=”file” name=”file” id=”file”/>
</div>
<div id=”fileName”></div>
<div id=”fileSize”></div>
<div id=”fileType”></div>
<div class=”row”>
<input type=”button” onClick=”uploadFile()” value=”Upload” />
</div>
<div id=”progressNumber”></div>
</form>

The last mystery will be how to get the Access Key ID and Secret Access Key.  This is done in AWS’s IAM service.  I will not go into detail.  You need to set up an IAM user that has access to the S3 Buckets.  I did this a long time ago and do not have the specific steps.

 

Raccoon Communication

I woke up early this morning.  After making use of the time to get a little work done, I lay myself down to try to sleep a little bit more.  It was working too, however just as I was about to doze off I heard a strange sound … like a cooing.  I discounted it at first, but the cooing persisted.  It was coming from outside, I could tell, so I wasn’t worried about it.  I knew it was likely a raccoon.  As long as it didn’t find its way through the cat door and inside to the cat food, we won’t have any trouble.  There hasn’t been a raccoon invasion in a long time.  Until now I had not known if they had just not been around or if they had given up trying to get through the cat door.  I used to block it off every night since the last invasion.  However, I had grown lazy about it after a month or so of consistent cat door closure and stopped doing it.  Six or so months had past without an incident.  I, as well as the cats, have been happy about that.

The cooing outside continued.  Sometimes closer, sometimes at a greater distance.  I had to investigate, and I looked out the window into the dark street.  I could hear the cooing across the street.  Then I got a visual and saw the critter running down the sidewalk.  The silouette definitely looked like a raccoon, but I was not sure.  I watched as it crossed the streets, up and down, back and forth.  Then into our yard where it climbed up the tree.  I had to go out to investigate, and I put on my robe.

I turned on the porch light and cracked open the front door.  I heard nothing so walked on out onto the lawn.  Then, I heard the rustling of the tree and the scampering of the critter as it ran away.  That would have put an end to my raccoon adventure for the night, had it not been for my curious and humorous mind.  “What strange behavior,” I thought, for a creature of the night … the scampering back and for and the constant chattering.  Wouldn’t a thieving animal want to be more stealthy as it went about its mission?  The only thing that I could think of is that it had a partner in crime and had been separated from it.  It was running around looking for it … back and forth, calling out to its friend “coo, coo.”  No, the poor raccoons did not have the convenience of cell phone technology to text each other, “Where the f$#% are you.”  Or did they?  Perhaps it was running back and forth and up the tree trying to get the best signal.  The cooing … the phone seeking out a signal.  Raccoon Cellular is just not that strong in Southampton, Benicia.

It’s Not the Truth …

“It’s not the truth.  It’s what I believe to me the truth.”  Huh?  Here we are distinguishing between the truth and what one believes to be the truth.  OK, people have a hard time telling the difference.  To compare the truth with a belief about the truth is like comparing a painting of a landscape with the actual landscape.  Even to most accurate painting is going to have some variation.  On top of that, the canvas is just not big enough to include the entire landscape.  A belief is the canvas for which the person paints their estimation of the landscape of truth.  It will never be 100% accurate, but it gives us somewhere to roam, otherwise we only will roam within our immediate surroundings.

On a simple level, I have to believe that there is a roadway, a bridge and that my car is in the driveway before I will attempt to go out the front door and drive to another City.  Those beliefs are based on my experience of reality.  However I have not experienced everything.  On each journey, I will add more to those beliefs.  Each time expanding the beliefs a fraction of an inch closer to reality.

I must be humble to know by beliefs will never 100% be the truth about reality.  And, one piece of new information may change everything.

A Real Abbott and Costello Moment

The scene:  Mom & Jay watching the Giants’ baseball game.  Mike Krukow and Duane Kuiper are announcing:

Krukow: He does that a lot like Bobby Bonds always did.
Mom (look of confusion on her face): Bobby Bonds?  Who is Bobby Bonds?
Jay: Bobby Bonds was Barry Bonds’ father.  (Mom still looks confused).
Jay (trying to guess what she is confused about.  Sadly, her cognitive abilities have been declining with her age):  Barry Bonds was the Giants’ big star that retired a few years ago.
Mom:  I know that, but I’ve never heard of Bobby Bonds (she’s trying to put things into perspective)
Mom (here it comes): Who played 1st?
Jay (in disbelieve she just asked that question.  I can’t think of how to reply until I just start laughing):  They both played left field.
Mom (starts laughing and references Abbott & Costello): Who played first (laughing).

She meant who played in Major League Baseball before the other.

Kirby Cove Swim, 2014

I failed the last time I did the Kirby Cove swim in 2012.  By the time I got to the opening of Aquatic Park I was still a quarter of a mile out.  I had to be picked up and repositioned.  In retrospect I wished I had just swum straight across and let the current do the work to carry me east.  That was my intention this year.   I’d rather end up across the bay early and swim parallel to the shore with the current than end up carried too far east and have to be repositioned again.

But ultimately it is up to the pilots.  We have to listen to the pilots even if we disagree.  It’s an issue of the safety of the entire swim and all the other swimmers.    We can’t get too far spread out, or the boat coverage is not as good.  They may also be aware of other hazard we cannot see with our fish-eyed view.

During the briefing we were instructed to swim directly south until we reached mid span of the bridge.  We wanted to go under the bridge south of mid span.  This is important because at that point the current splits, the southern current heads straight into the Bay.  The north current will start to head north to fill Richardson Bay, flow through the Raccoon Straight and head on up to San Pablo Bay.  If a swimmer is stuck in that northern current it becomes a fight to get across.

After we cross under the bridge, we were instructed to swim east for a while.  The current is stronger the further out we are, but we don’t want to be out too far to make it too difficult to get to the other side before the current carries us to the opening of Aquatic Park.  That is the balancing act with this swim … finding the sweet spot, far out enough to catch the current, but not too far out we can’t get in on time.

This briefing was contrary to my plan, but I had to let that go and trust the pilots and swim organizers.

We had the coverage of one kayak for every two swimmers.  We were to pod up with someone our speed.  I’m pretty slow and had a hard time finding another slow swimmer.  I podded up with someone I did not know too well, but suspected was faster than me.  He asked me how fast I was in the pool.  He said he was about the same … but that’s another story.  That’s the pool.

We swam together for about 25 minutes.  He was backstroking to keep pace with me.  Eventually he started to pull ahead, splitting the kayak coverage.  The kayaker was staying in-between us, with each minute getting further away and I was swimming more alone.

I caught up to him at the bridge.  I crossed under about 100 yards south of mid span, so I was in good shape.  The kayaker instructed me to swim direct east.  I felt good that I made it past mid span and was perfectly OK abandoning my desire to keep swimming south.

From that point on I had the kayaker all to my self, Bill James, a very experienced pilot for our swims.  He told the other swimmer to go on ahead and catch up with another kayak.  Later I learned that he did this with no problem.

After about 10 minutes of swimming east Bill James instructed me to start heading into the shore.  Not directly at 90 degrees, but at about 30 degrees.  I still wanted to get across as soon as possible, but trusted his guidance.

It turned out to be perfect as you can see from my map:

KirbyCove2014

Unfortunately I do not have a GPS trail of my last attempt, but what I think happened then is a failure to cross under the bridge before mid span.  Then I must have got caught in the northern current, which kept me out too far and for too long.

Now, what if I did the swim my way?  Here’s the deal … I’m a slow swimmer, yet I completed this swim mid pack instead of towards the end, like I usually do.  I finished before swimmers that I know are faster than me.  The reason?  After interviewing a few of them I learned that they went too far south where the current was not as strong and even reaching where there is a back eddy near Crissy Field.  If I did the swim my way … that too would have been my fate.  Instead, I had the perfect line.  I attribute this to my highly skilled pilot, Bill James.

Here are GPS details of the swim: http://connect.garmin.com/activity/540008064

Buzzard Road Kill

I almost hit a buzzard on my bike ride today.  I was cruising down a slope about 25 mph when I heard the rustling of a startled animal in the bushes ahead of me.  Suddenly the shape of a huge bird flew out in front of me, just a few feet … I could have reach out and touched it!  I could hear the powerful trusts of its wings as it pushed against the air trying to get further out in front of me.  It’s big read head looked back at me as it gave a couple more trusts of its wings and veered off to the left.  “Wow!” I thought.  Then I started to wonder … who eats the buzzards when they become road kill?

Salton Sea

I just had an interesting visit to a very fascinating place that may not be around very much longer, the Salton Sea.

Most of this information comes from this website: http://saltonseamuseum.org.  Please check it often for updated information.

Most lakes have been around for thousands of years and are a part of the natural balance of nature.  The Salton Sea was made by accident.  An engineering mistake flooded the waters of the Colorado River into the Imperial Valley over the course of almost two years.  The valley was not new to water:

View Larger Map

Above you can see how the area where the Salton Sea is now used to be a part of the Gulf of California.  Over the centuries the Colorado River dumped enough sediment to cut the Imperial Valley off.  Over the years 5 lakes have come and gone from the region.

Because

 

You Never Know What May Happen

I was walking down the street, thinking and worrying about the outcome of something.  I don’t quite remember what.  There some paramedics across the street at a restaurant wheeling a person into the back of an ambulance.  I did not pay it much attention because what I was worrying about seemed more important.  I must have just started thinking positive about the situation because when an old woman’s voice said as I passed a bench, “You never know what’s going may happen,” I was filled with joy about the positive things that can take place that I can not even imagine with my worrisome mind.  I turned to look at her, smiled and said with deep sincerity, “Thank you.”  But instead of what I was expecting, an old woman reading my mind and filling me with the wisdom I needed in the moment, I saw a frail old lady filled with worry herself.  My joy sank.  She was watching the scene across the street, staring her own mortality right in the face.  She said to me, “One minute you might just be sitting there, enjoying lunch and the next minute this …” she motioned to the ambulance.  I said, something back to her, perhaps a little insensitive, “You never know what good may happen,” attempting to give some of the unintended wisdom she gave to me back to her.  I don’t think it worked.  She just shook her head with sadness in her eyes, “You never know what’s going to happen.”  I walked on, a little later regretting I did not stay with her a little longer.