sim.plified.com

Chris Pollock

Chris Pollock - web developer (PHP/mySQL & ASP.NET)
undivided… my thoughts on world, family, church, business, technology and Jesus Christ (all in all)

Pushing Leads to Salesforce with PHP

Recently our company began a trial of Salesforce.com.  In doing so we opted not to layout the cash for the program that gives you full API access (at the moment any ways).  I needed a way to push leads into the system.  They have a standard web-to-lead process that requires a form submission and then post back to return URL.  I already had a lot of forms that I was using to capture data.  Instead of reworking all my forms, I just created a way to post to the Salesforce web-to-lead form from the server side. 

I started by creating a basic function which passes in the data I want to capture and pushes it to the Sales force form.

    function add_to_salesforce($source, $name, $email, $company, $city, $state, $zip, $phone, $description, $street = "")
    {
        // simple way of breaking apart the name
        $names = split(" ", $name);
        
        //set POST variables
        $url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
        $fields = array(
                                'last_name'=>urlencode($names[1]),
                                'first_name'=>urlencode($names[0]),
                                'street'=>urlencode($street),
                                'city'=>urlencode($city),
                                'state'=>urlencode($state),
                                'zip'=>urlencode($zip),
                                'company'=>urlencode($company),
                                'description'=>urlencode($description),
                                'email'=>urlencode($email),
                                'phone'=>urlencode($phone),
                                'mycustomefieldid' => urlencode($source), // custom field
                                'oid' => 'youridgoeshere', // insert with your id
                                'retURL' => urlencode('http://www.yourreturnurl.com'), // sending this just in case
                                'debug' => '1',
                                'debugEmail' => urlencode("youremail@youremail.com"), // your debugging email
                        );
        
        //url-ify the data for the POST
        foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
        rtrim($fields_string,'&');
        
        //open connection
        $ch = curl_init();
        
        //set the url, number of POST vars, POST data
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_POST,count($fields));
        curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
        
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch,CURLOPT_FOLLOWLOCATION, TRUE);
        
        //execute post
        $result = curl_exec($ch);
        
        //close connection
        curl_close($ch);
    }

 

Once that was setup all I had to do was call the function (which I wrapped in a class with something like this:

$myclass = new Myclass;
$myclass->add_to_salesforce("Contact Page", $name, $email_address, $company, "", "", "", $phone, $enquiry);
      

Works like a charm so far.  If you’ve got a slicker way of perfoming this operation, let me know, I’d love to learn how you did it.

[ Leave a Comment ]

Non-Charitable Charity – Why Giving the Government’s Way is Void of Love

It’s tax time again and for the past couple of years I’ve been struck that my method of giving is totally unrecognized by the government.  Before you mistake this as a complaint, it’s not, it’s simply an observation that I wish to bring to the attention of those that are interested in love.  It has slowly become my conviction that what the government calls “charity” is exactly self-interest in disguise.  Why self interest?  Giving to get.  If I give X to a valid 501(c)3 organization I’ll get my tax write off.  I admit that loving the way God tells us to love is full of rewards, but none of those rewards have anything to do with mammon.  Giving to get a tax write off is simply NOT charity… call it what you will, but don’t call it love. 

For more clarity I call your attention to one of the most well known passages of Scripture.  Where do we get our understanding of love?  Is it not from the story of the Samaritan?  After all, who loved their neighbor?  The one who picked up a stranger, washed his wounds (at expense to himself) and paid for his needs of recovery.  Where were the other two headed (the priest and the Levite), but off to their jobs at the governmentally-recognized institution. 

Ironically the government does not recognize “contribution to a specific individual” or “contribution to a nonqualified organization”.   The Samaritan’s expenses would not have been recognized by the government.   The irony is rich and hopefully the implications are clear.  What God desires is not for us to leverage and extra percentage or two by getting a tax write off, but rather to be open to do radical works of love to those whom won’t be recognized or “qualified” as outlets for the world’s charity.

[ Leave a Comment ]

Super Geeky: Removing Subversion files from a directory with Windows Powershell

There have been times when I’ve wanted to remove the .svn subversion repository folder from an entire directory.  With Windows Powershell, you can do that in a one line command:

get-childitem C:\your-directory -include .svn -recurse -force | foreach ($_) { remove-item $_.fullname -recurse -force}

The one thing I discovered is that you need to include “-force” in order for windows to “see” the hidden folders and files.

I highly recommend you add the –whatif parameter to the end of the remove-item command before you run this just to be sure its only hitting the files you want.

This article was helpful in getting me on track.

[ Leave a Comment ]

Sliding content from a partial height with jQuery.

One of the request for the Pattern Tap Stream was the ability to show part of a post that then "slide down" when the reader clicked "read more".  At first I thought this would be a cinch using jQuery's "slideDown()" command.  I soon found that it did not support initially being open to a partial height.  Below is a my brief explanation and code for how I accomplished a partial height slide with jQuery.

Click here for the Demo Page.

  1. Let the height of the box be its full size when it loads in the browser.
  2. Attach a new attribute to each box the holds the height of the open slider div.
  3. Set the height to the partial height you want.  Remember to consider the line-height with the box height so that you don't have you text cut off.

Here's the code

var sliderHeight = "100px";
 
$(document).ready(function(){
    $('.slider').each(function () {
                var current = $(this);
                current.attr("box_h", current.height());
            }
 
     );
 
    $(".slider").css("height", sliderHeight);
    $(".slider_menu").html('<a href="#">Read More</a>');
    $(".slider_menu a").click(function() { openSlider() })
 
});
 
function openSlider()
 
{
    var open_height = $(".slider").attr("box_h") + "px";
    $(".slider").animate({"height": open_height}, {duration: "slow" });
    $(".slider_menu").html('<a href="#">Close</a>');
    $(".slider_menu a").click(function() { closeSlider() })
}
 
function closeSlider()
 
{
    $(".slider").animate({"height": sliderHeight}, {duration: "slow" });
    $(".slider_menu").html('<a href="#">Read More</a>');
    $(".slider_menu a").click(function() { openSlider() })
}

See this in action on the Pattern Tap Stream page.

[ Leave a Comment ]

Accessing Google Spreadsheet with PHP

Google spreadsheet can be used as a pseudo-database when setting up a more formal mySQL table is more than you’re looking for.  I was looking to write a simple app that pulled in email addresses and sent a short email (it will be run on a monthly cron as a reminder).   I wanted to easily be able to manage those email addresses.  Google Spreadsheet was the ticket. 

See my code below where I access the sheet, pull out the second row, and sends an email to any string the qualifies as an email address.

Consult the Google Spreadsheet API for more access methods.  I am using the “cells” feed.

   1: <?php
   2:  
   3:     $key = "THE KEY FOR YOUR SPREADSHEET";
   4:     
   5:     $url = "http://spreadsheets.google.com/feeds/cells/$key/1/public/values";
   6:     
   7:     $ch = curl_init();
   8:  
   9:     // set URL and other appropriate options
  10:     curl_setopt($ch, CURLOPT_URL, $url);
  11:     curl_setopt($ch, CURLOPT_HEADER, 0);
  12:     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  13:     
  14:     // grab URL and pass it to the browser
  15:     $google_sheet = curl_exec($ch);
  16:     
  17:     // close cURL resource, and free up system resources
  18:     curl_close($ch);
  19:  
  20:     $doc = new DOMDocument();
  21:     $doc->loadXML($google_sheet); 
  22:     
  23:     $nodes = $doc->getElementsByTagName("cell");
  24:         
  25:     if($nodes->length > 0)
  26:     {
  27:         foreach($nodes as $node)
  28:         {
  29:             // 2nd row is the email row.
  30:             if ($node->getAttribute("row") == 2)
  31:             {
  32:                 if (eregi("^[\.\+_a-z0-9-]+@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$", $node->nodeValue) ) 
  33:                 {
  34:                       mail($node->nodeValue, "Mail Subject", "Mail Message.", "From: email@yourdomain.com");
  35:                 }
  36:                     
  37:             }
  38:         }
  39:     }
  40:  
  41: ?>

In order to access the sheet with PHP I had to set the sheet to “public”.  There is probably a way to create a secure connection with an Auth Token, but that was the not the purpose of this exercise.  The key for your spread sheet can be found in the URL of the sheet when you have it open in the browser.

Technorati Tags: ,

[ Leave a Comment ]

Magento: Jump back to Payment Screen when Payment Declined

On my installation of Magento, I wanted to return the user to the payment screen when their card was declined.  This is a bit of a hack, but it does work.  I simply inserted some custom JavaScript into the opcheckout.js file which is located in /skin/frontend/default/default/js/

I searched my error message for the word "declined" and based on that, push the user back to the payment screen just before showing the alert box.

if (msg.indexOf("declined") > -1)
{
     checkout.accordion.openSection('opc-payment');
}

I insert this around line 760, right before the "alert(msg)".

 

Technorati Tags:

[ Leave a Comment ]

Laptop cooling stand – Keep your lap cool

I bought a new Dell Vostro a couple months back.  I really like it.  But what I realized the very first day is that I was going to need something to pad and cool my lap.  The laptop runs hot and was no fun to have on my lap after about 15 minutes.  I had seen one of my friends using a laptop stand, so I knew they existed.  I went on a search and found what I believe to be the perfect laptop stand.

CIMG7181

CIMG7186

It’s 1) affordable, 2) one piece 3) nice looking, 4) covered in fabric 5) angled perfectly 6) convenient to store and use.  Like I said, it’s the perfect laptop stand.  I have been so pleased with it I haven’t removed it from the bottom of the computer since I bought it.  It works great if I’m on the couch or at a table.  I highly recommend the ALLSOP Cool Channel Notebook Stand, purchase your by clicking on the link below (I’ll make a little dough).

[ Leave a Comment ]

Pattern Tap: We dig Jay because we got Dugg and not buried

On Sunday, August 10, one week ago, we experienced our first hit from Digg.  We had talked about the possibility of being Dugg but were by no means prepared for what that meant.  On our biggest day previous to this we saw a max of around 9k visitors.  Looking at the graph below you can see we far exceeded that topping out at almost 50k visitors on that one day.

ScreenShot001

So what.. people get dugg all the time, what's the big whip?  Well, currently PT is sitting on a shared virtual host with only 256MB of RAM.  This hit should of sent our server home crying and returning all sorts of "sorry, we were not prepared for you" types of errors.

However, thanks to the good foresight of our kung fu server master, Jay Janssen, the server did not come grinding to halt, but continued to gracefully serve pages as the onslaught of visitors continued.  Jay is a mysql guru who works for Yahoo!  (he's also a good friend and my roommate from R.I.T.).

The secret sauce was lighttp, a server component that allows you to bypass apache for non dynamic requests (e.g. jpg, js, css files).  See the graph below and you can see what lighttp did for us as the requests/sec. continued to mount.  lighttp skyrocket up to 110 req/sec. while apache laid low.

p4.sl1.simupt.com-lighttpd_rb-day

Long story short, apache would have never been able to handle 110 req/sec on our current configuration and our site would have been dugg and buried.

Kudos to Jay for his great work on keeping Pattern Tap alive and well.

You can find out more about Jay and his server kung fu at: http://mysqlguy.net/

Technorati Tags: ,,,

[ Leave a Comment ]

How To: Build a Custom Ergonomic Computer Desk

As a web developer, I spend LOTS of time at the keyboard.   For me, having an ergonomic computer desk is an absolute essential.  Recently, making the transition to working full time for myself, I decided that I needed a quality computer desk that would be adjustable and ergonomic.  I quickly found myself frustrated with the high cost of ergonomic desks on the market.

Researching desks started to give me an idea of what I did and did not want in a computer desk.  After a discussion with a friend I decided to make the plunge into building a desk to fit my needs.

Basic Strategy

I'm not a woodworker at heart, so I knew I needed to keep the construction of the desk simple.  I decided to build the desk legs and foundation using Kee Klamp fittings and fence post.  The aesthetic look isn't for everyone, but it makes construction MUCH EASIER. Building the foundation of the desk is as simple as cutting some pipe and using an Allen wrench.

For the desk top I used a custom cut piece of MDF that I primed, painted and sealed (a must if you are using MDF).

To make the desk ergonomic I custom cut some of the remaining MDF into a keyboard tray and bought an articulating keyboard adjustable unit.

Getting Started

The first thing I did was make a plan.  I drew out several sketches on some graph paper to see how I wanted the desktop surface to look.  Having a particular space in mind, I made one side of the desk longer than the other.

Here's my drawing:

CIMG6867

Cutting the Top

After I had my design, I marked the outline onto a  4×8 sheet of MDF.  I used the top of a coffee can as a stencil for my rounded corners.

CIMG6869

I supported it on saw horses and made the first couple of straight cuts with a circular saw.  I used a straight edge to guide the circular saw so that the edges were perfectly straight.

CIMG6865

CIMG6870

Then I used a HIGH QUALITY jig saw with a SHARP BLADE to cut out the curves and corners.

TIP: You need to be careful with how you support MDF — it is not as study as plywood and could crack if mishandled.

TIP: I borrowed a high quality jig saw. The performance of a high quality jig saw with a sharp blade is astounding compared to a cheaper unit.

An idea I got while cutting the desk was to include a section in the back for cord management.  I cut out an inch deep section in the back of the desk to accommodate power cords and various cables running off the desk.

CIMG6871

With that, the initial cut of the top was finished.

CIMG6872

At this point the desk had a rough edge.  I wanted a nice rounded edge.  Thankfully, a friend of mine had a high quality router.  With a simple pass around the edge, the desk top went from a rough cut piece of material to a smooth edged desktop.

CIMG6875CIMG6877

Attaching the Base

At this point we were ready to start attaching the fittings that would connect the legs to the desk top.  I spaced out the Kee Klamp L61-7 fittings on the bottom of the desktop and screwed them in with 3/4" #10 wood screws.

The fence post was cut (you can use a pipe cutter or a sawz-all — or just have the home center do it for you) to just under the desktop height (measure a height that works for you) and then attached to the fittings.

CIMG6880

A Word About Kee Klamp Fittings and Fence Post

I chose to use Kee Klamp fittings on this project for several reasons.

1. They are easy to use.  I'm not a carpenter, so it was a quick and easy way to build a study foundation for a desk that would look good.  Kee Klamp fittings slip onto pipe and then "bite down" into the pipe with a set screw.  Normally they are used as an alternative to welding in the handrail world, but they work great for all sorts of DIY projects as well.

2. I am partner in a company that distributes them so I get a pretty good discount on them (if you're a DIYer, mention this post and I'll cut you 10% discount on the parts).  They can be expensive, but when you consider the time and resources saved in other areas I think they are "worth" the investment.  Literally, it took me minutes to get the desk upright once the desktop was cut out.

3. The Aluminum fittings (Kee Lite) have some aesthetic value for a modern looking office.

4. The size 7 (1 1/4") fittings work well with fence post.  I used about 3 1/2 - 8 foot lengths of galvanized fence posts that can be obtained at any home store.  Fence post is a lot cheaper than the using galvanized schedule 40 pipe (not to mention it's easier to work with too).

Building the Base

The base consisted of six uprights with a pipe running between each of the uprights. The cross supports made the entire unit very stable.  They are necessary so that the horizontal forces on the desk (like when moving it) are not placed upon the MDF.  I think without the cross supports it would be easy for the MDF top to crack and break.

The pipe is held in the fittings with a set screw that is tightened down with a standard allen wrench.

CIMG6883

Here the cross supports are added with Kee Klamp L10-7 Fittings.  They were staggered in height for even greater stability.   Once the desk is in its final location the fittings can be adjusted and retightened.

CIMG6884CIMG6885

Painting the Desk

Painting the MDF desktop is a must. Without paint, the first time you set a glass of water on your desk you'll really wish you hadn't!  The MDF grain swells very easily and also continues to put off dust.

I painted the desk top in a thee part process.

1) Primed with a NON WATER BASED - BIN Primer
2) Painted with an Indoor Latex Paint
3) Finished with a Polycrylic to provide a protective finish.

I put one coat of primer on the surface and two on the edges, sanding lightly in between each coat.  I also wiped the surfaces down with a tack cloth.  Using a mini roller made the paint go on quickly and smoothly.

CIMG6901

When I was painting both sides (for the keyboard tray and shelves), I supported them with nails driven into the saw horses.  This allowed minimal damage to the underside of the painted surface.

CIMG6898

CIMG6891

Here is the paint and Polycrylic that I used.

CIMG6902

Finished Painting:

CIMG6987

CIMG6992

Finishing Touches

At this point the basic desk was done.  Now the only thing that needed to be added was the keyboard tray.  I ordered an articulating unit from www.ergoindemand.com.  I found their customer service people very helpful.

Here is the unit I ordered.

Here is the desk in place, ready for keyboard tray.

CIMG7027

Once the desk is in place, I adjusted the cross pieces to make sure that they were spaced properly and evenly.

CIMG6998

First I screwed the unit into the bottom of the keyboard tray.

CIMG7030

Then I screwed the track onto the bottom of the desk.

CIMG7031

The keyboard tray slid right into the track and worked perfectly.

CIMG7032

The cord management cut also worked very well.

CIMG7038

In order to keep the pipe from ruining the floor, I also added some plastic pipe end caps to make the desk easier to move around.

CIMG6995

Admiring the Finished Product

To finish it off I laid down some laminate floor so that my chair would roll.   I made the extra shelves out of MDF in hopes of using them down the road (that'll be another post).

CIMG7039

Desk setup with 22" wide screen monitors and ergonomic mouse and keyboard.

CIMG7040

At the time of writing I have been using the setup for about two weeks and am very happy with how everything turned out.

Counting the Cost

I mentioned that this was cheaper than buying your own ergonomic desk.  The cheapest ergonomic desk that I could find was around $600 (not including shipping), so what did this desk cost:

  1. 1pc. – 3/4” thick 4×8 MDF - $25
  2. 10pc. - L10-7 Tee Fitting - $80
  3. 6pc. -  L61-7 Flange - $65
  4. 6pc - 77-7 Plastic Plug - $9
  5. 4pc - 8ft Fence Post - $35
  6. Various Paint Supplies - $30
  7. Articulating Keyboard Unit - $100

Total Cost: ~ $350

$350 is NOT Cheap, but it is less expensive than the ergonomic desks that I could find on the market.  Of course that also doesn't include the fact that you get the satisfaction of building it yourself and customizing the desk to fit your space.

[ Leave a Comment ]

New Times… New Desk

2742433841_a1eacdcab5_m  2743273240_8a9e0bac30_m

Recently I have made the switch for working full time for “the man” to becoming an independent developer working out of my house.  This change meant that I needed a workspace that was more conducive for the long hours spent at the workstation.   I started looking online for desks and was totally unsatisfied.  I went to a local used office furniture store…nothing.  I went to the regular office stores.. nothing.  Finally I resolved that I would build my own desk. 

In a forthcoming post I will document the project in detail.  Basically it’s a sheet of custom cut MDF, build on a foundation of Kee Lite Pipe Fittings* and fence post.  For the keyboard tray I custom cut some of the remaining MDF and attached it to an articulating keyboard support. Net result: VERY COOL DESK for about 1/2 the cost of one that would have been totally lame.

Here’s a few more pictures to tease you until I get the project posted in detail.

 

Note the “faux” wood flooring, it’s cheaper than a solid chair mat and it works great.

2742435383_6e245d09af

 

Can you say “cord management”

CIMG7038 by you.

 

22” Wide Screens, Ergonomic Keyboard, Ergonomic Mouse… I don’t mess around.

CIMG7037 by you.

 

* I am a part owner of Simplified Building Concepts so obviously I got a good deal on the fittings :)

[ Leave a Comment ]

Things I see

Standing at the Desk (Simon Cameo)Standing at the DeskStanding at the DeskStanding at the DeskStanding at the DeskStanding at the DeskStanding at the DeskIt's a whole office full of Kee KlampIsaac's TowerIsaac's TowerBolts for Threaded RodHammer in CapsPipe CapPipe Tension AssemblyFit Cork on End of Rod

Chris Pollock

Web Developer - proficient in both PHP and ASP.NET.
Rochester, New York

View my web developement site.

View Chris Pollock's LinkedIn profile

My Pictures

Standing at the Desk (Simon Cameo)Standing at the DeskStanding at the DeskStanding at the DeskStanding at the DeskStanding at the DeskStanding at the DeskIt's a whole office full of Kee KlampIsaac's TowerIsaac's TowerBolts for Threaded RodHammer in CapsPipe CapPipe Tension AssemblyFit Cork on End of Rod